2009-04-06 15:13:06 +01:00
|
|
|
#!/bin/bash
|
2006-07-25 19:19:59 +01:00
|
|
|
# lw-build-system/scripts/module-create.sh
|
2006-07-25 19:00:04 +01:00
|
|
|
#
|
2009-01-03 22:55:04 +00:00
|
|
|
# (c)2009, Laurence Withers, <l@lwithers.me.uk>.
|
2007-10-14 11:31:40 +01:00
|
|
|
# Released under the GNU GPLv3. See file COPYING or
|
2006-07-25 19:00:04 +01:00
|
|
|
# http://www.gnu.org/copyleft/gpl.html for details.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Creates a new source module.
|
|
|
|
|
2006-07-26 20:18:00 +01:00
|
|
|
# save a copy of the commandline for the upgrade script
|
|
|
|
MODULE_PARAMS="$@"
|
|
|
|
|
2006-07-25 19:00:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Get the directory of the repository (needed to include functions file)
|
|
|
|
cd $(dirname $0)
|
|
|
|
cd $(dirname $(pwd))
|
2006-07-25 19:49:22 +01:00
|
|
|
P=$(basename $(pwd))
|
2006-07-26 19:30:26 +01:00
|
|
|
TOP=$(pwd)
|
2006-07-25 19:00:04 +01:00
|
|
|
[ -z "${VERBOSE}" ] && VERBOSE="0"
|
2009-04-06 15:13:06 +01:00
|
|
|
source "./scripts/functions.sh" || exit 1
|
2006-07-25 19:00:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Get arguments.
|
|
|
|
if [ $# -lt 3 ]
|
|
|
|
then
|
2006-12-09 16:32:22 +00:00
|
|
|
echo "Usage: scripts/module-create.sh <type> <lang> <name> [args]"
|
2006-12-08 15:08:09 +00:00
|
|
|
echo " available modules:"
|
2006-07-25 19:00:04 +01:00
|
|
|
for i in scripts/build.*
|
|
|
|
do
|
2006-12-08 15:08:09 +00:00
|
|
|
echo $i | sed "s,scripts/build\.\([^.]*\)\.\(.*\), module: \1 lang: \2,"
|
2006-07-25 19:00:04 +01:00
|
|
|
done
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
TYPE=$1
|
|
|
|
shift
|
2006-12-09 16:32:22 +00:00
|
|
|
LANG=$1
|
|
|
|
shift
|
2006-07-25 19:00:04 +01:00
|
|
|
NAME=$1
|
|
|
|
shift
|
2006-12-09 16:32:22 +00:00
|
|
|
TEMPLATE=scripts/build.${TYPE}.${LANG}
|
2006-07-25 19:00:04 +01:00
|
|
|
|
|
|
|
if [ ! -e ${TEMPLATE}/instantiate ]
|
|
|
|
then
|
|
|
|
echo "No such module type."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2006-07-25 19:28:20 +01:00
|
|
|
|
|
|
|
|
2006-07-25 19:49:22 +01:00
|
|
|
# function to rename a package to a bash/C identifier
|
|
|
|
get_cname() {
|
2006-07-30 13:13:31 +01:00
|
|
|
echo $1 | tr +-. p__
|
2006-07-25 19:49:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-07-25 19:28:20 +01:00
|
|
|
# function used to replace variables
|
|
|
|
# assumes that we're in the directory to replace files in
|
|
|
|
# for each argument X, it will replace @X@ with ${X}
|
|
|
|
do_parameter_subst() {
|
2006-07-25 19:49:22 +01:00
|
|
|
CNAME=$(get_cname ${NAME})
|
2009-04-06 15:17:04 +01:00
|
|
|
do_cmd source "${HOME}/.lwbuildrc" || exit 1
|
2006-07-25 19:49:22 +01:00
|
|
|
for param in P NAME CNAME AUTHOR EMAIL VIM_MODELINE KATE_MODELINE $@
|
2006-07-25 19:28:20 +01:00
|
|
|
do
|
2006-07-25 19:49:22 +01:00
|
|
|
do_cmd_redir sedscript echo "s,@${param}@,${!param},g" || exit 1
|
2006-07-25 19:28:20 +01:00
|
|
|
done
|
2006-07-25 19:49:22 +01:00
|
|
|
do_cmd find . -type f -a -not -name sedscript -exec sed -f sedscript -i {} \; || exit 1
|
|
|
|
do_cmd rm sedscript || exit 1
|
2006-07-25 19:28:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-12-08 15:51:18 +00:00
|
|
|
# function used to add configuration variables
|
|
|
|
# adds variables to the 'config' file; expects name and default value
|
|
|
|
# some default default values are given below
|
|
|
|
add_config_option() {
|
|
|
|
# don't add it if it already exists
|
|
|
|
grep -q "{$1}" ../../config && return 0
|
|
|
|
|
|
|
|
# add the default line
|
|
|
|
echo "[ -z \"\${$1}\" ] && $1=\"$2\"" >> ../../config
|
|
|
|
}
|
|
|
|
COPT_CC_DEFAULT="gcc"
|
|
|
|
COPT_CXX_DEFAULT="g++"
|
|
|
|
COPT_CFLAGS_DEFAULT="-g -O2 -W -Wall"
|
|
|
|
COPT_QTSTUFF_DEFAULT='-I${QTDIR}/include -L${QTDIR}/lib -lqt-mt'
|
|
|
|
|
|
|
|
|
2006-08-01 15:23:28 +01:00
|
|
|
if [ ! -e "src" ]
|
|
|
|
then
|
|
|
|
do_cmd mkdir src || exit 1
|
|
|
|
fi
|
|
|
|
|
2006-07-25 19:59:37 +01:00
|
|
|
if [ -e "src/${NAME}" ]
|
|
|
|
then
|
|
|
|
print_failure "Module 'src/${NAME}' already exists"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2006-07-25 20:19:46 +01:00
|
|
|
cleanup() {
|
2006-07-26 19:30:26 +01:00
|
|
|
cd ${TOP}
|
2006-07-25 20:19:46 +01:00
|
|
|
rm -rf "src/${NAME}"
|
|
|
|
print_failure "Removed 'src/${NAME}'"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2006-07-25 19:59:37 +01:00
|
|
|
echo "Instantiating module 'src/${NAME}'..."
|
2006-07-25 20:19:46 +01:00
|
|
|
do_cmd cp -rL ${TEMPLATE} src/${NAME} || cleanup
|
|
|
|
do_cmd cd src/${NAME} || cleanup
|
|
|
|
do_cmd rm instantiate || cleanup
|
2006-07-26 20:18:00 +01:00
|
|
|
do_cmd_redir .params echo "${MODULE_PARAMS}" || cleanup
|
2006-07-25 19:59:37 +01:00
|
|
|
|
2009-04-06 15:13:06 +01:00
|
|
|
( source "../../${TEMPLATE}/instantiate" ) || cleanup
|
2006-07-25 19:59:37 +01:00
|
|
|
|
2006-07-25 19:49:22 +01:00
|
|
|
print_success "Module instantiated"
|
|
|
|
grep -r "@TODO@" .
|
|
|
|
true
|
2006-07-25 19:00:04 +01:00
|
|
|
|
|
|
|
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
2007-08-08 13:03:18 +01:00
|
|
|
# vim: syntax=sh:expandtab:ts=4:sw=4
|