Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
444 lines (364 sloc) 12.2 KB
#!/bin/bash
# #
# build.lunar - building routines #
# #
############################################################
# #
# this WAS the subroutines of a source based Linux distro, #
# calls Sorcerer GNU/Linux, or SGL. SGL is no longer #
# available with GPL license. Since this script was taken #
# before licensing scheme change, no legal problems I #
# guess. #
# #
# the code is re-written for Lunar. The previous Copyright #
# notices are kept; just in case some code is left :=) #
# Kagan Kongar <kongar@tsrsb.org.tr>, 20020519 #
# #
############################################################
# #
# Copyright 2001 by Kyle Sallee #
# #
# Parts Copyrighted Hendrik Visage 2002 under GPLv2 #
# #
# Parts Copyrighted Kagan Kongar 2002 under GPLv2 #
# #
# Parts Copyrighted Steven Michalske 2004 under GPLv2 #
# #
############################################################
save_libraries() {
local OLD_VERSION OLD_LOG OLD_LIBS SAVED LINE
debug_msg "save_libraries ($@)"
[ "$MODULE" == "glibc" ] && return 0
OLD_VERSION=`installed_version $MODULE`
OLD_LOG=$INSTALL_LOGS/$MODULE-$OLD_VERSION
[ -e "$OLD_LOG" ] || return 0
OLD_LIBS=$SOURCE_DIRECTORY/old.libraries
mkdir -p $OLD_LIBS
SAVED=$OLD_LIBS/$MODULE.saved.libraries
rm -rf $SAVED
grep "/lib/" "$OLD_LOG" |
while read LINE; do
if [ -f "$LINE" ] &&
file -bL $LINE |
grep -q "shared object"
then
verbose_msg "saving library \"$LINE\""
if [ -h $LINE ]; then
DEST=$( basename $( ls -la "$LINE" |
cut -d '>' -f2 |
cut -c 2-
)
)
ln -sf $DEST $OLD_LIBS/`basename $LINE`
else
cp $LINE $OLD_LIBS
fi
echo $OLD_LIBS/`basename $LINE` >> $SAVED
fi
done
ldconfig $OLD_LIBS
if [ -z "$LD_LIBRARY_PATH" ]
then export LD_LIBRARY_PATH="$OLD_LIBS"
else export LD_LIBRARY_PATH="$OLD_LIBS:$LD_LIBRARY_PATH"
fi
}
release_saved_libraries() {
local OLD_LIBS SAVED FILE
debug_msg "release_saved_libraries ($@)"
OLD_LIBS=$SOURCE_DIRECTORY/old.libraries
SAVED=$OLD_LIBS/$MODULE.saved.libraries
if [ -f $SAVED ] ; then
while read FILE ; do
verbose_msg "releasing library \"$FILE\""
rm -f "$FILE"
done < $SAVED
fi
ldconfig $OLD_LIBS
}
export_ld() {
local DIRECTORY
debug_msg "export_ld ($@)"
for DIRECTORY in $* ; do
if file -b $DIRECTORY/*.so* | grep -q "shared object" ; then
if [ -z "$LD_LIBRARY_PATH" ] ; then
export LD_LIBRARY_PATH="$DIRECTORY"
else
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$DIRECTORY"
fi
fi
done
}
prepare_install() {
debug_msg "prepare_install ($@)"
if module_installed $MODULE || module_held $MODULE ; then
message "${MESSAGE_COLOR}Preparing to install" \
"${MODULE_COLOR}${MODULE}${DEFAULT_COLOR}"
save_libraries
verbose_msg "calling \"lrm --upgrade $MODULE\""
lrm --upgrade $MODULE
true
fi
# turn on tracking now
invoke_installwatch
plugin_call BUILD_INSTALL $MODULE
if [ $? == 2 ]; then
return 0
fi
}
default_pre_build() {
debug_msg "default_pre_build ($@)"
verbose_msg "running \"default_pre_build\""
validate_source_dir $SOURCE_DIRECTORY
if [[ -d $SOURCE_DIRECTORY ]] &&
[[ $KEEP_SOURCE == "on" ]]; then
cd $SOURCE_DIRECTORY &&
make clean
if [ $? -ne 0 ]; then
message "${PROBLEM_COLOR}ERROR: ${DEFAULT_COLOR}The source for ${MODULE_COLOR}$MODULE${DEFAULT_COLOR}: could not be made clean for build."
# Thoughts on forcing a new source directory?
# More of how should we handle this, currently we will bail out
# A vast majority of the moonbase will fail, (w/o: make clean)
fi
else
mk_source_dir $SOURCE_DIRECTORY &&
unpack $SOURCE
fi
}
# wrapper function to call ./configure
_configure()
{
debug_msg "_configure($@)"
if [ -e ./configure ]; then
verbose_msg "./configure $@"
./configure $@
elif [ -e Makefile -o -e makefile ]; then
verbose_msg "Missing \"configure\": skipping configure stage."
else
error_message "${PROBLEM_COLOR}Missing ${FILE_COLOR}configure${PROBLEM_COLOR} and/or ${FILE_COLOR}Makefile${PROBLEM_COLOR}!${DEFAULT_COLOR}"
return 1
fi
}
# cmake can be run two ways: in source and out of source. The determinante method is
# to look for a cmake macro, if it exists then do out of source. There have been inconsistancies
# with this, some apps compile fine out of source and others do not with the leaning towards
# more wanting out of source even though they do not say so. Making this the default and
# for those that do not want it, specify it in the BUILD.
cmake_build_target() {
debug_msg "cmake_build_target ($@)"
verbose_msg "running \"Out of source build is required; configuring\""
OOSB_DIR="$SOURCE_DIRECTORY/$MODULE-oosb" &&
mkdir $OOSB_DIR &&
cd $OOSB_DIR
}
default_config() {
debug_msg "default_config ($@)"
verbose_msg "running \"default_config\""
_configure --build=$BUILD \
--prefix=$MODULE_PREFIX \
--sysconfdir=/etc \
--localstatedir=/var \
--infodir=$MODULE_PREFIX/share/info \
--mandir=$MODULE_PREFIX/share/man \
$OPTS
}
default_game_config() {
debug_msg "default_game_config ($@)"
verbose_msg "running \"default_game_config\""
_configure --build=$BUILD \
--prefix=$MODULE_PREFIX \
--bindir=$MODULE_PREFIX/games \
--datadir=$MODULE_PREFIX/share/games \
--sysconfdir=/etc \
--localstatedir=/var/games \
--infodir=$MODULE_PREFIX/share/info \
--mandir=$MODULE_PREFIX/share/man \
$OPTS
}
default_cvs_config() {
debug_msg "default_cvs_config ($@)"
verbose_msg "running \"default_cvs_config\""
verbose_msg "MODULE_PREFIX=\"$MODULE_PREFIX\""
./autogen.sh --build=$BUILD \
--prefix=$MODULE_PREFIX \
--sysconfdir=/etc \
--localstatedir=/var \
--infodir=$MODULE_PREFIX/share/info \
--mandir=$MODULE_PREFIX/share/man \
$OPTS
}
default_cmake_config() {
debug_msg "default_cmake_config ($@)"
verbose_msg "running \"default_cmake_config\""
verbose_msg "MODULE_PREFIX=\"$MODULE_PREFIX\""
cmake_build_target
cmake -DCMAKE_INSTALL_PREFIX=$MODULE_PREFIX \
-DCMAKE_BUILD_TYPE=RELEASE \
-DSYSCONF_INSTALL_DIR:PATH=/etc \
$OPTS $SOURCE_DIRECTORY
}
default_make() {
debug_msg "default_make ($@)"
verbose_msg "running \"default_make\""
make ${MAKES:+-j${MAKES}} &&
prepare_install &&
make install
}
default_game_build() {
debug_msg "default_game_build ($@)"
verbose_msg "running \"default_game_build\""
default_game_config &&
default_make
}
default_cmake_build() {
debug_msg "default_cmake_build ($@)"
verbose_msg "running \"default_cmake_build\""
default_cmake_config &&
default_make
}
default_build() {
debug_msg "default_build ($@)"
verbose_msg "running \"default_build\""
default_config &&
default_make
}
default_cvs_build() {
debug_msg "default_cvs_build ($@)"
default_cvs_config &&
default_make
}
default_cpan_pre_build() {
local CPAN_MODULE CPAN_SOURCE_BRANCH
debug_msg "default_cpan_pre_build ($@)"
mk_source_dir $SOURCE_DIRECTORY
cd $SOURCE_DIRECTORY
CPAN_MODULE=${SOURCE_URL/cpan:\/\//}
CPAN_SOURCE_BRANCH=$(dirname $CPAN_MODULE)
mkdir -p authors/id/${CPAN_SOURCE_BRANCH}
install -m 444 $SOURCE_CACHE/$SOURCE authors/id/${CPAN_SOURCE_BRANCH}
}
default_cpan_build() {
local CPAN_MODULE
debug_msg "default_cpan_build ($@)"
prepare_install
verbose_msg "running \"default_cpan_build\""
if [ ! -x /usr/bin/cpan ] ; then
return 1
fi
CPAN_MODULE=${SOURCE_URL/cpan:\/\//}
echo "o conf cpan_root $STATE_DIRECTORY
o conf build_dir $SOURCE_DIRECTORY
o conf keep_source_where $SOURCE_DIRECTORY
install $CPAN_MODULE
quit" | /usr/bin/cpan || exit 1
rm_source_dir $SOURCE_DIRECTORY
}
default_post_build() {
debug_msg "default_post_build ($@)"
if [ $(wc -l $INSTALLWATCHFILE | awk '{print$1}') == "0" ] &&
[ "$PROFILE" != "yes" ] ; then
message "${PROBLEM_COLOR}WARNING: ${DEFAULT_COLOR}${FILE_COLOR}BUILD${DEFAULT_COLOR}${PROBLEM_COLOR} does not call prepare_install or installs zero files!${DEFAULT_COLOR}"
fi
update_plugin $MODULE install
plugin_call BUILD_POST_BUILD $MODULE
if [ $? != 2 ]; then
message "${PROBLEM_COLOR}ERROR: problems running POST_BUILD plugins!${PROBLEM_COLOR}"
return 1
fi
ldconfig
release_saved_libraries
cd /
}
syms_not_owned() {
local DEST
debug_msg "syms_not_owned ($@)"
while read ITEM ; do
if [ -h "$ITEM" ] && [ -f "$ITEM" ]; then
DEST=$(basename $(ls -la "$ITEM" | cut -d '>' -f2 | cut -c 2- ) )
if ! grep -q "$DEST" "$1" ; then
echo -n "$ITEM\|"
echo "$ITEM" >> $TMPDIR/$MODULE.rejected.symlinks
fi
fi
done < $1
}
prepare_module_config() {
debug_msg "prepare_module_config ($@)"
if [ ! -e "$MODULE_CONFIG" ] ; then
> $MODULE_CONFIG
fi
}
# run the CONFIGURE script
run_configure() {
debug_msg "run_configure ($@)"
if [ -n "$RECONFIGURE" ]; then
verbose_msg "Reconfiguring \"$MODULE\""
rm -f $DEPENDS_CONFIG/$MODULE
remove_depends $MODULE
fi
prepare_module_config
grep -q "^"$MODULE"\$" "$TEMP_PREPAREDDEPS" 2>/dev/null && return 0
# add custom passed OPTS before retrieving them
if [ -n "$PASS_OPTS" ] ; then
SAVE_OPTS="$(get_module_config OPTS) $PASS_OPTS"
set_module_config OPTS "$SAVE_OPTS"
fi
plugin_call BUILD_CONFIGURE $MODULE
if has_module_file $MODULE CONFIGURE ; then
run_module_file $MODULE CONFIGURE
fi
# store $OPTS for later use
echo "$MODULE:$OPTS" >> $TEMP_CONFIGOPTS
}
run_pre_build() {
debug_msg "run_pre_build ($@)"
message "${MESSAGE_COLOR}Building ${MODULE_COLOR}$MODULE${DEFAULT_COLOR}${MESSAGE_COLOR} version ${MODULE_COLOR}$VERSION${DEFAULT_COLOR}"
cd $BUILD_DIRECTORY
if verify_all_sources $MODULE ; then
plugin_call BUILD_PRE_BUILD $MODULE
if has_module_file $MODULE PRE_BUILD ; then
run_module_file $MODULE PRE_BUILD
else
if ! default_pre_build ; then
return 1
fi
fi
else
return 1
fi
}
run_build() {
debug_msg "run_build ($@)"
if [[ -d "$SOURCE_DIRECTORY" ]] ; then
cd $SOURCE_DIRECTORY
fi
verbose_msg "building \"$MODULE\" version \"$VERSION\" in `pwd`"
# this calls optimizations and others:
plugin_call BUILD_BUILD $MODULE
# now override compile wrappers if needed:
if [[ "${USE_WRAPPERS:-yes}" == "yes" ]]; then
export PATH=/var/lib/lunar/compilers:$PATH
fi
(
# fix errors, don't avoid them. This makes all errors fatal
shopt -s execfail
if has_module_file $MODULE BUILD ; then
run_module_file $MODULE BUILD
else
default_build
fi
) > $C_FIFO 2>&1
}
run_post_build() {
debug_msg "run_post_build ($@)"
if has_module_file $MODULE POST_BUILD ; then
run_module_file $MODULE POST_BUILD
fi
default_post_build
}
run_post_install() {
debug_msg "run_post_install ($@)"
plugin_call BUILD_POST_INSTALL $MODULE
if has_module_file $MODULE POST_INSTALL ; then
run_module_file $MODULE POST_INSTALL
fi
}
Something went wrong with that request. Please try again.