mirror of git://git.suckless.org/sbase
sbase-box: Simplify Makefile rule
The Makefile rule was too complex and these cases is better to just move it to a script where will be eassier to use sed properly and not looping over all the files 4 times.
This commit is contained in:
parent
8ca12835a5
commit
3c36fb4177
|
@ -1,4 +1,5 @@
|
||||||
*.o
|
*.o
|
||||||
|
/build
|
||||||
/getconf.h
|
/getconf.h
|
||||||
/libutf.a
|
/libutf.a
|
||||||
/libutil.a
|
/libutil.a
|
||||||
|
|
23
Makefile
23
Makefile
|
@ -236,27 +236,9 @@ dist: clean
|
||||||
gzip sbase-$(VERSION).tar
|
gzip sbase-$(VERSION).tar
|
||||||
rm -rf sbase-$(VERSION)
|
rm -rf sbase-$(VERSION)
|
||||||
|
|
||||||
sbase-box: $(LIB) $(SRC) getconf.h
|
sbase-box: $(BIN)
|
||||||
mkdir -p build
|
scripts/mkbox
|
||||||
cp $(HDR) build
|
|
||||||
cp getconf.h build
|
|
||||||
for f in $(SRC); do sed "s/^main(/$$(echo "$${f%.c}" | sed s/-/_/g)_&/" < $$f > build/$$f; done
|
|
||||||
echo '#include <libgen.h>' > build/$@.c
|
|
||||||
echo '#include <stdio.h>' >> build/$@.c
|
|
||||||
echo '#include <stdlib.h>' >> build/$@.c
|
|
||||||
echo '#include <string.h>' >> build/$@.c
|
|
||||||
echo '#include "util.h"' >> build/$@.c
|
|
||||||
for f in $(SRC); do echo "int $$(echo "$${f%.c}" | sed s/-/_/g)_main(int, char **);"; done >> build/$@.c
|
|
||||||
echo 'int main(int argc, char *argv[]) { char *s = basename(argv[0]);' >> build/$@.c
|
|
||||||
echo 'if(!strcmp(s,"sbase-box")) { argc--; argv++; s = basename(argv[0]); } if(0) ;' >> build/$@.c
|
|
||||||
echo "else if (!strcmp(s, \"install\")) return xinstall_main(argc, argv);" >> build/$@.c
|
|
||||||
echo "else if (!strcmp(s, \"[\")) return test_main(argc, argv);" >> build/$@.c
|
|
||||||
for f in $(SRC); do echo "else if(!strcmp(s, \"$${f%.c}\")) return $$(echo "$${f%.c}" | sed s/-/_/g)_main(argc, argv);"; done >> build/$@.c
|
|
||||||
echo 'else { fputs("[ ", stdout);' >> build/$@.c
|
|
||||||
for f in $(SRC); do echo "fputs(\"$${f%.c} \", stdout);"; done >> build/$@.c
|
|
||||||
echo 'putchar(0xa); }; return 0; }' >> build/$@.c
|
|
||||||
$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ build/*.c $(LIB)
|
$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ build/*.c $(LIB)
|
||||||
rm -r build
|
|
||||||
|
|
||||||
sbase-box-install: sbase-box
|
sbase-box-install: sbase-box
|
||||||
mkdir -p $(DESTDIR)$(PREFIX)/bin
|
mkdir -p $(DESTDIR)$(PREFIX)/bin
|
||||||
|
@ -276,5 +258,6 @@ sbase-box-uninstall: uninstall
|
||||||
clean:
|
clean:
|
||||||
rm -f $(BIN) $(OBJ) $(LIB) sbase-box sbase-$(VERSION).tar.gz
|
rm -f $(BIN) $(OBJ) $(LIB) sbase-box sbase-$(VERSION).tar.gz
|
||||||
rm -f getconf.h
|
rm -f getconf.h
|
||||||
|
rm -rf build
|
||||||
|
|
||||||
.PHONY: all install uninstall dist sbase-box-install sbase-box-uninstall clean
|
.PHONY: all install uninstall dist sbase-box-install sbase-box-uninstall clean
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
trap "rm -rf build" INT QUIT TERM
|
||||||
|
|
||||||
|
rm -rf build
|
||||||
|
mkdir -p build
|
||||||
|
|
||||||
|
cp *.h build
|
||||||
|
|
||||||
|
cat > build/sbase-box.c <<EOF
|
||||||
|
#include <libgen.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
|
#include "sbase-box.h"
|
||||||
|
|
||||||
|
struct cmd {
|
||||||
|
char *name;
|
||||||
|
int (*fn)(int, char **);
|
||||||
|
} cmds[] = {
|
||||||
|
{"install", xinstall_main},
|
||||||
|
{"[", test_main},
|
||||||
|
$(grep -l ^main *.c |
|
||||||
|
while read f
|
||||||
|
do
|
||||||
|
sed -n '
|
||||||
|
/^main/ {
|
||||||
|
s/main/'${f%.c}'_main/
|
||||||
|
s/-/_/g
|
||||||
|
w build/'$f'
|
||||||
|
s/\(^.*\)(.*)/ {"'${f%.c}'", \1},/p
|
||||||
|
d
|
||||||
|
}
|
||||||
|
w 'build/$f $f
|
||||||
|
done)
|
||||||
|
{NULL},
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char *s = basename(argv[0]);
|
||||||
|
struct cmd *bp;
|
||||||
|
|
||||||
|
if(!strcmp(s,"sbase-box")) {
|
||||||
|
argc--; argv++;
|
||||||
|
s = basename(argv[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (bp = cmds; bp->name; ++bp) {
|
||||||
|
if (strcmp(bp->name, s) == 0)
|
||||||
|
return (*bp->fn)(argc, argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (bp = cmds; bp->name; ++bp)
|
||||||
|
printf("%s ", bp->name);
|
||||||
|
putchar('\n');
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sed -n 's/.* \(.*_main\).*/int \1(int, char **);/p'\
|
||||||
|
build/sbase-box.c > build/sbase-box.h
|
Loading…
Reference in New Issue