# --- SDE-COPYRIGHT-NOTE-BEGIN --- # This copyright note is auto-generated by ./scripts/Create-CopyPatch. # # Filename: lib/functions.in # Copyright (C) 2006 - 2007 The OpenSDE Project # Copyright (C) 2004 - 2006 The T2 SDE Project # Copyright (C) 1998 - 2003 Clifford Wolf # # More information can be found in the files COPYING and README. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. A copy of the # GNU General Public License can be found in the file COPYING. # --- SDE-COPYRIGHT-NOTE-END --- . lib/core-functions.in # This function returns a "uniqe id" as output # get_unique() { local hostsum=`hostname 2>/dev/null | tr '()' _` if [ -z "$hostsum" -a -x /sbin/ip ]; then hostsum=`/sbin/ip link show eth0 | sed -e '/link\//!d' -e 's,.*link[^ ]* \([^ ]*\) .*,\1,'` fi if [ -z "$hostsum" -a -f /sbin/ifconfig ]; then hostsum=`/sbin/ifconfig eth0 | sed -e '/HWaddr/!d' -e 's/.* HWaddr \([^ ]*\)/\1/'` fi if [ -z "$hostsum" -a -x /usr/bin/hostid ]; then hostsum=`/usr/bin/hostid` fi date "+%Y%m%d.%H%M%S.$$.$hostsum" } # this functions expands an string replacing % with all possible values # listed after case "$BASH_VERSION" in # damn workaround for different syntax in both versions 2*) get_expanded() { local string="$1"; shift while [ $# -gt 0 ]; do echo "${string//\\%/$1}" shift done } ;; 3*) get_expanded() { local string="$1"; shift while [ $# -gt 0 ]; do echo "${string//\%/$1}" shift done } ;; esac # atstage ... # returns true if the build is on a stage related to the given name # atstage() { local x= for x; do case "$x" in toolchain) [ $stagelevel -gt 0 ] || return 0 ;; cross|crossbuild|crosscompile) [ $stagelevel -ne 1 ] || return 0 ;; rebuild) [ $stagelevel -ne 9 ] || return 0 ;; native) [ $stagelevel -lt 2 ] || return 0 ;; *) echo "atstage: '$x' stagename is not supported." >&2 break ;; esac done return 1 } # hasflag FLAG # hasflag() { [ "$desc_F" != "${desc_F/$1}" ] } # bz2filename [] # outputs filename converted to .bz2. stdin and $1 inputs are accepted # bz2filename() { local pattern='-e s,\.\(t\?\)\(gz\|Z\)$,.\1bz2,' pattern="-e s,\.gpg$,, $pattern" pattern="-e s,\.tar$,\.tar.bz2, $pattern" if [ -n "$1" ]; then echo "$1" | sed $pattern else sed $pattern fi } # Hook variables # unset hook_functions hook_fcounter declare -a hook_functions='()' hook_fcounter=0 # This function adds a code fragment to a named hook with the named priority # # hook_add hook_name priority code # hook_add() { hook_functions[hook_fcounter]="$3" # declare -a hookidx_$1 eval "hookidx_$1[\${#hookidx_$1[@]}]=\"$2 $hook_fcounter\"" eval "(( hookdirty_$1++ ))" || true ; (( hook_fcounter++ )) || true } # This function executes all code fragments from the named hook # # hook_eval hook_name # hook_eval() { while read pri fnr ; do [ "$pri" ] && eval "${hook_functions[fnr]}" done < <( IFS=$'\n' ; eval "echo \"\${hookidx_$1[*]}\"" | sort ) eval "unset hookdirty_$1" } # This function prints all hooks and their current contents # # hook_dump # hook_dump() { for hook in ${!hookidx_*} ; do hook=${hook#hookidx_} echo ; echo "Contents of hook $hook:" while read pri fnr ; do echo ; echo " $pri ($fnr)" echo "${hook_functions[fnr]}" | sed 's,^, ,' done < <( IFS=$'\n' eval "echo \"\${hookidx_$hook[*]}\"" | sort ) if eval "[ -n \"\$hookdirty_\$hook\" ]"; then echo ; echo -n " Hook is marked as dirty: " eval "echo \"\${hookdirty_$hook}\"" fi done echo } # This function can be used to duplicate a shell-function. E.g. when # overwriting a shell-function but the old one should stay available under # a new name: # # copy_function set_confopt set_confopt_foobar_old # # set_confopt() { # .... # set_confopt_foobar_old "$@" # .... # } # copy_function() { eval "$( declare -f $1 | sed "1 s,$1,$2," )" } # | column_clean | # # convert tabs to spaces, transform multiple consecutive spaces to one, # remove leading and trailing spaces column_clean() { tr '\t' ' ' | tr -s ' ' | sed -e 's,^[ ]*,,; s,[ ]*$,,;' } # | column_clean_tab | # # see column_clean, but with tabs column_clean_tab() { tr ' ' '\t' | tr -s '\t' | sed -e 's,^[\t]*,,; s,[\t]*$,,;' } # This function sets the 'confopt' and some other variables. # Re-run it in the package .conf file if you modify $prefix # set_confopt() { local x= z= prefix=${prefix#/} if atstage toolchain; then z="$root" fi confopt="--prefix=$z/$prefix" for x in bindir sbindir libdir datadir includedir \ docdir infodir mandir sysconfdir localstatedir do # bindir=/usr/bin eval "$x=`pkggetdir $x`" # --bindir=$root\$bindir confopt="$confopt --$x=$z\$$x" done export LIBSUFF=${libdir##*/lib} if [ "$SDECFG_CONFIGURE_OPTS" ] ; then confopt="$confopt $SDECFG_CONFIGURE_OPTS" fi if [ "$SDECFG_DEBUG" = 0 ] ; then confopt="$confopt --disable-debug" fi if ! atstage native || [ "$SDECFG_DISABLE_NLS" = 1 ] ; then confopt="${confopt//--enable-nls/} --disable-nls" fi confopt="$confopt \$extraconfopt" if atstage toolchain; then confopt="$confopt --target=\$arch_target --host=\$arch_build" else confopt="$confopt --build=\$arch_build --host=\$arch_target" fi } # # eval_config_command $( eval echo $confopt ) # function eval_config_command() { local config_command for x in /usr/share/automake/* do [ -x "$x" -a -f "$x" ] || continue x="$( basename "$x" )" if [ -L $x -a ! -e $x ] ; then echo "Fixing dead symlink $x." ln -sf /usr/share/automake/$x . fi done if atstage cross; then create_config_cache >> config.cache grep -q '.--cache-file=' $configscript && set -- "$@" "--cache-file=./config.cache" export cache_file=./config.cache fi config_command="$configprefix $configscript" sub_scripts="$( find $( dirname $configscript ) -name configure )" if [ "$cleanconfopt" == "0" ]; then config_command="$config_command $@" else # remove unsupported config script options for x ; do if grep -q "[[ ]${x%%=*}[]= ):]" $configscript $sub_scripts ; then config_command="$config_command $x" elif [[ $x = --*able-* ]] && egrep -q "\-\-(en|dis)able-\*" $configscript || [[ $x = --with* ]] && egrep -q "\-\-with(|out)-\*" $configscript; then echo "Autodetection for option impossible: " \ "$x passed thru." config_command="$config_command $x" else echo "Removing unsupported '$x' from" \ "configure option string." fi done fi echo Running "$config_command" eval "$config_command" } # run 'make check' if Makefile supports it. # function run_check() { if grep -q -e "^check:" ./Makefile; then echo "Running make check ..." $MAKE check fi if grep -q -e "^test:" ./Makefile; then echo "Running make test ..." $MAKE test fi } # move the static libs from lib to usr/lib and correct the libdir used # inside the .la file # postflist_static_lib() { echo "Processing static lib corrections ..." egrep '^(lib|lib64)/.*\.(a|la)$' $builddir/flist.txt | while read fn ; do [ -e $root/$fn -o -L $root/$fn ] || continue if [[ $fn = *.a ]] ; then mv -fv $root/$fn $root/usr/$fn else sed "s,\([ =']\)/lib\(.*\),\1/usr/lib\2,g" \ $root/$fn > $root/usr/$fn so=${fn%.la}.so ln -svf $root/$so $root/usr/$so add_flist $root/usr/$so rm $root/$fn fi add_flist $root/usr/$fn done # this check might be removed in the future when we decide this is not # an issue anymore ... echo "Verifing the .la files ..." defect_la="`egrep '(lib|lib64)/.*\.la$' $builddir/flist.txt | xargs egrep 'dependency_libs=.*-pthread.*' | cut -d : -f1 | sort -u | tr '\n' ' '`" if [ "$defect_la" ] ; then abort "-pthread in: $defect_la!" fi defect_la="`egrep '(lib|lib64)/.*\.la$' $builddir/flist.txt | xargs egrep "dependency_libs=.*(TOOLCHAIN|BACKUP|$SDECFG_ID).*" | cut -d : -f1 | sort -u | tr '\n' ' '`" if [ "$defect_la" ]; then local la echo_warning "Detected problems in following libtool files:" for la in $defect_la; do echo_warning " $la" done echo_warning "In absence of a proper fix (or replacement) for libtool and friends," echo_warning "for now the .la files are automatically corrected." # Cleanup dependency_libs, remove build system path local dependency_libs local dlibsnew="" local dlibtmp deplib local libsub=${libdir##*/} for la in $defect_la; do eval `grep ^dependency_libs= $root/$la` for deplib in $dependency_libs; do if [ $libsub != lib ]; then case "$deplib" in */lib|*/lib/*) deplib="`echo $deplib | sed "s,/lib$,/$libsub,g; s,/lib/,/$libsub/,g"`" ;; esac fi case "$deplib" in *TOOLCHAIN*|*BACKUP*|*$SDECFG_ID*) ;; *) dlibtmp=$dlibsnew ; var_remove dlibtmp ' ' "$deplib" [ "$dlibtmp" = "$dlibsnew" ] && var_append dlibsnew ' ' "$deplib" ;; esac done sed -i "s,^dependency_libs=.*,dependency_libs='$dlibsnew'," $root/$la dlibsnew= done fi } # Parse the *.desc file. Use the description from etc/desc_format and # save the tag data in $desc_*. # parse_desc() { tag="`grep '^\[' $base/etc/desc_format | sed 's, (\*),,; s,\] \[,|,g; s,\[,,; s,\],,;'`" for tag in $tag ; do tagdata="`egrep "^\[($tag)\]" $confdir/$1.desc | cut -f2- -d']' | sed 's,^ ,,'`" tag="`echo $tag | cut -f1 -d'|' | tr - _`" eval "desc_$tag=\"\$tagdata\"" done ver="`echo "$desc_V" | tail -n 1 | cut -f1 -d' '`" extraver="`echo "$desc_V" | tail -n 1 | cut -s -f2- -d' '`" [ -z "$extraver" ] && extraver="${sdever//DEV-*/DEV}" } # This function is used for forcing a file to be in the flist # add_flist() { for addfile ; do echo "$addfile" | fl_wrparse -D -r "$xroot/" \ >> $builddir/flist.txt done } # This function is used for forcing a package to be in the dependency list # add_dependency() { for addpackage ; do echo "$addpackage: add_dependency()" \ >> $builddir/dependencies.debug done } # This function is used to subsitute some important variables # using a D_ prefix thru m4 ... rock_substitute() { sed -e s,D_prefix,$prefix,g -e s,D_sysconfdir,$sysconfdir,g \ -e s,D_docdir,$docdir,g -e s,D_localstatedir,$localstatedir,g \ -e s,D_datadir,$datadir,g -e s,D_infodir,$infodir,g \ -e s,D_bindir,$bindir,g -e s,D_sbindir,$sbindir,g \ -e s,D_libdir,$libdir,g -e s,D_mandir,$mandir,g \ -e s,D_ver,$ver,g $1 } # This outputs a predefined config.cache file as it needed by some # packages to cross-build correctly in stages 0 and 1. # create_config_cache() { local x= cat $base/scripts/config.cache if [ $createarchcache -eq 1 ]; then cat <<-EOT # Architecture specific stuff\n" arch_sizeof_char=1 ac_cv_sizeof_short=$arch_sizeof_short ac_cv_sizeof_int=$arch_sizeof_int ac_cv_sizeof_long=$arch_sizeof_long ac_cv_sizeof_long_long=$arch_sizeof_long_long ac_cv_sizeof_char_p=$arch_sizeof_char_p ac_cv_sizeof_void_p=$arch_sizeof_char_p ac_cv_c_bigendian=$arch_bigendian EOT fi if [ "$configcache" ]; then cat <<-EOT # And some custom values EOT for x in $configcache; do echo "$x" done fi } # Abort build before actual build starts # (is overwritten in Build-Pkg) # abort() { echo -e "The package build aborted with the following config" \ "error:\n$*" > $root/var/adm/logs/$stagelevel-$xpkg.err echo_errorquote "`cat $root/var/adm/logs/$stagelevel-$xpkg.err`" echo_pkg_abort $stagelevel $repository $xpkg exit 1 } # Dump Environment # dump_env() { # Dump $base - only set if there is not already an older value. # echo "base=\"\${base:-$base}\"" # Dump all variables including their flags, but skip read-only # variables and $base. # # Substitute base directory with ${base}. # for name in ${!a*} ${!b*} ${!c*} ${!d*} ${!e*} ${!f*} ${!g*} ${!h*} \ ${!i*} ${!j*} ${!k*} ${!l*} ${!m*} ${!n*} ${!o*} ${!p*} \ ${!q*} ${!r*} ${!s*} ${!t*} ${!u*} ${!v*} ${!w*} ${!x*} \ ${!y*} ${!z*} \ ${!A*} ${!B*} ${!C*} ${!D*} ${!E*} ${!F*} ${!G*} ${!H*} \ ${!I*} ${!J*} ${!K*} ${!L*} ${!M*} ${!N*} ${!O*} ${!P*} \ ${!Q*} ${!R*} ${!S*} ${!T*} ${!U*} ${!V*} ${!W*} ${!X*} \ ${!Y*} ${!Z*} ${!_*} do [ $name = base -o $name = PWD ] && continue if declare -p $name | head -n 1 | grep -qv '^declare -[a-z]*r' then declare -p $name | sed "s,\\(^\\|[\"=:]\\)$base\\([\"=:/]\\|\$\\),\\1\${base}\\2,g" fi done # Dump functions # declare -f | sed 's/^declare -f //; s/<<(/< <(/;' # Dump aliases # alias } # Returns the value of a field of the .desc file of a package # pkgdesc() { local pattern= local descfile=$( ls -1d $base/package/*/$2/$2.desc 2> /dev/null ) case "$1" in ver) pattern="V" ;; *) pattern="$1" ;; esac if [ -s "$descfile" ]; then sed -n "s,^\[$pattern\] \(.*\)$,\1,p" "$descfile" else echo_error "pkgdesc: Package $2 not found." fi } # Check if a package is already installed # # It does check the build-list if not in the rebuild stage - and # the really installed package data for rebuilds (and so manual builds). # # space delimited list, -f as first arguent for effective check # pkginstalled() { local effective=0 if [ $# -eq 0 ]; then return 1 # nothing elif [ "$1" == "-f" ]; then effective=1; shift elif atstage rebuild; then effective=1 fi if [ $effective -eq 0 ]; then local pattern= [ $# -gt 0 ] || return 1 # we expect at least one package if [ $# -eq 1 ]; then pattern="$1" else pattern="($@)" fi pattern="${pattern//+/\\+}" egrep -q "^X.* ${pattern// /|} " $base/config/$config/packages # we return what egrep returns else local pkg= # be happy if any package from the list is installed for pkg; do [ ! -f "$root/var/adm/packages/$pkg" ] || return 0 done return 1 fi } # pkgprefix [-t] [] # returns the prefix or the location of a 'type' of an already build package # pkgprefix() { local type= pkg= local dotest= abortmsg= local prefix= value= # -t : only see if it's possible to get the values if [ "$1" = "-t" ]; then dotest=1; shift fi if [ $# -eq 2 ]; then type="$1"; shift fi pkg="$1" # test usual error causes if [ -z "$pkg" ]; then abortmsg="you must specify a package" elif [ ! -f "$root/var/adm/packages/$pkg" ]; then abortmsg="package $pkg is not present" elif grep -q "^Prefix:" "$root/var/adm/packages/$pkg"; then prefix=$( grep "^Prefix: " "$root/var/adm/packages/$pkg" | cut -d' ' -f2- ) else abortmsg=`echo "$pkg record is old, please rebuild the package $pkg. As an alternative, you can insert a line into the file $root/var/adm/packages/$pkg containing the text below:\n\nPrefix: " | fmt -w 55 | sed 's,$,\\n,g'` fi if [ "$dotest" ]; then # test mode: abort or continue if [ "$abortmsg" ]; then abort "pkgprefix: $abortmsg" else return 0 fi elif [ "$abortmsg" ]; then echo "pkgprefix: $abortmsg" 1>&2 elif [ -z "$type" -o "$type" = "prefix" ]; then echo "$prefix" return 0 elif [ "$type" = "ver" ]; then value=$( grep "^Package Name and Version:" "$root/var/adm/packages/$pkg" | cut -d' ' -f6 ) else value=$( grep "^Location $type: " "$root/var/adm/packages/$pkg" | cut -d' ' -f3- ) if [ -z "$value" ]; then # try default location for that $prefix value=$( xpkg="$pkg"; pkggetdir "$type" ) fi fi echo "${value:-PKGPREFIX_ERROR}" } # pkggetdir (needs $prefix and $xpkg) # returns the location for the file of a 'type' considering it's prefix # pkggetdir() { local xprefix=${prefix:+/$prefix} case "$1" in bindir) echo "$xprefix/bin" ;; sbindir) echo "$xprefix/sbin" ;; libdir) if [ "$SDECFG_MULTILIB" = 1 ]; then case $arch_machine in powerpc64|sparc64|x86_64|mips64) echo "$xprefix/lib64" ;; *) echo "$xprefix/lib" ;; esac else echo "$xprefix/lib" fi ;; datadir) echo "${xprefix:-/usr}/share" ;; infodir) echo "${xprefix:-/usr}/info" ;; mandir) echo "${xprefix:-/usr}/man" ;; docdir) echo "${xprefix:-/usr}/doc/$xpkg" ;; includedir) echo "${xprefix:-/usr}/include" ;; sysconfdir) echo "/etc${xprefix##/usr*}" ;; localstatedir) echo "/var${xprefix##/usr*}" ;; esac } # This function generates the T2 package checksum of $confdir. # The checksum includes the filenames and content (except of the .cache), # including subdirs but without whitespaces and comments and some tag lines # that are not vital for rebuilds during update checks. # # pkgchksum package-name | full-patch # pkgchksum() { ( # expand to full patch if only a package name was specified [[ $1 == */* ]] || set $base/package/*/$1/ cd $1 # find all files (without hidden (e.g. .svn) files) find . ! -path '*/.*' ! -name '*.cache' -print -exec cat \{\} \; \ 2>/dev/null | # strip some unimportant stuff (e.g. comments, whitespaces, ...) sed \ -e '/^[ ]*#.*/d' \ -e '/^\[COPY\]/d' \ -e '/^\[CV-*\]/d' \ -e '/^\[[T,I,U,A,M,L,S,C]\]/d' \ -e 's/[\t ]*//g' \ -e '/^ *$/d' | md5sum | cut -d ' ' -f 1 ) } # Create Package Database for gasgui install tool # create_package_db() { rm -f $3.tmp for file in $( echo $1/descs/* ) ; do [ -f "$file" ] || continue pkg="${file##*/}" # only include the package if a binary file is available if [ "$SDECFG_PKGFILE_VER" = 1 ] ; then v=-$(grep '^Package Name and Version' \ $1/packages/$pkg | cut -f6 -d' ') else v="" fi bfile=${pkg}${v}.$SDECFG_PKGFILE_TYPE if [ -e $2/$bfile ] ; then [ "$pkg" = TRANS.TBL ] && continue ( echo -e "$pkg" echo -e "\027" cat $1/descs/$pkg | grep -v '\[COPY\]' echo -e "\027" cat $1/dependencies/$pkg echo -e "\027" cat $1/cksums/$pkg echo -e "\027" echo -e "\004" ) >> $3.tmp else echo_error "Binary file for $bfile not present." \ "Skipped in package database." fi done gzip -c $3.tmp > $3 ; rm -f $3.tmp } # Add files to the 'badfiles' list # register_badfiles() { local x desc="$1" shift for x in "$@"; do var_append badfiles $'\n' " $x\$" badfiles_desc[$badfiles_nr]=" $x\$"$'\n'"$desc" (( badfiles_nr++ )) done } # Detect the available patchfiles # detect_patchfiles() { local x= y= patchfiles="`ls $confdir/*.patch{,.$arch} \ $confdir/*.patch_$xpkg{.$arch} \ 2> /dev/null | tr '\n' ' '`" for x in $( get_reverted $targetchain ); do for y in pkg_$pkg.patch{,.$arch} xpkg_$xpkg.patch{,.$arch}; do if [ -f $base/target/$x/$y ]; then patchfiles="$patchfiles $base/target/$x/$y" fi done done } # Apply the given $patchfiles # [ hook called for each patch ] [ filter script ] # apply_patchfiles() { local hook="$1" local filter="$2" [ "$filter" ] || filter=cat for x in $patchfiles; do # correct the abolute path - e.g for patchfiles supplied # in the .desc file # we assume relative path patches are mirrorables //mnemoc if [ ! -e "$x" -a -n "${x##*/*}" ] ; then x="$base/download/mirror/${x:0:1}/$x" fi echo "Apply patch $x ..." if [[ $x = *.bz2 ]] ; then patch_file=`mktemp` ; patch_del=1 bzcat $x > $patch_file else patch_file=$x ; patch_del=0 fi $filter $patch_file | patch $patchopt [ $patch_del = 1 ] && rm $patch_file eval "$hook" done } # ------------------------------------------------------------------- # The automatic extraction of archive (prior to building) supports # multiple archive types. For every archive type we have a separate # func that knows how to extract the archive. However, every func # should deliver two file: untar.txt and xsrcdir.txt. # # untar.txt needs to contain all extracted files. # xsrcdir.txt need to contain the top level extraction directories. # ------------------------------------------------------------------- autoextract_tar_bz2() { echo "Extracting $xsrctar ($taropt) ... " tar -v $taropt $1 > untar.txt } autoextract_zip() { echo "Extracting $xsrctar ($zipopt) ... " unzip $zipopt $1 | sed 's,^.*/$,,' | cut -f4 -d" " | grep -v "^$" > untar.txt } # Main program for building a package # build_this_package() { if [ ".$desc_SRC" == "." ] ; then # Autodetect source tar and extract it # if [ "$srctar" = auto ] ; then xsourceballs=$( echo "$desc_D" | head -n 1 | tr ' ' '\t' | tr -s '\t' | cut -f2 | bz2filename ) if [ -z "$xsourceballs" ] ; then echo "Can't auto-detect srctar for package '$xpkg'!" false fi else xsourceballs="$srctar" fi elif [ "$srctar" = auto ] ; then sourceballs=$( echo "$desc_D" | tr ' ' '\t' | tr -s '\t' | cut -f2 | bz2filename ) xsrcpattern=$( echo "$desc_SRC" | tr ' ' '\t' | tr -s '\t' | tr '\t' '\n' ) xsourceballs=$( echo "$sourceballs" | grep -F "$xsrcpattern" ) else xsourceballs="$srctar" fi for xsrctar in $xsourceballs; do saved_patchfiles="$patchfiles" buildloop=1 var_append patchfiles " " \ "`ls $confdir/*.patch.${xsrctar/-[v0-9]*/} 2> /dev/null`" if [ "$xsrctar" != none -a "$autoextract" = 1 ]; then cd $builddir if [ -z "$custextract" ]; then # No custom extraction, so determine what # autoextraction to use. case "$xsrctar" in *.zip) custextract="autoextract_zip" ;; *) custextract="autoextract_tar_bz2" ;; # *.tar.bz2|*.tbz2|*.tbz esac fi if [ -n "$custextract" ]; then # Do the actual extraction of the archive. eval "$custextract $archdir/$xsrctar" cat untar.txt | sed 's,^\./,,' | cut -f1 -d/ | sort -u > xsrcdir.txt fi # if [ "$srcdir" = auto ]; then xsrcdir=${xsrctar%.tar.bz2} xsrcdir=${xsrcdir%.tbz2} xsrcdir=${xsrcdir%.tbz} if [ ! -d $xsrcdir ] ; then for x in $pkg-$ver ${pkg}_$ver $pkg \ $xpkg-$ver ${xpkg}_$ver $xpkg \ "$( cat xsrcdir.txt )" do [ -d "$x" ] && xsrcdir="$x" done fi else xsrcdir="$srcdir" fi # if [ "$chownsrcdir" = 1 ]; then echo "Fixing ownership and permissions ..." chown -R 0:0 $builddir/$xsrcdir fi # if [ "$nocvsinsrcdir" = 1 ]; then echo "Removing CVS, .svn, {arch} and .arch-ids directories ..." egrep '(^|/)(CVS|\.svn|\{arch\}|\.arch-ids)(/|$)' untar.txt | while read x; do echo "Removing $x ..." rm -rf "$x" done fi # echo "Changeing into $builddir/$xsrcdir ..." cd $builddir/$xsrcdir # Apply patches # if [ $autopatch = 1 ]; then hook_eval prepatch apply_patchfiles hook_eval postpatch fi else cd $builddir fi if [ "$createprefix" = 1 ]; then echo "Creating $root/$prefix/<..> if required ..." for x in $foodirlist; do eval "x=\"$root\$$x\"" if [ ! -e $x ]; then mkdir -p $x rmemptydir="$rmemptydir $x" fi done fi if [ -z "$custmain" ]; then while [ ${buildloop:-1} -le ${buildloops:-1} ]; do [ "${buildloops:-1}" == "1" ] || echo "loop ${buildloop:-1} of ${buildloops:-1} for $xsrctar." hook_eval preconf # Maybe generate a configure first # if [ $autogen -eq 1 -o \ \( -f autogen.sh -a ! -f configure \) ] ; then if [ -f autogen.sh ] ; then echo "Running package autogen script." sed -i '/^\.\/configure /d' autogen.sh sh autogen.sh else echo "Running builtin autogen script." libtoolize --force --automake ; aclocal if grep AM_INIT_AUTOMAKE \ configure.[ia][nc] then automake ; fi autoconf fi fi # Run configure scripts etc. # if [ $runconf = 1 ]; then if [ -n "$( type -p $configscript )" -o $autogen = 1 ] then eval_config_command $( eval echo $confopt ) fi fi # automated package build # styles without make run first: if [ -f setup.py -a $runpysetup = 1 ] ; then pyconfopt="${pyconfopt:=--prefix $root/$prefix}" hook_eval premake eval ${pyscript:-python} setup.py build install $pyconfopt hook_eval postmake else # styles that include a make run if [ ! -f Makefile -a ! -f makefile -a \ -f Makefile.PL -a $runmkpl = 1 ]; then perl Makefile.PL ${plconfopt:-INSTALLDIRS=perl} fi # if [ ! -f Makefile -a ! -f makefile -a \ -f Imakefile -a $runxmkmf = 1 ]; then xmkmf -a fi # # Build it # hook_eval premake if [ "$makeopt" ]; then eval echo "Running $MAKE $makeopt" eval "$MAKE $makeopt" fi hook_eval inmake if [ "$makeinstopt" ]; then eval echo "Running $MAKE $makeinstopt" eval "$MAKE $makeinstopt" fi hook_eval postmake fi buildloop=$( expr ${buildloop:-1} + 1 ) done else eval "$custmain" for x in preconf premake inmake postmake; do if eval "[ -n \"\$hookdirty_$x\" ]"; then echo "Hook $x is still marked as dirty ..." hook_eval $x fi done fi if [ "$createdocs" != 0 ]; then if [ ! -e $root$docdir ]; then mkdir -p $docdir rmemptydir="$rmemptydir $root$docdir" fi [ -z "$createdocs" ] && createdocs="$SDECFG_CREATE_DOCS" fi if [ "$createdocs" = 1 ]; then echo "Trying to copy the default documentation ..." for x in [A-Z][A-Z]* *.lsm ChangeLog* README LICENSE COPYING; do [ "${x#*.[cho0-9]}" ] || continue [ "${x#*.info*}" ] || continue [ "${x#*.TAR*}" ] || continue [ "${x#*akefile*}" ] || continue [ -f $x ] && cp -v $x $root$docdir/$x done echo "Trying to copy even more documentation ..." [ -d $builddir/$xsrcdir ] && cd $builddir/$xsrcdir for x in `find -type d \( -name 'doc' -o -name 'docs' \ -o -name '[Dd]ocumentation' \) ! -empty` do if [ -d "$x" -a "`echo $x/*`" != "$x/*" ] then cp -rLv $x/* $root$docdir || true ; fi done for x in $confdir/*.doc; do if [ -f $x ] then cp -v $x $root$docdir/${x%.doc}; fi done find $root$docdir/ -name '*.[0-9]' -o -name '*.info*' \ -o -name '[Mm]akefile*' | xargs -r rm -f 2> /dev/null || true find $root$docdir/* -type d -empty 2> /dev/null | xargs -r rmdir 2> /dev/null || true fi hook_eval postdoc if atstage native && [ -f /sbin/ldconfig ] ; then echo "Running ldconfig ..." ldconfig fi patchfiles="$saved_patchfiles" done if [ "$rmemptydir" ]; then rmdir $rmemptydir 2> /dev/null || true fi return 0 } # source_file cksum file url # # Create the file path from 'file' and 'url'. # cksum and url are ignored # ([D] tag compatible format) # source_file() { local pre="" file="$2" url="$3" mirror="mirror" # '-' as $url prefix means, nomirrorable [ "${url:0:1}" == "-" ] && mirror="local" # inside Build-Pkg $archdir is set if [ -n "$archdir" ]; then pre=$base/; file="$( bz2filename $file )" fi echo ${pre}download/${mirror}/${file:0:1}/$file } # match_source_file [-p] pattern [[package] ...] # # returns path and name of a downloaded file from a list of packages, matching a grep pattern # without -p it only returns it's name, not the path. # match_source_file() { local pattern= package= showpath=0 local x= file= url= mirror= local found=1 if [ "$1" == "-p" ]; then showpath=1; shift fi pattern="$1"; shift for package in ${*:-$pkg}; do while read x x file url x; do file="$( bz2filename $file )" found=0 if [ $showpath -eq 0 ]; then echo $file else [ "${url:0:1}" == "-" ] && mirror="local" || mirror="mirror" echo $base/download/${mirror}/${file:0:1}/$file fi done < <( grep -e "^\[D\].*$pattern" $base/package/*/$package/$package.desc ) done return $found } # create the virtual $archdir symlinks # populate_archdir() { local x= missing=0 for x in `match_source_file -p .`; do if [ ! -f $x ]; then echo_warning "File not found: ${x#$base/}" missing=1 elif [ ! -e "$builddir/archdir/${x##*/}" ]; then ln -vs $x $builddir/archdir/ fi done if [ $missing -eq 1 ]; then echo_warning "Did you run ./scripts/Download for this package?" false fi } # search for the package confdir # detect_confdir() { confdir="" if [ -z "$pkgdir" ] ; then for x in package/*/$pkg/$pkg.desc ; do if [ -f "$x" ] ; then if [ "$confdir" ] ; then echo_pkg_deny $stagelevel $pkg "in multiple trees" echo "Package in multiple trees: $pkg !" \ > $root/var/adm/logs/$stagelevel-$xpkg.err exit 1 fi x=${x#package/}; x=${x%%/*} confdir="$base/package/$x/$pkg" repository=$x fi done else if [ -f "$pkgdir/$pkg.desc" ] ; then confdir="$pkgdir" repository=extern fi fi } # initialize standard vars and hooks # init_vars_and_hooks() { makeopt='CC="$CC" CPP="$CPP" CXX="$CXX"' if atstage toolchain; then makeopt="$makeopt"' prefix="$root/$prefix"' else makeopt="$makeopt"' prefix="/$prefix"' fi if ! atstage native; then makeopt="$makeopt"' CC_FOR_BUILD="$BUILDCC"' makeopt="$makeopt"' BUILDCC="$BUILDCC" BUILD_CC="$BUILD_CC"' makeopt="$makeopt"' HOSTCC="$HOSTCC" HOST_CC="$HOST_CC"' makeopt="$makeopt"' STRIP="$STRIP" AR="$AR" LD="$LD"' makeopt="$makeopt"' RANLIB="$RANLIB" NM="$NM"' fi if atstage native; then flistdel="$flistdel|`echo $base | sed s,^/,,`/.*" fi if atstage cross; then makeinstopt="$makeopt"' DESTDIR="$root" DEST_DIR="$root"' makeinstopt="$makeinstopt"' INSTROOT="$root" INSTALLROOT="$root" install' else makeinstopt="$makeopt"' install' fi custmain="" buildloop=1 buildloops=1 [ "$SDECFG_DO_CHECK" = 1 ] && hook_add inmake 6 'run_check' hook_add postflist 3 'postflist_static_lib' createarchcache=0 configprefix=""; configcache="" ; autogen=0 configscript="./configure" ; extraconfopt="" srcdir=auto ; srctar=auto taropt="--use-compress-program=bzip2 -xf" mainfunction="build_this_package" runconf=1 ; runxmkmf=1 ; runmkpl=1 ; runpysetup=1 ; autopatch=1 autoextract=1 ; chownsrcdir=1 ; nocvsinsrcdir=1 ; cleanconfopt=1 patchopt="-bfp1 -z .orig" createprefix=1 ; createdocs="" ; rmemptydir="" check_shared=1 check_usrlocal=1 check_badfiles=1 badfiles="" badfiles_nr=0 declare -a badfiles_desc } # this is a 2nd lightweight and modular "build this package" implementation # currently only used for the postlinux stuff - later maybe for more -ReneR # build_package() { logstamp=$PWD/log ( set -e pushd $base super=$pkg pkg="$1" ; xpkg="$pkg" conffile="$2" ; [ "$conffile" ] || conffile="$pkg.conf" unset ${!hook*} declare -a hook_functions='()' hook_fcounter=0 init_vars_and_hooks detect_confdir detect_patchfiles parse_desc $pkg # Erase positional parameters to prevent unintended parameter # passing. We do not want to pass the current positional parameters # to the loaded script. set -- eval "$desc_O" echo_status "Building $xpkg ($ver) within $super (using $conffile)." for x in $( get_expanded $base/target/%/pkg_$pkg.conf $targetchain ) \ $confdir/$conffile; do if [ -f $x ]; then if [[ $x == */$conffile ]]; then echo "Reading package configuration ($conffile) from package directory." else echo "Reading package configuration from target directory." fi . $x break fi done # short path - to not abort on missing downloads of postlinux.conf # packages that are not built anyway -ReneR if [ "$custmain" = "true" ] ; then echo "Nothing is going to be done ayway - returning quickly." return fi populate_archdir popd # dump for debugging hook_dump > $builddir/debug.hooks.$pkg dump_env > $builddir/debug.buildenv.$pkg echo "Running main build function '$mainfunction' ..." cd $builddir eval "$mainfunction" touch $logstamp ) [ -f $logstamp ] || return 1 rm $logstamp return 0 }