131 lines
3.1 KiB
Bash
Executable File
131 lines
3.1 KiB
Bash
Executable File
#!/bin/bash
|
|
# lw-build-system/scripts/module-create.sh
|
|
#
|
|
# (c)2006, Laurence Withers, <l@lwithers.me.uk>.
|
|
# Released under the GNU GPLv2. See file COPYING or
|
|
# http://www.gnu.org/copyleft/gpl.html for details.
|
|
#
|
|
|
|
# Creates a new source module.
|
|
|
|
# save a copy of the commandline for the upgrade script
|
|
MODULE_PARAMS="$@"
|
|
|
|
|
|
|
|
# Get the directory of the repository (needed to include functions file)
|
|
cd $(dirname $0)
|
|
cd $(dirname $(pwd))
|
|
P=$(basename $(pwd))
|
|
TOP=$(pwd)
|
|
[ -z "${VERBOSE}" ] && VERBOSE="0"
|
|
source scripts/functions.sh || exit 1
|
|
|
|
|
|
|
|
# Get arguments.
|
|
if [ $# -lt 3 ]
|
|
then
|
|
echo "Usage: scripts/module-create.sh <lang> <type> <name> [args]"
|
|
echo " available modules:"
|
|
for i in scripts/build.*
|
|
do
|
|
echo $i | sed "s,scripts/build\.\([^.]*\)\.\(.*\), module: \1 lang: \2,"
|
|
done
|
|
exit 1
|
|
fi
|
|
LANG=$1
|
|
shift
|
|
TYPE=$1
|
|
shift
|
|
NAME=$1
|
|
shift
|
|
TEMPLATE=scripts/build.${LANG}.${TYPE}
|
|
|
|
if [ ! -e ${TEMPLATE}/instantiate ]
|
|
then
|
|
echo "No such module type."
|
|
exit 1
|
|
fi
|
|
|
|
|
|
|
|
# function to rename a package to a bash/C identifier
|
|
get_cname() {
|
|
echo $1 | tr +-. p__
|
|
}
|
|
|
|
|
|
|
|
# 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() {
|
|
CNAME=$(get_cname ${NAME})
|
|
do_cmd source ~/.lwbuildrc || exit 1
|
|
for param in P NAME CNAME AUTHOR EMAIL VIM_MODELINE KATE_MODELINE $@
|
|
do
|
|
do_cmd_redir sedscript echo "s,@${param}@,${!param},g" || exit 1
|
|
done
|
|
do_cmd find . -type f -a -not -name sedscript -exec sed -f sedscript -i {} \; || exit 1
|
|
do_cmd rm sedscript || exit 1
|
|
}
|
|
|
|
|
|
|
|
# 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_BINDIR_DEFAULT='${PREFIX}/bin'
|
|
COPT_LIBDIR_DEFAULT='${PREFIX}/lib'
|
|
COPT_HEXDIR_DEFAULT='${PREFIX}/hexdir'
|
|
COPT_INCLUDEDIR_DEFAULT='${PREFIX}/include'
|
|
COPT_FINALLIBDIR_DEFAULT='${LIBDIR}'
|
|
COPT_FINALINCLUDEDIR_DEFAULT='${INCLUDEDIR}'
|
|
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'
|
|
COPT_DOCSDIR_DEFAULT="\${PREFIX}/doc/${P}"
|
|
|
|
|
|
if [ ! -e "src" ]
|
|
then
|
|
do_cmd mkdir src || exit 1
|
|
fi
|
|
|
|
if [ -e "src/${NAME}" ]
|
|
then
|
|
print_failure "Module 'src/${NAME}' already exists"
|
|
exit 1
|
|
fi
|
|
|
|
cleanup() {
|
|
cd ${TOP}
|
|
rm -rf "src/${NAME}"
|
|
print_failure "Removed 'src/${NAME}'"
|
|
exit 1
|
|
}
|
|
|
|
echo "Instantiating module 'src/${NAME}'..."
|
|
do_cmd cp -rL ${TEMPLATE} src/${NAME} || cleanup
|
|
do_cmd cd src/${NAME} || cleanup
|
|
do_cmd rm instantiate || cleanup
|
|
do_cmd_redir .params echo "${MODULE_PARAMS}" || cleanup
|
|
|
|
( source ../../${TEMPLATE}/instantiate ) || cleanup
|
|
|
|
print_success "Module instantiated"
|
|
grep -r "@TODO@" .
|
|
true
|
|
|
|
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
|
# vim: expandtab:ts=4:sw=4
|