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'
464 sizeof_int = $arch_sizeof_int
465 sizeof_wchar_t = $arch_sizeof_int
466 sizeof_void* = $arch_sizeof_char_p
468 alignment_void* = $arch_sizeof_int
470 has_function_printf = true
471 needs_exe_wrapper = true
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() {
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)
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
511 # Dump $base - only set if there is not already an older value.
513 echo "base=\"\${base:-$base}\""
515 # Dump all variables including their flags, but skip read-only
516 # variables and $base.
518 # Substitute base directory with ${base}.
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*} \
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*} \
529 [ $name = base -o $name = PWD ] && continue
530 if declare -p $name | head -n 1 | grep -qv '^declare -[a-z]*r'
532 declare -p $name | sed "s,\\(^\\|[\"=:]\\)$base\\([\"=:/]\\|\$\\),\\1\${base}\\2,g"
538 declare -f | sed 's/^declare -f //; s/<<(/< <(/;'
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).
551 if ! atstage rebuild; then
552 local pattern="$1"; pattern="${pattern//+/\\+}"
553 egrep -q "^X.* ($pattern) " $base/config/$config/packages
555 [ -f $root/var/adm/packages/$1 ]
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.
566 local dotest= abortmsg=
569 # -t : only see if it's possible to get the values
570 if [ "$1" = "-t" ]; then
574 if [ $# -eq 2 ]; then
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- )
587 abort "pkgprefix: $pkg record is to old (no Prefix: entry), please rebuild it."
590 if [ "$dotest" ]; then
591 # test mode: abort or continue
592 if [ "$abortmsg" ]; then
593 echo "pkgprefix: $abortmsg" 1>&2
598 elif [ "$abortmsg" ]; then
599 echo "pkgprefix: $abortmsg" 1>&2
600 elif [ -z "$type" -o "$type" = "prefix" ]; then
603 elif [ "$type" = "ver" ]; then
604 value=$( grep "^Package Name and Version:" "$root/var/adm/packages/$pkg" | cut -d' ' -f6 )
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" )
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
619 local xprefix=${prefix:+/$prefix}
621 bindir) echo "$xprefix/bin" ;;
622 sbindir) echo "$xprefix/sbin" ;;
624 if atstage toolchain; then
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"
634 echo "$xprefix/lib64"
638 echo "$xprefix/lib" ;;
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*}" ;;
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
664 # expand to full path if only a package name was specified
665 [[ $1 == */* ]] || set $base/package/*/$1/
667 # find all files (without hidden (e.g. .svn) files)
668 find . ! -path '*/.*' ! -name '*.cache' -print -exec cat \{\} \; \
670 # strip some unimportant stuff (e.g. comments, whitespaces, ...)
675 -e '/^\[[T,I,U,A,M,L,S,C]\]/d' \
678 md5sum | cut -d ' ' -f 1
682 # Create Package Database for gasgui install tool
684 create_package_db() {
686 for file in $( echo $1/descs/* ); do
687 [ -f "$file" ] || continue
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' ')
697 bfile=${pkg}${v}.$SDECFG_PKGFILE_TYPE
699 if [ -e $2/$bfile ]; then
700 [ "$pkg" = TRANS.TBL ] && continue
705 cat $1/descs/$pkg | grep -v '\[COPY\]'
708 cat $1/dependencies/$pkg
717 echo_error "Binary file for $bfile not present." \
718 "Skipped in package database."
721 gzip -c $3.tmp > $3; rm -f $3.tmp
724 # Add files to the 'badfiles' list
726 register_badfiles() {
731 var_append badfiles $'\n' " $x\$"
732 badfiles_desc[$badfiles_nr]=" $x\$"$'\n'"$desc"
737 # Detect the available patchfiles
742 patchfiles="`ls $confdir/*.patch{,.$arch} \
743 $confdir/*.patch_$xpkg{.$arch} \
744 2> /dev/null | tr '\n' ' '`"
747 var_append patchfiles ' ' "`ls $confdir/*.patch.cross0{,.$arch} \
748 2>/dev/null | tr '\n' ' '`"
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"
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' ' '`"
770 # Apply the given $patchfiles
771 # [ hook called for each patch ] [ filter script ]
776 [ "$filter" ] || filter=cat
777 for x in $patchfiles; do
778 # correct the abolute path - e.g for patchfiles supplied
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"
787 if [[ $x = *.zst ]]; then
788 patch_file=`mktemp`; patch_del=1
789 zstdcat $x > $patch_file
791 patch_file=$x; patch_del=0
794 $filter $patch_file | patch $patchopt
796 [ $patch_del = 1 ] && rm $patch_file
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
817 echo "Extracting $xsrctar ($zipopt) ... "
818 unzip $zipopt $1 | sed 's,^.*/$,,' |
819 cut -f4 -d" " | grep -v "^$" > untar.txt
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
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'!"
842 xsourceballs="$srctar"
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" )
850 xsourceballs="$srctar"
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
858 if [ -z "$custextract" ]; then
859 # No custom extraction, so determine what
860 # autoextraction to use.
862 *.zip) custextract="autoextract_zip" ;;
863 *.7z) custextract="autoextract_7z" ;;
864 *) custextract="autoextract_tar_bz2" ;; # *.tar.bz2|*.tbz2|*.tbz
867 if [ -n "$custextract" ]; then
868 # Do the actual extraction of the archive.
869 eval "$custextract $archdir/$xsrctar"
871 sed 's,^\./,,' | cut -f1 -d/ |
872 sort -u > xsrcdir.txt
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 )"
886 [ -d "$x" ] && xsrcdir="$x"
893 if [ "$chownsrcdir" = 1 ]; then
894 echo "Fixing ownership and permissions ..."
895 chown -R 0:0 $builddir/$xsrcdir
898 if [ "$nocvsinsrcdir" = 1 ]; then
899 echo "Removing CVS, .svn, {arch} and .arch-ids directories ..."
900 egrep '(^|/)(CVS|\.svn|\{arch\}|\.arch-ids)(/|$)' untar.txt |
902 echo "Removing $x ..."
907 echo "Changeing into $builddir/$xsrcdir ..."
908 cd $builddir/$xsrcdir
912 if [ $autopatch = 1 ]; then
922 if [ "$createprefix" = 1 ]; then
923 echo "Creating $root/$prefix/<..> if required ..."
924 for x in $foodirlist; do
925 eval "x=\"$root\$$x\""
928 rmemptydir="$rmemptydir $x"
933 if [ ".$custmain" = "." ]
937 # Maybe generate a configure first
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 )
946 echo "Running builtin autogen script"
947 libtoolize --force --automake
948 aclocal $ACLOCAL_FLAGS
949 if grep AM_INIT_AUTOMAKE \
951 then automake --add-missing; fi
955 # Run configure scripts etc.
957 if [ "$runconf" = 1 ]; then
958 if [ -n "$( type -p $configscript )" -o "$autogen" = 1 ]
960 eval_config_command $( eval echo $confopt )
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"
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)
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}"
989 eval ${pyscript:-python} setup.py build install $pyconfopt
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"
998 eval echo "Running meson $mesonopt"
999 eval "meson $mesonopt"
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
1005 elif [ -f build.zig -a $runzig = 1 ]; then # some projects still use makefile
1007 zigconfopt="${zigconfopt:=--prefix $root/$prefix}"
1008 eval "zig build $zigconfopt"
1010 eval "zig build install"
1012 elif [ -f META6.json -a $runzef = 1 ]; then
1014 var_append zefopt " " "--force-install --/depends --/test-depends --/build-depends"
1015 var_append zefopt " " "--install-to=inst#$root/$prefix/share/perl6/site"
1017 eval echo "Running zef install . $zefopt"
1018 eval "zef install . $zefopt"
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}
1026 if [ ! -f Makefile -a ! -f makefile -a \
1027 -f Imakefile -a $runxmkmf = 1 ]; then
1034 if [ "$makeopt" ]; then
1035 eval echo "Running $MAKE $makeopt"
1036 eval "$MAKE $makeopt"
1039 if [ "$makeinstopt" ]; then
1040 eval echo "Running $MAKE $makeinstopt"
1041 eval "$MAKE $makeinstopt"
1046 echo_warning "The use of custmain is deprecated, please use hooks instead."
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 ..."
1056 if [ "$createdocs" != 0 ]; then
1057 if [ ! -e $root$docdir ]; then
1059 rmemptydir="$rmemptydir $root$docdir"
1061 [ -z "$createdocs" ] && createdocs="$SDECFG_CREATE_DOCS"
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
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`
1079 if [ -d "$x" -a "`echo $x/*`" != "$x/*" ]
1080 then cp -rLv $x/* $root$docdir || true; fi
1082 for x in $confdir/*.doc; do
1084 then cp -v $x $root$docdir/${x%.doc}; fi
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
1094 if atstage native && [ -f /sbin/ldconfig ]; then
1095 echo "Running ldconfig"
1098 patchfiles="$saved_patchfiles"
1101 if [ "$rmemptydir" ]; then
1102 rmdir $rmemptydir 2> /dev/null || true
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)
1115 local pre="" file="$2" url="$3" mirror="mirror"
1117 # '-' as $url prefix means, nomirrorable
1118 [ "${url:0:1}" == "-" ] && mirror="local"
1120 # inside Build-Pkg $archdir is set
1121 if [ -n "$archdir" ]; then
1122 pre=$base/; file="$( bz2filename $file )"
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=
1141 -p) showpath=1; shift ;;
1143 *) break ;; # no abort as the pattern might start with a '-'
1148 for package in ${*:-$pkg}; do
1149 while read x x file url x; do
1150 [ $bz2 = 1 ] && file="$( bz2filename $file )"
1153 if [ $showpath -eq 0 ]; then
1156 [ "${url:0:1}" == "-" ] && mirror="local" || mirror="mirror"
1157 echo $base/download/${mirror}/${file:0:1}/$file
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
1169 # create the virtual $archdir symlinks
1174 for x in `match_source_file -p .`; do
1175 if [ ! -f $x ]; then
1176 echo_warning "File not found: ${x#$base/}"
1178 elif [ ! -e "$builddir/archdir/${x##*/}" ]; then
1179 ln -vs $x $builddir/archdir/
1182 if [ $missing -eq 1 ]; then
1183 echo_warning "Did you run scripts/Download for this package?"
1188 # search for the package 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
1201 x=${x#package/}; x=${x%%/*}
1202 confdir="$base/package/$x/$pkg"
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"'
1223 makeopt="$makeopt"' prefix="/$prefix" docdir="$docdir"'
1224 cmakeopt='-DCMAKE_INSTALL_PREFIX="/$prefix -DCMAKE_LIBRARY_PATH=$libdir"'
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"'
1235 if atstage native; then
1236 flistdel="$flistdel|`echo $base | sed s,^/,,`/.*"
1239 if atstage cross; then
1240 # everyting non-DESTDIR is passed in the specific packages
1241 makeinstopt="$makeopt"' DESTDIR="$root" install'
1243 makeinstopt="$makeopt"' install'
1248 [ "$SDECFG_DO_CHECK" = 1 ] && hook_add inmake 6 'run_check'
1249 [ "$SDECFG_STATIC_IN_USR" = 1 ] && hook_add postflist 3 'postflist_static_lib'
1253 configprefix=""; autogen=
1254 configscript="./configure"; extraconfopt=""
1255 cmakelists="./CMakeLists.txt"
1257 srcdir=auto; srctar=auto
1258 taropt="--use-compress-program=zstd -xf"
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=""
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
1286 pkg="$1"; xpkg="$pkg"
1287 conffile="$2"; [ "$conffile" ] || conffile="$pkg.conf"
1290 declare -a hook_functions='()'
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.
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
1312 if [[ $x == */$conffile ]]; then
1313 echo "Reading package configuration ($conffile) from package directory."
1315 echo "Reading package configuration from $x."
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."
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'"
1339 eval "$mainfunction"
1342 [ -f $logstamp ] || return 1