lw-build-system/skel/make.sh

297 lines
7.4 KiB
Bash
Raw Normal View History

#!/bin/bash
2006-07-24 14:24:06 +01:00
# @P@/make.sh
#
2009-01-03 22:55:04 +00:00
# (c)2009, @AUTHOR@, <@EMAIL@>.
2007-10-14 11:31:40 +01:00
# Released under the GNU GPLv3. See file COPYING or
# http://www.gnu.org/copyleft/gpl.html for details.
2006-07-24 14:24:06 +01:00
#
# This file is the script used to build @P@. There are some
2006-12-08 16:21:38 +00:00
# options that can be edited; these are set in the file 'config' (or you
# can pass them in as environment variables).
if [ ! -e "config" ]
then
echo "Configuration file not found???"
exit 1
fi
source "./config" # don't fail on error, since last command in config might return false
2006-07-25 09:54:09 +01:00
2006-07-24 14:24:06 +01:00
# Get version information
source "./version" || exit 1
2006-07-24 14:24:06 +01:00
VERSION="${VERMAJOR}.${VERMINOR}.${VERMICRO}"
# Get standard functions
[ -z "${VERBOSE}" ] && VERBOSE="0"
source "./scripts/functions.sh" || exit 1
2006-07-24 14:24:06 +01:00
# List of directories which will be emptied by clean.
OUTPUT_DIRS="obj html"
2006-07-24 14:24:06 +01:00
# This function makes a monolithic file out of several source files. Its
# first argument is the name of the output file, and the second is the
# format of monolithic file to create (for example, "C" will cause the
# inclusion of "#line" directives at the top of each included file).
#
# It also examines the following variables:
# MONOLITHIC_TESTS if any file mentioned in this list is newer
# than the output file, then we recreate it
# MONOLITHIC_SOURCE a list (in order) of the source files
2007-02-02 21:38:36 +00:00
# MONOLITHIC_OPTIONS will #define the options to match the respective
# environment variables.
2006-07-24 14:24:06 +01:00
#
# Recognised formats are:
# none no special processing happens before each file
# C #line directives are inserted before each file
# and VERSION, VERMAJOR etc. are #defined
# Ch Like C, but for header files (no VERSION #defines)
2006-07-24 14:24:06 +01:00
#
make_monolithic() {
if [ $# -ne 2 ]
then
print_failure "make_monolithic() called with wrong number of arguments"
print_failure "(expecting 2, got $#)"
return 1
fi
MONOLITHIC_OUT=$1
# extract options
HASHLINE=0
VERDEFINE=0
2007-02-02 21:38:36 +00:00
HASHDEFINE=0
2006-07-24 14:24:06 +01:00
if [ "$2" == "C" ]
then
HASHLINE=1
2006-07-24 15:32:19 +01:00
VERDEFINE=1
2007-02-02 21:38:36 +00:00
HASHDEFINE=1
elif [ "$2" == "Ch" ]
then
HASHLINE=1
2007-02-02 21:38:36 +00:00
HASHDEFINE=1
2006-07-24 14:24:06 +01:00
elif [ "$2" == "none" ]
then
2007-02-02 21:38:36 +00:00
HASHLINE=0 # dummy command
2006-07-24 14:24:06 +01:00
else
2007-02-02 21:38:36 +00:00
print_failure "make_monolithic() called with unknown format $2"
2006-07-24 15:32:19 +01:00
return 1
2006-07-24 14:24:06 +01:00
fi
echo " Building monolithic file '${MONOLITHIC_OUT}'..."
MODIFIED=0
for FILE in ${MONOLITHIC_TESTS} ${MONOLITHIC_SOURCE}
do
if [ ! -e "${FILE}" ]
then
print_failure "'${FILE}' does not exist"
return 1
fi
if [ "${FILE}" -nt ${MONOLITHIC_OUT} ]
then
MODIFIED=1
2006-07-24 15:32:19 +01:00
break
2006-07-24 14:24:06 +01:00
fi
done
if [ ${MODIFIED} -ne 0 ]
then
2006-07-24 15:32:19 +01:00
do_cmd mkdir -p $(dirname ${MONOLITHIC_OUT})
2006-07-24 14:24:06 +01:00
do_cmd rm -f ${MONOLITHIC_OUT} || exit 1
2006-07-24 15:32:19 +01:00
if [ ${VERDEFINE} -ne 0 ]
then
do_cmd_redir ${MONOLITHIC_OUT} echo "#define VERSION \"${VERSION}\"" || return 1
do_cmd_redir ${MONOLITHIC_OUT} echo "#define VERMAJOR ${VERMAJOR}" || return 1
do_cmd_redir ${MONOLITHIC_OUT} echo "#define VERMINOR ${VERMINOR}" || return 1
do_cmd_redir ${MONOLITHIC_OUT} echo "#define VERMICRO ${VERMICRO}" || return 1
do_cmd_redir ${MONOLITHIC_OUT} echo "#define VEREXTRA \"${VEREXTRA}\"" || return 1
fi
2006-07-24 14:24:06 +01:00
2007-02-02 21:38:36 +00:00
if [ ${HASHDEFINE} -ne 0 ]
then
for opt in ${MONOLITHIC_OPTIONS}
do
do_cmd_redir ${MONOLITHIC_OUT} echo "#define ${opt} ${!opt}" || return 1
done
fi
2006-07-24 14:24:06 +01:00
for FILE in ${MONOLITHIC_SOURCE}
do
2006-07-24 15:32:19 +01:00
if [ ${HASHLINE} -ne 0 ]
then
2006-07-24 14:24:06 +01:00
do_cmd_redir ${MONOLITHIC_OUT} echo "#line 1 \"${FILE}\"" || return 1
fi
do_cmd_redir ${MONOLITHIC_OUT} cat "${FILE}" || return 1
done
print_success "Done"
else
print_success "Up to date"
fi
}
# This will build a directory tree, if required, with mode 0755. The
# argument is the directory to build.
build_dir_tree() {
# sanity check
if [ $# -ne 1 ]
then
print_failure "build_dir_tree() called with wrong number of arguments"
print_failure "(expecting 1, got $#)"
return 1
fi
2007-02-05 13:36:48 +00:00
build_dir_tree_recurse "${INSTALL_PREFIX}$1"
}
build_dir_tree_recurse() {
local DIR="$1"
2006-07-24 14:24:06 +01:00
# if the directory already exists, return success
[ -d "${DIR}" ] && return 0
# if something with this name already exists, but not a directory,
# then fail
if [ -e "${DIR}" ]
then
print_failure "Failed to create directory '${DIR}'"
return 1
fi
# build the directory, but if it fails, recurse a level (and handle
# the case where recursion fails)
mkdir "${DIR}" >& /dev/null
if [ $? -ne 0 ]
then
2007-02-05 13:36:48 +00:00
build_dir_tree_recurse $(dirname "${DIR}") || return 1
2007-02-05 13:49:17 +00:00
echo " Creating directory '${DIR}'"
do_cmd mkdir "${DIR}"
2006-07-24 14:24:06 +01:00
if [ $? -ne 0 ]
then
print_failure "Failed to create directory '${DIR}'"
return 1
fi
fi
# set permissions on newly-created dir and return
chmod 0755 "${DIR}"
return 0
}
# This will install a file. The first parameter is the source, and the
# second is the destination. The third is the octal mode.
install_file() {
# figure out if $2 is a directory or not
DEST_FILE="${INSTALL_PREFIX}$2"
2007-02-05 13:49:17 +00:00
[ -d "${DEST_FILE}" ] && DEST_FILE="${INSTALL_PREFIX}$2/$(basename $1)"
2006-07-24 14:24:06 +01:00
2007-02-05 20:16:35 +00:00
echo " Installing: '$1' -> '${DEST_FILE}'"
2006-07-24 14:24:06 +01:00
do_cmd cp -fP "$1" "${DEST_FILE}" || return 1
do_cmd chmod "$3" "${DEST_FILE}" || return 1
return 0
}
# This will install a header file. It is basically similar to
# install_file(), only we strip out the #line directives.
install_header() {
DEST_FILE="${INSTALL_PREFIX}$2"
2007-02-05 13:49:17 +00:00
[ -d "${DEST_FILE}" ] && DEST_FILE="${INSTALL_PREFIX}$2/$(basename $1)"
2006-07-24 14:24:06 +01:00
2007-02-05 20:16:35 +00:00
echo " Installing: '$1' -> '${DEST_FILE}'"
2006-07-24 14:24:06 +01:00
do_cmd rm -f ${DEST_FILE} || exit 1
do_cmd_redir ${DEST_FILE} sed -e "s,^#line.*,," $1 || exit 1
do_cmd chmod "$3" "${DEST_FILE}" || return 1
return 0
}
# This installs a symlink. The first argument is the symlink's name; the
# second the symlink's source filename, and the third is the directory
# in which to create the symlink.
install_symlink() {
2007-02-05 14:58:38 +00:00
echo " Installing symlink: '${INSTALL_PREFIX}$3/$1' -> '$2'"
2006-07-24 14:24:06 +01:00
2007-02-05 14:58:38 +00:00
( do_cmd ln -sf $2 ${INSTALL_PREFIX}$3/$1 ) || return 1
2006-07-24 14:24:06 +01:00
return 0
}
build_target() {
2006-07-24 22:41:27 +01:00
ITEMS="src/$1/build.default"
2006-07-25 09:27:37 +01:00
if [ ! -e "${ITEMS}" ]
2006-07-24 22:41:27 +01:00
then
ITEMS="$(find src -type f -name build.$1)"
fi
2006-07-24 14:24:06 +01:00
if [ -z "${ITEMS}" ]
then
print_failure "Unrecognised target '$1'"
return 1
fi
for item in ${ITEMS}
do
2006-07-25 09:54:09 +01:00
do_cmd source ${item} || exit 1
2006-07-24 14:24:06 +01:00
done
return 0
}
########################################################################
# Main script
########################################################################
if [ $# -eq 0 ]
then
targets="default"
else
targets="$@"
fi
2006-08-01 13:50:04 +01:00
for func in ${targets}
2006-07-24 14:24:06 +01:00
do
case ${func} in
clean)
echo "Cleaning..."
rm -rf ${OUTPUT_DIRS}
2006-07-24 15:32:19 +01:00
print_success "Done"
2006-12-12 16:17:22 +00:00
true
2006-07-24 14:24:06 +01:00
;;
# bad Kdevelop! bad!
-j1)
;;
-k)
;;
*)
2006-07-24 15:32:19 +01:00
build_target ${func} || exit 1
2006-07-24 14:24:06 +01:00
;;
esac
done
exit 0
2006-07-24 22:41:27 +01:00
# kate: @KATE_MODELINE@
# vim: @VIM_MODELINE@