sbase/Makefile

124 lines
2.8 KiB
Makefile
Raw Normal View History

2011-05-22 21:36:34 -04:00
include config.mk
2012-01-30 17:41:33 -05:00
HDR = fs.h text.h util.h
2011-06-03 00:38:40 -04:00
LIB = \
2011-06-18 01:41:28 -04:00
util/afgets.o \
util/agetcwd.o \
2011-06-25 12:26:44 -04:00
util/apathmax.o \
2011-06-18 01:41:28 -04:00
util/concat.o \
2012-01-30 17:41:33 -05:00
util/cp.o \
2011-06-18 01:41:28 -04:00
util/enmasse.o \
util/eprintf.o \
util/enprintf.o \
util/estrtol.o \
2012-01-30 17:41:33 -05:00
util/fnck.o \
2011-06-18 01:41:28 -04:00
util/putword.o \
util/recurse.o \
2012-01-30 17:41:33 -05:00
util/rm.o \
2011-06-18 01:41:28 -04:00
util/venprintf.o
2011-06-03 00:38:40 -04:00
SRC = \
basename.c \
cat.c \
chmod.c \
chown.c \
2011-06-09 23:14:05 -04:00
cksum.c \
2011-06-09 20:55:12 -04:00
cmp.c \
2012-01-30 17:41:33 -05:00
cp.c \
2011-06-03 00:38:40 -04:00
date.c \
dirname.c \
echo.c \
false.c \
2011-06-08 16:30:33 -04:00
fold.c \
2011-06-03 00:38:40 -04:00
grep.c \
head.c \
2011-06-09 21:29:10 -04:00
kill.c \
2011-06-03 00:38:40 -04:00
ln.c \
ls.c \
mkdir.c \
mkfifo.c \
2012-01-30 17:41:33 -05:00
mv.c \
2011-06-03 00:38:40 -04:00
nl.c \
2011-06-18 01:41:28 -04:00
nohup.c \
2011-06-03 00:38:40 -04:00
pwd.c \
rm.c \
sleep.c \
sort.c \
tail.c \
tee.c \
2011-11-08 13:35:38 -05:00
test.c \
2011-06-03 00:38:40 -04:00
touch.c \
true.c \
tty.c \
uname.c \
wc.c
2011-05-26 20:20:03 -04:00
2011-05-24 08:00:30 -04:00
OBJ = $(SRC:.c=.o) $(LIB)
2011-05-22 21:36:34 -04:00
BIN = $(SRC:.c=)
MAN = $(SRC:.c=.1)
all: $(BIN)
2011-05-29 16:30:44 -04:00
$(OBJ): util.h config.mk
2011-05-24 08:00:30 -04:00
$(BIN): util.a
2012-01-30 17:41:33 -05:00
cat.o cp.o mv.o grep.o tail.o: text.h
cp.o mv.o rm.o: fs.h
2011-05-22 21:36:34 -04:00
.o:
2011-06-16 16:20:17 -04:00
@echo LD $@
2011-05-29 16:30:44 -04:00
@$(LD) -o $@ $< util.a $(LDFLAGS)
2011-05-22 21:36:34 -04:00
.c.o:
2011-06-16 16:20:17 -04:00
@echo CC $<
2011-05-24 08:00:30 -04:00
@$(CC) -c -o $@ $< $(CFLAGS)
util.a: $(LIB)
2011-06-16 16:20:17 -04:00
@echo AR $@
2011-06-01 16:31:22 -04:00
@$(AR) -r -c $@ $(LIB)
2011-06-20 13:37:39 -04:00
@ranlib $@
2011-05-22 21:36:34 -04:00
2011-06-08 11:26:05 -04:00
install: all
2011-06-08 06:37:00 -04:00
@echo installing executables to $(DESTDIR)$(PREFIX)/bin
@mkdir -p $(DESTDIR)$(PREFIX)/bin
@cp -f $(BIN) $(DESTDIR)$(PREFIX)/bin
@cd $(DESTDIR)$(PREFIX)/bin && chmod 755 $(BIN)
@echo installing manual pages to $(DESTDIR)$(MANPREFIX)/man1
@mkdir -p $(DESTDIR)$(MANPREFIX)/man1
@cp -f $(MAN) $(DESTDIR)$(MANPREFIX)/man1
@cd $(DESTDIR)$(MANPREFIX)/man1 && chmod 644 $(MAN)
uninstall:
2011-06-08 16:30:33 -04:00
@echo removing executables from $(DESTDIR)$(PREFIX)/bin
2011-06-08 06:37:00 -04:00
@cd $(DESTDIR)$(PREFIX)/bin && rm -f $(BIN)
2011-06-08 16:30:33 -04:00
@echo removing manual pages from $(DESTDIR)$(MANPREFIX)/man1
2011-06-08 06:37:00 -04:00
@cd $(DESTDIR)$(MANPREFIX)/man1 && rm -f $(MAN)
2011-05-22 21:36:34 -04:00
dist: clean
@echo creating dist tarball
@mkdir -p sbase-$(VERSION)
2011-05-26 20:20:03 -04:00
@cp -r LICENSE Makefile config.mk $(SRC) $(MAN) util $(HDR) sbase-$(VERSION)
2011-05-22 21:36:34 -04:00
@tar -cf sbase-$(VERSION).tar sbase-$(VERSION)
@gzip sbase-$(VERSION).tar
@rm -rf sbase-$(VERSION)
2011-06-16 16:20:17 -04:00
sbase-box: $(SRC) util.a
2011-06-15 20:53:33 -04:00
@echo creating box binary
@mkdir -p build
2011-06-16 16:20:17 -04:00
@cp $(HDR) build
@for f in $(SRC); do sed "s/^main(/`basename $$f .c`_&/" < $$f > build/$$f; done
2011-06-15 20:53:33 -04:00
@echo '#include <libgen.h>' > build/$@.c
@echo '#include <stdlib.h>' >> build/$@.c
@echo '#include <string.h>' >> build/$@.c
@echo '#include "util.h"' >> build/$@.c
2011-06-16 16:20:17 -04:00
@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(0) ;' >> build/$@.c
@for f in $(SRC); do echo "else if(!strcmp(s, \"`basename $$f .c`\")) `basename $$f .c`_main(argc, argv);" >> build/$@.c; done
@printf 'else eprintf("%%s: unknown program\\n", s); return EXIT_SUCCESS; }\n' >> build/$@.c
2011-06-15 20:53:33 -04:00
@echo LD $@
2011-06-16 16:20:17 -04:00
@$(LD) -o $@ build/*.c util.a $(CFLAGS) $(LDFLAGS)
2011-06-15 20:53:33 -04:00
@rm -r build
2011-05-22 21:36:34 -04:00
clean:
@echo cleaning
2011-06-15 20:53:33 -04:00
@rm -f $(BIN) $(OBJ) $(LIB) util.a sbase-box