#!/bin/sh # pwbuilder: builder.defs - kit for building Slackware packages # Copyright (c) 2002 Jaroslaw Swierczynski # 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; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # You should find the copy of GNU General Public License in file # /usr/doc/pwbuilder-*/COPYING. if [ "$nocolor" = "y" ]; then white_on="*** " white_off=" ***" red_on="*** " red_off=" ***" else white_on="" white_off="" red_on="" red_off="" fi pw_ver="0.5.13" if [ ! "$build_number" = "" ]; then build="$build_number" fi echo -e "\n${white_on}pwbuilder $pw_ver${white_off}" echo "${white_on}TGZ packages building system${white_off}" echo "${white_on}Copyright (c) 2002 Jaroslaw Swierczynski ${white_off}" echo -ne "\n${white_on}Building $title version $version build $build for " if [ "$noarch" = "y" ]; then echo "noarch." else echo "$target_architecture." fi if [ "$automatic" = "y" ]; then echo -e "Using default compile-time options.${white_off}\n" else echo -e "You may be asked for some compile-time options.${white_off}\n" fi tmp="/tmp/builder-$name-$RANDOM" pkg_main="$tmp/packages/main" doc_dir="$pkg_main/usr/doc/$name-$version" cwd="`pwd`" src_tgz=`dirname "$sources_dir"` if [ "$src_tgz" = "." ]; then src_tgz="/usr/src/tgz" fi src_pkg="$src_tgz/sources/$name" src_cnt="1" parent_name="$name" p_suffix="" langs="bg ca cs da de el es et fr gl he hr hu it ja nl no pl pt_BR ru sk sl sv tr uk zh_TW" if [ "$noarch" = "y" ]; then architecture="noarch" else architecture="$target_architecture" if [ "$architecture" = "i486" -o \ "$architecture" = "i586" -o \ "$architecture" = "i686" -o \ "$architecture" = "pentium" -o \ "$architecture" = "pentium-mmx" -o \ "$architecture" = "pentiumpro" -o \ "$architecture" = "pentium2" -o \ "$architecture" = "pentium3" -o \ "$architecture" = "pentium4" -o \ "$architecture" = "k6" -o \ "$architecture" = "k6-2" -o \ "$architecture" = "k6-3" -o \ "$architecture" = "athlon" -o \ "$architecture" = "athlon-tbird" -o \ "$architecture" = "athlon-4" -o \ "$architecture" = "athlon-xp" -o \ "$architecture" = "athlon-mp" ]; then export AM_CFLAGS="-march=$architecture -mcpu=$architecture" export AM_CPPFLAGS="-march=$architecture -mcpu=$architecture" export AM_CXXFLAGS="-march=$architecture -mcpu=$architecture" else export AM_CFLAGS="-march=i386 -mcpu=i686" export AM_CPPFLAGS="-march=i386 -mcpu=i686" export AM_CXXFLAGS="-march=i386 -mcpu=i686" architecture="i386" fi if [ "$disable_pw" = "y" ]; then build_host="--program-prefix= --program-suffix= i386-slackware-linux" else build_host="--host=`echo $architecture | tr - _`-pc-linux-gnu" fi fi slackver="`cat /etc/slackware-version | sed 's}Slackware }}' | cut -f 1 -d ' '`" slackver_max="`echo $slackver | cut -f 1 -d -`" slackver_ext="`echo $slackver | cut -f 2 -d -`" if [ "$slackver_max" = "$slackver_ext" ]; then slackver_ext="" fi slackver_maj="`echo $slackver_max | cut -f 1 -d '.'`" slackver_min="`echo $slackver_max | cut -f 2 -d '.'`" slackver_pat="`echo $slackver_max | cut -f 3 -d '.'`" slackver="$slackver_maj.$slackver_min" if [ "$slackver_pat" = "" ]; then slackver_pat="0" fi slackver_max="$slackver_maj.$slackver_min.$slackver_pat" rm -rf $tmp mkdir -p $tmp/sources chmod 700 $tmp mkdir -p $pkg_main cd $tmp function build_host_off() { build_host="" } function opt_flags_off() { unset AM_CFLAGS unset AM_CXXFLAGS unset AM_CPPFLAGS } function crunch() { read whatever echo $whatever } function file_size() { echo -n "`wc -c $1 | crunch | cut -d ' ' -f 1`" } function force_verbose() { automatic=n } function verbose() { if [ ! "$automatic" = "y" ]; then if [ ! "$first_verbose" = "n" -a ! "$src1" = "" ]; then echo fi first_verbose=n echo $* fi } function msg_configuring() { echo -e "\n${white_on}Configuring...${white_off}" } function msg_compiling() { echo -e "${white_on}Compiling...${white_off}" } function msg_installing() { echo -e "${white_on}Installing...${white_off}" } function write_info() { if [ "$name" = "$package" ]; then package="" fi cat << EOF > $tmp/package-info-$1 package_name="$name" package_fullname="$title" package_file="$package" package_version="$version" package_arch="$architecture" package_build="$build" package_build_info="$build_info" package_short_desc="$info" package_long_desc="$desc" package_kind="$category" package_type="$environment" package_creator_mail="$contact" parent_package="$parent_package" required_packages="$requires" conflicts="$conflicts" home_site="$home_site" EOF ### cat << EOF > $tmp/package-subinfo-$1 name="$name" title="$title" package="$package" version="$version" architecture="$architecture" build="$build" build_info="$build_info" info="$info" desc="$desc" category="$category" environment="$environment" contact="$contact" parent_package="$parent_package" requires="$requires" conflicts="$conflicts" home_site="$home_site" EOF ### for lang in $langs; do eval "cur_lang=\$info_$lang" if [ ! "$cur_lang" = "" ]; then echo "package_short_desc_$lang=\"$cur_lang\"" >> $tmp/package-info-$1 echo "info_$lang=\"$cur_lang\"" >> $tmp/package-subinfo-$1 fi eval "cur_lang=\$desc_$lang" if [ ! "$cur_lang" = "" ]; then echo "package_long_desc_$lang=\"$cur_lang\"" >> $tmp/package-info-$1 echo "desc_$lang=\"$cur_lang\"" >> $tmp/package-subinfo-$1 fi done } function add_source() { if [ "$first_verbose" = "n" -a "$src1" = "" ]; then echo fi if echo "$1" | egrep '(^ftp://)|(^http://)' > /dev/null 2>&1; then srcfile=`basename "$1"` srcurl="1" else srcfile="$1" srcurl="0" fi if [ ! -f "$src_pkg/$srcfile" -a "$srcurl" = "1" ]; then echo -en "${white_on}Downloading source $srcfile...${white_off}" wget -t 3 -P $src_pkg $1 > /dev/null 2>&1 if [ ! "$?" = "0" ]; then echo -e "\r${red_on}Downloading $srcfile failed. Can't continue.${red_off} " clean_up exit 1 fi echo -e "\r${white_on}Downloaded source $srcfile.${white_off} " elif [ ! -f "$src_pkg/$srcfile" -a "$srcurl" = "0" ]; then echo -e "\r${red_on}Source $srcfile not found. Can't continue.${red_off} " clean_up exit 1 fi echo -en "${white_on}Extracting source $srcfile...${white_off}" local foo foo=`pwd` cd $tmp/sources archdir="$2" if [ "$archdir" = "." ]; then narchdir="source-$RANDOM" mkdir $narchdir cd $narchdir fi case $srcfile in *.tar.gz) tar zxf $src_pkg/$srcfile > /dev/null 2>&1 [ ! "$?" = "0" ] && { echo -e "\r${red_on}Extracting source $srcfile failed. Can't continue.${red_off} " clean_up exit 1 } [ "$2" = "" ] && archdir="`basename $srcfile .tar.gz`" ;; *.tar.bz2) tar jxf $src_pkg/$srcfile > /dev/null 2>&1 [ ! "$?" = "0" ] && { echo -e "\r${red_on}Extracting source $srcfile failed. Can't continue.${red_off} " clean_up exit 1 } [ "$2" = "" ] && archdir="`basename $srcfile .tar.bz2`" ;; *.tgz) tar zxf $src_pkg/$srcfile > /dev/null 2>&1 [ ! "$?" = "0" ] && { echo -e "\r${red_on}Extracting source $srcfile failed. Can't continue.${red_off} " clean_up exit 1 } [ "$2" = "" ] && archdir="`basename $srcfile .tgz`" ;; *.zip) unzip -q $src_pkg/$srcfile > /dev/null 2>&1 [ ! "$?" = "0" ] && { echo -e "\r${red_on}Extracting source $srcfile failed. Can't continue.${red_off} " clean_up exit 1 } [ "$2" = "" ] && archdir="`basename $srcfile .zip`" ;; esac if [ ! "$narchdir" = "" ]; then cd .. archdir="$narchdir" fi if [ ! -d "$archdir" ]; then echo -e "\r${red_on}Wrong top directory for source $srcfile. Can't continue.${red_off} " clean_up exit 1 fi eval "src$src_cnt=\"$tmp/sources/$archdir\"" src_cnt="`expr $src_cnt + 1`" cd $foo echo -e "\r${white_on}Extracted source $srcfile.${white_off} " } function clean_up() { if [ "$debug" = "y" ]; then cd $cwd echo -e "${white_on}Left sources.${white_off}\n" else echo -en "${white_on}Cleaning up...${white_off}" cd $cwd rm -rf $tmp echo -e "\r${white_on}Cleaned up.${white_off} \n" fi } function is_set() { local foo eval "foo=\$def_$1" if [ "$foo" = "" ]; then return 1 else return 0 fi } function yes_or_no() { if [ "$automatic" = "y" ]; then if is_set $1; then eval "$1=\$def_$1" else eval "$1=$2" fi else local answer while true; do echo -n "Answer [y/n]: " read answer if [ "$answer" = "y" -o "$answer" = "n" ]; then eval "$1=$answer" break fi done fi } function configure_option() { if [ "$2" = "" ]; then target_source="1" else target_source="$2" fi eval "echo -n \"$1 \" >> \$src$target_source/pwbuilder-configure_options" } function make_option() { if [ "$2" = "" ]; then target_source="1" else target_source="$2" fi eval "echo -n \"$1 \" >> \$src$target_source/pwbuilder-make_options" } function install_option() { if [ "$2" = "" ]; then target_source="1" else target_source="$2" fi eval "echo -n \"$1 \" >> \$src$target_source/pwbuilder-install_options" } function package_suffix() { if [ "$p_suffix" = "" ]; then package=".$1" p_suffix="1" else package="${package}_$1" fi } function do_configure() { msg_configuring touch pwbuilder-configure_options if [ "$output" = "y" ]; then ./configure `cat pwbuilder-configure_options` $* $build_host else ( ./configure `cat pwbuilder-configure_options` $* $build_host ) > /dev/null fi if [ ! "$?" = "0" ]; then echo -e "${red_on}Configure failed. Can't continue.${red_off}" clean_up exit 1 fi } function do_make() { msg_compiling touch pwbuilder-make_options if [ "$output" = "y" ]; then make `cat pwbuilder-make_options` $* else ( make `cat pwbuilder-make_options` $* ) > /dev/null fi if [ ! "$?" = "0" ]; then echo -e "${red_on}Compilation failed. Can't continue.${red_off}" clean_up exit 1 fi } function do_python_make() { msg_compiling touch pwbuilder-make_options if [ "$output" = "y" ]; then python ./setup.py build `cat pwbuilder-make_options` $* else ( python ./setup.py build `cat pwbuilder-make_options` $* ) > /dev/null fi if [ ! "$?" = "0" ]; then echo -e "${red_on}Compilation failed. Can't continue.${red_off}" clean_up exit 1 fi } function do_install() { msg_installing touch pwbuilder-install_options if [ "$output" = "y" ]; then make `cat pwbuilder-install_options` install $* else ( make `cat pwbuilder-install_options` install $* ) > /dev/null fi if [ ! "$?" = "0" ]; then echo -e "${red_on}Installation failed. Can't continue.${red_off}" clean_up exit 1 fi } function do_python_install() { msg_installing touch pwbuilder-install_options if [ "$output" = "y" ]; then python ./setup.py install `cat pwbuilder-install_options` $* else ( python ./setup.py install `cat pwbuilder-install_options` $* ) > /dev/null fi if [ ! "$?" = "0" ]; then echo -e "${red_on}Installation failed. Can't continue.${red_off}" clean_up exit 1 fi } function make_package() { if [ "$first_subpackage" = "n" ]; then echo -e "\r${white_on}Prepared subpackages.${white_off} " first_subpackage=y fi source $tmp/package-info-$1 ### source $tmp/package-subinfo-$1 ### if [ "$1" = "main" ]; then packfile="main" makemsg="Making main package..." else packfile="$parent_package-$1" makemsg="Making package $1..." fi echo -en "$white_on$makemsg$white_off" local pkg="$tmp/packages/$packfile" cd $pkg if [ "$delete_cat" = "y" ]; then rm -rf $pkg/usr/man/cat* $pkg/var/man/cat* test "`ls $pkg/usr/man 2> /dev/null`" = "" && rm -rf $pkg/usr/man test "`ls $pkg/usr 2> /dev/null`" = "" && rm -rf $pkg/usr test "`ls $pkg/var/man 2> /dev/null`" = "" && rm -rf $pkg/var/man test "`ls $pkg/var 2> /dev/null`" = "" && rm -rf $pkg/var fi if [ -d $pkg/usr/info ]; then rm -f $pkg/usr/info/dir gzip -9f $pkg/usr/info/*.info* > /dev/null 2>&1 fi if [ "$reset_dir" = "y" ]; then find $pkg -type d -exec chmod 755 {} \; fi mkdir -p $pkg/install if [ ! "$1" = "main" ]; then scrsuf=".$1" fi if [ ! "$disable_pw" = "y" ]; then cp $src_pkg/script.preinst$scrsuf $pkg/install/slack-pw-preinst.sh 2> /dev/null cp $src_pkg/script.prerem$scrsuf $pkg/install/slack-pw-prerem.sh 2> /dev/null cp $src_pkg/script.postrem$scrsuf $pkg/install/slack-pw-postrem.sh 2> /dev/null cp $src_pkg/script.preup$scrsuf $pkg/install/slack-pw-preup.sh 2> /dev/null cp $src_pkg/script.postup$scrsuf $pkg/install/slack-pw-postup.sh 2> /dev/null fi find . -type l -exec ls -l {} \; | cut -b59- > $tmp/symlinks if [ ! "`file_size $tmp/symlinks`" = "0" ]; then count=1 line="`sed -n "$count p" $tmp/symlinks`" while [ ! "$line" = "" ]; do link_location="`echo "$line" | cut -f 1 -d " "`" link_location="`dirname $link_location`" link_name="`echo "$line" | cut -f 1 -d ' '`" link_name="`basename "$link_name"`" link_target="`echo "$line" | cut -f 3 -d ' '`" echo "( cd $link_location ; rm -rf $link_name )" >> $pkg/install/doinst.sh echo "( cd $link_location ; ln -sf $link_target $link_name )" >> $pkg/install/doinst.sh count=`expr $count + 1` line="`sed -n "$count p" $tmp/symlinks`" done find . -type l -exec rm -f {} \; fi rm -f $tmp/symlinks* if [ -f $src_pkg/script.postinst$scrsuf ]; then cat $src_pkg/script.postinst$scrsuf >> $pkg/install/doinst.sh 2> /dev/null fi echo -e "$info\n\n$desc" | sed "s}^}$package_name: }" > $pkg/install/slack-desc if [ ! "$disable_pw" = "y" ]; then cp $tmp/package-info-$1 $pkg/install/slack-pw-info cp $pkg/install/doinst.sh $pkg/install/slack-pw-postinst.sh 2> /dev/null required_libs=`find $pkg -type f -perm +111 | xargs ldd 2> /dev/null | grep "=>" | grep "[.]so[.]" | awk '{ print $1 }' | awk 'BEGIN { FS = "[.]so[.]" } { print $1 }' | sort | uniq | tr '\012' ' '` echo "required_libs=\"$required_libs\"" >> $pkg/install/slack-pw-info echo "libraries=\"$required_libs\"" >> $tmp/package-subinfo-$1 if [ ! -d $src_tgz/packages/$architecture ]; then mkdir -p $src_tgz/packages/$architecture fi cp $tmp/package-subinfo-$1 $src_tgz/packages/$architecture/$package_name-$package_version-`echo $package_arch | tr -d -`-$package_build$vendor_id$package_file.ppi stored_package="$src_tgz/packages/$architecture/$package_name-$package_version-`echo $package_arch | tr -d -`-$package_build$vendor_id$package_file.tgz" create_pkg $stored_package $1 else cp $pkg/install/slack-desc $src_tgz/packages/$package_name-$package_version-`echo $package_arch | tr -d -`-$package_build.txt stored_package="$src_tgz/packages/$architecture/$package_name-$package_version-`echo $package_arch | tr -d -`-$package_build.tgz" create_pkg $stored_package $1 fi if [ "$1" = "main" ]; then echo -e "\r${white_on}Made main package.${white_off} " else echo -e "\r${white_on}Made package $1.${white_off} " fi if [ "$print_results" = "y" ]; then echo "Stored package $stored_package." fi } function make_docs() { docdir="$pkg_main/usr/doc/$name-$version" mkdir -p $docdir ( cd $src1 ; eval "cp -af {$docs_source,} $pkg_main/usr/doc/$name-$version > /dev/null 2>&1" ) ( cd $src_pkg ; eval "cp -af {$docs_cwd,} $pkg_main/usr/doc/$name-$version > /dev/null 2>&1" ) } function create_pkg() { if [ "`id -u`" = "0" ]; then /usr/src/tgz/lib/builder.mkpkg $1 $tmp `basename $1 .tgz` $reset_own $reset_fil $tmp/ch_script-$2 $strip_bin else fakeroot "/usr/src/tgz/lib/builder.mkpkg $1 $tmp `basename $1 .tgz` $reset_own $reset_fil $tmp/ch_script-$2 $strip_bin" fi } function subpackage() { if [ ! "$first_subpackage" = "n" ]; then echo -en "${white_on}Preparing subpackages...${white_off}" first_subpackage=n fi source $src_pkg/package-info-$1 subpkg="$tmp/packages/$package" mkdir -p $subpkg if [ "$noarch" = "y" ]; then architecture="noarch" fi cat $src_pkg/package-files-$1 | while read line; do eval "entry=\"$line\"" entdir="`dirname $entry`" mkdir -p $subpkg/$entdir mv $pkg_main/$entry $subpkg/$entdir > /dev/null 2>&1 done write_info $1 source $tmp/package-info-main ### source $tmp/package-subinfo-main ### } function build_info() { build_info="$build_info$1" } function apply_patch() { echo -n "Applying patch $1..." if [ -r "$src_pkg/$name-$1.pw.patch" ]; then apatch="$name-$1.pw.patch" elif [ -r "$src_pkg/$1" ]; then apatch="$1" else echo -e "\r${red_on}Patch $1 not found.${red_off} " return fi if [ "$2" = "" ]; then level="0" else level="$2" fi if [ "$3" = "" ]; then srct="$src1" else eval "srct=\$src$3" fi case $apatch in *.gz) ( cd $srct ; zcat $src_pkg/$apatch | patch -p$level > /dev/null 2>&1 ) ;; *.bz2) ( cd $srct ; bzcat $src_pkg/$apatch | patch -p$level > /dev/null 2>&1 ) ;; *) ( cd $srct ; patch -p$level < $src_pkg/$apatch > /dev/null 2>&1 ) ;; esac if [ "$?" = "0" ]; then echo -e "\rApplied patch $1. " else echo -e "\r${red_on}Patch $1 failed.${red_off} " fi } function change_mod() { echo "chmod $3 $tmp/packages/$1/$2" >> $tmp/ch_script-$1 } function change_own() { echo "chown $3 $tmp/packages/$1/$2" >> $tmp/ch_script-$1 } function replace_regexp() { sed "s}$2}$3}g" $1 > $tmp/replace.tmp cat $tmp/replace.tmp > $1 rm -f $tmp/replace.tmp } function copy() { if [ ! -d "$2" ]; then mkdir -p "$2" fi cp $1 $2/$3 } .