* updated umbrello (21.12.1 -> 21.12.2), untested
[t2-trunk.git] / scripts / functions.in
blobc21b32d698fd3e111f97b7f9f2c4a99eb9b686b3
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # T2 SDE: scripts/functions.in
3 # Copyright (C) 2004 - 2022 The T2 SDE Project
4 # Copyright (C) 1998 - 2003 ROCK Linux Project
5
6 # This Copyright note is generated by scripts/Create-CopyPatch,
7 # more information can be found in the files COPYING and README.
8
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License version 2.
11 # --- T2-COPYRIGHT-NOTE-END ---
13 . scripts/core-functions.in
15 compressor="zstd --ultra -20 -T0"
17 # This function returns a "uniqe id" as output
19 get_unique() {
20         local hostsum=`hostname 2>/dev/null | sed 's/[()]/_/g; s/\..*//'`
21         if [ -z "$hostsum" -a -x /sbin/ip ]; then
22                 hostsum=`/sbin/ip link show eth0 |
23                 sed -e '/link\//!d' \
24                     -e 's,.*link[^ ]* \([^ ]*\) .*,\1,' \
25                     -e 's/://g'`
26         fi
27         if [ -z "$hostsum" -a -f /sbin/ifconfig ]; then
28                 hostsum=`/sbin/ifconfig eth0 |
29                 sed -e '/HWaddr/!d' -e 's/.* HWaddr \([^ ]*\)/\1/'`
30         fi
31         if [ -z "$hostsum" -a -x /usr/bin/hostid ]; then
32                 hostsum=`/usr/bin/hostid`
33         fi
34         date "+%Y%m%d.%H%M%S.$$.$hostsum" # "+%s.$$.$hostsum"
37 # this functions expands an string replacing % with all possible values
38 # listed after
39 case "$BASH_VERSION" in  # damn workaround for different syntax in both versions
40     2*)
41 get_expanded() {
42         local string="$1"; shift
43         while [ $# -gt 0 ]; do
44                 echo "${string//\\%/$1}"
45                 shift
46         done
50 get_expanded() {
51         local string="$1"; shift
52         while [ $# -gt 0 ]; do
53                 echo "${string//\%/$1}"
54                 shift
55         done
58 esac
60 # atstage <stagename> ...
61 # returns true if the build is on a stage related to the given name
63 atstage() {
64         local x=
65         for x; do
66                 case "$x" in
67                         toolchain)      
68                                 [ $stagelevel -gt 0 ] || return 0       ;;
69                         cross*)
70                                 [ $stagelevel -lt 1 -o $stagelevel -gt 2 ] || return 0  ;;
71                         rebuild)
72                                 [ $stagelevel -ne 9 ] || return 0       ;;
73                         native)
74                                 [ $stagelevel -lt 3 ] || return 0       ;;
75                         *)
76                                 echo "atstage: '$x' stagename is not supported." >&2
77                                 break   ;;
78                 esac
79         done
80         return 1
83 # hasflag FLAG
85 hasflag() {
86         local desc_F=" $desc_F " # surounding spaces for match below
87         [ "$desc_F" != "${desc_F/ $1 }" ]
90 # bz2filename [<filename>]
91 # outputs filename converted to .bz2. stdin and $1 inputs are accepted
93 bz2filename() {
94         local pattern='-e s,\.\(t\?\)\(gz\|Z\|xz\|bz2\|bz\|lz\)$,.\1zst,'
95         pattern="-e s,\.gpg$,, $pattern"
96         pattern="-e s,\.tar$,\.tar.zst, $pattern"
98         if [ -n "$1" ]; then
99                 echo "$1" | sed $pattern
100         else
101                 sed $pattern
102         fi
105 # Hook variables
107 unset hook_functions hook_fcounter
108 declare -a hook_functions='()'
109 hook_fcounter=0
111 # This function adds a code fragment to a named hook with the named priority
113 # hook_add hook_name priority code
115 hook_add() {
116         hook_functions[hook_fcounter]="$3" # declare -a hookidx_$1
117         eval "hookidx_$1[\${#hookidx_$1[@]}]=\"$2 $hook_fcounter\""
118         eval "(( hookdirty_$1++ ))" || true; (( hook_fcounter++ )) || true
121 # This function executes all code fragments from the named hook
123 # hook_eval hook_name
125 hook_eval() {
126         while read pri fnr; do
127                 [ "$pri" ] && eval "${hook_functions[fnr]}"
128         done < <( IFS=$'\n'; eval "echo \"\${hookidx_$1[*]}\"" | sort )
129         eval "unset hookdirty_$1"
132 # This function prints all hooks and their current contents
134 # hook_dump
136 hook_dump() {
137         for hook in ${!hookidx_*}; do
138                 hook=${hook#hookidx_}
139                 echo; echo "Contents of hook $hook:"
140                 
141                 while read pri fnr; do
142                         echo; echo "    $pri ($fnr)"
143                         echo "${hook_functions[fnr]}" | sed 's,^,       ,'
144                 done < <( IFS=$'\n'
145                           eval "echo \"\${hookidx_$hook[*]}\"" | sort )
146                 if eval "[ -n \"\$hookdirty_\$hook\" ]"; then
147                         echo; echo -n "    Hook is marked as dirty: "
148                         eval "echo \"\${hookdirty_$hook}\""
149                 fi
150         done
151         echo
154 # This function can be used to duplicate a shell-function. E.g. when
155 # overwriting a shell-function but the old one should stay available under
156 # a new name:
158 #       copy_function set_confopt set_confopt_foobar_old
160 #       set_confopt() {
161 #               ....
162 #               set_confopt_foobar_old "$@"
163 #               ....
164 #       }
166 copy_function() {
167         eval "$( declare -f $1 | sed "1 s,$1,$2," )"
170 # | column_clean |
172 # convert tabs to spaces, transform multiple consecutive spaces to one,
173 # remove leading and trailing spaces
174 column_clean() {
175         sed 's,\t, ,g; s,  *, ,g; s,^[ ]*,,; s,[ ]*$,,'
178 # This function sets the 'confopt' and some other variables.
179 # Re-run it in the package .conf file if you modify $prefix
181 set_confopt() {
182         local x= z=
183         prefix=${prefix#/}
185         if atstage toolchain; then
186                 z="$root"
187         fi
189         confopt="--prefix=$z/$prefix"
190         mesonopt="objdir/ --prefix=$z/$prefix"
192         for x in bindir sbindir libdir datadir includedir \
193             docdir infodir mandir sysconfdir localstatedir
194         do
195                 # bindir=/usr/bin
196                 eval "$x=`pkggetdir $x`"
197                 # --bindir=$root\$bindir
198                 if [ "$x" != docdir ]; then
199                         confopt="$confopt --$x=$z\$$x"
200                         mesonopt="$mesonopt --$x=$z\$$x"
201                 fi
202         done
204         export LIBSUFF=${libdir##*/lib}
206         if [ "$SDECFG_CONFIGURE_OPTS" ]; then
207                 var_append confopt " " "$SDECFG_CONFIGURE_OPTS"
208         fi
210         if [ "$SDECFG_DEBUG" = 0 ]; then
211                 var_append confopt " " "--disable-debug"
212         fi
214         if [ "$SDECFG_DISABLE_NLS" = 1 ]; then
215                 var_remove confopt ' ' '--enable-nls'
216                 var_append confopt ' ' '--disable-nls'
217         fi
219         confopt="$confopt \$extraconfopt"
221         atstage cross && var_append confopt ' ' '--with-sysroot=$root'
222         if atstage toolchain; then
223                 confopt="$confopt --target=\$arch_target --build=\$arch_build --host=\$arch_build"
224         else
225                 confopt="$confopt --build=\$arch_build --host=\$arch_target"
226         fi
230 # eval_config_command $( eval echo $confopt )
232 function eval_config_command() {
233         local config_command
235         for x in /usr/share/automake/*
236         do
237                 [ -x "$x" -a -f "$x" ] || continue
238                 x="$( basename "$x" )"
239                 if [ -L $x -a ! -e $x ]; then
240                         echo "Fixing dead symlink $x."
241                         ln -sf /usr/share/automake/$x .
242                 fi
243         done
245         if atstage cross; then
246                 create_config_cache >> config.cache
247                 grep -q '.--cache-file=' $configscript &&
248                         set -- "$@" "--cache-file=./config.cache"
249                 export cache_file=./config.cache
250         fi
252         config_command="$configprefix $configscript"
253         sub_scripts="$( find $( dirname $configscript ) -name configure )"
255         if [ "$cleanconfopt" == "0" ]; then
256                 config_command="$config_command $@"
257         else
258         # remove unsupported config script options
259         for x; do
260                 if grep -q "[[ ]${x%%=*}[]= ):]" $configscript $sub_scripts; then
261                         config_command="$config_command $x"
262                 elif [[ $x = --*able-* ]] && egrep -q "\-\-(en|dis)able-\*" $configscript ||
263                      [[ $x = --with* ]] && egrep -q "\-\-with(|out)-\*" $configscript; then
264                         echo "Autodetection for option impossible: " \
265                              "$x passed thru."
266                         config_command="$config_command $x"
267                 else
268                         echo "Removing unsupported '$x' from" \
269                              "configure option string."
270                 fi
271         done
272         fi
274         echo Running "$config_command"
275         eval "$config_command"
277         # the missing script is generally not very helpful, ...
278         if [ -f build/missing ]; then echo '#!/bin/true' > build/missing; fi
279         if [ -f missing ]; then echo '#!/bin/true' > missing; fi
282 # run 'make check' if Makefile supports it.
284 function run_check() {
285         if grep -q -e "^check:" ./Makefile; then
286                 echo "Running make check"
287                 $MAKE check
288         fi
289         if grep -q -e "^test:" ./Makefile; then
290                 echo "Running make test"
291                 $MAKE test
292         fi
295 # move the static libs from lib to usr/lib and correct the libdir used
296 # inside the .la file
298 postflist_static_lib() {
299         echo "Processing static lib corrections ..."
300         egrep '^(lib|lib64)/.*\.(a|la)$' $builddir/flist.txt |
301         while read fn; do
302                 [ -e $root/$fn -o -L $root/$fn ] || continue
303                 if [[ $fn = *.a ]]; then
304                         mv -fv $root/$fn $root/usr/$fn
305                 else
306                         sed "s,\([ =']\)/lib\(.*\),\1/usr/lib\2,g" \
307                                 $root/$fn > $root/usr/$fn
308                         so=${fn%.la}.so
309                         ln -svf ../../$so $root/usr/$so
310                         add_flist $root/usr/$so
311                         rm $root/$fn
312                 fi
313                 add_flist $root/usr/$fn
314         done
316         # this check might be removed in the future when we decide this is not
317         # an issue anymore ...
318         echo "Verifing the .la files ..."
319         defect_la="`egrep '(lib|lib64)/.*\.la$' $builddir/flist.txt |
320                     xargs egrep 'dependency_libs=.*-pthread.*' |
321                     cut -d : -f1 | sort -u | tr '\n' ' '`"
322         if [ "$defect_la" ]; then
323                 abort "-pthread in: $defect_la!"
324         fi
326         defect_la="`egrep '(lib|lib64)/.*\.la$' $builddir/flist.txt |
327                     xargs egrep "dependency_libs=.*(TOOLCHAIN|BACKUP|$SDECFG_ID).*" |
328                     cut -d : -f1 | sort -u | tr '\n' ' '`"
329         if [ "$defect_la" ]; then
330                 local la
331                 echo_warning "Detected problems in following libtool files:"
332                 for la in $defect_la; do
333                         echo_warning "  $la"
334                 done
335                 echo_warning "In absence of a proper fix (or replacement) for libtool and friends,"
336                 echo_warning "for now the .la files are automatically corrected."
338                 # Cleanup dependency_libs, remove build system path
339                 local dependency_libs
340                 local dlibsnew=""
341                 local dlibtmp deplib
342                 local libsub=${libdir##*/}
343                 for la in $defect_la; do
344                         eval `grep ^dependency_libs= $root/$la`
346                         for deplib in $dependency_libs; do
347                                 if [ $libsub != lib ]; then
348                                         case "$deplib" in
349                                         */lib|*/lib/*)
350                                                 deplib="`echo $deplib | sed "s,/lib$,/$libsub,g; s,/lib/,/$libsub/,g"`"
351                                                 ;;
352                                         esac
353                                 fi
355                                 case "$deplib" in
356                                 *TOOLCHAIN*|*BACKUP*|*$SDECFG_ID*) ;;
357                                 *)
358                                         dlibtmp=$dlibsnew; var_remove dlibtmp ' ' "$deplib"
359                                         [ "$dlibtmp" = "$dlibsnew" ] && var_append dlibsnew ' ' "$deplib"
360                                         ;;
361                                 
362                                 esac
363                         done
365                         sed -i "s,^dependency_libs=.*,dependency_libs='$dlibsnew'," $root/$la
366                         dlibsnew=
367                 done
368         fi
371 # Parse the *.desc file. Use the description from PKG-DESC-FORMAT and
372 # save the tag data in $desc_*.
374 parse_desc() {
375     unset ${!desc_*}
377     tags="`sed -n '/^\[/ { s/][^]]*$//; s/. ./|/g; s/^\[//; p }' \
378           $base/misc/share/PKG-DESC-FORMAT`"
380     descs=$base/package/*/$1/$1.desc
381     [ -e $base/architecture/$arch/package/$1/$1.desc ] &&
382          var_append descs ' ' $base/architecture/$arch/package/$1/$1.desc
383     [ -e $base/target/$target/package/$pkg/$pkg.desc ] &&
384          var_append descs ' ' $base/target/$target/package/$1/$1.desc
386     for desc in $descs; do
387         #echo_status "Reading $desc ..."
388         for tag in $tags; do
389                 tagdata="`egrep "^\[($tag)\]" $desc |
390                           cut -f2- -d']' | sed 's,^ ,,'`"
391                 tag="`echo $tag | cut -f1 -d'|' | tr - _`"
392                 # only overwrite defined tags
393                 [ "$tagdata" ] && eval "desc_$tag=\"\$tagdata\""
394         done
395     done
397     ver="`echo "$desc_V" | tail -n 1 | cut -f1 -d' '`"
398     extraver="`echo "$desc_V" | tail -n 1 | cut -s -f2- -d' '`"
399     [ -z "$extraver" ] && extraver="${sdever//DEV-*/DEV}"
402 # This function is used for forcing a file to be in the flist
404 add_flist() {
405         for addfile; do
406                 echo "$addfile" | fl_wrparse -D -r "$xroot/" \
407                         >> $builddir/flist.txt
408         done
411 # This function is used for forcing a package to be in the dependency list
413 add_dependency() {
414         for addpackage; do
415                 echo "$addpackage: add_dependency()" \
416                                         >> $builddir/dependencies.debug
417         done
420 # This function is used to subsitute some important variables
421 # using a D_ prefix thru m4 ...
422 sde_substitute() {
423         sed -e s,D_prefix,$prefix,g   -e s,D_sysconfdir,$sysconfdir,g \
424             -e s,D_docdir,$docdir,g   -e s,D_localstatedir,$localstatedir,g \
425             -e s,D_datadir,$datadir,g -e s,D_infodir,$infodir,g \
426             -e s,D_bindir,$bindir,g   -e s,D_sbindir,$sbindir,g \
427             -e s,D_libdir,$libdir,g   -e s,D_mandir,$mandir,g \
428             -e s,D_includedir,$includedir,g -e s,D_ver,$ver,g   $1
431 # This outputs a predefined config.cache file as it needed by some
432 # packages to cross-build correctly in stages 0 and 1.
434 create_config_cache() {
435         cat $base/scripts/config.cache
437         if [ $createarchcache -eq 1 ]; then
438                 cat  <<-EOT
439                 # Architecture specific stuff\n"
440                 arch_sizeof_char=1
441                 ac_cv_sizeof_char=1
442                 ac_cv_sizeof_short=$arch_sizeof_short
443                 ac_cv_sizeof_int=$arch_sizeof_int
444                 ac_cv_sizeof_long=$arch_sizeof_long
445                 ac_cv_sizeof_long_long=$arch_sizeof_long_long
446                 ac_cv_sizeof_char_p=$arch_sizeof_char_p
447                 ac_cv_sizeof_void_p=$arch_sizeof_char_p
448                 ac_cv_c_bigendian=$arch_bigendian
450         fi
453 create_meson_cross() {
454         cat <<-EOT
455 [binaries]
456 c = '$CC'
457 cpp = '$CXX'
458 ar = '$AR'
459 strip = '$STRIP'
460 pkgconfig = 'pkg-config'
461 llvm-config = 'llvm-config'
462 cmake = 'cmake'
464 [properties]
465 sizeof_int = $arch_sizeof_int
466 sizeof_wchar_t = $arch_sizeof_int
467 sizeof_void* = $arch_sizeof_char_p
468 alignment_char = 1
469 alignment_void* = $arch_sizeof_int
470 alignment_double = 4
471 has_function_printf = true
472 needs_exe_wrapper = true
474 [host_machine]
475 system = '$SDECFG_KERNEL'
476 cpu_family = '$(uname -m)'
477 cpu = '$arch' # or uname -m?
479 [ $arch_bigendian == "yes" ] && echo "endian = 'big'" || echo "endian = 'little'"
482 # Generate a CMake toolchain file for cross builds
484 create_cmake_toolchain_file() {
485         cat <<-EOT
486         SET(CMAKE_SYSTEM_NAME Linux)
487         SET(CMAKE_SYSTEM_VERSION 1)
488         SET(CMAKE_C_COMPILER $CC)
489         SET(CMAKE_CXX_COMPILER $CXX)
490         SET(CMAKE_FIND_ROOT_PATH $root)
491         SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
492         SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
493         SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
497 # Abort build before actual build starts
498 # (is overwritten in Build-Pkg)
500 abort() {
501         echo -e "The package build aborted with the following config" \
502              "error:\n$*" > $root/var/adm/logs/$stagelevel-$xpkg.err
503         echo_errorquote "$(< $root/var/adm/logs/$stagelevel-$xpkg.err)"
504         echo_pkg_abort $stagelevel $repository $xpkg
505         exit 1
508 # Dump Environment
510 dump_env() {
512         # Dump $base - only set if there is not already an older value.
513         #
514         echo "base=\"\${base:-$base}\""
516         # Dump all variables including their flags, but skip read-only
517         # variables and $base.
518         #
519         # Substitute base directory with ${base}.
520         #
521         for name in ${!a*} ${!b*} ${!c*} ${!d*} ${!e*} ${!f*} ${!g*} ${!h*} \
522                     ${!i*} ${!j*} ${!k*} ${!l*} ${!m*} ${!n*} ${!o*} ${!p*} \
523                     ${!q*} ${!r*} ${!s*} ${!t*} ${!u*} ${!v*} ${!w*} ${!x*} \
524                     ${!y*} ${!z*}                                           \
525                     ${!A*} ${!B*} ${!C*} ${!D*} ${!E*} ${!F*} ${!G*} ${!H*} \
526                     ${!I*} ${!J*} ${!K*} ${!L*} ${!M*} ${!N*} ${!O*} ${!P*} \
527                     ${!Q*} ${!R*} ${!S*} ${!T*} ${!U*} ${!V*} ${!W*} ${!X*} \
528                     ${!Y*} ${!Z*} ${!_*}
529         do
530                 [ $name = base -o $name = PWD ] && continue
531                 if declare -p $name | head -n 1 | grep -qv '^declare -[a-z]*r'
532                 then
533                         declare -p $name | sed "s,\\(^\\|[\"=:]\\)$base\\([\"=:/]\\|\$\\),\\1\${base}\\2,g"
534                 fi
535         done
537         # Dump functions
538         #
539         declare -f | sed 's/^declare -f //; s/<<(/< <(/;'
541         # Dump aliases
542         #
543         alias
546 # Check if a package is already installed
548 # It does check the build-list if not in the rebuild stage - and
549 # the really installed package data for rebuilds (and so manual builds).
551 pkginstalled() {
552         if ! atstage rebuild; then
553                 local pattern="$1"; pattern="${pattern//+/\\+}"
554                 egrep -q "^X.* ($pattern) " $base/config/$config/packages
555         else
556                 [ -f $root/var/adm/packages/$1 ]
557         fi
560 # pkgprefix [-t] [ <type> ] <package>
561 # Returns the prefix or the location of a 'type' of an already built package,
562 # or aborts the build if not yet installed.
563 # When run in the test mode [-t] it returns an error code accordingly.
565 pkgprefix() {
566         local type= pkg=
567         local dotest= abortmsg=
568         local prefix= value=
570         # -t : only see if it's possible to get the values
571         if [ "$1" = "-t" ]; then
572                 dotest=1; shift
573         fi
574         
575         if [ $# -eq 2 ]; then
576                 type="$1"; shift
577         fi
578         pkg="$1"
580         # test usual error causes
581         if [ -z "$pkg" ]; then
582                 abort "pkgprefix: you must specify a package"
583         elif [ ! -f "$root/var/adm/packages/$pkg" ]; then
584                 abortmsg="package $pkg is not present"
585         elif grep -q "^Prefix:" "$root/var/adm/packages/$pkg"; then
586                 prefix=$( grep "^Prefix: " "$root/var/adm/packages/$pkg" | cut -d' ' -f2- )
587         else
588                 abort "pkgprefix: $pkg record is to old (no Prefix: entry), please rebuild it."
589         fi
591         if [ "$dotest" ]; then
592                 # test mode: abort or continue
593                 if [ "$abortmsg" ]; then
594                         echo "pkgprefix: $abortmsg" 1>&2
595                         return 1
596                 else
597                         return 0
598                 fi
599         elif [ "$abortmsg" ]; then
600                 echo "pkgprefix: $abortmsg" 1>&2
601         elif [ -z "$type" -o "$type" = "prefix" ]; then
602                 echo "$prefix"
603                 return 0
604         elif [ "$type" = "ver" ]; then
605                 value=$( grep "^Package Name and Version:" "$root/var/adm/packages/$pkg" | cut -d' ' -f6 )
606         else
607                 value=$( grep "^Location $type: " "$root/var/adm/packages/$pkg" | cut -d' ' -f3- )
608                 if [ -z "$value" ]; then
609                         # try default location for that $prefix
610                         value=$( xpkg="$pkg"; pkggetdir "$type" )
611                 fi
612         fi
613         echo "${value:-PKGPREFIX_ERROR}"
616 # pkggetdir <type>     (needs $prefix and $xpkg)
617 # returns the location for the file of a 'type' considering it's prefix
619 pkggetdir() {
620         local xprefix=${prefix:+/$prefix}
621         case "$1" in
622                 bindir)  echo "$xprefix/bin"    ;;
623                 sbindir) echo "$xprefix/sbin"   ;;
624                 libdir)
625                   if atstage toolchain; then
626                         echo "$xprefix/lib"
627                   elif [ "$SDECFG_MULTILIB" = 1 ]; then
628                     case $arch_machine in
629                         powerpc64|sparc64|x86_64|mips64|riscv*)
630                                 if [ "$SDECFG_X8664_X32" = 1 ]; then
631                                         echo "$xprefix/libx32"
632                                 elif [ "$SDECFG_MIPS64_N32" = 1 ]; then
633                                         echo "$xprefix/lib32"
634                                 else
635                                         echo "$xprefix/lib64"
636                                 fi
637                                 ;;
638                         *)
639                                 echo "$xprefix/lib"     ;;
640                     esac
641                   else
642                         echo "$xprefix/lib"
643                   fi
644                   ;;
645                 datadir) echo "${xprefix:-/usr}/share"  ;;
646                 infodir) echo "${xprefix:-/usr}/info"   ;;
647                 mandir) echo "${xprefix:-/usr}/man"     ;;
648                 docdir) echo "${xprefix:-/usr}/doc/$xpkg"       ;;
649                 includedir) echo "${xprefix:-/usr}/include"     ;;
650                 sysconfdir) echo "/etc${xprefix##/usr*}"        ;;
651                 localstatedir) echo "/var${xprefix##/usr*}"     ;;
652         esac
656 # This function generates the T2 package checksum of $confdir.
657 # The checksum includes the filenames and content (except of the .cache),
658 # including subdirs but without whitespaces and comments and some tag lines
659 # that are not vital for rebuilds during update checks.
661 # pkgchksum package-name | full-patch
663 pkgchksum() {
664   (
665         # expand to full path if only a package name was specified
666         [[ $1 == */* ]] || set $base/package/*/$1/
667         cd $1 || return 1
668         # find all files (without hidden (e.g. .svn) files)
669         find . ! -path '*/.*' ! -name '*.cache' -print -exec cat \{\} \; \
670         2>/dev/null |
671         # strip some unimportant stuff (e.g. comments, whitespaces, ...)
672         sed \
673         -e '/^[ ]*#.*/d' \
674         -e '/^\[COPY\]/d' \
675         -e '/^\[CV-*\]/d' \
676         -e '/^\[[T,I,U,A,M,L,S,C]\]/d' \
677         -e 's/[\t ]*//g' \
678         -e '/^ *$/d' |
679         md5sum | cut -d ' ' -f 1
680   )
683 # Create Package Database for gasgui install tool
685 create_package_db() {
686         rm -f $3.tmp
687         for file in $( echo $1/descs/* ); do
688                 [ -f "$file" ] || continue
689                 pkg="${file##*/}"
690                 # only include the package if a binary file is available
692                 if [ "$SDECFG_PKGFILE_VER" = 1 ]; then
693                         v=-$(grep '^Package Name and Version' \
694                                 $1/packages/$pkg | cut -f6 -d' ')
695                 else
696                         v=""
697                 fi
698                 bfile=${pkg}${v}.$SDECFG_PKGFILE_TYPE
700                 if [ -e $2/$bfile ]; then
701                         [ "$pkg" = TRANS.TBL ] && continue
703                         ( echo -e "$pkg"
704                           echo -e "\027"
706                           cat $1/descs/$pkg | grep -v '\[COPY\]'
707                           echo -e "\027"
709                           cat $1/dependencies/$pkg
710                           echo -e "\027"
712                           cat $1/md5sums/$pkg
713                           echo -e "\027"
715                           echo -e "\004"
716                         ) >> $3.tmp
717                 else
718                         echo_error "Binary file for $bfile not present." \
719                                    "Skipped in package database."
720                 fi
721         done
722         gzip -c $3.tmp > $3; rm -f $3.tmp
725 # Add files to the 'badfiles' list
727 register_badfiles() {
728         local x desc="$1"
729         shift
731         for x in "$@"; do
732                 var_append badfiles $'\n' " $x\$"
733                 badfiles_desc[$badfiles_nr]=" $x\$"$'\n'"$desc"
734                 (( badfiles_nr++ ))
735         done
738 # Detect the available patchfiles
740 detect_patchfiles()
742         local x= y=
743         patchfiles="`ls $confdir/*.patch{,.$arch} \
744                         $confdir/*.patch_$xpkg{.$arch} \
745                         2> /dev/null | tr '\n' ' '`"
747         atstage toolchain &&
748         var_append patchfiles ' ' "`ls $confdir/*.patch.cross0{,.$arch} \
749                                     2>/dev/null | tr '\n' ' '`"
750         atstage cross &&
751         var_append patchfiles ' ' "`ls $confdir/*.patch.cross{,.$arch} \
752                                     2>/dev/null | tr '\n' ' '`"
754         for x in $( get_reverted $targetchain ); do
755                 for y in pkg_$pkg.patch{,.$arch} xpkg_$xpkg.patch{,.$arch}; do
756                         if [ -f $base/target/$x/$y ]; then
757                                 patchfiles="$patchfiles $base/target/$x/$y"
758                         fi
759                 done
760         done
762         # get additional patches from $targetdir/package/$pkg and architecture/package/$pkg -
763         # if it's not the confdir ie. contains the .desc file which overrides the default
764         for x in $targetdir/package/$pkg $base/architecture/$arch/package/$pkg; do
765                 if [ $confdir != $x ]; then
766                         var_append patchfiles ' ' "`ls $x/*.patch{,.$arch} 2> /dev/null | tr '\n' ' '`"
767                 fi
768         done
771 # Apply the given $patchfiles
772 # [ hook called for each patch ] [ filter script ]
774 apply_patchfiles() {
775         local hook="$1"
776         local filter="$2"
777         [ "$filter" ] || filter=cat
778         for x in $patchfiles; do
779                 # correct the abolute path - e.g  for patchfiles supplied
780                 # in the .desc file
781                 # we assume relative path patches are mirrorables //mnemoc
782                 if [ ! -e "$x" -a -n "${x##*/*}" ]; then
783                         x="$base/download/mirror/${x:0:1}/$x"
784                 fi
786                 echo "Applying $x"
788                 if [[ $x = *.zst ]]; then
789                         patch_file=`mktemp`; patch_del=1
790                         zstdcat $x > $patch_file
791                 else
792                         patch_file=$x; patch_del=0
793                 fi
795                 $filter $patch_file | patch $patchopt
797                 [ $patch_del = 1 ] && rm $patch_file
798                 eval "$hook"
799         done
802 # -------------------------------------------------------------------
803 # The automatic extraction of archive (prior to building) supports
804 # multiple archive types. For every archive type we have a separate
805 # func that knows how to extract the archive. However, every func
806 # should deliver two file: untar.txt and xsrcdir.txt.
808 # untar.txt needs to contain all extracted files.
809 # xsrcdir.txt need to contain the top level extraction directories.
810 # -------------------------------------------------------------------
812 autoextract_tar_bz2() {
813         echo "Extracting $xsrctar ($taropt) ... "
814         tar -v $taropt $1 > untar.txt
817 autoextract_zip() {
818         echo "Extracting $xsrctar ($zipopt) ... "
819         unzip $zipopt $1 | sed 's,^.*/$,,' |
820                 cut -f4 -d" " | grep -v "^$" > untar.txt
823 autoextract_7z() {
824         echo "Extracting $xsrctar ($sevenzipopt) ... "
825         7za $sevenzipopt $1 | sed 's,/,,' |
826                 cut -f3 -d" " | grep -v "^$" > untar.txt
829 # Main program for building a package
831 build_this_package() {
832         if [ ".$desc_SRC" == "." ]; then
833                 # Autodetect source tar and extract it
834                 #
835                 if [ "$srctar" = auto ]; then
836                         xsourceballs=$( echo "$desc_D" | head -n 1 | sed 's, ,\t,g; s,\t\t*,\t,g' |
837                                 cut -f2 | bz2filename )
838                         if [ -z "$xsourceballs" ]; then
839                                 echo "Can't auto-detect srctar for package '$xpkg'!"
840                                 false
841                         fi
842                 else
843                         xsourceballs="$srctar"
844                 fi
845         elif [ "$srctar" = auto ]; then
846                 sourceballs=$( echo "$desc_D" | sed 's, ,\t,g; s,\t\t*,\t,g' |
847                         cut -f2 | bz2filename )
848                 xsrcpattern=$( echo "$desc_SRC" | sed 's, ,\t,g; s,\t\t*,\n,g' )
849                 xsourceballs=$( echo "$sourceballs" | grep -F "$xsrcpattern" )
850         else
851                 xsourceballs="$srctar"
852         fi
853         for xsrctar in $xsourceballs; do
854                 saved_patchfiles="$patchfiles"
855                 var_append patchfiles " " \
856                            "`ls $confdir/*.patch.${xsrctar/-[v0-9]*/} 2> /dev/null`"
857                 if [ "$xsrctar" != none -a "$autoextract" = 1 ]; then
858                         cd $builddir
859                         if [ -z "$custextract" ]; then
860                                 # No custom extraction, so determine what
861                                 # autoextraction to use.
862                                 case "$xsrctar" in
863                                 *.zip) custextract="autoextract_zip" ;;
864                                 *.7z) custextract="autoextract_7z" ;;
865                                 *) custextract="autoextract_tar_bz2" ;; # *.tar.bz2|*.tbz2|*.tbz
866                                 esac
867                         fi
868                         if [ -n "$custextract" ]; then
869                                 # Do the actual extraction of the archive.
870                                 eval "$custextract $archdir/$xsrctar"
871                                 cat untar.txt |
872                                         sed 's,^\./,,' | cut -f1 -d/ |
873                                         sort -u > xsrcdir.txt
874                         fi
875                         #
876                         if [ "$srcdir" = auto ]; then
877                                 xsrcdir=${xsrctar%.tar.bz2}
878                                 xsrcdir=${xsrcdir%.tar.zst}
879                                 xsrcdir=${xsrcdir%.tar.xz}
880                                 xsrcdir=${xsrcdir%.tbz2}
881                                 xsrcdir=${xsrcdir%.tbz}
882                                 if [ ! -d $xsrcdir ]; then
883                                         for x in $pkg-$ver ${pkg}_$ver $pkg \
884                                                  $xpkg-$ver ${xpkg}_$ver $xpkg \
885                                                  "$( cat xsrcdir.txt )"
886                                         do
887                                                 [ -d "$x" ] && xsrcdir="$x"
888                                         done
889                                 fi
890                         else
891                                 xsrcdir="$srcdir"
892                         fi
893                         #
894                         if [ "$chownsrcdir" = 1 ]; then
895                                 echo "Fixing ownership and permissions ..."
896                                 chown -R 0:0 $builddir/$xsrcdir
897                         fi
898                         #
899                         if [ "$nocvsinsrcdir" = 1 ]; then
900                                 echo "Removing CVS, .svn, {arch} and .arch-ids directories ..."
901                                 egrep '(^|/)(CVS|\.svn|\{arch\}|\.arch-ids)(/|$)' untar.txt |
902                                 while read x; do
903                                         echo "Removing $x ..."
904                                         rm -rf "$x"
905                                 done
906                         fi
907                         #
908                         echo "Changeing into $builddir/$xsrcdir ..."
909                         cd $builddir/$xsrcdir
911                         # Apply patches
912                         #               
913                         if [ $autopatch = 1 ]; then
914                                 hook_eval prepatch
915                                 apply_patchfiles        
916                                 hook_eval postpatch
917                         fi
919                 else
920                         cd $builddir
921                 fi
923                 if [ "$createprefix" = 1 ]; then
924                         echo "Creating $root/$prefix/<..> if required ..."
925                         for x in $foodirlist; do
926                                 eval "x=\"$root\$$x\""
927                                 if [ ! -e $x ]; then
928                                         mkdir -p $x
929                                         rmemptydir="$rmemptydir $x"
930                                 fi
931                         done
932                 fi
933                 
934                 if [ ".$custmain" = "." ]
935                 then
936                         hook_eval preconf
938                         # Maybe generate a configure first
939                         #
940                         if [ "$autogen" = 1 -o \
941                              \( -f configure.in -a ! -f configure -a "$autogen" != 0 \) ]; then
942                                 if [ -f autogen.sh ]; then
943                                         echo "Running package autogen script"
944                                         #sed -i '/^\.\/configure /d' autogen.sh
945                                         sh autogen.sh $( eval echo $confopt )
946                                 else
947                                         echo "Running builtin autogen script"
948                                         libtoolize --force --automake
949                                         aclocal $ACLOCAL_FLAGS
950                                         if grep AM_INIT_AUTOMAKE \
951                                            configure.[ia][nc]
952                                         then automake --add-missing; fi
953                                         autoconf
954                                 fi
955                         fi
956                         # Run configure scripts etc.
957                         #
958                         if [ "$runconf" = 1 ]; then
959                           if [ -n "$( type -p $configscript )" -o "$autogen" = 1 ]
960                           then
961                                 eval_config_command $( eval echo $confopt )
962                           fi
963                         fi
965                         # CMake style
966                         #
967                         if [ $runcmake = 1 -a ! -f Makefile ] &&
968                            [ -e $cmakelists -o -e ../$cmakelists ]; then
969                                 if atstage cross; then
970                                         create_cmake_toolchain_file >> t2.cmake
971                                         var_insert cmakeopt " " "-DCMAKE_TOOLCHAIN_FILE=t2.cmake"
972                                 fi
974                                 # top-level CMakeLists?
975                                 [ ! -e $cmakelists ] && cmakelists="../$cmakelists"
977                                 # already ending with a directory?
978                                 [[ "$cmakeopt" = *. ]] || var_append cmakeopt ' ' "${cmakelists%%/*}"
980                                 eval echo "Running cmake $cmakeopt"
981                                 cmake $(eval echo $cmakeopt)
982                         fi
984                         # automated package build
986                         # styles without make run first:
987                         if [ -f setup.py -a $runpysetup = 1 ]; then
988                                 pyconfopt="${pyconfopt:=--prefix $root/$prefix}"
989                                 hook_eval premake
990                                 eval ${pyscript:-python} setup.py build install $pyconfopt
991                                 hook_eval postmake
992                         elif [ -f meson.build -a $runmeson = 1 ]; then
993                                 if atstage cross; then
994                                         create_meson_cross >> cross.ini
995                                         CC=cc CXX=c++ # make meson happy :-/
996                                         var_append mesonopt " " "--cross-file cross.ini"
997                                 fi
998                                 hook_eval premake
999                                 eval echo "Running meson $mesonopt"
1000                                 eval "meson $mesonopt"
1001                                 hook_eval inmake
1002                                 eval echo "Running ninja -C objdir/ -j$SDECFG_PARALLEL_MAX install"
1003                                 atstage cross && export DESTDIR=$root
1004                                 ninja -C objdir/ -j$SDECFG_PARALLEL_MAX install # TODO: $ninjainstopt
1005                                 hook_eval postmake
1006                         elif [ -f Cargo.toml -a $runcargo = 1 ]; then
1007                                 hook_eval premake
1008                                 if [ "$cargoopt" ]; then
1009                                         eval echo "Running cargo $cargoopt"
1010                                         eval "cargo $cargoopt"
1011                                 fi
1012                                 hook_eval inmake
1013                                 if [ "$cargoinstopt" ]; then
1014                                         eval echo "Running cargo $cargoinstopt"
1015                                         eval "cargo $cargoinstopt"
1016                                 fi
1017                                 hook_eval postmake
1018                         elif [ -f build.zig -a $runzig = 1 ]; then # some projects still use makefile
1019                                 hook_eval premake
1020                                 zigconfopt="${zigconfopt:=--prefix $root/$prefix}"
1021                                 eval "zig build $zigconfopt"
1022                                 hook_eval inmake
1023                                 eval "zig build install"
1024                                 hook_eval postmake
1025                         elif [ -f META6.json -a $runzef = 1 ]; then
1026                                 hook_eval premake
1027                                 var_append zefopt " " "--force-install --/depends --/test-depends --/build-depends"
1028                                 var_append zefopt " " "--install-to=inst#$root/$prefix/share/perl6/site"
1029                                 hook_eval inmake
1030                                 eval echo "Running zef install . $zefopt"
1031                                 eval "zef install . $zefopt"
1032                                 hook_eval postmake
1033                         else # styles that include a make run
1034                                 if [ ! -f Makefile -a ! -f makefile -a \
1035                                      -f Makefile.PL -a $runmkpl = 1 ]; then
1036                                         perl Makefile.PL ${plconfopt:-INSTALLDIRS=perl}
1037                                 fi
1038                                 #
1039                                 if [ ! -f Makefile -a ! -f makefile -a \
1040                                      -f Imakefile -a $runxmkmf = 1 ]; then
1041                                         xmkmf -a
1042                                 fi
1043                                 #
1044                                 # Build it
1045                                 #
1046                                 hook_eval premake
1047                                 if [ "$makeopt" ]; then
1048                                         eval echo "Running $MAKE $makeopt"
1049                                         eval "$MAKE $makeopt"
1050                                 fi
1051                                 hook_eval inmake
1052                                 if [ "$makeinstopt" ]; then
1053                                         eval echo "Running $MAKE $makeinstopt"
1054                                         eval "$MAKE $makeinstopt"
1055                                 fi
1056                                 hook_eval postmake
1057                         fi
1058                 else
1059                         echo_warning "The use of custmain is deprecated, please use hooks instead."
1060                         eval "$custmain"
1061                         for x in preconf premake inmake postmake; do
1062                                 if eval "[ -n \"\$hookdirty_$x\" ]"; then
1063                                         echo "Hook $x is still marked as dirty running it, now ..."
1064                                         hook_eval $x
1065                                 fi
1066                         done
1067                 fi
1069                 if [ "$createdocs" != 0 ]; then
1070                         if [ ! -e $root$docdir ]; then
1071                                 mkdir -p $docdir
1072                                 rmemptydir="$rmemptydir $root$docdir"
1073                         fi
1074                         [ -z "$createdocs" ] && createdocs="$SDECFG_CREATE_DOCS"
1075                 fi
1077                 if [ "$createdocs" = 1 ]; then
1078                         echo "Trying to copy the default documentation ..."
1079                         for x in [A-Z][A-Z]* *.lsm ChangeLog*; do
1080                                 [ "${x#*.[cho0-9]}" ] || continue
1081                                 [ "${x#*.info*}"    ] || continue
1082                                 [ "${x#*.TAR*}"     ] || continue
1083                                 [ "${x#*akefile*}"     ] || continue
1084                                 [ -f $x ] && cp -v $x $root$docdir/$x
1085                         done
1087                         echo "Trying to copy even more documentation ..."
1088                         [ -d $builddir/$xsrcdir ] && cd $builddir/$xsrcdir
1089                         for x in `find -type d \( -name 'doc' -o -name 'docs' \
1090                                        -o -name '[Dd]ocumentation' \) ! -empty`
1091                         do
1092                                 if [ -d "$x" -a "`echo $x/*`" != "$x/*" ]
1093                                 then cp -rLv $x/* $root$docdir || true; fi
1094                         done
1095                         for x in $confdir/*.doc; do
1096                                 if [ -f $x ]
1097                                 then cp -v $x $root$docdir/${x%.doc}; fi
1098                         done
1099                         find $root$docdir/ -name '*.[0-9]' -o -name '*.info*' \
1100                                 -o -name '[Mm]akefile*' |
1101                                 xargs -r rm -f 2> /dev/null || true
1102                         find $root$docdir/* -type d -empty 2> /dev/null |
1103                                 xargs -r rmdir 2> /dev/null || true
1104                 fi
1106                 hook_eval postdoc
1107                 if atstage native && [ -f /sbin/ldconfig ]; then
1108                         echo "Running ldconfig"
1109                         ldconfig
1110                 fi
1111                 patchfiles="$saved_patchfiles"
1112         done
1113   
1114         if [ "$rmemptydir" ]; then
1115                 rmdir $rmemptydir 2> /dev/null || true
1116         fi
1118         return 0
1121 # source_file cksum file url
1123 # Create the file path from 'file' and 'url'.
1124 # cksum and url are ignored
1125 # ([D] tag compatible format)
1127 source_file() {
1128         local pre="" file="$2" url="$3" mirror="mirror"
1130         # '-' as $url prefix means, nomirrorable
1131         [ "${url:0:1}" == "-" ] && mirror="local"
1132         
1133         # inside Build-Pkg $archdir is set
1134         if [ -n "$archdir" ]; then
1135                 pre=$base/; file="$( bz2filename $file )"
1136         fi
1137     
1138         echo ${pre}download/${mirror}/${file:0:1}/$file
1141 # match_source_file [-p] pattern [[package] ...]
1143 # Returns path and name of a downloaded file from a list of packages, matching
1144 # a grep pattern. Without -p it only returns it's name, not the path, with -n
1145 # it does not perform the usual translation to .bz2.
1147 match_source_file() {
1148         local pattern= package= showpath=0 bz2=1
1149         local x= file= url= mirror=
1150         local found=1
1152         while [ "$1" ]; do
1153           case "$1" in
1154                 -p) showpath=1; shift ;;
1155                 -n) bz2=0; shift ;;
1156                 *) break ;; # no abort as the pattern might start with a '-'
1157           esac
1158         done
1159         pattern="$1"; shift
1161         for package in ${*:-$pkg}; do
1162                 while read x x file url x; do
1163                         [ $bz2 = 1 ] && file="$( bz2filename $file )"
1164                         found=0
1166                         if [ $showpath -eq 0 ]; then
1167                                 echo $file
1168                         else
1169                                 [ "${url:0:1}" == "-" ] && mirror="local" || mirror="mirror"
1170                                 echo $base/download/${mirror}/${file:0:1}/$file
1171                         fi
1172                 done < <( for f in $base/target/$target/package/$package/$package.desc \
1173                                    $base/architecture/$arch/package/$package/$package.desc \
1174                                    $base/package/*/$package/$package.desc; do
1175                                 grep -e "^\[D\].*$pattern" $f 2> /dev/null
1176                                 grep -q -e "^\[D\]" $f 2> /dev/null && break
1177                           done )
1178         done
1179         return $found
1182 # create the virtual $archdir symlinks
1184 populate_archdir()
1186         local x= missing=0
1187         for x in `match_source_file -p .`; do
1188                 if [ ! -f $x ]; then
1189                         echo_warning "File not found: ${x#$base/}"
1190                         missing=1
1191                 elif [ ! -e "$builddir/archdir/${x##*/}" ]; then
1192                         ln -vs $x $builddir/archdir/
1193                 fi
1194         done
1195         if [ $missing -eq 1 ]; then
1196                 echo_warning "Did you run scripts/Download for this package?"
1197                 false
1198         fi
1201 # search for the package confdir
1203 detect_confdir()
1205         confdir=
1206         for x in package/*/$pkg/$pkg.desc; do
1207                 [ -f "$x" ] || continue
1208                 if [ "$confdir" ]; then
1209                         echo_pkg_deny $stagelevel $pkg "in multiple trees"
1210                         echo "Package in multiple trees: $pkg !" \
1211                           > $root/var/adm/logs/$stagelevel-$xpkg.err
1212                         exit 1
1213                 fi
1214                 x=${x#package/}; x=${x%%/*}
1215                 confdir="$base/package/$x/$pkg"
1216                 repository=$x
1217         done
1219         if [ -e architecture/$arch/package/$pkg/$pkg.desc ]
1220         then confdir="$base/architecture/$arch/package/$pkg"; fi
1222         if [ -e $base/target/$target/package/$pkg/$pkg.desc ]
1223         then confdir="$base/target/$target/package/$pkg"; fi
1226 # initialize standard vars and hooks
1228 init_vars_and_hooks()
1230         makeopt='CC="$CC" CPP="$CPP" CXX="$CXX"'
1231         cargoopt='build --release'
1232         cargoinstopt='install --path . --root $root/$prefix --no-track --force'
1233         if [ "$SDECFG_DEBUG" = 1 ]; then
1234                 var_remove cargoopt ' ' '--release'
1235                 var_append cargoinstopt ' ' '--debug'
1236         fi
1238         if atstage toolchain; then
1239                 makeopt="$makeopt"' prefix="$root/$prefix" docdir="$root$docdir"'
1240                 cmakeopt='-DCMAKE_INSTALL_PREFIX="$root/$prefix"'
1241         else
1242                 makeopt="$makeopt"' prefix="/$prefix" docdir="$docdir"'
1243                 cmakeopt='-DCMAKE_INSTALL_PREFIX="/$prefix -DCMAKE_LIBRARY_PATH=$libdir"'
1244         fi
1246         if ! atstage native; then
1247                 makeopt="$makeopt"' CC_FOR_BUILD="$BUILDCC"'
1248                 makeopt="$makeopt"' BUILDCC="$BUILDCC" BUILD_CC="$BUILD_CC"'
1249                 makeopt="$makeopt"' HOSTCC="$HOSTCC"   HOST_CC="$HOST_CC"'
1250                 makeopt="$makeopt"' STRIP="$STRIP" AR="$AR" LD="$LD" AS="$AS"'
1251                 makeopt="$makeopt"' RANLIB="$RANLIB" NM="$NM"'
1252         fi
1254         if atstage native; then
1255                 flistdel="$flistdel|`echo $base | sed s,^/,,`/.*"
1256         fi
1258         if atstage cross; then
1259                 # everyting non-DESTDIR is passed in the specific packages
1260                 makeinstopt="$makeopt"' DESTDIR="$root" install'
1262                 var_append cargoopt ' ' "--target ${arch_target/-t2-/-unknown-}"
1263                 var_append cargoinstopt ' ' "--target ${arch_target/-t2-/-unknown-}"
1264         else
1265                 makeinstopt="$makeopt"' install'
1266         fi
1268         custmain=""
1270         [ "$SDECFG_DO_CHECK" = 1 ] && hook_add inmake 6 'run_check'
1271         [ "$SDECFG_STATIC_IN_USR" = 1 ] && hook_add postflist 3 'postflist_static_lib'
1273         createarchcache=0
1275         configprefix=""; autogen=
1276         configscript="./configure"; extraconfopt=""
1277         cmakelists="./CMakeLists.txt"
1279         srcdir=auto; srctar=auto
1280         taropt="--use-compress-program=zstd -xf"
1281         sevenzipopt="x"
1283         mainfunction="build_this_package"
1284         runconf=1; runxmkmf=1; runmkpl=1; runpysetup=1; runcmake=1; runmeson=1
1285         runcargo=1; runzig=1; runzef=1
1286         autopatch=1; autoextract=1; chownsrcdir=1; nocvsinsrcdir=1; cleanconfopt=1
1287         patchopt="-bfp1 -z .orig"
1288         createprefix=1; createdocs=""; rmemptydir=""
1290         check_shared=1
1291         check_usrlocal=1
1292         check_badfiles=1
1294         badfiles="" badfiles_nr=0
1295         declare -a badfiles_desc
1298 # this is a 2nd lightweight and modular "build this package" implementation
1299 # currently only used for the postlinux stuff - later maybe for more -ReneR
1301 build_package()
1303   logstamp=$PWD/log
1304   (
1305         set -e
1306         pushd $base
1308         super=$pkg
1309         pkg="$1"; xpkg="$pkg"
1310         conffile="$2"; [ "$conffile" ] || conffile="$pkg.conf"
1312         unset ${!hook*}
1313         declare -a hook_functions='()'
1314         hook_fcounter=0
1315         init_vars_and_hooks
1317         detect_confdir
1318         detect_patchfiles
1320         parse_desc $pkg
1322         # Erase positional parameters to prevent unintended parameter
1323         # passing. We do not want to pass the current positional parameters
1324         # to the loaded script.
1325         set --
1326         eval "$desc_O"
1328         echo_status "Building $xpkg within $super (using $conffile)"
1330         for x in $( get_expanded $base/target/%/pkg_$pkg.conf $targetchain ) \
1331                 $targetdir/package/$pkg/$pkg.conf \
1332                 architecture/$arch/package/$pkg/$pkg.conf \
1333                 $confdir/$conffile; do
1334                 if [ -f $x ]; then
1335                         if [[ $x == */$conffile ]]; then
1336                                 echo "Reading package configuration ($conffile) from package directory."
1337                         else
1338                                 echo "Reading package configuration from $x."
1339                         fi
1340                         . $x
1341                         break
1342                 fi
1343         done
1345         # short path - to not abort on missing downloads of postlinux.conf
1346         # packages that are not built anyway -ReneR
1347         if [ "$custmain" = "true" ]; then
1348                 echo "Nothing is going to be done ayway - returning quickly."
1349                 return
1350         fi
1352         populate_archdir
1353         popd
1355         # dump for debugging
1356         hook_dump > $builddir/debug.hooks.$pkg
1357         dump_env > $builddir/debug.buildenv.$pkg
1359         echo "Running main build function '$mainfunction'"
1360         cd $builddir
1362         eval "$mainfunction"
1363         touch $logstamp
1364   )
1365   [ -f $logstamp ] || return 1
1366   rm $logstamp
1367   return 0