Drop @COMPILECMD in bake, improve shake

This commit is contained in:
Emil 2023-10-16 07:53:44 +00:00
parent 500b7047d4
commit 322ae7976e
No known key found for this signature in database
GPG Key ID: 5432DB986FDBCF8A
2 changed files with 25 additions and 21 deletions

14
bake.c
View File

@ -3,9 +3,11 @@
* *
* Licensed under the GNU Public License version 3 only, see LICENSE. * Licensed under the GNU Public License version 3 only, see LICENSE.
* *
* Using COMPILECMD and including the # STOP for bake & shake support * For Bake
* @COMPILECMD pwd; cc $@ -o $* -std=gnu89 -O2 -Wall -Wextra -Wpedantic -pipe $CFLAGS # @STOP * @EXEC cc $@ -o $* -std=gnu89 -O2 -Wall -Wextra -Wpedantic -pipe $CFLAGS @STOP
* @EXEC pwd; cc $@ -o $* -std=gnu89 -O2 -Wall -Wextra -Wpedantic -pipe $CFLAGS # @STOP *
* For Shake
* @COMPILECMD cc $@ -o $* -std=gnu89 -O2 -Wall -Wextra -Wpedantic -pipe $CFLAGS
*/ */
#include <assert.h> #include <assert.h>
@ -25,9 +27,9 @@
/* Require space after COMPILECMD/EXEC and before STOP (no space required around newline) */ /* Require space after COMPILECMD/EXEC and before STOP (no space required around newline) */
#define REQUIRE_SPACE #define REQUIRE_SPACE
/* May be be left undefined, comes second */ /* May be be left undefined, comes second */
#define OTHER_START "@EXEC" /* #define OTHER_START "@COMPILECMD" */
#define START "@COMPILECMD" #define START "@EXEC"
#define STOP "@STOP" #define STOP "@STOP"
#define HELP \ #define HELP \
"target-file [arguments ...]\n" \ "target-file [arguments ...]\n" \
@ -252,6 +254,8 @@ expand(char * buf) {
return buf; return buf;
} }
/* Strips all prefixing and leading whitespace.
* Except if the last character beforehand is a newline. */
static size_t static size_t
strip(char * buf) { strip(char * buf) {
size_t i = strlen(buf); size_t i = strlen(buf);

22
shake
View File

@ -5,8 +5,9 @@ GREEN='\033[32m'
BOLD='\033[1m' BOLD='\033[1m'
NORMAL='\033[0m' NORMAL='\033[0m'
MARK="@COMPILECMD " MARKNAME="@COMPILECMD"
MARKSTR="${BLUE}@COMPILECMD${NORMAL}" MARK="${MARKNAME} "
MARKSTR="${BLUE}${MARKNAME}${NORMAL}"
enable -n echo enable -n echo
@ -14,16 +15,15 @@ usage() {
IFSTR="${GREEN}<input_file>${NORMAL}" IFSTR="${GREEN}<input_file>${NORMAL}"
echo -e "${BOLD}Usage: $0 <input_file>${NORMAL}" >&2 echo -e "${BOLD}Usage: $0 <input_file>${NORMAL}" >&2
echo -e "\t$0 runs the value of ${MARKSTR}." >&2 echo -e "\t$0 runs the value of ${MARKSTR}." >&2
echo -e "\tThe point of this script is ease to compialation of singe source file (toy) programs." >&2 echo -e "\tThe point of this script is ease to compialation of single source file (toy) programs." >&2
echo -e "\tThe value of ${MARKSTR} is read from ${IFSTR} in is whatever comes after '${MARK}' until the end of the line." >&2 echo -e "\tThe value of ${MARKSTR} is read from ${IFSTR} in is whatever comes after '${MARK}' until the end of the line." >&2
echo -e "\tInside the value of ${MARKSTR} all mentions of special placeholders are replaced:" >&2 echo -e "\tInside the value of ${MARKSTR} all mentions of special placeholders are replaced:" >&2
echo -e "\t\t${BLUE}\$@${NORMAL} - ${IFSTR}" echo -e "\t\t${BLUE}\$@${NORMAL} - ${IFSTR}"
echo -e "\t\t${BLUE}\$*${NORMAL} - ${IFSTR} with the last extension cut off" echo -e "\t\t${BLUE}\$*${NORMAL} - ${IFSTR} with the last extension cut off"
echo -e "\t\t${BLUE}\$+${NORMAL} - All remaining arguments"
} }
if [[ $# -lt 1 ]]; then
if [[ $# -ne 1 ]]; then
usage usage
exit 1 exit 1
fi fi
@ -33,9 +33,8 @@ if [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
exit 0 exit 0
fi fi
input_file=$1 input_file=$1
shift 1
if [[ ! -f $input_file ]]; then if [[ ! -f $input_file ]]; then
echo -e "Input file '$input_file' does not exist." >&2 echo -e "Input file '$input_file' does not exist." >&2
@ -45,11 +44,12 @@ fi
line=$(grep "$MARK" "$input_file" | head -1) line=$(grep "$MARK" "$input_file" | head -1)
line=${line//\$@/$input_file} line=${line//\$@/$input_file}
line=${line//\$\*/${input_file%.*}} line=${line//\$\*/${input_file%.*}}
line=${line//\$+/$@}
if [[ -n $line ]]; then if [[ -n $line ]]; then
command="${line#*@COMPILECMD }" command="${line#*${MARK}}"
echo "Exec: $command"
echo "$command" echo "Output:"
eval "$command" eval "$command"
else else
echo -e "${MARKSTR} is not defined." >&2 echo -e "${MARKSTR} is not defined." >&2