[hackers] [sbase] use parameter expansion instead of basename in Makefile || Evan Gates
commit 4f92053be1a129a2a1904c9441027525a2d77ca4
Author: Evan Gates <evan.gates_AT_gmail.com>
Date: Fri Feb 20 12:12:12 2015 -0800
use parameter expansion instead of basename in Makefile
diff --git a/Makefile b/Makefile
index 4665605..337b33e 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -199,19 +199,19 @@ dist: clean
sbase-box: $(LIB) $(SRC)
mkdir -p build
cp $(HDR) build
- for f in $(SRC); do sed "s/^main(/`basename $$f .c`_&/" < $$f > build/$$f; done
+ for f in $(SRC); do sed "s/^main(/$${f%.c}_&/" < $$f > build/$$f; done
echo '#include <libgen.h>' > build/$_AT_.c
echo '#include <stdio.h>' >> build/$_AT_.c
echo '#include <stdlib.h>' >> build/$_AT_.c
echo '#include <string.h>' >> build/$_AT_.c
echo '#include "util.h"' >> build/$_AT_.c
- for f in $(SRC); do echo "int `basename $$f .c`_main(int, char **);" >> build/$_AT_.c; done
+ for f in $(SRC); do echo "int $${f%.c}_main(int, char **);" >> build/$_AT_.c; done
echo 'int main(int argc, char *argv[]) { char *s = basename(argv[0]); if(!strcmp(s,"sbase-box")) { argc--; argv++; s = basename(argv[0]); } if(0) ;' >> build/$_AT_.c
echo "else if (!strcmp(s, \"[\")) return test_main(argc, argv);" >> build/$_AT_.c
- for f in $(SRC); do echo "else if(!strcmp(s, \"`basename $$f .c`\")) return `basename $$f .c`_main(argc, argv);" >> build/$_AT_.c; done
+ for f in $(SRC); do echo "else if(!strcmp(s, \"$${f%.c}\")) return $${f%.c}_main(argc, argv);" >> build/$_AT_.c; done
echo 'else {' >> build/$_AT_.c
echo "printf(\"[\"); putchar(' ');" >> build/$_AT_.c
- for f in $(SRC); do echo "printf(\"`basename $$f .c`\"); putchar(' ');" >> build/$_AT_.c; done
+ for f in $(SRC); do echo "printf(\"$${f%.c}\"); putchar(' ');" >> build/$_AT_.c; done
echo "putchar(0xa); }; return 0; }" >> build/$_AT_.c
$(LD) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $_AT_ build/*.c $(LIB)
rm -r build
Received on Sat Feb 21 2015 - 10:33:30 CET
This archive was generated by hypermail 2.3.0
: Sat Feb 21 2015 - 10:36:32 CET