diff --git a/.gitignore b/.gitignore index d81b8dc..fa71939 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ a.out obj/ src/ +build/ diff --git a/cbuild.sh b/cbuild.sh index 4fec072..d73f975 100755 --- a/cbuild.sh +++ b/cbuild.sh @@ -110,6 +110,25 @@ export_vars() { export PROG_COMMAND } +make_dirs() { + # Default Directory Structure: + # -- root + # |-- ${SRCDIR} + # |-- ${HEADERDIR} + # |-- ${BUILDDIR} + # |-- ${RELEASEDIR} + # |-- ${OBJDIR} + # |-- ${DEBUGDIR} + # |-- ${OBJDIR} + + [ ! -d "${SRCDIR}" ] && mkdir -p ${SRCDIR} + [ ! -d "${BUILDDIR}" ] && mkdir -p ${BUILDDIR} + [ ! -d "${RELEASEDIR}" ] && mkdir -p ${RELEASEDIR} + [ ! -d "${RELEASEDIR}/${OBJDIR}" ] && mkdir -p ${RELEASEDIR}/${OBJDIR} + [ ! -d "${DEBUGDIR}" ] && mkdir -p ${DEBUGDIR} + [ ! -d "${DEBUGDIR}/${OBJDIR}" ] && mkdir -p ${DEBUGDIR}/${OBJDIR} +} + info() { printf "${info_color}${bold}[*]${clear_formatting}\ ${info_color} %s${clear_formatting} %s${info_color} %s${clear_formatting}\n" \ @@ -165,7 +184,7 @@ EOF build() { gen_makefile - [ ! -d "${OBJDIR}" ] && mkdir "${OBJDIR}" + make_dirs export_vars make -f "${MAKEFILE}" -e "${TARGET}" -n | grep -c "^${CC}" > .cbuild_prog.tmp if [ "$(cat .cbuild_prog.tmp)" = 0 ]; then @@ -274,6 +293,51 @@ EOF esac } +init() { + new module main + make_dirs + cat > "${BUILDDIR}/config" <<'EOF' +# Compiler +CC="gcc" + +# Compilation flags +CFLAGS="-Wall -Wpedantic" + +# Linker flags +LDFLAGS="" + +# Linker libraries +LDLIBS="" + +# Final binary name +BINNAME="a.out" + +# Directory containing source (.c) files +SRCDIR="src" + +# Directory for build files +BUILDDIR="build" + +# Directory for the release build +RELEASEDIR="${BUILDDIR}/release" + +# Directory for the debug build +DEBUGDIR="${BUILDDIR}/debug" + +# Subdirectory for object files (located in respective build dirs) +OBJDIR="obj" + +# Makefile name +MAKEFILE=".makefile" + +# Use pkg-config to get flags +PKG_CONFIG_LIBS="" + +# Subdirectory of ${SRCDIR} that will contain generated header files +HEADER_DIR="include" +EOF +} + __progress__() { ntargets=$(cat .cbuild_prog.tmp) export_vars @@ -299,7 +363,7 @@ case $1 in run) shift 1 && run $@;; dryrun) dry_run;; new) shift 1 && new $@;; - init) new module main;; + init) init;; -h|--help|help) usage;; __progress__) __progress__ "${2}" "${3}";; *) echo "Invalid command. Try --help";;