wrote usage function and set sensible defaults

This commit is contained in:
Noah Swerhun 2021-12-24 10:25:28 -06:00
parent bbf8c84ba8
commit c29f47851f

View file

@ -6,10 +6,10 @@
# --- USER CONFIG ---
CC="gcc"
CFLAGS="-Wall -Wpedantic -std=c99"
CFLAGS="-Wall -Wpedantic"
LDFLAGS=""
LDLIBS=""
TARGET="foo"
TARGET="a.out"
SRCDIR="src"
OBJDIR="obj"
MAKEFILE=".makefile"
@ -24,6 +24,41 @@ OBJ="$(find ${SRCDIR} -name '*\.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 CC
export CFLAGS
@ -121,6 +156,7 @@ __progress__() {
echo "${2}"
}
case $1 in
build) build;;
clean) clean;;
@ -129,4 +165,5 @@ case $1 in
run) run;;
dryrun) dry_run;;
__progress__) __progress__ "${2}" "${3}";;
*) usage;;
esac