## /usr/libexec/src2pkg/FUNCTIONS ## src2pkg FUNCTIONS Version-1.9.5 ## src2pkg (formerly PkgBuild) - Copyright 2005-2008 Gilbert Ashley ## src2pkg is free software released under the GNU General Public License Version 2 # How were we called? EXEC_NAME="${0##*/}" # Where were we called from? CWD ! [[ $CWD ]] && CWD=$(pwd) #&& export CWD # allow for user-specific src2pkg.conf files. If present, it is sourced before # the GLOBAL_CONF file. This allows users to have specific settings, but # still allows the system administrator to override any settings [[ -e ~/.src2pkg.conf ]] && . ~/.src2pkg.conf # If GLOBAL_CONF is not specified, look for the default GLOBAL.conf file ! [[ $GLOBAL_CONF ]] && GLOBAL_CONF="/etc/src2pkg/src2pkg.conf" # Read in the global configuration if it's there, though you can run without one. [[ -e $GLOBAL_CONF ]] && . $GLOBAL_CONF # You could also keep more than one configuration file as separate 'profiles' # and use the GLOBAL_CONF variable to control their use. This could be # used in much the same way as gentoo 'USE' or conary 'FLAVOR', # allowing you to set a group of global variables for particular ARCH's, etc # This variable allows you to run src2pkg from a non-standard location, if # needed. Then just make sure that DEFINES, FUNCTIONS and all the # separate function files are in the same directory. This would allow you # to run src2pkg from your $HOME directory or can be used to 'bootstrap' # src2pkg with itself. ! [[ $SRC2PKG_LIBDIR ]] && SRC2PKG_LIBDIR=/usr/libexec/src2pkg ## The DEFINES file sets some very important default variables which are needed for ## the individual functions. These variables set up the basic default behaviour of ## src2pkg. Advanced users could conceivably change some of the basic defaults ## by editing the DEFINES file. However, a better way is to put any permanent ## defaults in the src2pkg.conf file using the same syntax as is used in DEFINES ## The DEFINES file is kept separate so that no one should need to edit this ## FUNCTIONS file or any of the individual function files sourced by this file. ## The DEFINES file must be present for src2pkg to run correctly. ! [[ $DEFINES ]] && DEFINES=$SRC2PKG_LIBDIR/DEFINES if [[ -e $DEFINES ]] ; then source $DEFINES else echo "Warning! DEFINES file not found." FAILED="NO DEFINES" exit 0 fi ## This FUNCTIONS file used to contain *all* the src2pkg code except for ## what is found in the DEFINES file. But, since the code base has become ## quite large, since src2pkg-1.9 the code has been split up into separate ## files. This should make it easier to read and understand for those who ## are interested and makes it easier to work on for myself (and contributors). ## src2pkg is based on shell functions, each of which performs the ## steps associated with one step of preparing and building a package. ## So, each file mostly contains all the code which is used by each of the 16 ## src2pkg package-building instruction or steps. The names of each file ## are the same as the name of the src2pkg function, preceeded by a number ## which makes them easier to follow and to find specific parts of the code. ## The only exception to this is for the fake_install function. Since src2pkg ## can use any one of 3 different methods for creating the package content ## and the code is rather long, each of these methods is contained in a ## separate file. the file 08-fake_install contains the main function and ## the files 08A*, 08B* and 08C* contain the sub-functions. ## 'source' each of the smaller functions file to read in the code . $SRC2PKG_LIBDIR/01-pre_process . $SRC2PKG_LIBDIR/02-find_source . $SRC2PKG_LIBDIR/03-make_dirs . $SRC2PKG_LIBDIR/04-unpack_source . $SRC2PKG_LIBDIR/05-fix_source_perms . $SRC2PKG_LIBDIR/06-configure_source . $SRC2PKG_LIBDIR/07-compile_source . $SRC2PKG_LIBDIR/08-fake_install . $SRC2PKG_LIBDIR/08A-destdir_install . $SRC2PKG_LIBDIR/08B-jail_root_install . $SRC2PKG_LIBDIR/08C-real_root_install . $SRC2PKG_LIBDIR/09-fix_pkg_perms . $SRC2PKG_LIBDIR/10-strip_bins . $SRC2PKG_LIBDIR/11-create_docs . $SRC2PKG_LIBDIR/12-compress_man_pages . $SRC2PKG_LIBDIR/13-make_description . $SRC2PKG_LIBDIR/14-make_doinst . $SRC2PKG_LIBDIR/15-make_package . $SRC2PKG_LIBDIR/16-post_process ## None of the code in the above files is actually executed until the functions are ## called by the src2pkg program or from a src2pkg script. A standard src2pkg script ## calls the 16 steps in order as does the src2pkg command-line program. The program ## 'trackinstall' which is included with src2pkg is similar to checkinstall. Since it ## works with already decompressed and (mostly) compiled sources, it does not need ## all the steps. So only a partial list of them is called by trackinstall. Some of the src2pkg ## command-line options also use only a partial list of the functions. ### When no special code is needed and all processing steps can be succesfully run when ### building a package, it is possible to substitute the list of 16 steps (the functions) with ### a single 'short-cut' function which is named do_all_processes. ### The function do_all_processes summarizes the default execution order into a single ### command. Showing this here provides an overview of the standard list of commands. ### Most of the functions in this list also call other internal functions. But this list is the ### list used for a standard build and combined with the variables constitutes an API. ### Function do_all_processes ######################################## do_all_processes() { # This is exactly the way the functions are written in a standard src2pkg script: pre_process find_source make_dirs unpack_source fix_source_perms configure_source compile_source fake_install fix_pkg_perms strip_bins create_docs compress_man_pages make_description make_doinst make_package post_process } ### End Function do_all_processes ####################################### ### Processing Functions ## As mentioned above, the indiviudal processing functions which each perform a separate ## step in the package-making process have been split out into individual files. Some of the ## main functions which correspond to the list above also call sub-functions. Most of these ## sub-functions will be found in the same file they are called from. So, the only thing left ## in this file are a few small general functions which are called by various other functions. ## General Functions used internally # Eliminate whitespace function: white_out() { while read GAGA ; do echo $GAGA done } ## User cancelled at a safe place, so don't warn safe_user_cancel() { USER_CANCELLED=1 } ## User cancelled at a 'sensitive' spot, so scold them! trap_int() { echo echo $RED"*** OUCH!!! ***"$NORMAL emergency_restore FAILED="CANCELLED" exit } make_simple_desc() { echo $BLUE"Creating new.$PKG_DESC file - "$NORMAL echo "Edit, if needed and rename to $PKG_DESC for use." cat /dev/null > $CWD/new.$PKG_DESC # Align the text formatting guide starting at ':' (plus one space) namelen=${#NAME} offset=$(( $namelen + 1 )) spaces=0 echo -n '#' >> $CWD/new.$PKG_DESC while [[ $spaces -lt $offset ]] ; do echo -n ' ' >> $CWD/new.$PKG_DESC (( spaces++ )) done echo "|-------------Use this guide to format your text with--------------|" >> $CWD/new.$PKG_DESC cat >> $CWD/new.$PKG_DESC << END $NAME: $BLURB_1 $NAME: $BLURB_2 $NAME: $BLURB_3 $NAME: $BLURB_4 $NAME: $BLURB_5 $NAME: $BLURB_6 $NAME: $BLURB_7 $NAME: $BLURB_8 $NAME: $BLURB_9 $NAME: $BLURB_10 $NAME: $BLURB_11 END if [[ $BLURB_12 ]] ; then echo $NAME: ${BLURB_12} >> $CWD/$NAME.src2pkg.auto fi if [[ $BLURB_13 ]] ; then echo $NAME: ${BLURB_13} >> $CWD/$NAME.src2pkg.auto fi } write_script_src2pkg() { echo $BLUE"Writing build script - "$NORMAL"$NAME.src2pkg.auto in the current directory." # src2pkg.auto echo "#!/bin/bash" > $CWD/$NAME.src2pkg.auto echo "## src2pkg script for: $NAME" >> $CWD/$NAME.src2pkg.auto echo "## Auto-generated by src2pkg-$SRC2PKG_VERSION" >> $CWD/$NAME.src2pkg.auto echo "## src2pkg Copyright 2005-2008 Gilbert Ashley " >> $CWD/$NAME.src2pkg.auto #echo "## Full package name: $SHORT_NAME.tgz" >> $CWD/$NAME.src2pkg.auto echo "" >> $CWD/$NAME.src2pkg.auto if [[ $SOURCE_URL ]] ; then echo "SOURCE_URL='$SOURCE_URL'" >> $CWD/$NAME.src2pkg.auto echo "# SOURCE_NAME='$SOURCE_NAME'" >> $CWD/$NAME.src2pkg.auto elif [[ $SOURCE_NAME ]] ; then echo "SOURCE_NAME='$SOURCE_NAME'" >> $CWD/$NAME.src2pkg.auto fi if [[ "$ALT_NAME" != "" ]] ;then echo "ALT_NAME='$ALT_NAME'" >> $CWD/$NAME.src2pkg.auto else echo "NAME='$NAME'" >> $CWD/$NAME.src2pkg.auto fi if [[ "$ALT_VERSION" != "" ]] ;then echo "ALT_VERSION='$ALT_VERSION'" >> $CWD/$NAME.src2pkg.auto else echo "VERSION='$VERSION'" >> $CWD/$NAME.src2pkg.auto fi [[ $SRC_SUFFIX ]] && echo "SRC_SUFFIX='$SRC_SUFFIX'" >> $CWD/$NAME.src2pkg.auto echo "# ARCH='$ARCH'" >> $CWD/$NAME.src2pkg.auto echo "BUILD='$BUILD'" >> $CWD/$NAME.src2pkg.auto echo "PRE_FIX='$PRE_FIX'" >> $CWD/$NAME.src2pkg.auto echo "# Any extra options go here" >> $CWD/$NAME.src2pkg.auto [[ "$STD_CONFIGS" != "" ]] && echo "STD_CONFIGS='$STD_CONFIGS'" >> $CWD/$NAME.src2pkg.auto [[ $WRITE_CONFIG_COMMAND ]] && echo "CONFIG_COMMAND='$CONFIG_COMMAND'" >> $CWD/$NAME.src2pkg.auto if [[ "$EXTRA_CONFIGS" != "" ]] ; then echo "EXTRA_CONFIGS='${EXTRA_CONFIGS}'" >> $CWD/$NAME.src2pkg.auto else echo "# EXTRA_CONFIGS='${EXTRA_CONFIGS}'" >> $CWD/$NAME.src2pkg.auto fi if [[ $WRITE_FLAGS ]] ; then echo "STD_FLAGS='$STD_FLAGS'" >> $CWD/$NAME.src2pkg.auto else echo "# STD_FLAGS='$STD_FLAGS'" >> $CWD/$NAME.src2pkg.auto fi [[ $WRITE_INSTALL_TYPE ]] && echo "INSTALL_TYPE='$INSTALL_TYPE'" >> $CWD/$NAME.src2pkg.auto [[ $NEW_BUILD ]] && get_patch_list [[ "$PATCHLIST" != "" ]] && echo "PATCHLIST='${PATCHLIST}'" >> $CWD/$NAME.src2pkg.auto [ "$MAKEFILE" != "" -a "$MAKEFILE" != "Makefile" ] && echo "MAKEFILE='$MAKEFILE'" >> $CWD/$NAME.src2pkg.auto [ "$MAKE_COMMAND" != "" -a "$MAKE_COMMAND" != "make" ] && echo "MAKE_COMMAND='$MAKE_COMMAND'" >> $CWD/$NAME.src2pkg.auto [ "$INSTALL_LINE" != "" -a "$INSTALL_LINE" != "make install" ] && echo "INSTALL_LINE='$INSTALL_LINE'" >> $CWD/$NAME.src2pkg.auto if [[ $FUNNY_SUBDIR ]] ; then echo "CONFIG_SUBDIR='$FUNNY_SUBDIR'" >> $CWD/$NAME.src2pkg.auto elif [[ $CONFIG_SUBDIR ]] && [[ $NEW_BUILD ]] ; then echo "CONFIG_SUBDIR='$CONFIG_SUBDIR'" >> $CWD/$NAME.src2pkg.auto fi [[ "$DOCLIST" ]] && echo "DOCLIST='$DOCLIST'" >> $CWD/$NAME.src2pkg.auto [[ "$USE_OBJ_DIR" = "YES" ]] && echo "USE_OBJ_DIR='YES'" >> $CWD/$NAME.src2pkg.auto [[ $AUTO_PATCH = "NO" ]] && echo "AUTO_PATCH='NO'" >> $CWD/$NAME.src2pkg.auto [[ $CORRECT_PERMS = "NO" ]] && echo "CORRECT_PERMS='NO'" >> $CWD/$NAME.src2pkg.auto [[ $EXTRA_SOURCES ]] && echo "EXTRA_SOURCES='$EXTRA_SOURCES'" >> $CWD/$NAME.src2pkg.auto echo "" >> $CWD/$NAME.src2pkg.auto echo "# Get the functions and configs" >> $CWD/$NAME.src2pkg.auto echo ". /usr/libexec/src2pkg/FUNCTIONS ;" >> $CWD/$NAME.src2pkg.auto echo "" >> $CWD/$NAME.src2pkg.auto echo "# do_all_processes can substitute these 16 steps:" >> $CWD/$NAME.src2pkg.auto echo "" >> $CWD/$NAME.src2pkg.auto cat >> $CWD/$NAME.src2pkg.auto << EOF pre_process find_source make_dirs unpack_source fix_source_perms configure_source compile_source fake_install fix_pkg_perms strip_bins create_docs compress_man_pages make_description make_doinst make_package post_process EOF echo "" >> $CWD/$NAME.src2pkg.auto echo "# src2pkg - Copyright 2005-2008 Gilbert Ashley " >> $CWD/$NAME.src2pkg.auto echo "## See the documentation for more help and examples. Below are some of" >> $CWD/$NAME.src2pkg.auto echo "# the most common Extras and Options for easy cut-and-paste use." >> $CWD/$NAME.src2pkg.auto echo "# EXTRA_CONFIGS='' PRE_FIX='' DOCLIST=''" >> $CWD/$NAME.src2pkg.auto echo "# MAKE_COMMAND='' INSTALL_LINE='' " >> $CWD/$NAME.src2pkg.auto echo "# SHELL_INSTALL='YES' CORRECT_PERMS='NO'" >> $CWD/$NAME.src2pkg.auto echo "# When editing src2pkg scripts to add custom code, use these variables" >> $CWD/$NAME.src2pkg.auto echo "# to refer to the current directory, the sources or the package tree:" >> $CWD/$NAME.src2pkg.auto echo "# \$CWD (current directory), \$SRC_DIR (sources), \$PKG_DIR (package tree)" >> $CWD/$NAME.src2pkg.auto # echo "" >> $CWD/$NAME.src2pkg.auto }