# This file is part of the src2pkg program: # Copyright 2005-2008 Gilbert Ashley # src2pkg is released under the GNU General Public License Version 2 ### configure_source configure_source() { if [[ "$FAILED" = "" ]] ; then if [[ "$CONFIG_COMMAND" = "skip" ]] ; then echo $BLUE"Skipped configure_source - "$NORMAL CONFIG_DIR=$SRC_DIR else # find the main configuration directory if [[ $CONFIG_SUBDIR ]] ; then CONFIG_DIR=$SRC_DIR/$CONFIG_SUBDIR else for keydir in $SRC_DIR $SRC_DIR/src $SRC_DIR/Src $SRC_DIR/source $SRC_DIR/$NAME-$VERSION $SRC_DIR/$NAME $SRC_DIR/$NAMElib $SRC_DIR/lib$NAME $SRC_DIR/$VERSION $SRC_DIR/abi ; do for keyfile in configure Makefile configure.in configure.ac Makefile.in Makefile.am autogen.sh GNUmakefile GNUmakefile.in GNUmakefile.am Imakefile SConstruct makefile Jamfile install.sh setup.py ; do if [[ -e $keydir/$keyfile ]] ; then CONFIG_SUBDIR=$keydir KEYFILE="$keyfile" break ; fi done if [[ $CONFIG_SUBDIR ]] ; then CONFIG_DIR=$keydir break ; fi if [[ $CONFIG_DIR ]] ; then CONFIG_DIR=$keydir break ; fi done fi [[ $DEBUG ]] && echo $BLUE"Using keyfile: "$NORMAL"$KEYFILE" ! [[ "$CONFIG_DIR" ]] && CONFIG_DIR=$SRC_DIR if [[ "$CONFIG_DIR" != "$SRC_DIR" ]] ; then FUNNY_SUBDIR=$(basename $CONFIG_DIR) echo $BLUE"Notice - "$NORMAL"The configuration files are in a subdirectory: $FUNNY_SUBDIR" ! [[ $USE_OBJ_DIR ]] && OBJ_DIR=$CONFIG_DIR fi ! [[ $USE_OBJ_DIR ]] && [[ ! $OBJ_DIR ]] && OBJ_DIR=$CONFIG_DIR # If there are GNUmakefile.in or GNUmakefile.am files *and* a Makefile we have to get # rid of the Makefile as it would take precedence over the generated GNUmakefile if [[ -e $CONFIG_DIR/GNUmakefile.in ]] && [[ -e $CONFIG_DIR/Makefile ]] ; then echo $BLUE"Notice - "$NORMAL"This packages uses GNUmakefiles, instead of Makefiles." if ! [[ $USE_DEFAULT_MAKEFILES = "YES" ]] ; then MAKEFILE="GNUmakefile" #if [[ -e $CONFIG_DIR/Makefile ]] ; then echo "We rename the Makefile to Makefile.found and start fresh." echo "If not, the Makefile would be used instead of the new GNUmakefile." mv $CONFIG_DIR/Makefile $CONFIG_DIR/Makefile.found #fi fi elif [[ -e $CONFIG_DIR/Makefile.in ]] && [[ -e $CONFIG_DIR/GNUmakefile ]] ; then # If there are Makefile.in or Makefile.am files *and* a GNUmakefile we have to get # rid of the GNUmakefile as it might take precedence over the generated Makefile echo $BLUE"Notice - "$NORMAL"This packages contains both a Makefile.in and a GNUmakefile." if ! [[ $USE_DEFAULT_MAKEFILES = "YES" ]] ; then MAKEFILE="Makefile" #if [[ -e $CONFIG_DIR/Makefile ]] ; then echo "We rename the GNUmakefile to GNUmakefile.found and start fresh." echo "If not, the GNUmakefile might be used instead of the new Makefile." mv $CONFIG_DIR/GNUmakefile $CONFIG_DIR/GNUmakefile.found #fi fi fi if [[ -e $CONFIG_DIR/makefile ]] ; then MAKEFILE="makefile" elif [[ -e $CONFIG_DIR/GNUmakefile ]] || [[ -e $CONFIG_DIR/GNUmakefile.am ]] || [[ -e $CONFIG_DIR/GNUmakefile.in ]] ; then MAKEFILE="GNUmakefile" elif [[ -e $CONFIG_DIR/Makefile ]] || [[ -e $CONFIG_DIR/Makefile.am ]] || [[ -e $CONFIG_DIR/Makefile.in ]] ; then MAKEFILE="Makefile" fi if [[ $PATCHES_APPLIED ]] && [[ $SHOULD_AUTORECONF ]] && [[ "$AUTORECONF" != "NO" ]] ; then echo $CYAN"NOTICE - "$NORMAL"'.am', '.ac' or '.in' config files were patched" #echo " You can disable this with AUTORECONF=NO if necessary." echo -n $BLUE"Regenerating config files - "$NORMAL"Using: autoreconf -if " cd $CONFIG_DIR ; autoreconf --install --force &> /dev/null autoconf &> /dev/null echo $GREEN"Done!"$NORMAL fi if ! [[ -x $CONFIG_DIR/configure ]] ; then if [[ -e $CONFIG_DIR/configure.in ]] || [[ -e $CONFIG_DIR/configure.ac ]] ; then if [[ -e $CONFIG_DIR/$MAKEFILE.in ]] && [[ -e $CONFIG_DIR/$MAKEFILE.am ]] ; then echo -n $BLUE"Found autoconf files. "$NORMAL"We'll try running autoconf - " cd $CONFIG_DIR ; autoconf 1> /dev/null && echo $GREEN"Done"$NORMAL || echo $YELLOW"FAILED!"$NORMAL elif [[ -e $CONFIG_DIR/$MAKEFILE.am ]] ; then echo -n $BLUE"Found incomplete autoconf sources - "$NORMAL"Running autoreconf -if " cd $CONFIG_DIR ; autoreconf -if &> /dev/null autoconf &> /dev/null echo $GREEN"Done!"$NORMAL fi fi fi if ! [[ -x $CONFIG_DIR/configure ]] && [[ -e $CONFIG_DIR/autogen.sh ]] ; then echo "Found an autogen.sh script. We'll try running that - " cd $CONFIG_DIR ; sh ./autogen.sh 2> /dev/null && echo $GREEN"Done"$NORMAL || echo $YELLOW"FAILED!"$NORMAL echo -n "Now we'll try running autoconf - " autoconf 2> /dev/null && echo $GREEN"Done"$NORMAL || echo $YELLOW"FAILED!"$NORMAL fi # if all else fails try this generic routine. if ! [[ -x $CONFIG_DIR/configure ]] && [[ -e $CONFIG_DIR/$MAKEFILE.am ]] && [[ -e $CONFIG_DIR/$MAKEFILE.in ]] ; then if [[ -e $CONFIG_DIR/configure.ac ]] || [[ -e $CONFIG_DIR/configure.in ]] ; then echo $BLUE"Found Makefile.am and configure.in. "$NORMAL"We'll try with these generic commands:" echo "aclocal -I. ; autoheader ; automake -a --force --copy --foreign ; autoconf" [[ -d $CONFIG_DIR/autom4te.cache ]] && rm -rf $CONFIG_DIR/autom4te.cache [[ -d $CONFIG_DIR/.deps ]] && rm -rf $CONFIG_DIR/.deps [[ -f $CONFIG_DIR/.deps ]] && rm -f $CONFIG_DIR/.deps [[ -f $CONFIG_DIR/config.status ]] && rm -f $CONFIG_DIR/config.status [[ -f $CONFIG_DIR/config.cache ]] && rm -f $CONFIG_DIR/config.cache cd $CONFIG_DIR ; # automake aclocal -I . 2> /dev/null 1> /dev/null autoheader 2> /dev/null 1> /dev/null # automake --add-missing --copy --foreign 2> /dev/null 1> /dev/null automake -a --force --copy --foreign 2> /dev/null 1> /dev/null autoconf 2> /dev/null fi if ! [[ -x $CONFIG_DIR/configure ]] ; then echo $YELLOW"WARNING! "$NORMAL"This looks like a non-working autoconf package or maybe needs automake-1.4." if [[ -e $CONFIG_DIR/$MAKEFILE ]] ; then echo "But we have a Makefile, so we'll proceed anyway. Maybe it's your lucky day." else echo $YELLOW"WARNING! "$NORMAL"No Makefile and no configure script found. "$BLUE"Skipping..."$NORMAL fi fi fi if [[ -x $CONFIG_DIR/configure ]] ; then trap safe_user_cancel 2 echo -n $BLUE"Found configure script - "$NORMAL if [[ $USE_OBJ_DIR = "YES" ]] ; then echo "" echo $BLUE"Using OBJ_DIR: "$NORMAL "$(basename ${OBJ_DIR})" if [[ -e $CONFIG_DIR/$MAKEFILE ]] ; then echo $BLUE"NOTICE - "$NORMAL"Stale Makefile found. Running 'make distclean' - " cd $CONFIG_DIR && make distclean &> /dev/null && echo $GREEN"Okay"$NORMAL fi if ! [[ $CONFIG_COMMAND ]] ; then CONFIG_COMMAND="../$SRC_DIR_NAME/configure" ; else CONFIG_COMMAND="../$SRC_DIR_NAME/$CONFIG_COMMAND" ; fi fi if ! [[ $CONFIG_COMMAND ]] ; then CONFIG_COMMAND="$CONFIG_DIR/configure" else CONFIG_COMMAND="$CONFIG_DIR/$CONFIG_COMMAND" fi # if no EXTRA_CONFIGS were given and we are in AUTO_SCRIPT mode, # look for defaults in an rpm spec file or debian 'rules', if one is present if [[ $EXTRA_CONFIGS = "" ]] && [[ $AUTO_SCRIPT ]] ; then if [[ -e $SRC_DIR/$NAME.spec ]] ; then SPECFILE=$SRC_DIR/$NAME.spec elif [[ -e $SRC_DIR/$NAME.spec.in ]] ; then SPECFILE=$SRC_DIR/$NAME.spec.in fi if [[ $SPECFILE != "" ]] ; then FOREIGN_CONFIGS=$(cat $SPECFILE | get_rpm_config) [[ $FOREIGN_CONFIGS = "" ]] && FOREIGN_CONFIGS=$(cat $SPECFILE | get_rpm_config2) [[ $FOREIGN_CONFIGS = "" ]] && FOREIGN_CONFIGS=$(cat $SPECFILE | get_rpm_cflags_config) elif [[ -e $SRC_DIR/debian/rules ]] ; then SPECFILE=$SRC_DIR/debian/rules FOREIGN_CONFIGS=$(cat $SPECFILE | get_deb_config) fi if [[ $FOREIGN_CONFIGS != "" ]] ; then echo"" echo $BLUE"Found default configuration options in: "$NORMAL"$(basename $SPECFILE)" fi EXTRA_CONFIGS=$FOREIGN_CONFIGS fi # if using interactive mode, pause and get config options from the user. Use the FOREIGN_CONFIGS from above if available if [[ "$QUERY_FOR_EXTRA_CONFIGS" = "YES" ]] ; then echo $BLUE"Running interactive configuration - "$NORMAL cd $CONFIG_DIR ; $CONFIG_COMMAND --help # show this prompt again since the --help command throws the first one way off the screen if [[ $FOREIGN_CONFIGS != "" ]] ; then DEFAULT_CONFIGS="$FOREIGN_CONFIGS" echo $BLUE"Default configuration options were found in:"$NORMAL $(basename $SPECFILE) fi echo $BLUE"Interactive mode: "$NORMAL"If you need to pass extra arguments to the configure" echo " script you can do so now. Using SHIFT+PGUP lets you scroll up to see the" echo " available options. Don't pass the '--prefix=??' as it is supplied separately." echo " Just press ENTER to accept the default of: $DEFAULT_CONFIGS" read NEW_CONFIGS if [[ $NEW_CONFIGS != "" ]] ; then EXTRA_CONFIGS=$NEW_CONFIGS fi #echo "" fi CONFIG_ARGS="$(echo --prefix=/$PRE_FIX $STD_CONFIGS $EXTRA_CONFIGS| white_out)" if ! [[ $FLAG_LINE ]] ; then FLAG_LINE="$(echo $STD_FLAGS $EXTRA_FLAGS |white_out)" fi # try this by default -remove stale files -probably should use find for .deps [[ -d $CONFIG_DIR/autom4te.cache ]] && rm -rf $CONFIG_DIR/autom4te.cache [[ -d $CONFIG_DIR/.deps ]] && rm -rf $CONFIG_DIR/.deps [[ -f $CONFIG_DIR/.deps ]] && rm -f $CONFIG_DIR/.deps [[ -f $CONFIG_DIR/config.status ]] && rm -f $CONFIG_DIR/config.status [[ -f $CONFIG_DIR/config.cache ]] && rm -f $CONFIG_DIR/config.cache # run the configure script if [[ $QUIET = "YES" ]] ; then cd $OBJ_DIR ; echo "Configuring sources using:" echo " CFLAGS=$FLAG_LINE ./$(basename $CONFIG_COMMAND) $CONFIG_ARGS" export CFLAGS=$FLAG_LINE export CXXFLAGS=$FLAG_LINE export LDFLAGS $CONFIG_COMMAND $CONFIG_ARGS &> /dev/null else cd $OBJ_DIR ; echo "Configuring sources using:" echo " CFLAGS=$FLAG_LINE ./$(basename $CONFIG_COMMAND) $CONFIG_ARGS" echo "Messages from configure:" export CFLAGS=$FLAG_LINE export CXXFLAGS=$FLAG_LINE export LDFLAGS $CONFIG_COMMAND $CONFIG_ARGS fi if [[ $? -eq 0 ]] ; then echo $BLUE"Configuration has been - "$GREEN"Successful!"$NORMAL if [[ "$CONFIRM_BUILD" = "YES" ]] ; then echo -n $BLUE"Continue with the build? [ y or n ] > "$NORMAL read ANSWER if [ $ANSWER == "n" ]; then echo $RED"CANCELLED! "$NORMAL"Quitting at users request." FAILED="CANCELLED interactively" exit 0 fi fi elif [[ $USER_CANCELLED ]] ; then echo $RED"STOPPED! "$NORMAL"Operation cancelled during configuration!" FAILED="CANCELLED" else FAILED="configure_source" echo $RED"ERROR! "$NORMAL"Configuring sources has failed!"$NORMAL echo "This usually happens because of missing libraries, or you" echo "may need to pass extra options to configure using EXTRA_CONFIGS." if [[ $REPLAY_ERRORS = "YES" ]] && [[ $QUIET = "YES" ]] ; then if [[ $DISPLAY ]] ; then cd $CONFIG_DIR ; echo $CYAN"NOTICE-"$NORMAL"Replaying failed configuration in a separate xterm:" export CFLAGS=$STD_FLAGS$EXTRA_FLAGS ( xterm -hold -e "$CONFIG_COMMAND" "$CONFIG_ARGS" & ) else cd $CONFIG_DIR ; echo $CYAN"NOTICE-"$NORMAL"Replaying failed configuration:" export CFLAGS=$STD_FLAGS$EXTRA_FLAGS $CONFIG_COMMAND $CONFIG_ARGS fi else show_requires #./configure --help=short &> /dev/null #if [[ $? -eq 0 ]] ; then # ./configure --help=short #else echo $BLUE"Running 'configure --help:"$NORMAL ./configure --help #fi fi fi elif [[ -f $CONFIG_DIR/Imakefile ]] ; then if ! [[ $USE_DEFAULT_MAKEFILES = "YES" ]] ; then echo -n $BLUE"Found Imakefile - "$NORMAL"Configuring using: 'xmkmf -a' - " cd $CONFIG_DIR ; xmkmf -a 2> /dev/null 1> /dev/null MAKEFILE="Makefile" echo $GREEN"Done"$NORMAL fi elif [[ -f $CONFIG_DIR/SConstruct ]] ; then echo -n $BLUE"Found SConstruct file - "$NORMAL"Configuring using: 'scons configure' - " cd $CONFIG_DIR ; if [[ $QUIET = "YES" ]] ; then scons configure 2> /dev/null 1> /dev/null else scons configure fi MAKEFILE="SConstruct" echo $GREEN"Done"$NORMAL elif [[ -f $CONFIG_DIR/$MAKEFILE ]] ; then #echo $BLUE"Skipping autoconf configuration - "$NORMAL"Continuing since we found a "$BLUE"$MAKEFILE"$NORMAL cd $CONFIG_DIR ; if [[ -f $CONFIG_DIR/CMakeLists.txt ]] && [[ "$(grep 'cmake' $MAKEFILE)" != "" ]] ; then if ! [[ $FLAG_LINE ]] ; then FLAG_LINE="$(echo $STD_FLAGS $EXTRA_FLAGS |white_out)" #export CFLAGS=$FLAG_LINE fi export CFLAGS=$FLAG_LINE echo $BLUE"Found 'cmake' configuration - "$NORMAL"Configuring using: cmake . -DCMAKE_INSTALL_PREFIX=/${PRE_FIX}" if ! [[ $(which cmake) ]] ; then echo $RED"FAILED! "$NORMAL"No cmake found in path. "$RED"Exiting..."$NORMAL FAILED="CONFIGURATION - Missing cmake" elif [[ "$PRE_FIX" != "usr/local" ]] ; then if [[ $QUIET = "YES" ]] ; then # this is what you need to change the default PREFIX for cmake non-interactively cmake . -DCMAKE_INSTALL_PREFIX=/${PRE_FIX} &> /dev/null else cmake . -DCMAKE_INSTALL_PREFIX=/${PRE_FIX} fi else if [[ $QUIET = "YES" ]] ; then cmake . &> /dev/null else cmake . fi fi elif [[ $(find . -name "$MAKEFILE" |wc -l) -ge 1 ]] ; then # We have at least one Makfile so we continue echo $BLUE"Skipping autoconf configuration:"$NORMAL echo $BLUE"Continuing - "$NORMAL"We found at least one "$BLUE"$MAKEFILE"$NORMAL fi elif [[ -f $CONFIG_DIR/setup.py ]] ; then #MAKEFILE="setup.py" MAKE_COMMAND="./setup.py build" INSTALL_LINE="./setup.py install" else echo $BLUE"Skipping configure_source - "$NORMAL fi # Some Makefiles have hard-coded installation paths to /usr/local and some configure routines # also fail to set prefix properly because the variable is called PREFIX, DEST or INSTALLROOT # We try to correct these here unless the user is using PRE_FIX under /usr/local or /opt in which # case CORRECT_MAKEFILES will have been set to NO in pre_process if [[ "$CORRECT_MAKEFILES" != "NO" ]] && [[ $(find . -name "$MAKEFILE") ]] ; then if [[ "$(grep 'PREFIX' $MAKEFILE |grep 'usr/local' )" != "" ]] \ || [[ "$(grep 'prefix' $MAKEFILE |grep 'usr/local' )" != "" ]] \ || [[ "$(grep 'DEST' $MAKEFILE |grep 'usr/local' )" != "" ]] \ || [[ "$(grep 'INSTALLROOT' $MAKEFILE |grep 'usr/local' )" != "" ]] ; then echo $CYAN"NOTICE - "$NORMAL"Correcting $MAKEFILE(s) with incorrect hard-coded prefix." find . -name "$MAKEFILE" |xargs sed -i -e s:"/usr/local":"/$PRE_FIX": fi fi fi fi } get_rpm_config() { LINE_COUNT=0 FIRST_LINE=0 LAST_LINE=0 while read LINE ; do (( LINE_COUNT++ )) CHUNK=$LINE if [[ $FIRST_LINE -ne 0 ]] && [[ $LINE_COUNT -eq $FIRST_LINE ]] ; then echo $CHUNK elif [[ ${CHUNK:0:10} = "%configure" ]] && [[ $FIRST_LINE -eq 0 ]] ; then if [[ ${CHUNK:10} != "" ]] ; then CHUNK=${CHUNK/\%configure/} CHUNK=${CHUNK/--prefix=/} CHUNK=${CHUNK/\%_prefix/} CHUNK=${CHUNK/\%_libdir//$PRE_FIX/lib} echo $CHUNK fi FIRST_LINE=$(( $LINE_COUNT )) elif [[ ${CHUNK:0:1} = "%" ]] || [[ ${CHUNK:0:1} != " " ]] && [[ $FIRST_LINE -ne 0 ]] ; then LAST_LINE=$(( $LINE_COUNT -1 )) break elif [[ $FIRST_LINE -ne 0 ]] && [[ $LAST_LINE -eq 0 ]] ; then if [[ "$CHUNK" != "" ]] ; then CHUNK=${CHUNK/\%configure/} CHUNK=${CHUNK/--prefix=/} CHUNK=${CHUNK/\%_prefix/} CHUNK=${CHUNK/\%_libdir//$PRE_FIX/lib} echo $CHUNK fi fi done } get_rpm_config2() { FOUND_LINE=0 while read LINE ; do (( LINE_COUNT++ )) CHUNK=$LINE if [[ ${CHUNK:0:11} = "./configure" ]] && [[ $FOUND_LINE -eq 0 ]] ; then # the configure options are everything to the right of ./configure CHUNK=${CHUNK#*./configure} # remove the --prefix stuff CHUNK=${CHUNK/--prefix=/} CHUNK=${CHUNK/\%_prefix/} # if --prefix was hard coded above then it still remains (/usr) # so skip to the next '--'option to the right CHUNK=--${CHUNK#*--} # substitute these rpm options with slackware defaults CHUNK=${CHUNK/\%_libdir//$PRE_FIX/lib} CHUNK=${CHUNK/\%_infodir//usr/info} CHUNK=${CHUNK/\%_mandir//usr/man} #CHUNK=${CHUNK/\%_datadir//usr\/lib} CHUNK=${CHUNK/\%_sysconfdir//etc} echo $CHUNK FOUND_LINE=1 fi done } get_rpm_cflags_config() { FOUND_LINE=0 while read LINE ; do (( LINE_COUNT++ )) CHUNK=$LINE if [[ ${CHUNK:0:7} = "CFLAGS=" ]] && [[ $FOUND_LINE -eq 0 ]] ; then if [[ ${CHUNK:8} != "" ]] ; then # get the CFLAGS -everything to the left of ./configure CFLAGS=${CHUNK%./configure*} # remove these variables which we don't use CFLAGS=${CFLAGS/\$RPM_OPT_FLAGS /} CFLAGS=${CFLAGS/\$EXTRACFLAGS/} # the configure options are everything to the right of ./configure CHUNK=${CHUNK#*./configure} # remove the --prefix stuff CHUNK=${CHUNK/--prefix=/} CHUNK=${CHUNK/\%\{_prefix\}/} # if --prefix was hard coded above then it still remains (/usr) # so skip to the next '--'option to the right CHUNK=--${CHUNK#*--} # substitute these rpm options with slackware defaults CHUNK=${CHUNK/\%\{_infodir\}/\/usr\/info} CHUNK=${CHUNK/\%\{_mandir\}/\/usr\/man} CHUNK=${CHUNK/\%\{_datadir\}/\/usr\/lib} CHUNK=${CHUNK/\%\{_sysconfdir\}/\/etc} echo $CHUNK fi FOUND_LINE=1 fi done } get_deb_config() { FOUND_LINE=0 while read LINE ; do (( LINE_COUNT++ )) CHUNK=$LINE #echo $LINE if [[ $(echo $CHUNK |grep "./configure" ) != "" ]] && [[ $FOUND_LINE -eq 0 ]] ; then # the configure options are everything to the right of ./configure CHUNK=${CHUNK#*./configure} # remove the --host stuff CHUNK=${CHUNK/--host=/} CHUNK=${CHUNK/\$\(DEB_HOST_GNU_TYPE\)/} # remove the --host stuff CHUNK=${CHUNK/--build=/} CHUNK=${CHUNK/\$\(DEB_BUILD_GNU_TYPE\)/} # remove the --prefix stuff CHUNK=${CHUNK/--prefix=\/usr\/} CHUNK=${CHUNK/--prefix=\/usr} CHUNK=${CHUNK/--prefix=/} # if --prefix was hard coded above then it still remains (/usr) # so skip to the next '--'option to the right [[ "$CHUNK" != "" ]] && CHUNK=--${CHUNK#*--} # substitute these debian options with slackware defaults CHUNK=${CHUNK/\$\$\{prefix\}/\/$PRE_FIX} #CHUNK=${CHUNK/$${prefix}/\/$PRE_FIX} CHUNK=${CHUNK/usr\/share\/info/usr\/info} CHUNK=${CHUNK/usr\/share\/man/usr\/man} CHUNK=${CHUNK/usr\/share\/doc/usr\/doc} [[ "$CHUNK" = "-- " ]] && CHUNK="" [[ "$CHUNK" = "--" ]] && CHUNK="" [[ "$CHUNK" != "" ]] && echo $CHUNK FOUND_LINE=1 fi done }