5 # CVSROOT is inherited from the environment
46 # Readlink is not present on some older distributions: emulate it.
50 if [ -L "$path" ]; then
51 ll="$(LC_ALL=C ls -l "$path" 2> /dev/null)" &&
65 [ "$1" ] && echo -e "\n${0##*/}: $1"
77 (( $PUBLISH )) || return 0
82 (( $RELEASE )) || return 0
87 echo -n "Available targets:"
88 for target in $TOPDIR/lustre/lustre/kernel_patches/targets/*.target ; do
89 target_file=${target##*/}
90 echo -n " ${target_file%%.target}"
98 Usage: ${0##*/} [OPTION]... [-- <lustre configure options>]
101 Specifies the CVS Root to use when pulling files from CVS. The
102 environment variable \$CVSROOT is used if this option is not
105 --external-patches=EXTERNAL_PATCHES
106 Directory similar to lustre/lustre/kernel_patches/ that lbuild should
107 look for seres and config files in before looking in the lustre
110 --extraversion=EXTRAVERSION
111 Text to use for the rpm release and kernel extraversion.
113 --kerneldir=KERNELDIR
114 Directory containing Linux source tarballs referenced by target
118 Path to an existing lustre source tarball to use instead of
122 Do not try to download a kernel from ftp.lustre.org
125 Do not build a .src.rpm, a full kernel patch, or a patched kernel
129 Publish the packages, patches, and tarballs on the ftp server.
132 Specifies that the files generated do not include timestamps, and
133 that this is an official release.
136 A CVS branch/tag name to build from when pulling from CVS.
139 The name of the target to build. The available targets are listed
142 --target-archs=TARGET_ARCHS
143 A (space delimited) list of architectures to build. By default,
144 all of the archs supported by the TARGET will be built, in
145 addition to a .src.rpm. This option can limit those, for machines
146 that can only build certain archs or if you only want a certain
147 arch built (for testing, or a one-off kernel).
149 Also note that by using a non-"base" arch (eg, i386) only kernels
150 will be built - there will be no lustre-lite-utils package.
153 Prevents the datestamp flag (-D) from being passed to cvs for
154 checkouts. This is a workaround for a problem encountered when
155 using lbuild with tinderbox.
166 if [ "$LUSTRE" ] ; then
167 [ -r "$LUSTRE" ] || \
168 usage 1 "Could not find Lustre source tarball '$LUSTRE'."
171 usage 1 "Either specify a CVS Root with -d, or a Lustre source tarball with --lustre."
173 usage 1 "A branch/tag name must be specified with --tag when not building from a tarball."
176 [ "$KERNELDIR" ] || \
177 usage 1 "A kernel directory must be specified with --kerneldir."
179 [ -d "$KERNELDIR" ] || \
180 usage 1 "$KERNELDIR is not a directory."
182 if ! (( $RELEASE )) ; then
184 usage 1 "When building a snapshot, a tag name must be used."
187 TIMESTAMP=$(date -d "$DATE" "+%Y%m%d%H%M")
189 [ "$TARGET" ] || usage 1 "A target must be specified with --target."
190 # TARGET_FILE="$TOPDIR/lustre/kernel_patches/targets/$TARGET.target"
191 # [ -r "$TARGET_FILE" ] || \
192 # usage 1 "Target '$TARGET' was not found."
194 RPMBUILD=$(which rpmbuild 2>/dev/null | head -1)
195 if [ ! "$RPMBUILD" -o "$RPMBUILD" == "" ]; then
196 RPMBUILD=$(which rpm 2>/dev/null | head -1)
197 if [ ! "$RPMBUILD" -o "$RPMBUILD" == "" ]; then
198 usage 1 "Could not find binary for making rpms (tried rpmbuild and rpm)."
205 echo $(echo "$*" | xargs -n 1 | sort -u)
210 EXTRA_VERSION_save="$EXTRA_VERSION"
211 for patchesdir in "$EXTERNAL_PATCHES" "$TOPDIR/lustre/lustre/kernel_patches" ; do
212 TARGET_FILE="$patchesdir/targets/$TARGET.target"
213 [ -r "$TARGET_FILE" ] && break
215 [ -r "$TARGET_FILE" ] || \
216 fatal 1 "Target $TARGET was not found."
218 echo "Loading target config file $TARGET.target..."
222 [ "$KERNEL" ] || fatal 1 "Target $TARGET did not specify a kernel."
223 # [ "$SERIES" ] || fatal 1 "Target $TARGET did not specify a kernel patch series."
224 # [ "$CONFIG" ] || fatal 1 "Target $TARGET did not specify a kernel config."
225 [ "$VERSION" ] || fatal 1 "Target $TARGET did not specify a kernel version."
227 if [ "$KERNELDIR" ] ; then
228 KERNEL_FILE="$KERNELDIR/$KERNEL"
229 if [ ! -r "$KERNELDIR/$KERNEL" ] ; then
248 if (( $DOWNLOAD )) ; then
249 echo "Downloading http://ftp.lustre.org/kernels/$dldir/old/$KERNEL..."
250 if ! wget -nv "http://ftp.lustre.org/kernels/$dldir/old/$KERNEL" \
251 -O "$KERNELDIR/$KERNEL" ; then
252 fatal 1 "Could not download target $TARGET's kernel file $KERNEL from ftp.lustre.org."
255 fatal 1 "Target $TARGET's kernel file $KERNEL not found in kernel directory $KERNELDIR."
260 if [ "$SERIES" ] ; then
261 for series in $SERIES ; do
262 for patchesdir in "$EXTERNAL_PATCHES" "$TOPDIR/lustre/lustre/kernel_patches" ; do
263 [ -r "$patchesdir/series/$series" ] && continue 2
265 fatal 1 "Target $TARGET's series $SERIES could not be found.\nSearched:\n\t$EXTERNAL_PATCHES/series\n\t$TOPDIR/lustre/lustre/kernel_patches/series."
269 CONFIG_FILE="$TOPDIR/lustre/lustre/kernel_patches/kernel_configs/$CONFIG"
270 [ -r "$CONFIG_FILE" ] || \
271 fatal 1 "Target $TARGET's config file $CONFIG missing from $TOPDIR/lustre/lustre/kernel_patches/kernel_configs/."
273 if [ "$EXTRA_VERSION_save" ] ; then
274 EXTRA_VERSION="$EXTRA_VERSION_save"
275 elif ! (( $RELEASE )) ; then
276 #remove the @VERSION@ (lustre version)
277 EXTRA_VERSION=$(echo $EXTRA_VERSION | sed -e "s/\(.*_lustre\)\..*/\1/")
278 EXTRA_VERSION="${EXTRA_VERSION}-${TAG}.${TIMESTAMP}"
280 # EXTRA_VERSION=${EXTRA_VERSION//-/_}
282 ALL_ARCHS="$BASE_ARCHS $BIGMEM_ARCHS $BOOT_ARCHS $JENSEN_ARCHS $SMP_ARCHS $BIGSMP_ARCHS $PSERIES64_ARCHS $UP_ARCHS"
285 for arch in $(uniqify "$ALL_ARCHS") ; do
286 if [ -z "$TARGET_ARCHS" ] || echo "$TARGET_ARCHS" | grep "$arch" >/dev/null 2>/dev/null ; then
287 BUILD_ARCHS="$BUILD_ARCHS $arch"
290 [ "$BUILD_ARCHS" ] || usage 1 "No available target archs to build."
291 echo "Building for: $BUILD_ARCHS"
298 fatal 1 "tarflags(): File name argument missing."
307 fatal 1 "tarflags(): Unrecognized tar extension in file: $1"
314 echo "Untarring ${1##*/}..."
315 tar $(tarflags "$1") "$1"
320 DIRNAME="lustre-$TAG-$TIMESTAMP"
321 if [ "$LUSTRE" ] ; then
323 [ -d lustre ] || ln -sf lustre* lustre
325 if [ "$USE_DATESTAMP" ]; then
326 DATESTAMP="-D '$DATE'"
331 cvs -d "$CVSROOT" -qz3 co $DATESTAMP -d "$DIRNAME" lustre || \
332 fatal 1 "There was an error checking out toplevel Lustre from CVS."
333 pushd "$DIRNAME" > /dev/null
334 ./lustrecvs "$TAG" || \
335 fatal 1 "There was an error checking out Lustre/Portals/Build from CVS."
336 echo "Creating lustre tarball..."
337 sh autogen.sh || fatal 1 "There was an error running autogen.sh."
338 ./configure --disable-{modules,utils,liblustre,tests,doc} || \
339 fatal 1 "There was an error running ./configure to create makefiles."
340 make dist || fatal 1 "There was an error running 'make dist'."
342 fname=`basename $DIRNAME/lustre-*.tar.gz`
343 cp $DIRNAME/$fname . || fatal 1 "There was an error copying lustre tarball."
345 ln -sf "$DIRNAME" lustre
352 [ -d linux ] || ln -sf linux* linux
357 [ "$SERIES" ] || return 0
358 FULL_PATCH="$PWD/lustre-kernel-${TARGET}-${EXTRA_VERSION}.patch"
359 [ -f "$FULL_PATCH" ] && rm -f "$FULL_PATCH"
360 pushd linux >/dev/null
361 for series in $SERIES ; do
362 echo -n "Applying series $series:"
363 for patchesdir in "$EXTERNAL_PATCHES" "$TOPDIR/lustre/lustre/kernel_patches" ; do
364 [ -r "$patchesdir/series/$series" ] || continue
365 SERIES_FILE="$patchesdir/series/$series"
366 for patch in $(<"$SERIES_FILE") ; do
368 PATCH_FILE="$patchesdir/patches/$patch"
369 [ -r "$PATCH_FILE" ] || \
370 fatal 1 "Patch $patch does not exist in Lustre tree."
371 cat "$PATCH_FILE" >> "$FULL_PATCH" || \
372 fatal 1 "Error adding patch $patch to full patch."
373 patch -s -p1 < "$PATCH_FILE" || fatal 1 "Error applying patch $patch."
380 echo "Full patch has been saved in ${FULL_PATCH##*/}."
381 echo "Replacing .config files..."
382 [ -d linux/configs ] || mkdir linux/configs || \
383 fatal 1 "Error creating configs directory."
384 rm -f linux/configs/*
386 for patchesdir in "$EXTERNAL_PATCHES" "lustre/lustre/kernel_patches" ; do
387 [ "$patchesdir" ] && \
388 cp -v $patchesdir/kernel_configs/kernel-${VERSION}-${TARGET}*.config linux/configs/ >/dev/null && copysuccess=1
390 [ "$copysuccess" = "1" ] || \
391 fatal 1 "Error copying in kernel configs."
396 TARBALL="$(readlink linux)-$EXTRA_VERSION.tar.gz"
397 echo "Creating patched linux tarball $TARBALL..."
398 tar zcf "$TARBALL" "$(readlink linux)" \
399 --exclude "CVS" --exclude ".cvsignore" || \
400 --exclude "*.orig" --exclude "*~" --exclude "*.rej" || \
401 fatal 1 "Error creating patched Linux tarball."
406 [ -d linux ] || return 0
407 echo "Cleaning linux..."
408 [ -L linux ] && rm -rf $(readlink linux)
415 ENABLE_INIT_SCRIPTS=""
417 -e "s^@BASE_ARCHS@^$BASE_ARCHS^g" \
418 -e "s^@BIGMEM_ARCHS@^$BIGMEM_ARCHS^g" \
419 -e "s^@BIGSMP_ARCHS@^$BIGSMP_ARCHS^g" \
420 -e "s^@BOOT_ARCHS@^$BOOT_ARCHS^g" \
421 -e "s^@CONFIGURE_FLAGS@^$CONFIGURE_FLAGS^g" \
422 -e "s^@ENABLE_INIT_SCRIPTS@^$ENABLE_INIT_SCRIPTS^g" \
423 -e "s^@JENSEN_ARCHS@^$BOOT_ARCHS^g" \
424 -e "s^@KERNEL_EXTRA_VERSION@^$EXTRA_VERSION^g" \
425 -e "s^@KERNEL_RELEASE@^${EXTRA_VERSION//-/_}^g" \
426 -e "s^@KERNEL_SOURCE@^$KERNEL^g" \
427 -e "s^@KERNEL_VERSION@^$VERSION^g" \
428 -e "s^@LINUX26@^$LINUX26^g" \
429 -e "s^@LUSTRE_SOURCE@^${LUSTRE##*/}^g" \
430 -e "s^@LUSTRE_TARGET@^$TARGET^g" \
431 -e "s^@PSERIES64_ARCHS@^$PSERIES64_ARCHS^g" \
432 -e "s^@RHBUILD@^$RHBUILD^g" \
433 -e "s^@SMP_ARCHS@^$SMP_ARCHS^g" \
434 -e "s^@SUSEBUILD@^$SUSEBUILD^g" \
435 -e "s^@SUSEBUILD@^$SUSEBUILD^g" \
436 -e "s^@UP_ARCHS@^$UP_ARCHS^g" \
437 < $TOPDIR/lustre/build/lustre-kernel-2.4.spec.in \
438 > lustre-kernel-2.4.spec
439 [ -d SRPMS ] || mkdir SRPMS
440 [ -d RPMS ] || mkdir RPMS
441 [ -d BUILD ] || mkdir BUILD
442 [ -d SOURCES ] || mkdir SOURCES
443 for script in linux-{rhconfig.h,merge-config.awk,merge-modules.awk} \
444 suse-{functions.sh,post.sh,postun.sh,trigger-script.sh.in} \
445 sles8-{pre,post,postun,update_{INITRD_MODULES,rcfile_setting}}.sh ; do
446 cp $TOPDIR/lustre/build/$script SOURCES
448 cp "$LUSTRE" "$KERNEL_FILE" SOURCES
449 if [ "$EXTERNAL_PATCHES" -a -d "$EXTERNAL_PATCHES" ] ; then
450 tar zcf SOURCES/external-patches.tar.gz -C "$EXTERNAL_PATCHES" series targets patches kernel_configs
452 touch SOURCES/external-patches.tar.gz
458 [ -d lustre ] || return 0
459 echo "Cleaning lustre..."
460 [ -L lustre ] && rm -rf $(readlink lustre)
466 echo "Building rpms for: $BUILD_ARCHS..."
468 for arch in $BUILD_ARCHS ; do
469 targets="--target $arch $targets"
472 $RPMBUILD $targets -bb lustre-kernel-2.4.spec \
473 --define "_topdir $TOPDIR" || \
474 fatal 1 "Error building rpms for $arch."
476 if (( $DO_SRC )) ; then
477 $RPMBUILD -bs lustre-kernel-2.4.spec \
478 --define "_topdir $TOPDIR" || \
479 fatal 1 "Error building .src.rpm."
485 publishing || return 0
488 [ -r ~/.lbuildrc ] && . ~/.lbuildrc
490 options=$(getopt -o d:D:h -l external-patches:,extraversion:,kerneldir:,lustre:,nodownload,nosrc,publish,release,tag:,target:,target-archs:,disable-datestamp -- "$@")
492 eval set -- "$options"
564 usage 1 "Unrecognized option: $1"
574 if (( $DO_SRC )) ; then
581 # prep_build needs the .spec.in from the lustre source