libutf8/make.sh

297 lines
7.5 KiB
Bash
Raw Normal View History

2006-07-31 15:21:56 +01:00
#!/bin/bash
# libutf8/make.sh
#
2009-10-13 11:12:52 +01:00
# (c)2006-2009, Laurence Withers, <l@lwithers.me.uk>.
2009-10-13 11:22:29 +01:00
# Released under the GNU GPLv3. See file COPYING or
2006-07-31 15:21:56 +01:00
# http://www.gnu.org/copyleft/gpl.html for details.
#
# This file is the script used to build libutf8. There are some
2009-10-13 11:22:29 +01: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-31 15:21:56 +01:00
# Get version information
2009-10-13 11:22:29 +01:00
source "./version" || exit 1
2006-07-31 15:21:56 +01:00
VERSION="${VERMAJOR}.${VERMINOR}.${VERMICRO}"
# Get standard functions
[ -z "${VERBOSE}" ] && VERBOSE="0"
2009-10-13 11:22:29 +01:00
source "./scripts/functions.sh" || exit 1
2006-07-31 15:21:56 +01:00
# List of directories which will be emptied by clean.
OUTPUT_DIRS="obj html"
# 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
2009-10-13 11:22:29 +01:00
# MONOLITHIC_OPTIONS will #define the options to match the respective
# environment variables.
2006-07-31 15:21:56 +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-31 15:21:56 +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
2009-10-13 11:22:29 +01:00
HASHDEFINE=0
2006-07-31 15:21:56 +01:00
if [ "$2" == "C" ]
then
HASHLINE=1
VERDEFINE=1
2009-10-13 11:22:29 +01:00
HASHDEFINE=1
elif [ "$2" == "Ch" ]
then
HASHLINE=1
2009-10-13 11:22:29 +01:00
HASHDEFINE=1
2006-07-31 15:21:56 +01:00
elif [ "$2" == "none" ]
then
2009-10-13 11:22:29 +01:00
HASHLINE=0 # dummy command
2006-07-31 15:21:56 +01:00
else
2009-10-13 11:22:29 +01:00
print_failure "make_monolithic() called with unknown format $2"
2006-07-31 15:21:56 +01:00
return 1
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
break
fi
done
if [ ${MODIFIED} -ne 0 ]
then
do_cmd mkdir -p $(dirname ${MONOLITHIC_OUT})
do_cmd rm -f ${MONOLITHIC_OUT} || exit 1
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
2009-10-13 11:22:29 +01: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-31 15:21:56 +01:00
for FILE in ${MONOLITHIC_SOURCE}
do
if [ ${HASHLINE} -ne 0 ]
then
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
2009-10-13 11:22:29 +01:00
build_dir_tree_recurse "${INSTALL_PREFIX}$1"
}
build_dir_tree_recurse() {
2006-07-31 15:21:56 +01:00
local DIR="$1"
# 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
2009-10-13 11:22:29 +01:00
build_dir_tree_recurse $(dirname "${DIR}") || return 1
echo " Creating directory '${DIR}'"
do_cmd mkdir "${DIR}"
2006-07-31 15:21:56 +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
2009-10-13 11:22:29 +01:00
DEST_FILE="${INSTALL_PREFIX}$2"
[ -d "${DEST_FILE}" ] && DEST_FILE="${INSTALL_PREFIX}$2/$(basename $1)"
2006-07-31 15:21:56 +01:00
2009-10-13 11:22:29 +01:00
echo " Installing: '$1' -> '${DEST_FILE}'"
2006-07-31 15:21:56 +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() {
2009-10-13 11:22:29 +01:00
DEST_FILE="${INSTALL_PREFIX}$2"
[ -d "${DEST_FILE}" ] && DEST_FILE="${INSTALL_PREFIX}$2/$(basename $1)"
2006-07-31 15:21:56 +01:00
2009-10-13 11:22:29 +01:00
echo " Installing: '$1' -> '${DEST_FILE}'"
2006-07-31 15:21:56 +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() {
2009-10-13 11:22:29 +01:00
echo " Installing symlink: '${INSTALL_PREFIX}$3/$1' -> '$2'"
2006-07-31 15:21:56 +01:00
2009-10-13 11:22:29 +01:00
( do_cmd ln -sf $2 ${INSTALL_PREFIX}$3/$1 ) || return 1
2006-07-31 15:21:56 +01:00
return 0
}
build_target() {
ITEMS="src/$1/build.default"
if [ ! -e "${ITEMS}" ]
then
ITEMS="$(find src -type f -name build.$1)"
fi
if [ -z "${ITEMS}" ]
then
print_failure "Unrecognised target '$1'"
return 1
fi
for item in ${ITEMS}
do
do_cmd source ${item} || exit 1
done
return 0
}
########################################################################
# Main script
########################################################################
if [ $# -eq 0 ]
then
targets="default"
else
targets="$@"
fi
for func in ${targets}
2006-07-31 15:21:56 +01:00
do
case ${func} in
clean)
echo "Cleaning..."
rm -rf ${OUTPUT_DIRS}
print_success "Done"
2009-10-13 11:22:29 +01:00
true
2006-07-31 15:21:56 +01:00
;;
# bad Kdevelop! bad!
-j1)
;;
-k)
;;
*)
build_target ${func} || exit 1
;;
esac
done
exit 0
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
# vim: expandtab:ts=4:sw=4