## /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 # 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 ]] && source $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 }