3 # author: hackbard@hackdaworld.dyndns.org
5 # this script is used to build hdw-linux packages.
16 -stage) stage=$2 ; shift 2 ;;
17 -package) package=$2 ; shift 2 ;;
18 -no_src_del) no_src_del="1" ; shift 1 ;;
19 -priority) priority=$2 ; shift 2 ;;
20 -dir) dir=$2 ; shift 2 ;;
25 echo -e " ./scripts/Build \t-stage stagelevel"
26 echo -e "\t\t\t-package package-name"
32 if [ -z "$package" ]; then
33 echo "no package specified, abort."
37 if [ -z "$stage" ]; then
38 echo "no stage level specified, abort."
42 if [ -z "$priority" ] ; then
43 echo "no priority specified, abort."
48 # load config andsubroutines
49 . ./scripts/Config -stage $stage
50 . ./scripts/subroutines
52 . ./scripts/optimization
55 if [ "$stage" != "1" -a "$hdw_use_dietlibc" = "1" ] ; then
56 export CC="diet-dyn $CC -nostdinc"
57 export CXX="diet-dyn $CXX -nostdinc"
60 # okay, this is going to be fun - happy h4ck1n6
63 # defining build environment variables to build a package.
64 if [ "$dir" = "*" ] ; then
65 dirs="`ls ./packages/*/$package/$package`"
66 if [ "`echo $dirs | awk '{ print NF }'`" -gt "1" ] ; then
67 echo "please specify a category using -dir, possibilities:"
73 dir="`echo $dirs | awk -F/ '{ print $3 }'`"
77 if [ -f ./packages/$dir/$package/$package ] ; then
78 echo "found $package config file ..."
80 # defining help variables
81 confdir="$hdw_home_dir/packages/$dir/$package"
82 archdir="$hdw_home_dir/download/$dir/$package"
84 # lets get some package info
85 pkgs=`cat $confdir/$package | grep '^#\ \[D\]' | \
87 pkg=`echo $pkgs | awk '{ print $1 }'` # to make sure there is only 1
88 ver=`cat $confdir/$package | grep '^#\ \[V\]' | \
90 patch=`cat $confdir/$package | grep '^#\ \[P\]' | \
93 # lets see whether we have the source
94 if [ ! -f ./download/$dir/$package/$pkg -a ! -z "$pkg" ]; then
95 echo "sources for $package not found, trying to get them ..."
96 ./scripts/Download -package $package
98 if [ ! -f ./download/$dir/$package/$pkg -a ! -z "$pkg" ]; then
99 echo "sources still not found, aborting ..."
103 # compress format of source?
104 if [ ! -z "`echo \`detect_file_ending $pkg\` | grep 'bz2'`" ] ; then
106 elif [ ! -z "`echo \`detect_file_ending $pkg\` | grep 'tbz2'`"] ; then
113 # defining elementary build functions and variables
119 make_conf=""; install_conf=""
122 if [ "$stage" -lt "2" ] ; then
123 # use the symlink as prefix
125 docdir="$prefix/share/doc/$package"
126 install_conf="PREFIX=$prefix"
128 if [ "$stage" = "2" -o "$stage" = "3" ] ; then
129 prefix="$root/usr"; docdir="$root/usr/doc/$package"
130 localstatedir="$root/var"
131 sysconfdir="$root/etc"
132 elif [ "$stage" = "4" ] ; then
133 prefix="$root/opt/$package"
134 docdir="$root/opt/$package/doc"
135 localstatedir="$root/var/opt/$package"
136 sysconfdir="$root/etc/opt/$package"
140 if [ -z "$prefix" ] ; then
141 echo "problem: no prefix found! aborting .."
145 # defining confopt now
146 confopt="--prefix=$prefix --bindir=$prefix/bin"
147 confopt="$confopt --sbindir=$prefix/sbin"
148 confopt="$confopt --libdir=$prefix/lib"
149 confopt="$confopt --datadir=$prefix/share"
150 confopt="$confopt --infodir=$prefix/info"
151 confopt="$confopt --mandir=$prefix/man"
152 if [ "$stage" -gt "1" ] ; then
153 confopt="$confopt --localstatedir=$localstatedir"
154 confopt="$confopt --sysconfdir=$sysconfdir"
156 # architecture specific stuff
157 confopt="$confopt --build=$hdw_arch_build"
158 confopt="$confopt --host=$hdw_arch_host"
160 [ "$package" = "gcc" -o "$package" = "binutils" ] && \
161 confopt="$confopt --target=$hdw_arch_target"
172 echo "hdw-linux: \$confopt = $confopt"
173 echo "hdw-linux: \$make_conf = $make_conf"
174 echo "hdw-linux: \$install_conf = $install_conf"
175 echo "lets do it ..."
176 if [ -f ./configure ] ; then
177 echo "run ./configure $confopt"
180 echo ; echo "run make $make_conf"
182 echo ; echo "run make $install_conf install"
183 make $install_conf install
186 # flist find variables/command
187 flist_path="bin/ boot/ etc/ lib/ opt/ sbin/ usr/ var/"
188 [ "$stage" -lt "2" ] && flist_path="${flist_path} ${tc_name}/"
189 flist_cmd="find \$flist_path \( -cnewer $root/.time_$package -o \
190 -newer $root/.time_$package \) \( -not -type d -o \
191 -type d -empty \) -print"
192 flist_pruned="var/adm|var/log|var/run|var/tmp|var/spool"
193 flist_pruned="${flist_pruned}|var/cache|var/lock"
195 # reading config functions and variables
198 # lets begin building, in case we dont skip it!
199 if [ -z "$skip" ] ; then
201 # setting umask, we dont reset it!
204 # run ldconfig to, maybe we installed some libs before!
205 if [ "$stage" != "1" ] ; then
206 echo "running ldconfig ..."
210 # for creating the flist
213 touch .time_${package} && sleep 1
217 # use trap to catch errors in block
218 # we may kick out abort_when_package_build_failed lines
219 # can we use $_ instead off TRAP_ERR ?
221 trap 'abort_when_package_build_failed 1 $_' ERR
223 # automated build procedure
224 if [ "$custmain" != "0" ] ; then
225 #build according packages custmain function
226 if [ "$no_src_del" != "1" ] ; then
227 rm -rf $root/src.$package
229 mkdir -p $root/src.$package
230 cd $root/src.$package
231 if [ "$hdw_debug_buildenv" = "1" ] ; then
233 echo "Debug: (buildenvironment)"
239 rm -rf $root/src.$package
241 #now we go for automated building
243 if [ "$no_src_del" != "1" ] ; then
244 if [ "$autoextract" != "0" ] ; then
245 rm -rf $root/src.$package
246 mkdir -p $root/src.$package
247 tar --use-compress-program=$compress \
248 -xvf ./download/$dir/$package/$pkg \
249 -C $root/src.$package
252 # change to directory and build
253 cd $root/src.$package/$srcdir &&
254 # patches from [P] tag
255 if [ ! -z "$patch" ] ; then
256 for every_single_patch in $patch; do
257 echo "aplying patch $every_single_patch ..."
258 patch -Nfp1 < $hdw_home_dir/download/$dir/$package/$every_single_patch
262 # patches from confdir
264 for xtra_patch in `ls $confdir/*.patch 2> /dev/null`; do
265 echo "applying patch $xtra_patch ..."
266 patch -Nfp1 < $xtra_patch
268 # architecture dependent patches
269 for xtra_patch in `ls $confdir/*.patch.${hdw_arch} 2> /dev/null`; do
270 echo "applying patch $xtra_patch ..."
271 patch -Nfp1 < $xtra_patch
273 # target specific patches
274 for xtra_patch in `ls $confdir/*.patch.${hdw_target} 2> /dev/null`; do
275 echo "applying patch $xtra_patch ..."
276 patch -Nfp1 < $xtra_patch
279 if [ "$hdw_use_dietlibc" = "1" ] ; then
280 for xtra_patch in `ls $confdir/*.patch.dietlibc 2> /dev/null`; do
281 echo "applying patch $xtra_patch ..."
282 patch -Nfp1 < $xtra_patch
285 # stage specific patches
286 for xtra_patch in `ls $confdir/*.patch.${stage} 2> /dev/null`; do
287 echo "applying patch $xtra_patch ..."
288 patch -Nfp1 < $xtra_patch
290 # patch section end ;)
293 if [ "$hdw_debug_buildenv" = "1" ] ; then
295 echo "Debug: (buildenvironment)"
297 echo "gcc to use: `which gcc`, `which cc`"
303 rm -rf $root/src.$package
306 # dirty! not create *.init for 00-init-conf, manually done.
307 if [ "$package" != "00-init-conf" ] ; then
308 for my_init in `ls $confdir/*.init 2> /dev/null`; do
313 if [ "$stage" != "1" ] ; then
314 for my_setup in `ls $confdir/*.setup 2> /dev/null`; do
315 create_setup_scripts $my_setup
322 # let's see what we installed
325 eval $flist_cmd | grep -vE $flist_pruned > flist.$package
327 # let's create the flist
329 [ "$stage" = "0" ] && append=".stage0"
330 [ "$stage" = "1" ] && append=".stage1"
331 append="${append}-${priority}"
337 BEGIN { package=ENVIRON["package"] ; append=ENVIRON["append"] ; \
338 stage=ENVIRON["stage"] ; priority=ENVIRON["priority"] } \
339 { print package ": " $0 } \
340 END { print package ": " "var/adm/logs/" stage "-" priority "-" \
342 print package ": " "var/adm/flists/" package append }' \
343 $root/flist.$package > $root/var/adm/flists/${package}${append}
344 # manually add dependency files, calculated after flist
345 if [ "$stage" -ge "3" ] ; then
346 echo "${package}: var/adm/deps/build/$package" >> \
347 $root/var/adm/flists/${package}${append}
348 echo "${package}: var/adm/deps/run/$package" >> \
349 $root/var/adm/flists/${package}${append}
352 # build/runtime dependencies (just libs >= stage 3,
353 # default is 'hardcoded')
354 # still in development !!
355 if [ "$stage" -ge "3" ] ; then
357 rm -f $root/var/adm/deps/build/$package
358 echo -n "calculating build dependencies ... "
360 for lib in `grep '\ -l[A-Za-z]' \
361 $root/var/adm/logs/${stage}-${priority}-$package.out`; do
362 if [ -n "`echo $lib | grep '^-l'`" ] ; then
364 for dep in `grep "/$lib\." \
365 -r $root/var/adm/flists | \
366 awk -F: '{ print $2 }'`; do
368 for cmp in $alldeps; do
369 [ "$cmp" = "$dep" ] && add=0
371 [ "$add" = "1" ] && \
372 alldeps="$dep $alldeps"
376 for dep in $alldeps; do
377 echo "$dep" >> $root/var/adm/deps/build/$package
379 touch $root/var/adm/deps/build/$package
382 rm -f $root/var/adm/deps/run/$package
383 echo -n "calculating runtime dependencies ... "
385 for binary in `grep 'bin\/' \
386 $root/var/adm/flists/${package}${append} | \
387 awk '{ print $2 }'`; do
388 for rdep in `ldd $root/$binary 2>&1 | \
389 awk '{ print $3 }' | \
390 sed 's$/$$' | grep -v 'dynamic' | \
392 for rpkg in `grep $rdep -r \
393 $root/var/adm/flists | \
395 awk -F: '{ print $2 }'`; do
397 for cmp in $alldeps; do
398 [ "$cmp" = "$rpkg" ] && add=0
400 [ "$add" = "1" ] && \
401 alldeps="$rpkg $alldeps"
405 for library in `grep 'lib\/.*.so.*' \
406 $root/var/adm/flists/${package}${append} | \
407 awk '{ print $2 }'`; do
408 for rdep in `ldd $root/$library 2>&1 | \
409 awk '{ print $3 }' | \
410 sed 's$/$$' | grep -v 'dynamic' | \
412 for rpkg in `grep $rdep -r \
413 $root/var/adm/flists | \
415 awk -F: '{ print $2 }'`; do
417 for cmp in $alldeps; do
418 [ "$cmp" = "$rpkg" ] && add=0
420 [ "$add" = "1" ] && \
421 alldeps="$rpkg $alldeps"
425 for dep in $alldeps; do
426 echo "$dep" >> $root/var/adm/deps/run/$package
428 touch $root/var/adm/deps/run/$package
438 [ -z "$s_reason" ] && s_reason=unknown
440 echo "FYI: $package build skipped, reason: $s_reason"
441 fi # (if [ -z "$skip" ])
444 echo "cannot find $package config file ..."