lw-build-system/create.sh

108 lines
2.3 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
#
# Copyright: ©20062010, Laurence Withers.
# Author: Laurence Withers <l@lwithers.me.uk>
# License: GPLv3
#
#
# Used to create a new project. You pass it the template parameters, it
# does the rest.
[ -z "${VERBOSE}" ] && VERBOSE="0"
# Sanity checks
case "$#" in
1)
DEST_DIR="$(pwd)"
P="$1"
;;
2)
DEST_DIR="$1"
P="$2"
;;
**)
echo "Creates a new project using lw-build-system."
echo "Usage: $0 [path/to/projects] @P@"
echo " path/to/projects directory in which project subdir will be created"
echo " @P@ package name"
exit 1
;;
esac
cd "$(dirname $0)"
TEMPLATE="$(pwd)/skel"
DEVSCRIPTS="$(pwd)/scripts"
# Get arguments, include standard functions
source "${TEMPLATE}/scripts/functions.sh" || exit 1
DEST_DIR="${DEST_DIR}/${P}"
# Ensure that we have our .lwbuildrc set up correctly.
LWBUILDRC="${HOME}/.lwbuildrc"
if [ ! -e "${LWBUILDRC}" ]
then
echo "You don't have a ${LWBUILDRC}, so I'll create a blank one for you."
do_cmd cp skel-.lwbuildrc ${LWBUILDRC}
echo "Edit this file, and then re-run the build process."
exit 1
fi
do_cmd source "${LWBUILDRC}" || exit 1
if [ -z "${COPYRIGHT}" ]
then
echo "You now need to set COPYRIGHT= in ~/.lwbuildrc ."
exit 1
fi
# Copy to destination directory. Deal with the case where the user has
# specified the name of the resulting directory, and the case where the
# user simply specified where the directory should be created.
echo "Copying ${TEMPLATE} directory..."
do_cmd cp -rp "${TEMPLATE}" "${DEST_DIR}" || exit 1
do_cmd cd "${DEST_DIR}" || exit 1
do_cmd mkdir src || exit 1
print_success "Done: $(pwd)"
# Fixups
echo "Installing symlinks, fixing up stuff..."
# Install devscript symlinks
do_cmd ln -s ${DEVSCRIPTS}/* scripts/ || exit 1
print_success "Done"
# Substitute all relevant variables in files
echo " Substituting variables in files"
YEAR="$(date +%Y)"
do_cmd find . -type f -exec sed \
-e "s,@P@,${P},g" \
-e "s,@AUTHOR@,${AUTHOR},g" \
-e "s,@EMAIL@,${EMAIL},g" \
-e "s,@COPYRIGHT@,${COPYRIGHT},g" \
-e "s,@YEAR@,${YEAR},g" \
-e "s,@VIM_MODELINE@,${VIM_MODELINE},g" \
-i {} \; || exit 1
# Print the todo list
echo
echo " ======== TODO list ========"
find . -type f -a -not -path './scripts/build.*' -exec grep -Hrn @TODO@ {} \;
print_success "Done"
# vim: expandtab:ts=4:sw=4