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: libutil.a $(MAKE) bin bin: $(BIN) $(OBJ): $(HDR) config.mk .o: $(LD) $(LDFLAGS) -o $@ $< libutil.a .c.o: $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $< libutil.a: $(LIB) $(AR) -r -c $@ $? ranlib $@ install: all mkdir -p $(DESTDIR)$(PREFIX)/bin cp -f $(BIN) $(DESTDIR)$(PREFIX)/bin cd $(DESTDIR)$(PREFIX)/bin && chmod 755 $(BIN) mkdir -p $(DESTDIR)$(MANPREFIX)/man1 for m in $(MAN); do sed "s/VERSION/$(VERSION)/g" < "$$m" > $(DESTDIR)$(MANPREFIX)/man1/"$$m"; done cd $(DESTDIR)$(MANPREFIX)/man1 && chmod 644 $(MAN) uninstall: cd $(DESTDIR)$(PREFIX)/bin && rm -f $(BIN) cd $(DESTDIR)$(MANPREFIX)/man1 && rm -f $(MAN) dist: clean mkdir -p sbase-$(VERSION) cp -r LICENSE Makefile README TODO config.mk $(SRC) $(MAN) util $(HDR) sbase-$(VERSION) tar -cf sbase-$(VERSION).tar sbase-$(VERSION) gzip sbase-$(VERSION).tar rm -rf sbase-$(VERSION) sbase-box: libutil.a $(SRC) mkdir -p build cp $(HDR) build for f in $(SRC); do sed "s/^main(/`basename $$f .c`_&/" < $$f > build/$$f; done echo '#include ' > build/$@.c echo '#include ' >> build/$@.c echo '#include ' >> build/$@.c echo '#include ' >> build/$@.c echo '#include "util.h"' >> build/$@.c for f in $(SRC); do echo "int `basename $$f .c`_main(int, char **);" >> build/$@.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/$@.c for f in $(SRC); do echo "else if(!strcmp(s, \"`basename $$f .c`\")) return `basename $$f .c`_main(argc, argv);" >> build/$@.c; done echo 'else {' >> build/$@.c for f in $(SRC); do echo "printf(\"`basename $$f .c`\"); putchar(' ');" >> build/$@.c; done echo "putchar(0xa); }; return 0; }" >> build/$@.c $(LD) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ build/*.c libutil.a rm -r build clean: rm -f $(BIN) $(OBJ) $(LIB) libutil.a sbase-box sbase-$(VERSION).tar.gz