make-packages-common.sh 4.29 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#!/bin/bash

set -e

DATE=`date +%F|tr - .`.`date +%T| tr -d :`
dir=`dirname $0`

MAJOR_VER=`${dir}/../beegfs-version --print_major_version`
MINOR_VER=`${dir}/../beegfs-version --print_minor_version`

packages="beegfs_helperd beegfs_meta beegfs_mgmtd beegfs_storage beegfs_utils          \
	beegfs_common_package beegfs_client_devel beeond beeond_thirdparty_gpl"
 
client_packages="beegfs_client_module"
admon_package="beegfs_admon"
opentk_package="beegfs_opentk_lib" # deletes the libopentk.so, so needs to be last

export CONCURRENCY=${MAKE_CONCURRENCY:-4}
PACKAGEDIR="/tmp/beegfs_packages-${DATE}/"

21
DO_CLEAN=true
22 23 24 25 26 27 28 29 30

# print usage information
print_usage()
{
	echo
	echo "USAGE:"
	echo "  $ `basename $0` [options]"
	echo
	echo "OPTIONS:"
Sven Breuner's avatar
Sven Breuner committed
31
        echo "  -v S   Major version string (e.g. \"6\")."
32
	echo "         Default is based on current date."
Sven Breuner's avatar
Sven Breuner committed
33
        echo "  -m S   Minor version string (e.g. \"2\")."
34 35 36 37 38 39 40 41 42
        echo "         Default is based on current date."
        echo "  -j N   Number of parallel processes for \"make\"."
        echo "  -p S   Package destination directory."
	echo "         Default is a subdir of \"/tmp\"."
	echo "  -c     Run \"make clean\" only."
	echo "  -d     Dry-run, only print export variables."
	echo "  -D     Disable beegfs-admon package build."
	echo "  -C     Build client packages only."
	echo "  -x     Build with BEEGFS_DEBUG."
43 44
        echo "  -l F   log to specific file"
        echo "  -K     keep previously built files (no clean)"
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
	echo
	echo "EXAMPLE:"
	echo "  $ `basename $0` -j 4 -p /tmp/my_beegfs_packages"
	echo
}

# print given command, execute it and terminate on error return code
run_cmd()
{
	cmd="$@"
	echo "$cmd"
	eval $cmd
	res=$?
	if [ $res -ne 0 ]; then
		echo " failed: $res"
		echo "Aborting"
		exit 1
	fi
}

# parse command line arguments

DRY_RUN=0
CLEAN_ONLY=0
CLIENT_ONLY=0
LOGFILE=

72
while getopts "hcdm:v:DCxj:p:l:K" opt; do
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
	case $opt in
	h)
		print_usage
		exit 1
		;;
	c)
		CLEAN_ONLY=1
		;;
	d)
		DRY_RUN=1
		;;
	m)	
		MINOR_VER="$OPTARG"
                ;;
	v)
		MAJOR_VER="$OPTARG"
		;;
	D)
		admon_package=""
		echo "Admon package disabled."
		;;
	C)
		CLIENT_ONLY=1
		;;
	x)
		export BEEGFS_DEBUG=1
		;;
	j)
		export CONCURRENCY="$OPTARG"
		export MAKE_CONCURRENCY="$OPTARG"
		;;
104 105 106 107 108 109 110
        l)
                if [[ "$OPTARG" == /* ]]; then
                    LOGFILE="$OPTARG"
                else
                    LOGFILE="$PWD/$OPTARG"
                fi
                ;;
111 112 113
	p)
		PACKAGEDIR="$OPTARG"
		;;
114 115 116
        K)
                DO_CLEAN=false
                ;;
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
        :)
                echo "Option -$OPTARG requires an argument." >&2
                print_usage
                exit 1
                ;;
        *)
                echo "Invalid option: -$OPTARG" >&2
                print_usage
                exit 1
                ;;
   esac
done


if [ $CLIENT_ONLY -eq 0 ]; then
	echo "Building all packages."
	packages="$packages $admon_package $opentk_package $client_packages"
else
	echo "Building client packages only."
	packages=$client_packages
fi

BEEGFS_VERSION="${MAJOR_VER}.${MINOR_VER}"

echo
run_cmd "export BEEGFS_VERSION=$BEEGFS_VERSION"
echo

opentk="beegfs_opentk_lib"
common="beegfs_common"
thirdparty="beegfs_thirdparty"

pushd `dirname $0`/../
ROOT=`pwd`

if [ $DRY_RUN -eq 1 ]; then
	exit 0
fi


# build dependency libs
make_dep_lib()
{
	lib="$1"
	parallel_override="$2"
	targets="$3"

	if [ -n "$parallel_override" ]; then
		make_concurrency=$parallel_override
	else
		make_concurrency=$CONCURRENCY
	fi

	echo "CONCURRENCY: using 'make -j $make_concurrency'"

	echo ${lib}
	pwd
174 175 176 177
	if ${DO_CLEAN}
        then
                run_cmd "make -C ${lib}/${EXTRA_DIR}/build clean >${LOGFILE:-/dev/null}"
        fi 
178 179 180 181 182
	run_cmd "make -C ${lib}/${EXTRA_DIR}/build -j $make_concurrency $targets >${LOGFILE:-/dev/null}"
}

# clean packages up here first, do not do it below, as we need
# common and opentk
183 184 185 186 187 188 189 190
if ${DO_CLEAN}
then
   for package in $packages $thirdparty $opentk $common; do
   	echo $package clean
   	make -C ${package}/${EXTRA_DIR}/build clean --silent
   done
fi

191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
if [ ${CLEAN_ONLY} -eq 1 ]; then
	exit 0
fi


# build common, opentk and thirdparty, as others depend on them
if [ $CLIENT_ONLY -eq 0 ]; then
	make_dep_lib $thirdparty "" "all cppunit sqlite openssl"
	make_dep_lib $common
	make_dep_lib $opentk 
fi


mkdir -p $PACKAGEDIR
export DEBIAN_ARCHIVE_DIR=$PACKAGEDIR