-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcreate_cproject
executable file
·96 lines (81 loc) · 2.43 KB
/
create_cproject
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env bash
#=======================================================================
# create_cproject
# File ID: 0aa2560c-8683-11e0-bc0d-00023faf1383
#
# Create skeleton for new C project
#
# Author: Øyvind A. Holm <[email protected]>
# License: GNU General Public License version 2 or later.
#=======================================================================
progname=create_cproject
VERSION=0.4.0
ARGS="$(getopt -o "\
c\
h\
q\
v\
" -l "\
copying,\
help,\
quiet,\
verbose,\
version,\
" -n "$progname" -- "$@")"
test "$?" = "0" || exit 1
eval set -- "$ARGS"
opt_copying=0
opt_help=0
opt_quiet=0
opt_verbose=0
while :; do
case "$1" in
-c|--copying) opt_copying=1; shift ;;
-h|--help) opt_help=1; shift ;;
-q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
-v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
--version) echo $progname $VERSION; exit 0 ;;
--) shift; break ;;
*) echo $progname: Internal error >&2; exit 1 ;;
esac
done
opt_verbose=$(($opt_verbose - $opt_quiet))
if test "$opt_help" = "1"; then
test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
cat <<END
Create skeleton for a new C project in the current directory where the
main .c file is called PROJECT_NAME.c.
Usage: $progname [options] PROJECT_NAME
Options:
-c, --copying
Also create a COPYING file with the current license.
-h, --help
Show this help.
-q, --quiet
Be more quiet. Can be repeated to increase silence.
-v, --verbose
Increase level of verbosity. Can be repeated.
--version
Print version information.
END
exit 0
fi
name=$1
test -z "$name" && { echo $progname: Name not specified as arg 1 >&2; exit 1; }
echo -n "Makefile: " && std -t exec=$name c/Makefile Makefile &&
echo -n "Gen-version: " && std -t exec=$name c/Gen-version Gen-version &&
echo -n "gdbrc: " && std c/gdbrc gdbrc &&
echo -n "$name.c: " && std -t exec=$name c/std.c $name.c &&
echo -n "$name.h: " && std -t exec=$name c/std.h $name.h &&
echo -n "selftest.c: " && std -t exec=$name c/selftest.c selftest.c || exit 1
if test "$opt_copying" = "1"; then
echo -n "COPYING: " && std COPYING COPYING && echo OK || exit 1
fi
std -t exec=$name c/.gitignore .gitignore &&
sort -u .gitignore >.gitignore.tmp &&
mv .gitignore.tmp .gitignore || exit 1
mkdir -p t &&
echo -n "t/$name.t: " &&
cd t &&
std c-tests $name.t -t progname=$name &&
std -t exec=$name c/t/Makefile Makefile || exit 1