* updated ktp-desktop-applets (21.12.0 -> 21.12.1), untested
[t2-trunk.git] / scripts / functions.in
blobb2232201317c311b38d9efccb7728cb01fbad432
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # T2 SDE: scripts/functions.in
3 # Copyright (C) 2004 - 2021 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 build.zig -a $runzig = 1 ]; then # some projects still use makefile
1007                                 hook_eval premake
1008                                 zigconfopt="${zigconfopt:=--prefix $root/$prefix}"
1009                                 eval "zig build $zigconfopt"
1010                                 hook_eval inmake
1011                                 eval "zig build install"
1012                                 hook_eval postmake
1013                         elif [ -f META6.json -a $runzef = 1 ]; then
1014                                 hook_eval premake
1015                                 var_append zefopt " " "--force-install --/depends --/test-depends --/build-depends"
1016                                 var_append zefopt " " "--install-to=inst#$root/$prefix/share/perl6/site"
1017                                 hook_eval inmake
1018                                 eval echo "Running zef install . $zefopt"
1019                                 eval "zef install . $zefopt"
1020                                 hook_eval postmake
1021                         else # styles that include a make run
1022                                 if [ ! -f Makefile -a ! -f makefile -a \
1023                                      -f Makefile.PL -a $runmkpl = 1 ]; then
1024                                         perl Makefile.PL ${plconfopt:-INSTALLDIRS=perl}
1025                                 fi
1026                                 #
1027                                 if [ ! -f Makefile -a ! -f makefile -a \
1028                                      -f Imakefile -a $runxmkmf = 1 ]; then
1029                                         xmkmf -a
1030                                 fi
1031                                 #
1032                                 # Build it
1033                                 #
1034                                 hook_eval premake
1035                                 if [ "$makeopt" ]; then
1036                                         eval echo "Running $MAKE $makeopt"
1037                                         eval "$MAKE $makeopt"
1038                                 fi
1039                                 hook_eval inmake
1040                                 if [ "$makeinstopt" ]; then
1041                                         eval echo "Running $MAKE $makeinstopt"
1042                                         eval "$MAKE $makeinstopt"
1043                                 fi
1044                                 hook_eval postmake
1045                         fi
1046                 else
1047                         echo_warning "The use of custmain is deprecated, please use hooks instead."
1048                         eval "$custmain"
1049                         for x in preconf premake inmake postmake; do
1050                                 if eval "[ -n \"\$hookdirty_$x\" ]"; then
1051                                         echo "Hook $x is still marked as dirty running it, now ..."
1052                                         hook_eval $x
1053                                 fi
1054                         done
1055                 fi
1057                 if [ "$createdocs" != 0 ]; then
1058                         if [ ! -e $root$docdir ]; then
1059                                 mkdir -p $docdir
1060                                 rmemptydir="$rmemptydir $root$docdir"
1061                         fi
1062                         [ -z "$createdocs" ] && createdocs="$SDECFG_CREATE_DOCS"
1063                 fi
1065                 if [ "$createdocs" = 1 ]; then
1066                         echo "Trying to copy the default documentation ..."
1067                         for x in [A-Z][A-Z]* *.lsm ChangeLog*; do
1068                                 [ "${x#*.[cho0-9]}" ] || continue
1069                                 [ "${x#*.info*}"    ] || continue
1070                                 [ "${x#*.TAR*}"     ] || continue
1071                                 [ "${x#*akefile*}"     ] || continue
1072                                 [ -f $x ] && cp -v $x $root$docdir/$x
1073                         done
1075                         echo "Trying to copy even more documentation ..."
1076                         [ -d $builddir/$xsrcdir ] && cd $builddir/$xsrcdir
1077                         for x in `find -type d \( -name 'doc' -o -name 'docs' \
1078                                        -o -name '[Dd]ocumentation' \) ! -empty`
1079                         do
1080                                 if [ -d "$x" -a "`echo $x/*`" != "$x/*" ]
1081                                 then cp -rLv $x/* $root$docdir || true; fi
1082                         done
1083                         for x in $confdir/*.doc; do
1084                                 if [ -f $x ]
1085                                 then cp -v $x $root$docdir/${x%.doc}; fi
1086                         done
1087                         find $root$docdir/ -name '*.[0-9]' -o -name '*.info*' \
1088                                 -o -name '[Mm]akefile*' |
1089                                 xargs -r rm -f 2> /dev/null || true
1090                         find $root$docdir/* -type d -empty 2> /dev/null |
1091                                 xargs -r rmdir 2> /dev/null || true
1092                 fi
1094                 hook_eval postdoc
1095                 if atstage native && [ -f /sbin/ldconfig ]; then
1096                         echo "Running ldconfig"
1097                         ldconfig
1098                 fi
1099                 patchfiles="$saved_patchfiles"
1100         done
1101   
1102         if [ "$rmemptydir" ]; then
1103                 rmdir $rmemptydir 2> /dev/null || true
1104         fi
1106         return 0
1109 # source_file cksum file url
1111 # Create the file path from 'file' and 'url'.
1112 # cksum and url are ignored
1113 # ([D] tag compatible format)
1115 source_file() {
1116         local pre="" file="$2" url="$3" mirror="mirror"
1118         # '-' as $url prefix means, nomirrorable
1119         [ "${url:0:1}" == "-" ] && mirror="local"
1120         
1121         # inside Build-Pkg $archdir is set
1122         if [ -n "$archdir" ]; then
1123                 pre=$base/; file="$( bz2filename $file )"
1124         fi
1125     
1126         echo ${pre}download/${mirror}/${file:0:1}/$file
1129 # match_source_file [-p] pattern [[package] ...]
1131 # Returns path and name of a downloaded file from a list of packages, matching
1132 # a grep pattern. Without -p it only returns it's name, not the path, with -n
1133 # it does not perform the usual translation to .bz2.
1135 match_source_file() {
1136         local pattern= package= showpath=0 bz2=1
1137         local x= file= url= mirror=
1138         local found=1
1140         while [ "$1" ]; do
1141           case "$1" in
1142                 -p) showpath=1; shift ;;
1143                 -n) bz2=0; shift ;;
1144                 *) break ;; # no abort as the pattern might start with a '-'
1145           esac
1146         done
1147         pattern="$1"; shift
1149         for package in ${*:-$pkg}; do
1150                 while read x x file url x; do
1151                         [ $bz2 = 1 ] && file="$( bz2filename $file )"
1152                         found=0
1154                         if [ $showpath -eq 0 ]; then
1155                                 echo $file
1156                         else
1157                                 [ "${url:0:1}" == "-" ] && mirror="local" || mirror="mirror"
1158                                 echo $base/download/${mirror}/${file:0:1}/$file
1159                         fi
1160                 done < <( for f in $base/target/$target/package/$package/$package.desc \
1161                                    $base/architecture/$arch/package/$package/$package.desc \
1162                                    $base/package/*/$package/$package.desc; do
1163                                 grep -e "^\[D\].*$pattern" $f 2> /dev/null
1164                                 grep -q -e "^\[D\]" $f 2> /dev/null && break
1165                           done )
1166         done
1167         return $found
1170 # create the virtual $archdir symlinks
1172 populate_archdir()
1174         local x= missing=0
1175         for x in `match_source_file -p .`; do
1176                 if [ ! -f $x ]; then
1177                         echo_warning "File not found: ${x#$base/}"
1178                         missing=1
1179                 elif [ ! -e "$builddir/archdir/${x##*/}" ]; then
1180                         ln -vs $x $builddir/archdir/
1181                 fi
1182         done
1183         if [ $missing -eq 1 ]; then
1184                 echo_warning "Did you run scripts/Download for this package?"
1185                 false
1186         fi
1189 # search for the package confdir
1191 detect_confdir()
1193         confdir=
1194         for x in package/*/$pkg/$pkg.desc; do
1195                 [ -f "$x" ] || continue
1196                 if [ "$confdir" ]; then
1197                         echo_pkg_deny $stagelevel $pkg "in multiple trees"
1198                         echo "Package in multiple trees: $pkg !" \
1199                           > $root/var/adm/logs/$stagelevel-$xpkg.err
1200                         exit 1
1201                 fi
1202                 x=${x#package/}; x=${x%%/*}
1203                 confdir="$base/package/$x/$pkg"
1204                 repository=$x
1205         done
1207         if [ -e architecture/$arch/package/$pkg/$pkg.desc ]
1208         then confdir="$base/architecture/$arch/package/$pkg"; fi
1210         if [ -e $base/target/$target/package/$pkg/$pkg.desc ]
1211         then confdir="$base/target/$target/package/$pkg"; fi
1214 # initialize standard vars and hooks
1216 init_vars_and_hooks()
1218         makeopt='CC="$CC" CPP="$CPP" CXX="$CXX"'
1220         if atstage toolchain; then
1221                 makeopt="$makeopt"' prefix="$root/$prefix" docdir="$root$docdir"'
1222                 cmakeopt='-DCMAKE_INSTALL_PREFIX="$root/$prefix"'
1223         else
1224                 makeopt="$makeopt"' prefix="/$prefix" docdir="$docdir"'
1225                 cmakeopt='-DCMAKE_INSTALL_PREFIX="/$prefix -DCMAKE_LIBRARY_PATH=$libdir"'
1226         fi
1228         if ! atstage native; then
1229                 makeopt="$makeopt"' CC_FOR_BUILD="$BUILDCC"'
1230                 makeopt="$makeopt"' BUILDCC="$BUILDCC" BUILD_CC="$BUILD_CC"'
1231                 makeopt="$makeopt"' HOSTCC="$HOSTCC"   HOST_CC="$HOST_CC"'
1232                 makeopt="$makeopt"' STRIP="$STRIP" AR="$AR" LD="$LD" AS="$AS"'
1233                 makeopt="$makeopt"' RANLIB="$RANLIB" NM="$NM"'
1234         fi
1236         if atstage native; then
1237                 flistdel="$flistdel|`echo $base | sed s,^/,,`/.*"
1238         fi
1240         if atstage cross; then
1241                 # everyting non-DESTDIR is passed in the specific packages
1242                 makeinstopt="$makeopt"' DESTDIR="$root" install'
1243         else
1244                 makeinstopt="$makeopt"' install'
1245         fi
1247         custmain=""
1249         [ "$SDECFG_DO_CHECK" = 1 ] && hook_add inmake 6 'run_check'
1250         [ "$SDECFG_STATIC_IN_USR" = 1 ] && hook_add postflist 3 'postflist_static_lib'
1252         createarchcache=0
1254         configprefix=""; autogen=
1255         configscript="./configure"; extraconfopt=""
1256         cmakelists="./CMakeLists.txt"
1258         srcdir=auto; srctar=auto
1259         taropt="--use-compress-program=zstd -xf"
1260         sevenzipopt="x"
1262         mainfunction="build_this_package"
1263         runconf=1; runxmkmf=1; runmkpl=1; runpysetup=1; runcmake=1; runmeson=1; runzig=1; runzef=1
1264         autopatch=1; autoextract=1; chownsrcdir=1; nocvsinsrcdir=1; cleanconfopt=1
1265         patchopt="-bfp1 -z .orig"
1266         createprefix=1; createdocs=""; rmemptydir=""
1268         check_shared=1
1269         check_usrlocal=1
1270         check_badfiles=1
1272         badfiles="" badfiles_nr=0
1273         declare -a badfiles_desc
1276 # this is a 2nd lightweight and modular "build this package" implementation
1277 # currently only used for the postlinux stuff - later maybe for more -ReneR
1279 build_package()
1281   logstamp=$PWD/log
1282   (
1283         set -e
1284         pushd $base
1286         super=$pkg
1287         pkg="$1"; xpkg="$pkg"
1288         conffile="$2"; [ "$conffile" ] || conffile="$pkg.conf"
1290         unset ${!hook*}
1291         declare -a hook_functions='()'
1292         hook_fcounter=0
1293         init_vars_and_hooks
1295         detect_confdir
1296         detect_patchfiles
1298         parse_desc $pkg
1300         # Erase positional parameters to prevent unintended parameter
1301         # passing. We do not want to pass the current positional parameters
1302         # to the loaded script.
1303         set --
1304         eval "$desc_O"
1306         echo_status "Building $xpkg within $super (using $conffile)"
1308         for x in $( get_expanded $base/target/%/pkg_$pkg.conf $targetchain ) \
1309                 $targetdir/package/$pkg/$pkg.conf \
1310                 architecture/$arch/package/$pkg/$pkg.conf \
1311                 $confdir/$conffile; do
1312                 if [ -f $x ]; then
1313                         if [[ $x == */$conffile ]]; then
1314                                 echo "Reading package configuration ($conffile) from package directory."
1315                         else
1316                                 echo "Reading package configuration from $x."
1317                         fi
1318                         . $x
1319                         break
1320                 fi
1321         done
1323         # short path - to not abort on missing downloads of postlinux.conf
1324         # packages that are not built anyway -ReneR
1325         if [ "$custmain" = "true" ]; then
1326                 echo "Nothing is going to be done ayway - returning quickly."
1327                 return
1328         fi
1330         populate_archdir
1331         popd
1333         # dump for debugging
1334         hook_dump > $builddir/debug.hooks.$pkg
1335         dump_env > $builddir/debug.buildenv.$pkg
1337         echo "Running main build function '$mainfunction'"
1338         cd $builddir
1340         eval "$mainfunction"
1341         touch $logstamp
1342   )
1343   [ -f $logstamp ] || return 1
1344   rm $logstamp
1345   return 0