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
6 # This Copyright note is generated by scripts/Create-CopyPatch,
7 # more information can be found in the files COPYING and README.
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
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 |
24 -e 's,.*link[^ ]* \([^ ]*\) .*,\1,' \
27 if [ -z "$hostsum" -a -f /sbin/ifconfig ]; then
28 hostsum=`/sbin/ifconfig eth0 |
29 sed -e '/HWaddr/!d' -e 's/.* HWaddr \([^ ]*\)/\1/'`
31 if [ -z "$hostsum" -a -x /usr/bin/hostid ]; then
32 hostsum=`/usr/bin/hostid`
34 date "+%Y%m%d.%H%M%S.$$.$hostsum" # "+%s.$$.$hostsum"
37 # this functions expands an string replacing % with all possible values
39 case "$BASH_VERSION" in # damn workaround for different syntax in both versions
42 local string="$1"; shift
43 while [ $# -gt 0 ]; do
44 echo "${string//\\%/$1}"
51 local string="$1"; shift
52 while [ $# -gt 0 ]; do
53 echo "${string//\%/$1}"
60 # atstage <stagename> ...
61 # returns true if the build is on a stage related to the given name
68 [ $stagelevel -gt 0 ] || return 0 ;;
70 [ $stagelevel -lt 1 -o $stagelevel -gt 2 ] || return 0 ;;
72 [ $stagelevel -ne 9 ] || return 0 ;;
74 [ $stagelevel -lt 3 ] || return 0 ;;
76 echo "atstage: '$x' stagename is not supported." >&2
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
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"
99 echo "$1" | sed $pattern
107 unset hook_functions hook_fcounter
108 declare -a hook_functions='()'
111 # This function adds a code fragment to a named hook with the named priority
113 # hook_add hook_name priority code
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
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
137 for hook in ${!hookidx_*}; do
138 hook=${hook#hookidx_}
139 echo; echo "Contents of hook $hook:"
141 while read pri fnr; do
142 echo; echo " $pri ($fnr)"
143 echo "${hook_functions[fnr]}" | sed 's,^, ,'
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}\""
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
158 # copy_function set_confopt set_confopt_foobar_old
162 # set_confopt_foobar_old "$@"
167 eval "$( declare -f $1 | sed "1 s,$1,$2," )"
172 # convert tabs to spaces, transform multiple consecutive spaces to one,
173 # remove leading and trailing spaces
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
185 if atstage toolchain; then
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
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"
204 export LIBSUFF=${libdir##*/lib}
206 if [ "$SDECFG_CONFIGURE_OPTS" ]; then
207 var_append confopt " " "$SDECFG_CONFIGURE_OPTS"
210 if [ "$SDECFG_DEBUG" = 0 ]; then
211 var_append confopt " " "--disable-debug"
214 if [ "$SDECFG_DISABLE_NLS" = 1 ]; then
215 var_remove confopt ' ' '--enable-nls'
216 var_append confopt ' ' '--disable-nls'
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"
225 confopt="$confopt --build=\$arch_build --host=\$arch_target"
230 # eval_config_command $( eval echo $confopt )
232 function eval_config_command() {
235 for x in /usr/share/automake/*
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 .
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
252 config_command="$configprefix $configscript"
253 sub_scripts="$( find $( dirname $configscript ) -name configure )"
255 if [ "$cleanconfopt" == "0" ]; then
256 config_command="$config_command $@"
258 # remove unsupported config script options
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: " \
266 config_command="$config_command $x"
268 echo "Removing unsupported '$x' from" \
269 "configure option string."
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"
289 if grep -q -e "^test:" ./Makefile; then
290 echo "Running make test"
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 |
302 [ -e $root/$fn -o -L $root/$fn ] || continue
303 if [[ $fn = *.a ]]; then
304 mv -fv $root/$fn $root/usr/$fn
306 sed "s,\([ =']\)/lib\(.*\),\1/usr/lib\2,g" \
307 $root/$fn > $root/usr/$fn
309 ln -svf ../../$so $root/usr/$so
310 add_flist $root/usr/$so
313 add_flist $root/usr/$fn
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!"
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
331 echo_warning "Detected problems in following libtool files:"
332 for la in $defect_la; do
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
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
350 deplib="`echo $deplib | sed "s,/lib$,/$libsub,g; s,/lib/,/$libsub/,g"`"
356 *TOOLCHAIN*|*BACKUP*|*$SDECFG_ID*) ;;
358 dlibtmp=$dlibsnew; var_remove dlibtmp ' ' "$deplib"
359 [ "$dlibtmp" = "$dlibsnew" ] && var_append dlibsnew ' ' "$deplib"
365 sed -i "s,^dependency_libs=.*,dependency_libs='$dlibsnew'," $root/$la
371 # Parse the *.desc file. Use the description from PKG-DESC-FORMAT and
372 # save the tag data in $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 ..."
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\""
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
406 echo "$addfile" | fl_wrparse -D -r "$xroot/" \
407 >> $builddir/flist.txt
411 # This function is used for forcing a package to be in the dependency list
415 echo "$addpackage: add_dependency()" \
416 >> $builddir/dependencies.debug
420 # This function is used to subsitute some important variables
421 # using a D_ prefix thru m4 ...
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
439 # Architecture specific stuff\n"
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
453 create_meson_cross() {
460 pkgconfig = 'pkg-config'
461 llvm-config = 'llvm-config'
465 sizeof_int = $arch_sizeof_int
466 sizeof_wchar_t = $arch_sizeof_int
467 sizeof_void* = $arch_sizeof_char_p
469 alignment_void* = $arch_sizeof_int
471 has_function_printf = true
472 needs_exe_wrapper = true
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() {
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)
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
512 # Dump $base - only set if there is not already an older value.
514 echo "base=\"\${base:-$base}\""
516 # Dump all variables including their flags, but skip read-only
517 # variables and $base.
519 # Substitute base directory with ${base}.
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*} \
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*} \
530 [ $name = base -o $name = PWD ] && continue
531 if declare -p $name | head -n 1 | grep -qv '^declare -[a-z]*r'
533 declare -p $name | sed "s,\\(^\\|[\"=:]\\)$base\\([\"=:/]\\|\$\\),\\1\${base}\\2,g"
539 declare -f | sed 's/^declare -f //; s/<<(/< <(/;'
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).
552 if ! atstage rebuild; then
553 local pattern="$1"; pattern="${pattern//+/\\+}"
554 egrep -q "^X.* ($pattern) " $base/config/$config/packages
556 [ -f $root/var/adm/packages/$1 ]
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.
567 local dotest= abortmsg=
570 # -t : only see if it's possible to get the values
571 if [ "$1" = "-t" ]; then
575 if [ $# -eq 2 ]; then
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- )
588 abort "pkgprefix: $pkg record is to old (no Prefix: entry), please rebuild it."
591 if [ "$dotest" ]; then
592 # test mode: abort or continue
593 if [ "$abortmsg" ]; then
594 echo "pkgprefix: $abortmsg" 1>&2
599 elif [ "$abortmsg" ]; then
600 echo "pkgprefix: $abortmsg" 1>&2
601 elif [ -z "$type" -o "$type" = "prefix" ]; then
604 elif [ "$type" = "ver" ]; then
605 value=$( grep "^Package Name and Version:" "$root/var/adm/packages/$pkg" | cut -d' ' -f6 )
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" )
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
620 local xprefix=${prefix:+/$prefix}
622 bindir) echo "$xprefix/bin" ;;
623 sbindir) echo "$xprefix/sbin" ;;
625 if atstage toolchain; then
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"
635 echo "$xprefix/lib64"
639 echo "$xprefix/lib" ;;
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*}" ;;
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
665 # expand to full path if only a package name was specified
666 [[ $1 == */* ]] || set $base/package/*/$1/
668 # find all files (without hidden (e.g. .svn) files)
669 find . ! -path '*/.*' ! -name '*.cache' -print -exec cat \{\} \; \
671 # strip some unimportant stuff (e.g. comments, whitespaces, ...)
676 -e '/^\[[T,I,U,A,M,L,S,C]\]/d' \
679 md5sum | cut -d ' ' -f 1
683 # Create Package Database for gasgui install tool
685 create_package_db() {
687 for file in $( echo $1/descs/* ); do
688 [ -f "$file" ] || continue
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' ')
698 bfile=${pkg}${v}.$SDECFG_PKGFILE_TYPE
700 if [ -e $2/$bfile ]; then
701 [ "$pkg" = TRANS.TBL ] && continue
706 cat $1/descs/$pkg | grep -v '\[COPY\]'
709 cat $1/dependencies/$pkg
718 echo_error "Binary file for $bfile not present." \
719 "Skipped in package database."
722 gzip -c $3.tmp > $3; rm -f $3.tmp
725 # Add files to the 'badfiles' list
727 register_badfiles() {
732 var_append badfiles $'\n' " $x\$"
733 badfiles_desc[$badfiles_nr]=" $x\$"$'\n'"$desc"
738 # Detect the available patchfiles
743 patchfiles="`ls $confdir/*.patch{,.$arch} \
744 $confdir/*.patch_$xpkg{.$arch} \
745 2> /dev/null | tr '\n' ' '`"
748 var_append patchfiles ' ' "`ls $confdir/*.patch.cross0{,.$arch} \
749 2>/dev/null | tr '\n' ' '`"
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"
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' ' '`"
771 # Apply the given $patchfiles
772 # [ hook called for each patch ] [ filter script ]
777 [ "$filter" ] || filter=cat
778 for x in $patchfiles; do
779 # correct the abolute path - e.g for patchfiles supplied
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"
788 if [[ $x = *.zst ]]; then
789 patch_file=`mktemp`; patch_del=1
790 zstdcat $x > $patch_file
792 patch_file=$x; patch_del=0
795 $filter $patch_file | patch $patchopt
797 [ $patch_del = 1 ] && rm $patch_file
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
818 echo "Extracting $xsrctar ($zipopt) ... "
819 unzip $zipopt $1 | sed 's,^.*/$,,' |
820 cut -f4 -d" " | grep -v "^$" > untar.txt
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
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'!"
843 xsourceballs="$srctar"
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" )
851 xsourceballs="$srctar"
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
859 if [ -z "$custextract" ]; then
860 # No custom extraction, so determine what
861 # autoextraction to use.
863 *.zip) custextract="autoextract_zip" ;;
864 *.7z) custextract="autoextract_7z" ;;
865 *) custextract="autoextract_tar_bz2" ;; # *.tar.bz2|*.tbz2|*.tbz
868 if [ -n "$custextract" ]; then
869 # Do the actual extraction of the archive.
870 eval "$custextract $archdir/$xsrctar"
872 sed 's,^\./,,' | cut -f1 -d/ |
873 sort -u > xsrcdir.txt
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 )"
887 [ -d "$x" ] && xsrcdir="$x"
894 if [ "$chownsrcdir" = 1 ]; then
895 echo "Fixing ownership and permissions ..."
896 chown -R 0:0 $builddir/$xsrcdir
899 if [ "$nocvsinsrcdir" = 1 ]; then
900 echo "Removing CVS, .svn, {arch} and .arch-ids directories ..."
901 egrep '(^|/)(CVS|\.svn|\{arch\}|\.arch-ids)(/|$)' untar.txt |
903 echo "Removing $x ..."
908 echo "Changeing into $builddir/$xsrcdir ..."
909 cd $builddir/$xsrcdir
913 if [ $autopatch = 1 ]; then
923 if [ "$createprefix" = 1 ]; then
924 echo "Creating $root/$prefix/<..> if required ..."
925 for x in $foodirlist; do
926 eval "x=\"$root\$$x\""
929 rmemptydir="$rmemptydir $x"
934 if [ ".$custmain" = "." ]
938 # Maybe generate a configure first
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 )
947 echo "Running builtin autogen script"
948 libtoolize --force --automake
949 aclocal $ACLOCAL_FLAGS
950 if grep AM_INIT_AUTOMAKE \
952 then automake --add-missing; fi
956 # Run configure scripts etc.
958 if [ "$runconf" = 1 ]; then
959 if [ -n "$( type -p $configscript )" -o "$autogen" = 1 ]
961 eval_config_command $( eval echo $confopt )
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"
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)
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}"
990 eval ${pyscript:-python} setup.py build install $pyconfopt
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"
999 eval echo "Running meson $mesonopt"
1000 eval "meson $mesonopt"
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
1006 elif [ -f build.zig -a $runzig = 1 ]; then # some projects still use makefile
1008 zigconfopt="${zigconfopt:=--prefix $root/$prefix}"
1009 eval "zig build $zigconfopt"
1011 eval "zig build install"
1013 elif [ -f META6.json -a $runzef = 1 ]; then
1015 var_append zefopt " " "--force-install --/depends --/test-depends --/build-depends"
1016 var_append zefopt " " "--install-to=inst#$root/$prefix/share/perl6/site"
1018 eval echo "Running zef install . $zefopt"
1019 eval "zef install . $zefopt"
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}
1027 if [ ! -f Makefile -a ! -f makefile -a \
1028 -f Imakefile -a $runxmkmf = 1 ]; then
1035 if [ "$makeopt" ]; then
1036 eval echo "Running $MAKE $makeopt"
1037 eval "$MAKE $makeopt"
1040 if [ "$makeinstopt" ]; then
1041 eval echo "Running $MAKE $makeinstopt"
1042 eval "$MAKE $makeinstopt"
1047 echo_warning "The use of custmain is deprecated, please use hooks instead."
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 ..."
1057 if [ "$createdocs" != 0 ]; then
1058 if [ ! -e $root$docdir ]; then
1060 rmemptydir="$rmemptydir $root$docdir"
1062 [ -z "$createdocs" ] && createdocs="$SDECFG_CREATE_DOCS"
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
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`
1080 if [ -d "$x" -a "`echo $x/*`" != "$x/*" ]
1081 then cp -rLv $x/* $root$docdir || true; fi
1083 for x in $confdir/*.doc; do
1085 then cp -v $x $root$docdir/${x%.doc}; fi
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
1095 if atstage native && [ -f /sbin/ldconfig ]; then
1096 echo "Running ldconfig"
1099 patchfiles="$saved_patchfiles"
1102 if [ "$rmemptydir" ]; then
1103 rmdir $rmemptydir 2> /dev/null || true
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)
1116 local pre="" file="$2" url="$3" mirror="mirror"
1118 # '-' as $url prefix means, nomirrorable
1119 [ "${url:0:1}" == "-" ] && mirror="local"
1121 # inside Build-Pkg $archdir is set
1122 if [ -n "$archdir" ]; then
1123 pre=$base/; file="$( bz2filename $file )"
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=
1142 -p) showpath=1; shift ;;
1144 *) break ;; # no abort as the pattern might start with a '-'
1149 for package in ${*:-$pkg}; do
1150 while read x x file url x; do
1151 [ $bz2 = 1 ] && file="$( bz2filename $file )"
1154 if [ $showpath -eq 0 ]; then
1157 [ "${url:0:1}" == "-" ] && mirror="local" || mirror="mirror"
1158 echo $base/download/${mirror}/${file:0:1}/$file
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
1170 # create the virtual $archdir symlinks
1175 for x in `match_source_file -p .`; do
1176 if [ ! -f $x ]; then
1177 echo_warning "File not found: ${x#$base/}"
1179 elif [ ! -e "$builddir/archdir/${x##*/}" ]; then
1180 ln -vs $x $builddir/archdir/
1183 if [ $missing -eq 1 ]; then
1184 echo_warning "Did you run scripts/Download for this package?"
1189 # search for the package 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
1202 x=${x#package/}; x=${x%%/*}
1203 confdir="$base/package/$x/$pkg"
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"'
1224 makeopt="$makeopt"' prefix="/$prefix" docdir="$docdir"'
1225 cmakeopt='-DCMAKE_INSTALL_PREFIX="/$prefix -DCMAKE_LIBRARY_PATH=$libdir"'
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"'
1236 if atstage native; then
1237 flistdel="$flistdel|`echo $base | sed s,^/,,`/.*"
1240 if atstage cross; then
1241 # everyting non-DESTDIR is passed in the specific packages
1242 makeinstopt="$makeopt"' DESTDIR="$root" install'
1244 makeinstopt="$makeopt"' install'
1249 [ "$SDECFG_DO_CHECK" = 1 ] && hook_add inmake 6 'run_check'
1250 [ "$SDECFG_STATIC_IN_USR" = 1 ] && hook_add postflist 3 'postflist_static_lib'
1254 configprefix=""; autogen=
1255 configscript="./configure"; extraconfopt=""
1256 cmakelists="./CMakeLists.txt"
1258 srcdir=auto; srctar=auto
1259 taropt="--use-compress-program=zstd -xf"
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=""
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
1287 pkg="$1"; xpkg="$pkg"
1288 conffile="$2"; [ "$conffile" ] || conffile="$pkg.conf"
1291 declare -a hook_functions='()'
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.
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
1313 if [[ $x == */$conffile ]]; then
1314 echo "Reading package configuration ($conffile) from package directory."
1316 echo "Reading package configuration from $x."
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."
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'"
1340 eval "$mainfunction"
1343 [ -f $logstamp ] || return 1