# This file is part of the src2pkg program: # Copyright 2005-2008 Gilbert Ashley # src2pkg is released under the GNU General Public License Version 2 ##### pre_process ##### This is the only function which is really required as it is where all ##### the main variables get setup and crunched into usable form pre_process() { # color is on only if COLOR_PROMPT=YES get_color_options ; # If the -W (--cleanup) option is used it will remove the generated build files # new.doinst.sh new.slack.desc and *.src2pkg.auto. But if there is a # src2pkg.auto file present here from the start don't remove it. if [ -f *.src2pkg.auto ] ; then DONT_CLOBBER_DOT_AUTO=1 fi # check to make sure we have been setup. If not run setup if the user is root # otherwise warn the user if ! [[ -x /usr/libexec/src2pkg/lib/libsentry.so ]] ; then if [[ "$(id -u)" = "0" ]] ; then cd /usr/src/src2pkg/src2pkg ; . src2pkg.setup cd $CWD; else echo $RED"NOTICE! "$NORMAL"src2pkg has not been setup yet! In order to" echo " use src2pkg you must first login as root and run src2pkg the" echo " first time with the command 'src2pkg --setup'" exit 0 fi fi # you must be root to run src2pkg in REAL mode if [[ "$(id -u)" != "0" ]] && [[ "$INSTALL_TYPE" = "REAL" ]] ; then echo $RED"FATAL!!! "$NORMAL"You have chosen to use the -REAL installation option for src2pkg." echo "Normal users don't have the write priviledges needed for doing this." echo "You must be logged in as root or su to root to run src2pkg in this mode." echo "Or choose to use one of the other installation methods -JAIL or -DESTDIR." exit 1 fi OWNER="$(id -un)" GROUP="$(id -gn)" # These are important defaults that need to be set ! [[ $STD_MASK ]] && STD_MASK="000" umask $STD_MASK ! [[ $MAKE_LINKS ]] && MAKE_LINKS="YES" # REALLY_INSTALL=YES is similar to what checkinstall does. # Among the first goals of src2pkg was to *not* install packages by default ! [[ $REALLY_INSTALL = "YES" ]] && REALLY_INSTALL="NO" # This is the most-used option of all. But if not specified it should be nulled. ! [[ $EXTRA_CONFIGS ]] && EXTRA_CONFIGS="" # A BUILD number is required, so supply a default if none was given. ! [[ $BUILD ]] && BUILD="1" if [[ "$INTERACTIVE_MODE" = "ALL" ]] ; then QUERY_FOR_EXTRA_CONFIGS="YES" CONFIRM_BUILD="YES" QUERY_FOR_PKG_DESC="YES" fi DESC_WRAP_LENGTH=70 # this variable tells the text wrapper how many lines to pad the PKG_DESC file. # the PKG_DESC file should be at least 11 lines -the first, second and 11th line # are supplied separately (8+3=11) and lines 12 and 13 are optionally added DESC_MAX_LINES=8 # get the ARCH and compiler tuning flags for CFLAGS (function is near end of file) get_flags ; # Use our own statically-linked binaries at least for the most critical stuff ! [[ $STATIC_DIR ]] && STATIC_DIR=/usr/libexec/src2pkg/static # These are the programs needed during restoration of overwritten files # and removal of any left over new files, before running ldconfig in fake_install # we use a version of tar from the full sources instead of the busybox version # The static tar program is used in all cases for consistency and to allow # re-building the 'tar' or pkgtools packages. This version of tar is identical # to the one that Slackware uses, except that the '-j' option is used for bzip2 # archives for syntax consistency with versions of tar>=1.15 TAR_STATIC=$STATIC_DIR/tar-1.13 # Get the name, version and source suffix(SOURCE_NAME) # early PkgBuild versions supplied NAME VERSION and SRC_SUFFIX separately if [ "$NAME" -a "$VERSION" -a "$SRC_SUFFIX" ] ; then SOURCE_NAME="$NAME-$VERSION$SRC_SUFFIX" fi # newer versions of src2pkg derive NAME & VERSION from SOURCE_URL, SOURCE or SOURCE_NAME if [[ "$SOURCE_URL" != "" ]] ; then # SOURCE_URL was given explicitly SOURCE_NAME="$(basename $SOURCE_URL)" SOURCE=$SOURCES_DIR/$SOURCE_NAME elif [[ "$SOURCE" != "" ]] ; then SOURCE_NAME=$(basename $SOURCE) case $SOURCE in # SOURCE is a URL *://*) SOURCE_URL="$SOURCE" ; SOURCE=$SOURCES_DIR/$SOURCE_NAME ; shift ;; # Double slashes get corrected if this is not a URL //*) SOURCE=${SOURCE#*/} ; shift ;; # Relative path(./) ./*) SOURCE=$CWD/${SOURCE#*/} ; shift ;; # Absoulte path" /*) SOURCE=$SOURCE ;; # Extended relative path [a-z,A-Z,0-9]*/*) SOURCE=$CWD/$SOURCE ; shift ;; # No path given -assume it's in SOURCES_DIR *) SOURCE=$SOURCES_DIR/$SOURCE ; shift ;; esac elif [[ "$SOURCE_NAME" != "" ]] ; then case $SOURCE_NAME in # use the same rules as above for SOURCE_NAME *://*) SOURCE_URL="$SOURCE" ; SOURCE=$SOURCES_DIR/$SOURCE_NAME SOURCE_NAME=$(basename $SOURCE_NAME) ; shift ;; //*) SOURCE=${SOURCE_NAME#*/} ;; ./*) SOURCE=$CWD/${SOURCE_NAME#*/} ;; /*) SOURCE=$SOURCE_NAME ;; [a-z,A-Z,0-9]*/*) SOURCE=$CWD/$SOURCE_NAME ;; *) SOURCE=$SOURCES_DIR/$SOURCE_NAME ;; esac fi # local function used to retrieve the given architecture when converting binary package names get_my_arch() { ARCH_CHUNK=$(echo $NAMVERS |rev |cut -f1,2 -d'-' |rev) case $ARCH_CHUNK in *i386*) MYARCH=i386 ;; *i486*) MYARCH=i486 ;; *i586*) MYARCH=i586 ;; *i686*) MYARCH=i686 ;; *ppc*) MYARCH=ppc ;; *powerpc*) MYARCH=powerpc ;; *x86_64*) MYARCH=x86_64 ;; *s390*) MYARCH=s390 ;; *s390x*) MYARCH=s390x ;; *noarch*) MYARCH=noarch ;; esac } # local function translate_underlines() { if [[ $(echo $NAMVERS |grep -v "_") = "" ]] ; then if [[ $(echo $NAMVERS |grep -v ".") = "" ]] ; then #echo "Translating underlines to periods" NAMVERS=$(echo $NAMVERS |tr '_' '.') fi fi } # The next +-200 lines analyze the SOURCE_NAME and try to figure out the correct NAME and VERSION # Handling of debian and especially rpm archives make this pretty complex. Of course it still won't always # get them both right. you can always override them easily with '-n=?' (ALT_NAME) and '-v=?' (ALT_VERSION). # The logic is based on heuristic rules built up from thousands of real archive names and error scenarios # if [[ "$SOURCE_NAME" != "" ]] ; then [[ $DEBUG ]] && echo -n $BLUE"Guessed content type: "$NORMAL NAMVERS=$(basename $SOURCE_NAME) case $NAMVERS in *src.rpm) EXT='src.rpm' ;; *src.tgz) EXT='src.tgz' ;; *src.tar.gz) EXT='src.tar.gz' ;; *rpm) EXT='rpm' ;; *deb) EXT='deb' ;; *orig.tar.gz) EXT='orig.tar.gz' ;; *orig.tar.bz2) EXT='orig.tar.bz2' ;; *tgz) EXT='tgz' ;; *tbz) EXT='tbz' ;; *tar.gz) EXT='tar.gz' ;; *tar.bz2) EXT='tar.bz2' ;; esac # this is where the user gave just a suffix and no package name if [[ $NAMVERS = ".$EXT" ]] || [[ $NAMVERS = $EXT ]] ; then echo $RED"Error! "$NORMAL"Invalid package name -probably null name or suffix-only. Exiting..." exec $0 exit 0 else RAW_SOURCE_NAME=$(basename $NAMVERS ."$EXT") fi NAMVERS=$RAW_SOURCE_NAME case $EXT in src.rpm|src.tgz|src.tar.gz) if [[ $DEBUG ]] ; then [[ "$EXT" = "src.rpm" ]] && echo -n "RPM source archive" #\ # || echo -n "rpm2tgz-converted RPM source" fi translate_underlines if [[ $(echo $NAMVERS |grep '-') ]] ; then if [[ $(echo $NAMVERS |rev |cut -f2 -d'-') != $(echo $NAMVERS |rev |cut -f3 -d'-') ]] ; then if [[ $(echo $NAMVERS |rev |cut -f1 -d'.' |grep "-") ]] ; then # [[ $DEBUG ]] && echo " Rule 1" CHUNK=$(echo $NAMVERS |rev |cut -f1 -d'.' |rev) CARRY=$(echo $CHUNK |cut -f1 -d'-') REV_CHUNK=$(echo $CHUNK |cut -f2- -d'-') NAMVERS=$(basename $NAMVERS .$CHUNK).$CARRY else # [[ $DEBUG ]] && echo " Rule 2" REV_CHUNK=$(echo $NAMVERS |rev |cut -f1 -d'-' |rev) NAMVERS=$(echo $NAMVERS |rev |cut -f2- -d'-' |rev) fi fi VERSION=$(echo $NAMVERS |rev |cut -f1 -d'-' |rev) NAME=$(echo $NAMVERS |rev |cut -f2- -d'-' |rev) else # [[ $DEBUG ]] && echo "Name contains no dashes" true fi if [[ $NAME = $VERSION ]] ; then # [[ $DEBUG ]] && echo "Reconverting! This is not an RPM-type name" VERSION=$(echo $RAW_SOURCE_NAME |rev |cut -f1 -d'-' |rev) NAME=$(basename $RAW_SOURCE_NAME -$VERSION) fi [[ "$VERSION" = "$NAME" ]] && VERSION=0.0.0 ;; rpm) translate_underlines get_my_arch if [[ $(echo $NAMVERS |grep "$MYARCH") != "" ]] ; then [[ $DEBUG ]] && echo -n "RPM binary package" ARCH=$(echo $NAMVERS |rev |cut -f1 -d'.' |rev) NAMVERS=$(basename $NAMVERS .$ARCH) if [[ $(echo $ARCH |grep "-") ]] ; then ARCH=$(echo $ARCH |rev |cut -f2- -d'-' |rev) fi else [[ $DEBUG ]] && echo -n "Generic RPM archive" fi if [[ $(echo $NAMVERS |rev |cut -f2 -d'-') != $(echo $NAMVERS |rev |cut -f3 -d'-') ]] ; then if [[ $(echo $NAMVERS |rev |cut -f1 -d'.' |grep "-") ]] ; then # [[ $DEBUG ]] && echo -n " Rule 1" CHUNK=$(echo $NAMVERS |rev |cut -f1 -d'.' |rev) REV_CHUNK=$(echo $CHUNK |cut -f2- -d'-') CARRY=$(echo $CHUNK |cut -f1 -d'-') NAMVERS=$(basename $NAMVERS .$CHUNK).$CARRY else #[[ $DEBUG ]] && echo -n " Rule 2" REV_CHUNK=$(echo $NAMVERS |rev |cut -f1 -d'-' |rev) NAMVERS=$(echo $NAMVERS |rev |cut -f2- -d'-' |rev) fi fi if [[ $(echo $NAMVERS |rev |cut -f1 -d'-' |rev |grep "_") ]] ; then #[[ $DEBUG ]] && echo -n " Rule 3" VERSION=$(echo $NAMVERS |rev |cut -f1 -d'-' |rev) VERSION=$(echo $NAMVERS |tr '_' '.') NAME=$(echo $NAMVERS |rev |cut -f2- -d'-' |rev) else #[[ $DEBUG ]] && echo -n " Rule 4" VERSION=$(echo $NAMVERS |rev |cut -f1 -d'-' |rev) NAME=$(echo $NAMVERS |rev |cut -f2- -d'-' |rev) fi ;; deb) [[ $DEBUG ]] && echo "Debian binary package" ARCH=$(echo $NAMVERS |rev |cut -f1 -d'_' |rev) NAMVERS=$(echo $NAMVERS |rev |cut -f2- -d'_' |rev) if [[ $(echo $NAMVERS |rev |cut -f1 -d'.' |grep '-') ]] ; then NAMVERS=$(echo $NAMVERS |rev |cut -f2- -d'-' |rev) fi VERSION=$(echo $NAMVERS |cut -f2- -d'_') NAME=$(echo $NAMVERS |cut -f1 -d'_') ;; *) get_my_arch if [[ "$MYARCH" != "" ]] ; then if [[ $(echo $ARCH_CHUNK |cut -f1 -d '-') = $ARCH ]] ; then [[ $DEBUG ]] && echo "Slackware binary package" ARCH=$(echo $NAMVERS |rev |cut -f2 -d'-' |rev) NAMVERS=$(echo $NAMVERS |rev |cut -f2- -d'-' |rev) VERSION=$(echo $NAMVERS |rev |cut -f2 -d'-' |rev) NAME=$(basename $NAMVERS -$VERSION-$ARCH) elif [[ $(echo $NAMVERS |rev |cut -f1 -d'.' |rev |grep $MYARCH) != "" ]] ; then translate_underlines ARCH_CHUNK=$(echo $NAMVERS |rev |cut -f1 -d'.' |rev) # [[ $DEBUG ]] && echo "Binary rpm2$EXT archive" NAMVERS=$(basename $NAMVERS .$ARCH_CHUNK) if [[ $(echo $ARCH_CHUNK |grep '-') ]] ; then ARCH=$(echo $ARCH_CHUNK |rev |cut -f2- -d'-' |rev) else ARCH="$ARCH_CHUNK" fi if [[ $(echo $NAMVERS |rev |cut -f1 -d'.' |grep "-") ]] ; then CHUNK=$(echo $NAMVERS |rev |cut -f1 -d'.' |rev) REV_CHUNK=$(echo $CHUNK |cut -f2- -d'-') CARRY=$(echo $CHUNK |cut -f1 -d'-') NAMVERS=$(basename $NAMVERS .$CHUNK).$CARRY else REV_CHUNK=$(echo $NAMVERS |rev |cut -f1 -d'-' |rev) NAMVERS=$(echo $NAMVERS |rev |cut -f2- -d'-' |rev) fi VERSION=$(echo $NAMVERS |rev |cut -f1 -d'-' |rev) NAME=$(echo $NAMVERS |rev |cut -f2- -d'-' |rev) else translate_underlines [[ $DEBUG ]] && echo "Generic binary $EXT archive" if [[ $(echo $NAMVERS |grep '-') ]] ; then VERSION=$(echo $NAMVERS |rev |cut -f1 -d'-' |rev) NAME=$(basename $NAMVERS -$VERSION) elif [[ $(echo $NAMVERS |grep '.') ]] ; then NAME=$(echo $NAMVERS |cut -f1 -d'.') NAME=$(echo $NAMVERS |cut -f2- -d'.') else echo "What is this?" NAME=unknown VERSION=0.0 fi fi else case $EXT in tgz|tar.gz|tbz|tar.bz2|orig.tar.gz|orig.tar.bz2) if [[ $(basename $SOURCE_NAME |grep ".orig.") ]] ; then [[ $DEBUG ]] && echo -n "Debian source archive" NAMVERS=$(basename $NAMVERS ".orig") elif [[ $(basename $SOURCE_NAME |grep "_") ]] ; then [[ $DEBUG ]] && echo -n "Possible Debian source archive" elif [[ $(basename $SOURCE_NAME |grep ".source.") ]] ; then [[ $DEBUG ]] && echo -n "Converted RPM source archive" NAMVERS=$(basename $NAMVERS ".source") translate_underlines else [[ $DEBUG ]] && echo -n "Generic source archive" fi #translate_underlines if [[ $(echo $NAMVERS |grep '_') != "" ]] ; then # debian #[[ $DEBUG ]] && echo -n " Rule 1" VERSION=$(echo $NAMVERS |rev |cut -f1 -d'_' |rev) NAME=$(basename $NAMVERS _$VERSION) VERSION=$(echo $VERSION |tr '-' '.') elif [[ $(echo $NAMVERS |grep '-') != "" ]] ; then #[[ $DEBUG ]] && echo && echo " Rule 2" VERSION=$(echo $NAMVERS |rev |cut -f1 -d'-' |rev) NAME=$(basename $NAMVERS -$VERSION) else #[[ $DEBUG ]] && echo && echo " Rule 3" NAME=$(echo $NAMVERS |cut -f1 -d'.') VERSION=$(echo $NAMVERS |cut -f2- -d'.') [[ "$VERSION" = "$NAME" ]] && VERSION=0.0.0 fi ;; esac fi ;; esac [[ $DEBUG ]] && echo "" # Whew!! The derived name and version can always be overridden. else # trackinstall and src2pkg are 'clients' of these FUNCTIONS if [[ $NAME ]] && [[ $VERSION ]] ; then NAMVERS="$NAME-$VERSION" echo $BLUE"Client or user supplied NAME and VERSION: "$NORMAL"$NAMVERS" else NAMVERS=$(basename $CWD) echo $BLUE"Using NAME and VERSION from CWD: "$NORMAL"$NAMVERS" fi if [[ $(echo $NAMVERS |grep '-') != "" ]] ; then VERSION=$(echo $NAMVERS |rev |cut -f1 -d'-' |rev) NAME=$(basename $NAMVERS -$VERSION) elif [[ $(echo $NAMVERS |grep '_') != "" ]] ; then VERSION=$(echo $NAMVERS |rev |cut -f1 -d'_' |rev) NAME=$(basename $NAMVERS _$VERSION) elif [[ $(echo $NAMVERS |grep '.') ]] ; then NAME=$(echo $NAMVERS |cut -f1 -d'.') VERSION=$(echo $NAMVERS |cut -f2- -d'.') [[ "$VERSION" = "$NAME" ]] && VERSION=0.0.0 else echo "What in the world is this? We'll name it: unknown-0.unknown.0 " NAME=unknown VERSION=0.unknown.0 fi VERSION=$(echo $VERSION |tr '-' '_') fi # ORIG_NAME & ORIG_VERSION are the 'best guess' from above. We save the values before # correcting or overriding them. They are used later to help second-guess tarball names, if needed. ORIG_NAME="$NAME" ORIG_VERSION="$VERSION" # [[ $DEBUG ]] && [[ $ARCH_CHUNK ]] && echo $BLUE"ARCH_CHUNK="$NORMAL"$ARCH_CHUNK" # [[ $DEBUG ]] && [[ $MYARCH ]] && echo $BLUE"MYARCH="$NORMAL"$MYARCH" # [[ $DEBUG ]] && [[ $REV_CHUNK ]] && echo $BLUE"REV_CHUNK="$NORMAL"$REV_CHUNK" [[ $DEBUG ]] && echo $BLUE"ORIG_NAME="$NORMAL"$ORIG_NAME" [[ $DEBUG ]] && echo $BLUE"ORIG_VERSION="$NORMAL"$ORIG_VERSION" # Now correct the name for capital letters if needed and corrections are not turned off or overridden if [[ $(echo $NAME | grep -e "[A-Z]") ]] ; then echo $BLUE"Notice - "$NORMAL"Source name contains capital letters." if [[ "$CORRECT_NAMES" = "YES" ]] && [[ ! $ALT_NAME ]] ; then ALT_NAME=$(echo $NAME | tr 'A-Z' 'a-z') elif [[ $ALT_NAME ]] ; then if echo $ALT_NAME | grep -e "[A-Z]" &> /dev/null ; then echo $BLUE"Notice - "$NORMAL"Alternate Name contains capital letters." echo -n "A better name for $ALT_NAME might be: " echo $ALT_NAME | tr 'A-Z' 'a-z' fi fi fi if [[ "$ALT_VERSION" != "" ]] ; then if echo $ALT_VERSION | grep -e "-" &> /dev/null ; then echo $YELLOW"ERROR - "$NORMAL"Version numbers with a '-' character are not allowed." ALT_VERSION=$(echo $ALT_VERSION |tr '-' '.') fi echo $BLUE"Resetting version number - "$NORMAL"Using: "$BLUE"$ALT_VERSION"$NORMAL VERSION="$ALT_VERSION" fi if [[ "$ALT_NAME" != "" ]] ; then echo $BLUE"Resetting package name - "$NORMAL"Using: "$BLUE"$ALT_NAME"$NORMAL NAME="$ALT_NAME" fi # exit if no NAME or VERSION are found if [[ ! $NAME ]] ; then echo $RED"ERROR - "$NORMAL"Unable to find a NAME. Please give one!" exit elif [[ ! $VERSION ]] ; then echo $RED"ERROR - "$NORMAL"Unable to find a VERSION. Please give one!" exit fi if [[ $TRACK_INSTALL ]] ; then SRC_DIR=$CWD OBJ_DIR=$SRC_DIR elif [[ $USE_OBJ_DIR ]] ; then SRC_DIR_NAME=$NAME-$VERSION-src-$BUILD$SIG SRC_DIR=$SRC_BUILDS_DIR/$SRC_DIR_NAME OBJ_DIR_NAME=$NAME-$VERSION-obj-$BUILD$SIG OBJ_DIR=$SRC_BUILDS_DIR/$OBJ_DIR_NAME elif [[ $SOURCE_NAME ]] ; then # let configure_source sort our CONFIG_DIR and OBJ_DIR SRC_DIR_NAME=$NAME-$VERSION-src-$BUILD$SIG SRC_DIR=$SRC_BUILDS_DIR/$SRC_DIR_NAME elif [[ $NAME ]] && [[ $VERSION ]] ; then # try assuming this, which should allow using a src2pkg script inside sources SRC_DIR=$CWD OBJ_DIR=$SRC_DIR fi PKG_DIR_NAME=$NAME-$VERSION-pkg-$BUILD$SIG PKG_DIR=$PKG_BUILDS_DIR/$PKG_DIR_NAME # make script writing easier by using DOC_DIR and MAN_DIR DOC_DIR=usr/doc/$NAME-$VERSION MAN_DIR=usr/man # This should help make code from SlackBuild scripts compatible PKG=$PKG_DIR # these are internal abbreviations to shorten code lines SHORT_NAME="$NAME-$VERSION-$ARCH-$BUILD$SIG" PKG_NAME=$SHORT_NAME.tgz PACKAGE=$PKG_DEST_DIR/$PKG_NAME # remove the leading / from PRE_FIX. This obsoletes some of my own old scripts that used # $PKG_DIR$PREFIX, but that just doesn't look or feel right like writing: $PKG_DIR/$PREFIX if [[ $(echo ${PRE_FIX:0:1}) = "/" ]] ; then PRE_FIX="$(echo ${PRE_FIX:1})" fi pflen=${#PRE_FIX} pfoffset=$(( $pflen - 1 )) # also remove trailing slashes if [[ $(echo ${PRE_FIX:$pfoffset:1}) = "/" ]] ; then PRE_FIX="$(echo ${PRE_FIX:0:$pfoffset})" fi # if the user is installing somewhere under/usr/local or /opt, let them do what they want? # this keeps Makefiles, docs and man-pages from being messed with if [[ $(echo $PRE_FIX |grep "usr/local") ]] || [[ $(echo $PRE_FIX |grep "opt/") ]] ; then CORRECT_MAKEFILES="NO" CORRECT_DOCS="NO" CORRECT_MANS="NO" fi # set default text for the description file if not given ! [[ $BLURB_1 ]] && BLURB_1=$NAME ! [[ $BLURB_3 ]] && BLURB_3="No description was given for this package." # ! [[ $BLURB_11 ]] && BLURB_11="Packaged by src2pkg" # check the validity of the directories (function near end of file). This important check # insures that the user isn't trying to unpack sources or build packages inside some # system directory or / root directory. check_dirs1 # now check to make sure the user has permission to write in all the needed places check_write_permissions if [ "FAILED" != "" ] ; then post_process fi } # end pre_process # this function figures out the architecture and CFLAGS get_flags() { # # Machine architecture tuning flags and package ARCH if [[ "$(uname -m)" = "ppc" ]] ; then ! [[ $ARCH ]] && ARCH="powerpc" ! [[ $TUNE_FLAGS ]] && TUNE_FLAGS="" ! [[ $OPTIM_FLAGS ]] && OPTIM_FLAGS="-O0" elif [[ "$(uname -m)" = "powerpc" ]] ; then ! [[ $ARCH ]] && ARCH="powerpc" ! [[ $TUNE_FLAGS ]] && TUNE_FLAGS="" ! [[ $OPTIM_FLAGS ]] && OPTIM_FLAGS="-O0" elif [[ "$(uname -m)" = "s390" ]] ; then ! [[ $ARCH ]] && ARCH="s390" ! [[ $TUNE_FLAGS ]] && TUNE_FLAGS="" ! [[ $OPTIM_FLAGS ]] && OPTIM_FLAGS="-O0" elif [[ "$(uname -m)" = "s390x" ]] ; then ! [[ $ARCH ]] && ARCH="s390x" ! [[ $TUNE_FLAGS ]] && TUNE_FLAGS="" ! [[ $OPTIM_FLAGS ]] && OPTIM_FLAGS="-O0" elif [[ "$(uname -i)" = "AuthenticAMD" ]] ; then ! [[ $ARCH ]] && ARCH="athlon_xp" ! [[ $TUNE_FLAGS ]] && TUNE_FLAGS="-march=athlon-xp -pipe -fomit-frame-pointer" ! [[ $OPTIM_FLAGS ]] && OPTIM_FLAGS="-O3" elif [[ "$(uname -m)" = "x86_64" ]] ; then ! [[ $ARCH ]] && ARCH="x86_64" # We'll try this as it seems to work more often than not if ! [[ -e /etc/bluewhite64-version ]] ; then ! [[ $STD_CONFIGS ]] && STD_CONFIGS="--libdir=/usr/lib64" ! [[ $LDFLAGS ]] && LDFLAGS=-L/usr/lib64 fi ! [[ $TUNE_FLAGS ]] && TUNE_FLAGS="-fPIC" ! [[ $OPTIM_FLAGS ]] && OPTIM_FLAGS="-O2" elif [[ "$(uname -m |grep 86)" != "" ]] ; then GCCVERSION=$(gcc --version|grep 'GCC' |cut -f3 -d' ') if [[ $(expr $GCCVERSION) > 3.4 ]] ; then CPU_TAG="-mtune" else CPU_TAG="-mcpu" fi # ! [[ $MARCH_FLAG ]] && MARCH_FLAG="i486" ! [[ $CPU_FLAG ]] && CPU_FLAG="i686" # Could set dynamically : MARCH_FLAG= or CPU_FLAG="$(uname -m)" # This ARCH is for the package name. ! [[ $ARCH ]] && ARCH="$MARCH_FLAG" ! [[ $TUNE_FLAGS ]] && TUNE_FLAGS="$(echo -march=$MARCH_FLAG $CPU_TAG=$CPU_FLAG |white_out)" else ! [[ $ARCH ]] && ARCH="unknown" ! [[ $TUNE_FLAGS ]] && TUNE_FLAGS="" fi # Compiler options # Using -O3 gives results similar to -Os. # Optimize for smaller binaries [[ $OPTIMIZE_4_SIZE = "YES" ]] && OPTIM_FLAGS="-Os" ! [[ $OPTIM_FLAGS ]] && OPTIM_FLAGS="-O2" ! [[ $STD_FLAGS ]] && STD_FLAGS="$(echo $OPTIM_FLAGS $TUNE_FLAGS |white_out)" ! [[ $EXTRA_FLAGS ]] && EXTRA_FLAGS="" } check_dirs1 () { for VAR_NAME in PKG_BUILDS_DIR PKG_DEST_DIR SRC_DIR PKG_DIR CWD; do if [[ "${VAR_NAME}" = "" ]] ; then echo $RED"FATAL! "$NORMAL"Null value given for critical src2pkg variable." echo "Please read the src2pkg documentation for help." exit 1 fi if [[ "${VAR_NAME}" = "/" ]] ; then echo $RED"FATAL! "$NORMAL"Root directory was given as a critical src2pkg variable," echo "or is the current directory. Please read the src2pkg documentation for help." exit 1 fi if [[ "${VAR_NAME}" = "${HOME}" ]] ; then if [[ "${VAR_NAME}" = "PKG_DEST_DIR" ]] ; then true else echo $RED"FATAL! "$NORMAL"Home directory was given as a critical src2pkg variable," echo "or is the current directory. Please read the src2pkg documentation for help." exit 1 fi fi # MISC_DIRS="boot etc dev home mnt opt proc root sys usr var usr/share usr/local" CRITICAL_DIRS="$BIN_DIRS $LIB_DIRS $INC_DIRS $LOCALE_DIRS $MAN_DIRS $MISC_DIRS" for SYSTEM_DIR in $(echo $CRITICAL_DIRS 2> /dev/null) ; do SYSTEM_DIR="/""$SYSTEM_DIR" if [[ "${VAR_NAME}" = "$SYSTEM_DIR" ]] ; then echo $RED"FATAL! "$NORMAL"$SYSTEM_DIR was given as a critical src2pkg variable," echo "or is the current directory. Please read the src2pkg documentation for help." exit 1 fi done done } check_dirs2() { if [[ "${SRC_BUILDS_DIR}" = "" ]] || [[ "${SRC_BUILDS_DIR}" = "/" ]] ; then echo $RED"FATAL ERROR "$NORMAL"Please give a valid SRC_BUILDS_DIR." exit 1 fi if [[ "${PKG_BUILDS_DIR}" = "" ]] || [[ "${PKG_BUILDS_DIR}" = "/" ]] ; then echo $RED"FATAL ERROR "$NORMAL"Please give a valid PKG_BUILDS_DIR." echo "Don't give a null PKG_BUILDS_DIR or use / !" exit 1 fi if [[ "${PRE_FIX}" = "" ]] || [[ "${PRE_FIX}" = "/" ]] ; then echo $RED"FATAL ERROR "$NORMAL"Please give a valid PRE_FIX." echo "Don't give a null PRE_FIX or use / !" exit 1 fi if [[ "${SRC_DIR}" = "" ]] || [[ "${SRC_DIR}" = "/" ]] ; then echo $RED"FATAL ERROR "$NORMAL"Please give a valid SRC_DIR." exit 1 fi if [[ "${PKG_DIR}" = "" ]] || [[ "${PKG_DIR}" = "/" ]] ; then echo $RED"FATAL ERROR "$NORMAL"Please give a valid PKG_DIR." exit 1 fi # This shouldn't happen either [[ "${PACKAGE}" = "" ]] || [[ "${PACKAGE}" = "/" ]] && echo $RED"ERROR "$NORMAL"Bad PACKAGE name!" && exit 1 } check_write_permissions() { touch $CWD/perms-test.txt &> /dev/null if [ $? -eq 0 ] ; then rm -f $CWD/perms-test.txt else echo $RED"FAILED! "$NORMAL"You don't have permission to create files in" echo "the current directory: $CWD" FAILED=WRITE_PERMISSION fi touch $SRC_BUILDS_DIR/perms-test.txt &> /dev/null if [ $? -eq 0 ] ; then rm -f $SRC_BUILDS_DIR/perms-test.txt else echo $RED"FAILED! "$NORMAL"You don't have permission to create files in" echo "the SRC_BUILDS_DIR directory: $SRC_BUILDS_DIR" FAILED=WRITE_PERMISSION fi touch $PKG_BUILDS_DIR/perms-test.txt &> /dev/null if [ $? -eq 0 ] ; then rm -f $PKG_BUILDS_DIR/perms-test.txt else echo $RED"FAILED! "$NORMAL"You don't have permission to create files in" echo "the PKG_BUILDS_DIR directory: $PKG_BUILDS_DIR" FAILED=WRITE_PERMISSION fi touch $PKG_DEST_DIR/perms-test.txt &> /dev/null if [ $? -eq 0 ] ; then rm -f $PKG_DEST_DIR/perms-test.txt else echo $RED"FAILED! "$NORMAL"You don't have permission to create files in" echo "the PKG_DEST_DIR directory: $PKG_DEST_DIR" FAILED=WRITE_PERMISSION fi } # color get_color_options() { # Check for color prompting if [[ $COLOR_PROMPT = "YES" ]] ; then # ANSI COLORS CRE="" NORMAL="" # RED: Failure or error message RED="" # GREEN: Success message GREEN="" # YELLOW: Warnings YELLOW="" # BLUE: Summary messages BLUE="" # CYAN: Current Process CYAN="" fi }