implemented make_dirs and new init

This commit is contained in:
Noah Swerhun 2022-07-10 21:17:32 -05:00
parent c23c4ff458
commit 7c45225832
2 changed files with 67 additions and 2 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@
a.out a.out
obj/ obj/
src/ src/
build/

View file

@ -110,6 +110,25 @@ export_vars() {
export PROG_COMMAND 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() { info() {
printf "${info_color}${bold}[*]${clear_formatting}\ printf "${info_color}${bold}[*]${clear_formatting}\
${info_color} %s${clear_formatting} %s${info_color} %s${clear_formatting}\n" \ ${info_color} %s${clear_formatting} %s${info_color} %s${clear_formatting}\n" \
@ -165,7 +184,7 @@ EOF
build() { build() {
gen_makefile gen_makefile
[ ! -d "${OBJDIR}" ] && mkdir "${OBJDIR}" make_dirs
export_vars export_vars
make -f "${MAKEFILE}" -e "${TARGET}" -n | grep -c "^${CC}" > .cbuild_prog.tmp make -f "${MAKEFILE}" -e "${TARGET}" -n | grep -c "^${CC}" > .cbuild_prog.tmp
if [ "$(cat .cbuild_prog.tmp)" = 0 ]; then if [ "$(cat .cbuild_prog.tmp)" = 0 ]; then
@ -274,6 +293,51 @@ EOF
esac 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__() { __progress__() {
ntargets=$(cat .cbuild_prog.tmp) ntargets=$(cat .cbuild_prog.tmp)
export_vars export_vars
@ -299,7 +363,7 @@ case $1 in
run) shift 1 && run $@;; run) shift 1 && run $@;;
dryrun) dry_run;; dryrun) dry_run;;
new) shift 1 && new $@;; new) shift 1 && new $@;;
init) new module main;; init) init;;
-h|--help|help) usage;; -h|--help|help) usage;;
__progress__) __progress__ "${2}" "${3}";; __progress__) __progress__ "${2}" "${3}";;
*) echo "Invalid command. Try --help";; *) echo "Invalid command. Try --help";;