added CheckVersion info for dyncall
[t2.git] / scripts / functions.in
blobe285fa22649f794a222c99df422fa334db99aa90
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'
463 [properties]
464 sizeof_int = $arch_sizeof_int
465 sizeof_wchar_t = $arch_sizeof_int
466 sizeof_void* = $arch_sizeof_char_p
467 alignment_char = 1
468 alignment_void* = $arch_sizeof_int
469 alignment_double = 4
470 has_function_printf = true
471 needs_exe_wrapper = true
473 [host_machine]
474 system = '$SDECFG_KERNEL'
475 cpu_family = '$(uname -m)'
476 cpu = '$arch' # or uname -m?
478 [ $arch_bigendian == "yes" ] && echo "endian = 'big'" || echo "endian = 'little'"
481 # Generate a CMake toolchain file for cross builds
483 create_cmake_toolchain_file() {
484         cat <<-EOT
485         SET(CMAKE_SYSTEM_NAME Linux)
486         SET(CMAKE_SYSTEM_VERSION 1)
487         SET(CMAKE_C_COMPILER $CC)
488         SET(CMAKE_CXX_COMPILER $CXX)
489         SET(CMAKE_FIND_ROOT_PATH $root)
490         SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
491         SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
492         SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
496 # Abort build before actual build starts
497 # (is overwritten in Build-Pkg)
499 abort() {
500         echo -e "The package build aborted with the following config" \
501              "error:\n$*" > $root/var/adm/logs/$stagelevel-$xpkg.err
502         echo_errorquote "$(< $root/var/adm/logs/$stagelevel-$xpkg.err)"
503         echo_pkg_abort $stagelevel $repository $xpkg
504         exit 1
507 # Dump Environment
509 dump_env() {
511         # Dump $base - only set if there is not already an older value.
512         #
513         echo "base=\"\${base:-$base}\""
515         # Dump all variables including their flags, but skip read-only
516         # variables and $base.
517         #
518         # Substitute base directory with ${base}.
519         #
520         for name in ${!a*} ${!b*} ${!c*} ${!d*} ${!e*} ${!f*} ${!g*} ${!h*} \
521                     ${!i*} ${!j*} ${!k*} ${!l*} ${!m*} ${!n*} ${!o*} ${!p*} \
522                     ${!q*} ${!r*} ${!s*} ${!t*} ${!u*} ${!v*} ${!w*} ${!x*} \
523                     ${!y*} ${!z*}                                           \
524                     ${!A*} ${!B*} ${!C*} ${!D*} ${!E*} ${!F*} ${!G*} ${!H*} \
525                     ${!I*} ${!J*} ${!K*} ${!L*} ${!M*} ${!N*} ${!O*} ${!P*} \
526                     ${!Q*} ${!R*} ${!S*} ${!T*} ${!U*} ${!V*} ${!W*} ${!X*} \
527                     ${!Y*} ${!Z*} ${!_*}
528         do
529                 [ $name = base -o $name = PWD ] && continue
530                 if declare -p $name | head -n 1 | grep -qv '^declare -[a-z]*r'
531                 then
532                         declare -p $name | sed "s,\\(^\\|[\"=:]\\)$base\\([\"=:/]\\|\$\\),\\1\${base}\\2,g"
533                 fi
534         done
536         # Dump functions
537         #
538         declare -f | sed 's/^declare -f //; s/<<(/< <(/;'
540         # Dump aliases
541         #
542         alias
545 # Check if a package is already installed
547 # It does check the build-list if not in the rebuild stage - and
548 # the really installed package data for rebuilds (and so manual builds).
550 pkginstalled() {
551         if ! atstage rebuild; then
552                 local pattern="$1"; pattern="${pattern//+/\\+}"
553                 egrep -q "^X.* ($pattern) " $base/config/$config/packages
554         else
555                 [ -f $root/var/adm/packages/$1 ]
556         fi
559 # pkgprefix [-t] [ <type> ] <package>
560 # Returns the prefix or the location of a 'type' of an already built package,
561 # or aborts the build if not yet installed.
562 # When run in the test mode [-t] it returns an error code accordingly.
564 pkgprefix() {
565         local type= pkg=
566         local dotest= abortmsg=
567         local prefix= value=
569         # -t : only see if it's possible to get the values
570         if [ "$1" = "-t" ]; then
571                 dotest=1; shift
572         fi
573         
574         if [ $# -eq 2 ]; then
575                 type="$1"; shift
576         fi
577         pkg="$1"
579         # test usual error causes
580         if [ -z "$pkg" ]; then
581                 abort "pkgprefix: you must specify a package"
582         elif [ ! -f "$root/var/adm/packages/$pkg" ]; then
583                 abortmsg="package $pkg is not present"
584         elif grep -q "^Prefix:" "$root/var/adm/packages/$pkg"; then
585                 prefix=$( grep "^Prefix: " "$root/var/adm/packages/$pkg" | cut -d' ' -f2- )
586         else
587                 abort "pkgprefix: $pkg record is to old (no Prefix: entry), please rebuild it."
588         fi
590         if [ "$dotest" ]; then
591                 # test mode: abort or continue
592                 if [ "$abortmsg" ]; then
593                         echo "pkgprefix: $abortmsg" 1>&2
594                         return 1
595                 else
596                         return 0
597                 fi
598         elif [ "$abortmsg" ]; then
599                 echo "pkgprefix: $abortmsg" 1>&2
600         elif [ -z "$type" -o "$type" = "prefix" ]; then
601                 echo "$prefix"
602                 return 0
603         elif [ "$type" = "ver" ]; then
604                 value=$( grep "^Package Name and Version:" "$root/var/adm/packages/$pkg" | cut -d' ' -f6 )
605         else
606                 value=$( grep "^Location $type: " "$root/var/adm/packages/$pkg" | cut -d' ' -f3- )
607                 if [ -z "$value" ]; then
608                         # try default location for that $prefix
609                         value=$( xpkg="$pkg"; pkggetdir "$type" )
610                 fi
611         fi
612         echo "${value:-PKGPREFIX_ERROR}"
615 # pkggetdir <type>     (needs $prefix and $xpkg)
616 # returns the location for the file of a 'type' considering it's prefix
618 pkggetdir() {
619         local xprefix=${prefix:+/$prefix}
620         case "$1" in
621                 bindir)  echo "$xprefix/bin"    ;;
622                 sbindir) echo "$xprefix/sbin"   ;;
623                 libdir)
624                   if atstage toolchain; then
625                         echo "$xprefix/lib"
626                   elif [ "$SDECFG_MULTILIB" = 1 ]; then
627                     case $arch_machine in
628                         powerpc64|sparc64|x86_64|mips64|riscv*)
629                                 if [ "$SDECFG_X8664_X32" = 1 ]; then
630                                         echo "$xprefix/libx32"
631                                 elif [ "$SDECFG_MIPS64_N32" = 1 ]; then
632                                         echo "$xprefix/lib32"
633                                 else
634                                         echo "$xprefix/lib64"
635                                 fi
636                                 ;;
637                         *)
638                                 echo "$xprefix/lib"     ;;
639                     esac
640                   else
641                         echo "$xprefix/lib"
642                   fi
643                   ;;
644                 datadir) echo "${xprefix:-/usr}/share"  ;;
645                 infodir) echo "${xprefix:-/usr}/info"   ;;
646                 mandir) echo "${xprefix:-/usr}/man"     ;;
647                 docdir) echo "${xprefix:-/usr}/doc/$xpkg"       ;;
648                 includedir) echo "${xprefix:-/usr}/include"     ;;
649                 sysconfdir) echo "/etc${xprefix##/usr*}"        ;;
650                 localstatedir) echo "/var${xprefix##/usr*}"     ;;
651         esac
655 # This function generates the T2 package checksum of $confdir.
656 # The checksum includes the filenames and content (except of the .cache),
657 # including subdirs but without whitespaces and comments and some tag lines
658 # that are not vital for rebuilds during update checks.
660 # pkgchksum package-name | full-patch
662 pkgchksum() {
663   (
664         # expand to full path if only a package name was specified
665         [[ $1 == */* ]] || set $base/package/*/$1/
666         cd $1 || return 1
667         # find all files (without hidden (e.g. .svn) files)
668         find . ! -path '*/.*' ! -name '*.cache' -print -exec cat \{\} \; \
669         2>/dev/null |
670         # strip some unimportant stuff (e.g. comments, whitespaces, ...)
671         sed \
672         -e '/^[ ]*#.*/d' \
673         -e '/^\[COPY\]/d' \
674         -e '/^\[CV-*\]/d' \
675         -e '/^\[[T,I,U,A,M,L,S,C]\]/d' \
676         -e 's/[\t ]*//g' \
677         -e '/^ *$/d' |
678         md5sum | cut -d ' ' -f 1
679   )
682 # Create Package Database for gasgui install tool
684 create_package_db() {
685         rm -f $3.tmp
686         for file in $( echo $1/descs/* ); do
687                 [ -f "$file" ] || continue
688                 pkg="${file##*/}"
689                 # only include the package if a binary file is available
691                 if [ "$SDECFG_PKGFILE_VER" = 1 ]; then
692                         v=-$(grep '^Package Name and Version' \
693                                 $1/packages/$pkg | cut -f6 -d' ')
694                 else
695                         v=""
696                 fi
697                 bfile=${pkg}${v}.$SDECFG_PKGFILE_TYPE
699                 if [ -e $2/$bfile ]; then
700                         [ "$pkg" = TRANS.TBL ] && continue
702                         ( echo -e "$pkg"
703                           echo -e "\027"
705                           cat $1/descs/$pkg | grep -v '\[COPY\]'
706                           echo -e "\027"
708                           cat $1/dependencies/$pkg
709                           echo -e "\027"
711                           cat $1/md5sums/$pkg
712                           echo -e "\027"
714                           echo -e "\004"
715                         ) >> $3.tmp
716                 else
717                         echo_error "Binary file for $bfile not present." \
718                                    "Skipped in package database."
719                 fi
720         done
721         gzip -c $3.tmp > $3; rm -f $3.tmp
724 # Add files to the 'badfiles' list
726 register_badfiles() {
727         local x desc="$1"
728         shift
730         for x in "$@"; do
731                 var_append badfiles $'\n' " $x\$"
732                 badfiles_desc[$badfiles_nr]=" $x\$"$'\n'"$desc"
733                 (( badfiles_nr++ ))
734         done
737 # Detect the available patchfiles
739 detect_patchfiles()
741         local x= y=
742         patchfiles="`ls $confdir/*.patch{,.$arch} \
743                         $confdir/*.patch_$xpkg{.$arch} \
744                         2> /dev/null | tr '\n' ' '`"
746         atstage toolchain &&
747         var_append patchfiles ' ' "`ls $confdir/*.patch.cross0{,.$arch} \
748                                     2>/dev/null | tr '\n' ' '`"
749         atstage cross &&
750         var_append patchfiles ' ' "`ls $confdir/*.patch.cross{,.$arch} \
751                                     2>/dev/null | tr '\n' ' '`"
753         for x in $( get_reverted $targetchain ); do
754                 for y in pkg_$pkg.patch{,.$arch} xpkg_$xpkg.patch{,.$arch}; do
755                         if [ -f $base/target/$x/$y ]; then
756                                 patchfiles="$patchfiles $base/target/$x/$y"
757                         fi
758                 done
759         done
761         # get additional patches from $targetdir/package/$pkg and architecture/package/$pkg -
762         # if it's not the confdir ie. contains the .desc file which overrides the default
763         for x in $targetdir/package/$pkg $base/architecture/$arch/package/$pkg; do
764                 if [ $confdir != $x ]; then
765                         var_append patchfiles ' ' "`ls $x/*.patch{,.$arch} 2> /dev/null | tr '\n' ' '`"
766                 fi
767         done
770 # Apply the given $patchfiles
771 # [ hook called for each patch ] [ filter script ]
773 apply_patchfiles() {
774         local hook="$1"
775         local filter="$2"
776         [ "$filter" ] || filter=cat
777         for x in $patchfiles; do
778                 # correct the abolute path - e.g  for patchfiles supplied
779                 # in the .desc file
780                 # we assume relative path patches are mirrorables //mnemoc
781                 if [ ! -e "$x" -a -n "${x##*/*}" ]; then
782                         x="$base/download/mirror/${x:0:1}/$x"
783                 fi
785                 echo "Applying $x"
787                 if [[ $x = *.zst ]]; then
788                         patch_file=`mktemp`; patch_del=1
789                         zstdcat $x > $patch_file
790                 else
791                         patch_file=$x; patch_del=0
792                 fi
794                 $filter $patch_file | patch $patchopt
796                 [ $patch_del = 1 ] && rm $patch_file
797                 eval "$hook"
798         done
801 # -------------------------------------------------------------------
802 # The automatic extraction of archive (prior to building) supports
803 # multiple archive types. For every archive type we have a separate
804 # func that knows how to extract the archive. However, every func
805 # should deliver two file: untar.txt and xsrcdir.txt.
807 # untar.txt needs to contain all extracted files.
808 # xsrcdir.txt need to contain the top level extraction directories.
809 # -------------------------------------------------------------------
811 autoextract_tar_bz2() {
812         echo "Extracting $xsrctar ($taropt) ... "
813         tar -v $taropt $1 > untar.txt
816 autoextract_zip() {
817         echo "Extracting $xsrctar ($zipopt) ... "
818         unzip $zipopt $1 | sed 's,^.*/$,,' |
819                 cut -f4 -d" " | grep -v "^$" > untar.txt
822 autoextract_7z() {
823         echo "Extracting $xsrctar ($sevenzipopt) ... "
824         7za $sevenzipopt $1 | sed 's,/,,' |
825                 cut -f3 -d" " | grep -v "^$" > untar.txt
828 # Main program for building a package
830 build_this_package() {
831         if [ ".$desc_SRC" == "." ]; then
832                 # Autodetect source tar and extract it
833                 #
834                 if [ "$srctar" = auto ]; then
835                         xsourceballs=$( echo "$desc_D" | head -n 1 | sed 's, ,\t,g; s,\t\t*,\t,g' |
836                                 cut -f2 | bz2filename )
837                         if [ -z "$xsourceballs" ]; then
838                                 echo "Can't auto-detect srctar for package '$xpkg'!"
839                                 false
840                         fi
841                 else
842                         xsourceballs="$srctar"
843                 fi
844         elif [ "$srctar" = auto ]; then
845                 sourceballs=$( echo "$desc_D" | sed 's, ,\t,g; s,\t\t*,\t,g' |
846                         cut -f2 | bz2filename )
847                 xsrcpattern=$( echo "$desc_SRC" | sed 's, ,\t,g; s,\t\t*,\n,g' )
848                 xsourceballs=$( echo "$sourceballs" | grep -F "$xsrcpattern" )
849         else
850                 xsourceballs="$srctar"
851         fi
852         for xsrctar in $xsourceballs; do
853                 saved_patchfiles="$patchfiles"
854                 var_append patchfiles " " \
855                            "`ls $confdir/*.patch.${xsrctar/-[v0-9]*/} 2> /dev/null`"
856                 if [ "$xsrctar" != none -a "$autoextract" = 1 ]; then
857                         cd $builddir
858                         if [ -z "$custextract" ]; then
859                                 # No custom extraction, so determine what
860                                 # autoextraction to use.
861                                 case "$xsrctar" in
862                                 *.zip) custextract="autoextract_zip" ;;
863                                 *.7z) custextract="autoextract_7z" ;;
864                                 *) custextract="autoextract_tar_bz2" ;; # *.tar.bz2|*.tbz2|*.tbz
865                                 esac
866                         fi
867                         if [ -n "$custextract" ]; then
868                                 # Do the actual extraction of the archive.
869                                 eval "$custextract $archdir/$xsrctar"
870                                 cat untar.txt |
871                                         sed 's,^\./,,' | cut -f1 -d/ |
872                                         sort -u > xsrcdir.txt
873                         fi
874                         #
875                         if [ "$srcdir" = auto ]; then
876                                 xsrcdir=${xsrctar%.tar.bz2}
877                                 xsrcdir=${xsrcdir%.tar.zst}
878                                 xsrcdir=${xsrcdir%.tar.xz}
879                                 xsrcdir=${xsrcdir%.tbz2}
880                                 xsrcdir=${xsrcdir%.tbz}
881                                 if [ ! -d $xsrcdir ]; then
882                                         for x in $pkg-$ver ${pkg}_$ver $pkg \
883                                                  $xpkg-$ver ${xpkg}_$ver $xpkg \
884                                                  "$( cat xsrcdir.txt )"
885                                         do
886                                                 [ -d "$x" ] && xsrcdir="$x"
887                                         done
888                                 fi
889                         else
890                                 xsrcdir="$srcdir"
891                         fi
892                         #
893                         if [ "$chownsrcdir" = 1 ]; then
894                                 echo "Fixing ownership and permissions ..."
895                                 chown -R 0:0 $builddir/$xsrcdir
896                         fi
897                         #
898                         if [ "$nocvsinsrcdir" = 1 ]; then
899                                 echo "Removing CVS, .svn, {arch} and .arch-ids directories ..."
900                                 egrep '(^|/)(CVS|\.svn|\{arch\}|\.arch-ids)(/|$)' untar.txt |
901                                 while read x; do
902                                         echo "Removing $x ..."
903                                         rm -rf "$x"
904                                 done
905                         fi
906                         #
907                         echo "Changeing into $builddir/$xsrcdir ..."
908                         cd $builddir/$xsrcdir
910                         # Apply patches
911                         #               
912                         if [ $autopatch = 1 ]; then
913                                 hook_eval prepatch
914                                 apply_patchfiles        
915                                 hook_eval postpatch
916                         fi
918                 else
919                         cd $builddir
920                 fi
922                 if [ "$createprefix" = 1 ]; then
923                         echo "Creating $root/$prefix/<..> if required ..."
924                         for x in $foodirlist; do
925                                 eval "x=\"$root\$$x\""
926                                 if [ ! -e $x ]; then
927                                         mkdir -p $x
928                                         rmemptydir="$rmemptydir $x"
929                                 fi
930                         done
931                 fi
932                 
933                 if [ ".$custmain" = "." ]
934                 then
935                         hook_eval preconf
937                         # Maybe generate a configure first
938                         #
939                         if [ "$autogen" = 1 -o \
940                              \( -f configure.in -a ! -f configure -a "$autogen" != 0 \) ]; then
941                                 if [ -f autogen.sh ]; then
942                                         echo "Running package autogen script"
943                                         #sed -i '/^\.\/configure /d' autogen.sh
944                                         sh autogen.sh $( eval echo $confopt )
945                                 else
946                                         echo "Running builtin autogen script"
947                                         libtoolize --force --automake
948                                         aclocal $ACLOCAL_FLAGS
949                                         if grep AM_INIT_AUTOMAKE \
950                                            configure.[ia][nc]
951                                         then automake --add-missing; fi
952                                         autoconf
953                                 fi
954                         fi
955                         # Run configure scripts etc.
956                         #
957                         if [ "$runconf" = 1 ]; then
958                           if [ -n "$( type -p $configscript )" -o "$autogen" = 1 ]
959                           then
960                                 eval_config_command $( eval echo $confopt )
961                           fi
962                         fi
964                         # CMake style
965                         #
966                         if [ $runcmake = 1 -a ! -f Makefile ] &&
967                            [ -e $cmakelists -o -e ../$cmakelists ]; then
968                                 if atstage cross; then
969                                         create_cmake_toolchain_file >> t2.cmake
970                                         var_insert cmakeopt " " "-DCMAKE_TOOLCHAIN_FILE=t2.cmake"
971                                 fi
973                                 # top-level CMakeLists?
974                                 [ ! -e $cmakelists ] && cmakelists="../$cmakelists"
976                                 # already ending with a directory?
977                                 [[ "$cmakeopt" = *. ]] || var_append cmakeopt ' ' "${cmakelists%%/*}"
979                                 eval echo "Running cmake $cmakeopt"
980                                 cmake $(eval echo $cmakeopt)
981                         fi
983                         # automated package build
985                         # styles without make run first:
986                         if [ -f setup.py -a $runpysetup = 1 ]; then
987                                 pyconfopt="${pyconfopt:=--prefix $root/$prefix}"
988                                 hook_eval premake
989                                 eval ${pyscript:-python} setup.py build install $pyconfopt
990                                 hook_eval postmake
991                         elif [ -f meson.build -a $runmeson = 1 ]; then
992                                 if atstage cross; then
993                                         create_meson_cross >> cross.ini
994                                         CC=cc CXX=c++ # make meson happy :-/
995                                         var_append mesonopt " " "--cross-file cross.ini"
996                                 fi
997                                 hook_eval premake
998                                 eval echo "Running meson $mesonopt"
999                                 eval "meson $mesonopt"
1000                                 hook_eval inmake
1001                                 eval echo "Running ninja -C objdir/ -j$SDECFG_PARALLEL_MAX install"
1002                                 atstage cross && export DESTDIR=$root
1003                                 ninja -C objdir/ -j$SDECFG_PARALLEL_MAX install # TODO: $ninjainstopt
1004                                 hook_eval postmake
1005                         elif [ -f build.zig -a $runzig = 1 ]; then # some projects still use makefile
1006                                 hook_eval premake
1007                                 zigconfopt="${zigconfopt:=--prefix $root/$prefix}"
1008                                 eval "zig build $zigconfopt"
1009                                 hook_eval inmake
1010                                 eval "zig build install"
1011                                 hook_eval postmake
1012                         elif [ -f META6.json -a $runzef = 1 ]; then
1013                                 hook_eval premake
1014                                 var_append zefopt " " "--force-install --/depends --/test-depends --/build-depends"
1015                                 var_append zefopt " " "--install-to=inst#$root/$prefix/share/perl6/site"
1016                                 hook_eval inmake
1017                                 eval echo "Running zef install . $zefopt"
1018                                 eval "zef install . $zefopt"
1019                                 hook_eval postmake
1020                         else # styles that include a make run
1021                                 if [ ! -f Makefile -a ! -f makefile -a \
1022                                      -f Makefile.PL -a $runmkpl = 1 ]; then
1023                                         perl Makefile.PL ${plconfopt:-INSTALLDIRS=perl}
1024                                 fi
1025                                 #
1026                                 if [ ! -f Makefile -a ! -f makefile -a \
1027                                      -f Imakefile -a $runxmkmf = 1 ]; then
1028                                         xmkmf -a
1029                                 fi
1030                                 #
1031                                 # Build it
1032                                 #
1033                                 hook_eval premake
1034                                 if [ "$makeopt" ]; then
1035                                         eval echo "Running $MAKE $makeopt"
1036                                         eval "$MAKE $makeopt"
1037                                 fi
1038                                 hook_eval inmake
1039                                 if [ "$makeinstopt" ]; then
1040                                         eval echo "Running $MAKE $makeinstopt"
1041                                         eval "$MAKE $makeinstopt"
1042                                 fi
1043                                 hook_eval postmake
1044                         fi
1045                 else
1046                         echo_warning "The use of custmain is deprecated, please use hooks instead."
1047                         eval "$custmain"
1048                         for x in preconf premake inmake postmake; do
1049                                 if eval "[ -n \"\$hookdirty_$x\" ]"; then
1050                                         echo "Hook $x is still marked as dirty running it, now ..."
1051                                         hook_eval $x
1052                                 fi
1053                         done
1054                 fi
1056                 if [ "$createdocs" != 0 ]; then
1057                         if [ ! -e $root$docdir ]; then
1058                                 mkdir -p $docdir
1059                                 rmemptydir="$rmemptydir $root$docdir"
1060                         fi
1061                         [ -z "$createdocs" ] && createdocs="$SDECFG_CREATE_DOCS"
1062                 fi
1064                 if [ "$createdocs" = 1 ]; then
1065                         echo "Trying to copy the default documentation ..."
1066                         for x in [A-Z][A-Z]* *.lsm ChangeLog*; do
1067                                 [ "${x#*.[cho0-9]}" ] || continue
1068                                 [ "${x#*.info*}"    ] || continue
1069                                 [ "${x#*.TAR*}"     ] || continue
1070                                 [ "${x#*akefile*}"     ] || continue
1071                                 [ -f $x ] && cp -v $x $root$docdir/$x
1072                         done
1074                         echo "Trying to copy even more documentation ..."
1075                         [ -d $builddir/$xsrcdir ] && cd $builddir/$xsrcdir
1076                         for x in `find -type d \( -name 'doc' -o -name 'docs' \
1077                                        -o -name '[Dd]ocumentation' \) ! -empty`
1078                         do
1079                                 if [ -d "$x" -a "`echo $x/*`" != "$x/*" ]
1080                                 then cp -rLv $x/* $root$docdir || true; fi
1081                         done
1082                         for x in $confdir/*.doc; do
1083                                 if [ -f $x ]
1084                                 then cp -v $x $root$docdir/${x%.doc}; fi
1085                         done
1086                         find $root$docdir/ -name '*.[0-9]' -o -name '*.info*' \
1087                                 -o -name '[Mm]akefile*' |
1088                                 xargs -r rm -f 2> /dev/null || true
1089                         find $root$docdir/* -type d -empty 2> /dev/null |
1090                                 xargs -r rmdir 2> /dev/null || true
1091                 fi
1093                 hook_eval postdoc
1094                 if atstage native && [ -f /sbin/ldconfig ]; then
1095                         echo "Running ldconfig"
1096                         ldconfig
1097                 fi
1098                 patchfiles="$saved_patchfiles"
1099         done
1100   
1101         if [ "$rmemptydir" ]; then
1102                 rmdir $rmemptydir 2> /dev/null || true
1103         fi
1105         return 0
1108 # source_file cksum file url
1110 # Create the file path from 'file' and 'url'.
1111 # cksum and url are ignored
1112 # ([D] tag compatible format)
1114 source_file() {
1115         local pre="" file="$2" url="$3" mirror="mirror"
1117         # '-' as $url prefix means, nomirrorable
1118         [ "${url:0:1}" == "-" ] && mirror="local"
1119         
1120         # inside Build-Pkg $archdir is set
1121         if [ -n "$archdir" ]; then
1122                 pre=$base/; file="$( bz2filename $file )"
1123         fi
1124     
1125         echo ${pre}download/${mirror}/${file:0:1}/$file
1128 # match_source_file [-p] pattern [[package] ...]
1130 # Returns path and name of a downloaded file from a list of packages, matching
1131 # a grep pattern. Without -p it only returns it's name, not the path, with -n
1132 # it does not perform the usual translation to .bz2.
1134 match_source_file() {
1135         local pattern= package= showpath=0 bz2=1
1136         local x= file= url= mirror=
1137         local found=1
1139         while [ "$1" ]; do
1140           case "$1" in
1141                 -p) showpath=1; shift ;;
1142                 -n) bz2=0; shift ;;
1143                 *) break ;; # no abort as the pattern might start with a '-'
1144           esac
1145         done
1146         pattern="$1"; shift
1148         for package in ${*:-$pkg}; do
1149                 while read x x file url x; do
1150                         [ $bz2 = 1 ] && file="$( bz2filename $file )"
1151                         found=0
1153                         if [ $showpath -eq 0 ]; then
1154                                 echo $file
1155                         else
1156                                 [ "${url:0:1}" == "-" ] && mirror="local" || mirror="mirror"
1157                                 echo $base/download/${mirror}/${file:0:1}/$file
1158                         fi
1159                 done < <( for f in $base/target/$target/package/$package/$package.desc \
1160                                    $base/architecture/$arch/package/$package/$package.desc \
1161                                    $base/package/*/$package/$package.desc; do
1162                                 grep -e "^\[D\].*$pattern" $f 2> /dev/null
1163                                 grep -q -e "^\[D\]" $f 2> /dev/null && break
1164                           done )
1165         done
1166         return $found
1169 # create the virtual $archdir symlinks
1171 populate_archdir()
1173         local x= missing=0
1174         for x in `match_source_file -p .`; do
1175                 if [ ! -f $x ]; then
1176                         echo_warning "File not found: ${x#$base/}"
1177                         missing=1
1178                 elif [ ! -e "$builddir/archdir/${x##*/}" ]; then
1179                         ln -vs $x $builddir/archdir/
1180                 fi
1181         done
1182         if [ $missing -eq 1 ]; then
1183                 echo_warning "Did you run scripts/Download for this package?"
1184                 false
1185         fi
1188 # search for the package confdir
1190 detect_confdir()
1192         confdir=
1193         for x in package/*/$pkg/$pkg.desc; do
1194                 [ -f "$x" ] || continue
1195                 if [ "$confdir" ]; then
1196                         echo_pkg_deny $stagelevel $pkg "in multiple trees"
1197                         echo "Package in multiple trees: $pkg !" \
1198                           > $root/var/adm/logs/$stagelevel-$xpkg.err
1199                         exit 1
1200                 fi
1201                 x=${x#package/}; x=${x%%/*}
1202                 confdir="$base/package/$x/$pkg"
1203                 repository=$x
1204         done
1206         if [ -e architecture/$arch/package/$pkg/$pkg.desc ]
1207         then confdir="$base/architecture/$arch/package/$pkg"; fi
1209         if [ -e $base/target/$target/package/$pkg/$pkg.desc ]
1210         then confdir="$base/target/$target/package/$pkg"; fi
1213 # initialize standard vars and hooks
1215 init_vars_and_hooks()
1217         makeopt='CC="$CC" CPP="$CPP" CXX="$CXX"'
1219         if atstage toolchain; then
1220                 makeopt="$makeopt"' prefix="$root/$prefix" docdir="$root$docdir"'
1221                 cmakeopt='-DCMAKE_INSTALL_PREFIX="$root/$prefix"'
1222         else
1223                 makeopt="$makeopt"' prefix="/$prefix" docdir="$docdir"'
1224                 cmakeopt='-DCMAKE_INSTALL_PREFIX="/$prefix -DCMAKE_LIBRARY_PATH=$libdir"'
1225         fi
1227         if ! atstage native; then
1228                 makeopt="$makeopt"' CC_FOR_BUILD="$BUILDCC"'
1229                 makeopt="$makeopt"' BUILDCC="$BUILDCC" BUILD_CC="$BUILD_CC"'
1230                 makeopt="$makeopt"' HOSTCC="$HOSTCC"   HOST_CC="$HOST_CC"'
1231                 makeopt="$makeopt"' STRIP="$STRIP" AR="$AR" LD="$LD" AS="$AS"'
1232                 makeopt="$makeopt"' RANLIB="$RANLIB" NM="$NM"'
1233         fi
1235         if atstage native; then
1236                 flistdel="$flistdel|`echo $base | sed s,^/,,`/.*"
1237         fi
1239         if atstage cross; then
1240                 # everyting non-DESTDIR is passed in the specific packages
1241                 makeinstopt="$makeopt"' DESTDIR="$root" install'
1242         else
1243                 makeinstopt="$makeopt"' install'
1244         fi
1246         custmain=""
1248         [ "$SDECFG_DO_CHECK" = 1 ] && hook_add inmake 6 'run_check'
1249         [ "$SDECFG_STATIC_IN_USR" = 1 ] && hook_add postflist 3 'postflist_static_lib'
1251         createarchcache=0
1253         configprefix=""; autogen=
1254         configscript="./configure"; extraconfopt=""
1255         cmakelists="./CMakeLists.txt"
1257         srcdir=auto; srctar=auto
1258         taropt="--use-compress-program=zstd -xf"
1259         sevenzipopt="x"
1261         mainfunction="build_this_package"
1262         runconf=1; runxmkmf=1; runmkpl=1; runpysetup=1; runcmake=1; runmeson=1; runzig=1; runzef=1
1263         autopatch=1; autoextract=1; chownsrcdir=1; nocvsinsrcdir=1; cleanconfopt=1
1264         patchopt="-bfp1 -z .orig"
1265         createprefix=1; createdocs=""; rmemptydir=""
1267         check_shared=1
1268         check_usrlocal=1
1269         check_badfiles=1
1271         badfiles="" badfiles_nr=0
1272         declare -a badfiles_desc
1275 # this is a 2nd lightweight and modular "build this package" implementation
1276 # currently only used for the postlinux stuff - later maybe for more -ReneR
1278 build_package()
1280   logstamp=$PWD/log
1281   (
1282         set -e
1283         pushd $base
1285         super=$pkg
1286         pkg="$1"; xpkg="$pkg"
1287         conffile="$2"; [ "$conffile" ] || conffile="$pkg.conf"
1289         unset ${!hook*}
1290         declare -a hook_functions='()'
1291         hook_fcounter=0
1292         init_vars_and_hooks
1294         detect_confdir
1295         detect_patchfiles
1297         parse_desc $pkg
1299         # Erase positional parameters to prevent unintended parameter
1300         # passing. We do not want to pass the current positional parameters
1301         # to the loaded script.
1302         set --
1303         eval "$desc_O"
1305         echo_status "Building $xpkg within $super (using $conffile)"
1307         for x in $( get_expanded $base/target/%/pkg_$pkg.conf $targetchain ) \
1308                 $targetdir/package/$pkg/$pkg.conf \
1309                 architecture/$arch/package/$pkg/$pkg.conf \
1310                 $confdir/$conffile; do
1311                 if [ -f $x ]; then
1312                         if [[ $x == */$conffile ]]; then
1313                                 echo "Reading package configuration ($conffile) from package directory."
1314                         else
1315                                 echo "Reading package configuration from $x."
1316                         fi
1317                         . $x
1318                         break
1319                 fi
1320         done
1322         # short path - to not abort on missing downloads of postlinux.conf
1323         # packages that are not built anyway -ReneR
1324         if [ "$custmain" = "true" ]; then
1325                 echo "Nothing is going to be done ayway - returning quickly."
1326                 return
1327         fi
1329         populate_archdir
1330         popd
1332         # dump for debugging
1333         hook_dump > $builddir/debug.hooks.$pkg
1334         dump_env > $builddir/debug.buildenv.$pkg
1336         echo "Running main build function '$mainfunction'"
1337         cd $builddir
1339         eval "$mainfunction"
1340         touch $logstamp
1341   )
1342   [ -f $logstamp ] || return 1
1343   rm $logstamp
1344   return 0