wrote usage function and set sensible defaults
This commit is contained in:
parent
bbf8c84ba8
commit
c29f47851f
1 changed files with 39 additions and 2 deletions
41
cbuild.sh
41
cbuild.sh
|
@ -6,10 +6,10 @@
|
||||||
|
|
||||||
# --- USER CONFIG ---
|
# --- USER CONFIG ---
|
||||||
CC="gcc"
|
CC="gcc"
|
||||||
CFLAGS="-Wall -Wpedantic -std=c99"
|
CFLAGS="-Wall -Wpedantic"
|
||||||
LDFLAGS=""
|
LDFLAGS=""
|
||||||
LDLIBS=""
|
LDLIBS=""
|
||||||
TARGET="foo"
|
TARGET="a.out"
|
||||||
SRCDIR="src"
|
SRCDIR="src"
|
||||||
OBJDIR="obj"
|
OBJDIR="obj"
|
||||||
MAKEFILE=".makefile"
|
MAKEFILE=".makefile"
|
||||||
|
@ -24,6 +24,41 @@ OBJ="$(find ${SRCDIR} -name '*\.c' |
|
||||||
|
|
||||||
srcnum="$(find ${SRCDIR} -name '*\.c' -exec printf %c {} + | wc -c)"
|
srcnum="$(find ${SRCDIR} -name '*\.c' -exec printf %c {} + | wc -c)"
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
cat <<EOF
|
||||||
|
cbuild.sh: A simple, customizable, automated, and portable build script for C
|
||||||
|
projects. This script works by automatically detecting .c source files in
|
||||||
|
SRCDIR, generating a makefile, compiling them into objects in OBJDIR, and
|
||||||
|
finally linking them to TARGET.
|
||||||
|
|
||||||
|
Customization:
|
||||||
|
Open cbuild.sh in your editor and navigate to the USER CONFIG section (at
|
||||||
|
the top of the file).
|
||||||
|
|
||||||
|
CC the compiler to use (default: gcc)
|
||||||
|
CFLAGS compilation flags (default: -Wall -Wpedantic)
|
||||||
|
LDFLAGS linker flags (default: none)
|
||||||
|
LDLIBS linker libraries (default: none)
|
||||||
|
TARGET final target to link (default: a.out)
|
||||||
|
SRCDIR the directory where the script will search for .c source files
|
||||||
|
(default: src)
|
||||||
|
OBJDIR the directory where compiled objects will be placed. (default: obj)
|
||||||
|
MAKEFILE the filename of the generated makefile (default: .makefile)
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
./cbuild.sh [COMMAND]
|
||||||
|
|
||||||
|
COMMAND:
|
||||||
|
build generate the makefile, compile objects and link target.
|
||||||
|
clean remove makefile, objects, and target.
|
||||||
|
buildcn clean, and then build.
|
||||||
|
generate ONLY generate the makefile.
|
||||||
|
run build, then execute TARGET.
|
||||||
|
dryrun print all commands that will be executed during the build process
|
||||||
|
to stdout.
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
export_vars() {
|
export_vars() {
|
||||||
export CC
|
export CC
|
||||||
export CFLAGS
|
export CFLAGS
|
||||||
|
@ -121,6 +156,7 @@ __progress__() {
|
||||||
|
|
||||||
echo "${2}"
|
echo "${2}"
|
||||||
}
|
}
|
||||||
|
|
||||||
case $1 in
|
case $1 in
|
||||||
build) build;;
|
build) build;;
|
||||||
clean) clean;;
|
clean) clean;;
|
||||||
|
@ -129,4 +165,5 @@ case $1 in
|
||||||
run) run;;
|
run) run;;
|
||||||
dryrun) dry_run;;
|
dryrun) dry_run;;
|
||||||
__progress__) __progress__ "${2}" "${3}";;
|
__progress__) __progress__ "${2}" "${3}";;
|
||||||
|
*) usage;;
|
||||||
esac
|
esac
|
||||||
|
|
Loading…
Reference in a new issue