diff --git a/cbuild.sh b/cbuild.sh index 56abb15..6e51063 100755 --- a/cbuild.sh +++ b/cbuild.sh @@ -2,10 +2,10 @@ # Written by Noah Swerhun # https://noahsw.xyz -# Development: https://git.noahsw.xyz/cbuild.sh/log.html +# Development: https://git.noahsw.xyz/cbuild.sh/log.html -# --- USER CONFIG --- -CC="gcc" +# --- USER CONFIG --- +CC="gcc" CFLAGS="-Wall -Wpedantic" LDFLAGS="" LDLIBS="" @@ -13,19 +13,29 @@ TARGET="a.out" SRCDIR="src" OBJDIR="obj" MAKEFILE=".makefile" + +HEADER_DIR="include" # ------------------- PROG_COMMAND="./cbuild.sh __progress__" -SRC="$(find ${SRCDIR} -name '*\.c')" -OBJ="$(find ${SRCDIR} -name '*\.c' | +SRC="$(find ${SRCDIR} -name '*\.c' 2> /dev/null)" +OBJ="$(find ${SRCDIR} -name '*\.c' 2> /dev/null | sed "s/${SRCDIR}\//${OBJDIR}\//" | sed "s/\.c$/.o/" | tr '\n' ' ')" -srcnum="$(find ${SRCDIR} -name '*\.c' -exec printf %c {} + | wc -c)" +srcnum="$(find ${SRCDIR} -name '*\.c' -exec printf %c {} + 2> /dev/null | wc -c)" + +clear_formatting="\033[0m" +bold="\033[1m" +info_color="\033[34m" # default: "\033[34m" - blue +err_color="\033[31m" # default: "\033[31m" - red +build_progress_color="\033[35m" # default: "\033[35m" - magenta +build_info_color="\033[32m" # default: "\033[32m" - green +link_info_color="\033[36m" # default: "\033[36m" - cyan usage() { - cat < .cbuild_prog.tmp if [ "$(cat .cbuild_prog.tmp)" = 0 ]; then - info "Target ${TARGET} up to date" + info "Target" "${TARGET}" "up to date" rm .cbuild_prog.tmp return 0; fi @@ -150,9 +180,9 @@ clean() { run() { build || exit $? args="$@" - info "Running ./${TARGET} ${args}" + info "Running" "./${TARGET} ${args}" "./${TARGET}" $@ || - err "Run FAILURE ./${TARGET} returned $?" + err "Run FAILURE" "./${TARGET}" "returned $?" } dry_run() { @@ -161,17 +191,86 @@ dry_run() { make -f "${MAKEFILE}" -e "${TARGET}" -n } +new() { + case $1 in + header) + shift 1 + for arg in $@; do + if [ "${arg}" != "__MODULE__" ]; then + path="${SRCDIR}/${HEADER_DIR}/${arg%.h}.h" + clean_path="${path//.\//}" + macro="$(basename ${clean_path} .h | tr '[a-z]' '[A-Z]')" + [ ! -d "$(dirname ${clean_path})" ] && + mkdir -p "$(dirname ${clean_path})" + if [ ! -f "${clean_path}" ]; then + cat > "${clean_path}" < "${path}" <> "${path}" || + cat >> "${path}" <