Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- usage()
- {
- cat <<EOF
- Usage: $(basename $0) [OPTIONS] NAME
- This script assists in setting up a default autotools project.
- OPTIONS:
- --help, -h Show this message
- --author, -a Set the project's author
- --target, -t Set the target directory
- EOF
- }
- run()
- {
- curdir="$PWD"
- echo -n "Creating project structure..."
- mkdir -p ${targetdir}
- cd "${targetdir}"
- cat > ./configure.ac <<EOF
- AC_INIT( [${projectname}], [0.1], [${author}] )
- AM_INIT_AUTOMAKE([-Wall -Werror foreign])
- AC_PROG_CC
- AC_CONFIG_HEADERS([config.h])
- AC_CONFIG_FILES([
- Makefile
- src/Makefile
- ])
- AC_OUTPUT
- EOF
- mkdir -p ./src
- cat > ./Makefile.am <<EOF
- SUBDIRS = src
- dist_doc_DATA = README
- EOF
- cat > ./src/Makefile.am <<EOF
- bin_PROGRAMS = ${projectname}
- ${projectname}_SOURCES = main.c
- EOF
- touch README
- autoreconf --install &> /dev/null
- cd "$curdir"
- echo "Done."
- }
- OPTIONS=`getopt -l help,author:,target: ha:t: "$@"`
- let ret=$?
- if [ $ret -eq 1 ];then
- usage
- exit 2
- fi
- set -- `getopt -l help,author:,target: ha:t: "$@"`
- [ $# -lt 1 ] && usage && exit 1 #Failed to get command line parameters
- while [ $# -gt 0 ];do
- case "$1" in
- #Help options
- --help)
- usage
- exit 2
- ;;
- -h)
- usage
- exit 2
- ;;
- #Set the author
- --author)
- author="${2//\'}"
- shift
- ;;
- -a)
- author="${2//\'}"
- shift
- ;;
- #Set the target
- --target)
- targetdir="${2%\'}"
- targetdir="${targetdir#\'}"
- shift
- ;;
- -t)
- targetdir="${2%\'}"
- targetdir="${targetdir#\'}"
- shift
- ;;
- #All of our default parameter stuff goes below here
- --)
- projectname="${2//\'}"
- shift
- break
- ;;
- --*)
- usage
- exit 2
- ;;
- -*)
- usage
- exit 2
- ;;
- *)
- break
- ;;
- esac
- shift
- done
- #Double check all of our variables
- [[ -z "$projectname" ]] && usage && exit 2
- [[ -z "$author" ]] && author="unknown@unknown.com"
- [[ -z "$targetdir" ]] && targetdir="."
- run
Add Comment
Please, Sign In to add comment