[hackers] [sbase] Convert build system to mk || sin
commit 86e6dfdd93c1bee7401b5d9e67494b04035085ed
Author: sin <sin_AT_2f30.org>
Date: Sun Nov 16 16:33:51 2014 +0000
Convert build system to mk
There's some more cleanup to be done here.
diff --git a/Makefile b/Makefile
deleted file mode 100644
index 575f31b..0000000
--- a/Makefile
+++ /dev/null
_AT_@ -1,195 +0,0 @@
-include config.mk
-
-.POSIX:
-.SUFFIXES: .c .o
-
-HDR = \
- arg.h \
- crypt.h \
- fs.h \
- md5.h \
- queue.h \
- sha1.h \
- sha256.h \
- sha512.h \
- text.h \
- util.h
-
-LIB = \
- util/agetcwd.o \
- util/agetline.o \
- util/apathmax.o \
- util/concat.o \
- util/cp.o \
- util/crypt.o \
- util/ealloc.o \
- util/enmasse.o \
- util/eprintf.o \
- util/eregcomp.o \
- util/estrtod.o \
- util/estrtol.o \
- util/fnck.o \
- util/getlines.o \
- util/human.o \
- util/md5.o \
- util/mode.o \
- util/putword.o \
- util/recurse.o \
- util/rm.o \
- util/sha1.o \
- util/sha256.o \
- util/sha512.o \
- util/strlcat.o \
- util/strlcpy.o
-
-SRC = \
- basename.c \
- cal.c \
- cat.c \
- chgrp.c \
- chmod.c \
- chown.c \
- chroot.c \
- cksum.c \
- cmp.c \
- col.c \
- cols.c \
- comm.c \
- cp.c \
- csplit.c \
- cut.c \
- date.c \
- dirname.c \
- du.c \
- echo.c \
- env.c \
- expand.c \
- expr.c \
- false.c \
- fold.c \
- grep.c \
- head.c \
- hostname.c \
- kill.c \
- link.c \
- ln.c \
- logname.c \
- ls.c \
- md5sum.c \
- mkdir.c \
- mkfifo.c \
- mktemp.c \
- mv.c \
- nice.c \
- nl.c \
- nohup.c \
- paste.c \
- printenv.c \
- printf.c \
- pwd.c \
- readlink.c \
- renice.c \
- rm.c \
- rmdir.c \
- sleep.c \
- setsid.c \
- sort.c \
- split.c \
- sponge.c \
- strings.c \
- sync.c \
- tail.c \
- tar.c \
- tee.c \
- test.c \
- touch.c \
- tr.c \
- true.c \
- tty.c \
- uudecode.c \
- uuencode.c \
- uname.c \
- unexpand.c \
- uniq.c \
- unlink.c \
- seq.c \
- sha1sum.c \
- sha256sum.c\
- sha512sum.c\
- wc.c \
- xargs.c \
- yes.c
-
-OBJ = $(SRC:.c=.o) $(LIB)
-BIN = $(SRC:.c=)
-MAN = $(SRC:.c=.1)
-
-all: binlib
-
-binlib: util.a
- $(MAKE) bin
-
-bin: $(BIN)
-
-$(OBJ): $(HDR) config.mk
-
-.o:
- _AT_echo LD $@
- _AT_$(LD) -o $@ $< util.a $(LDFLAGS)
-
-.c.o:
- _AT_echo CC $<
- _AT_$(CC) -c -o $@ $< $(CFLAGS)
-
-util.a: $(LIB)
- _AT_echo AR $@
- _AT_$(AR) -r -c $@ $?
- _AT_ranlib $@
-
-install: all
- _AT_echo installing executables to $(DESTDIR)$(PREFIX)/bin
- _AT_mkdir -p $(DESTDIR)$(PREFIX)/bin
- _AT_cp -f $(BIN) $(DESTDIR)$(PREFIX)/bin
- _AT_cd $(DESTDIR)$(PREFIX)/bin && chmod 755 $(BIN)
- _AT_echo installing manual pages to $(DESTDIR)$(MANPREFIX)/man1
- _AT_mkdir -p $(DESTDIR)$(MANPREFIX)/man1
- _AT_for m in $(MAN); do sed "s/VERSION/$(VERSION)/g" < "$$m" > $(DESTDIR)$(MANPREFIX)/man1/"$$m"; done
- _AT_cd $(DESTDIR)$(MANPREFIX)/man1 && chmod 644 $(MAN)
-
-uninstall:
- _AT_echo removing executables from $(DESTDIR)$(PREFIX)/bin
- _AT_cd $(DESTDIR)$(PREFIX)/bin && rm -f $(BIN)
- _AT_echo removing manual pages from $(DESTDIR)$(MANPREFIX)/man1
- _AT_cd $(DESTDIR)$(MANPREFIX)/man1 && rm -f $(MAN)
-
-dist: clean
- _AT_echo creating dist tarball
- _AT_mkdir -p sbase-$(VERSION)
- _AT_cp -r LICENSE Makefile README TODO config.mk $(SRC) $(MAN) util $(HDR) sbase-$(VERSION)
- _AT_tar -cf sbase-$(VERSION).tar sbase-$(VERSION)
- _AT_gzip sbase-$(VERSION).tar
- _AT_rm -rf sbase-$(VERSION)
-
-sbase-box: $(SRC) util.a
- _AT_echo creating box binary
- _AT_mkdir -p build
- _AT_cp $(HDR) build
- _AT_for f in $(SRC); do sed "s/^main(/`basename $$f .c`_&/" < $$f > build/$$f; done
- _AT_echo '#include <libgen.h>' > build/$@.c
- _AT_echo '#include <stdio.h>' >> build/$@.c
- _AT_echo '#include <stdlib.h>' >> build/$@.c
- _AT_echo '#include <string.h>' >> build/$@.c
- _AT_echo '#include "util.h"' >> build/$@.c
- _AT_for f in $(SRC); do echo "int `basename $$f .c`_main(int, char **);" >> build/$@.c; done
- _AT_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/$@.c
- _AT_for f in $(SRC); do echo "else if(!strcmp(s, \"`basename $$f .c`\")) return `basename $$f .c`_main(argc, argv);" >> build/$@.c; done
- _AT_echo 'else {' >> build/$@.c
- _AT_for f in $(SRC); do echo "printf(\"`basename $$f .c`\"); putchar(' ');" >> build/$@.c; done
- _AT_echo "putchar(0xa); }; return 0; }" >> build/$@.c
- _AT_echo LD $@
- _AT_$(LD) -o $@ build/*.c util.a $(CFLAGS) $(LDFLAGS)
- _AT_rm -r build
-
-clean:
- _AT_echo cleaning
- _AT_rm -f $(BIN) $(OBJ) $(LIB) util.a sbase-box sbase-$(VERSION).tar.gz
diff --git a/config.mk b/config.mk
index c605648..bc418aa 100644
--- a/config.mk
+++ b/config.mk
_AT_@ -3,17 +3,11 @@ VERSION = 0.0
# paths
PREFIX = /usr/local
-MANPREFIX = $(PREFIX)/share/man
+MANPREFIX = $PREFIX/share/man
-#CC = gcc
-#CC = musl-gcc
-LD = $(CC)
+AR = ar
+CC = cc
+LD = $CC
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_GNU_SOURCE
-CFLAGS = -g -std=c99 -Wall -pedantic $(CPPFLAGS)
+CFLAGS = -g -std=c99 -Wall -pedantic $CPPFLAGS
LDFLAGS = -g
-
-#CC = tcc
-#LD = $(CC)
-#CPPFLAGS = -D_POSIX_C_SOURCE=200112L
-#CFLAGS = -Os -Wall $(CPPFLAGS) -D_GNU_SOURCE
-#LDFLAGS =
diff --git a/mkfile b/mkfile
new file mode 100644
index 0000000..5ec7d31
--- /dev/null
+++ b/mkfile
_AT_@ -0,0 +1,177 @@
+<config.mk
+
+LIB=libutil.a
+LIBOFILES= \
+ util/agetcwd.o \
+ util/agetline.o \
+ util/apathmax.o \
+ util/concat.o \
+ util/cp.o \
+ util/crypt.o \
+ util/ealloc.o \
+ util/enmasse.o \
+ util/eprintf.o \
+ util/eregcomp.o \
+ util/estrtod.o \
+ util/estrtol.o \
+ util/fnck.o \
+ util/getlines.o \
+ util/human.o \
+ util/md5.o \
+ util/mode.o \
+ util/putword.o \
+ util/recurse.o \
+ util/rm.o \
+ util/sha1.o \
+ util/sha256.o \
+ util/sha512.o \
+ util/strlcat.o \
+ util/strlcpy.o
+
+SRC = \
+ basename.c \
+ cal.c \
+ cat.c \
+ chgrp.c \
+ chmod.c \
+ chown.c \
+ chroot.c \
+ cksum.c \
+ cmp.c \
+ col.c \
+ cols.c \
+ comm.c \
+ cp.c \
+ csplit.c \
+ cut.c \
+ date.c \
+ dirname.c \
+ du.c \
+ echo.c \
+ env.c \
+ expand.c \
+ expr.c \
+ false.c \
+ fold.c \
+ grep.c \
+ head.c \
+ hostname.c \
+ kill.c \
+ link.c \
+ ln.c \
+ logname.c \
+ ls.c \
+ md5sum.c \
+ mkdir.c \
+ mkfifo.c \
+ mktemp.c \
+ mv.c \
+ nice.c \
+ nl.c \
+ nohup.c \
+ paste.c \
+ printenv.c \
+ printf.c \
+ pwd.c \
+ readlink.c \
+ renice.c \
+ rm.c \
+ rmdir.c \
+ sleep.c \
+ setsid.c \
+ sort.c \
+ split.c \
+ sponge.c \
+ strings.c \
+ sync.c \
+ tail.c \
+ tar.c \
+ tee.c \
+ test.c \
+ touch.c \
+ tr.c \
+ true.c \
+ tty.c \
+ uudecode.c \
+ uuencode.c \
+ uname.c \
+ unexpand.c \
+ uniq.c \
+ unlink.c \
+ seq.c \
+ sha1sum.c \
+ sha256sum.c\
+ sha512sum.c\
+ wc.c \
+ xargs.c \
+ yes.c
+
+HFILES = \
+ arg.h \
+ crypt.h \
+ fs.h \
+ md5.h \
+ queue.h \
+ sha1.h \
+ sha256.h \
+ sha512.h \
+ text.h \
+ util.h
+
+OFILES=${SRC:%.c=%.o}
+TARG=${SRC:%.c=%}
+MAN=${SRC:%.c=%.1}
+
+all:V: $LIB $TARG
+
+$LIB(%):N: %
+$LIB: ${LIBOFILES:%=$LIB(%)}
+ $AR rc $LIB $LIBOFILES
+
+%: %.o
+ $LD $LDFLAGS -o $target $prereq $LIB
+
+%.o: %.c
+ $CC $CFLAGS -o $stem.o -c $stem.c
+
+install:V: all
+ mkdir -p $DESTDIR/$PREFIX/bin
+ cp -f $TARG $DESTDIR/$PREFIX/bin
+ mkdir -p $DESTDIR/$MANPREFIX/man1
+ cp -f $MAN $DESTDIR/$MANPREFIX/man1
+
+uninstall:V: all
+ cd $DESTDIR/$PREFIX/bin
+ rm -f $TARG
+ cd $DESTDIR/$MANPREFIX/man1
+ rm -f $MAN
+
+dist:V: clean
+ mkdir -p sbase-$VERSION
+ cp -r LICENSE Makefile README TODO config.mk $SRC $MAN util $HFILES sbase-$VERSION
+ tar -cf sbase-$VERSION.tar sbase-$VERSION
+ gzip sbase-$VERSION.tar
+ rm -rf sbase-$VERSION
+
+sbase-box:V: $LIB $SRC $HFILES
+ echo creating box binary
+ mkdir -p build
+ cp $HFILES build
+ for f in $SRC; do sed "s/^main(/`basename $f .c`_&/" < $f > build/$f; done
+ echo '#include <libgen.h>' > build/$target.c
+ echo '#include <stdio.h>' >> build/$target.c
+ echo '#include <stdlib.h>' >> build/$target.c
+ echo '#include <string.h>' >> build/$target.c
+ echo '#include "util.h"' >> build/$target.c
+ for f in $SRC; do echo "int `basename $f .c`_main(int, char **);" >> build/$target.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/$target.c
+ for f in $SRC; do echo "else if(!strcmp(s, \"`basename $f .c`\")) return `basename $f .c`_main(argc, argv);" >> build/$target.c; done
+ echo 'else {' >> build/$target.c
+ for f in $SRC; do echo "printf(\"`basename $f .c`\"); putchar(' ');" >> build/$target.c; done
+ echo "putchar(0xa); }; return 0; }" >> build/$target.c
+ echo LD $target
+ $LD -o $target build/*.c libutil.a $CFLAGS $LDFLAGS
+ rm -r build
+
+clean nuke:V:
+ rm -f $LIBOFILES $LIB $OFILES $TARG sbase-box sbase-$VERSION.tar.gz
Received on Sun Nov 16 2014 - 17:34:55 CET
This archive was generated by hypermail 2.3.0
: Sun Nov 16 2014 - 17:36:19 CET