Use LIB, LIBSRC and LIBOBJ and derive SRC, OBJ and MAN from BIN

This commit is contained in:
sin 2014-11-17 12:12:10 +00:00
parent afa2e6ec54
commit 2ee3ae5994

226
Makefile
View File

@ -15,118 +15,120 @@ HDR = \
text.h \ text.h \
util.h util.h
LIB = \ LIB = libutil.a
util/agetcwd.o \ LIBSRC = \
util/agetline.o \ util/agetcwd.c \
util/apathmax.o \ util/agetline.c \
util/concat.o \ util/apathmax.c \
util/cp.o \ util/concat.c \
util/crypt.o \ util/cp.c \
util/ealloc.o \ util/crypt.c \
util/enmasse.o \ util/ealloc.c \
util/eprintf.o \ util/enmasse.c \
util/eregcomp.o \ util/eprintf.c \
util/estrtod.o \ util/eregcomp.c \
util/estrtol.o \ util/estrtod.c \
util/fnck.o \ util/estrtol.c \
util/getlines.o \ util/fnck.c \
util/human.o \ util/getlines.c \
util/md5.o \ util/human.c \
util/mode.o \ util/md5.c \
util/putword.o \ util/mode.c \
util/recurse.o \ util/putword.c \
util/rm.o \ util/recurse.c \
util/sha1.o \ util/rm.c \
util/sha256.o \ util/sha1.c \
util/sha512.o \ util/sha256.c \
util/strlcat.o \ util/sha512.c \
util/strlcpy.o util/strlcat.c \
util/strlcpy.c
SRC = \ BIN = \
basename.c \ basename \
cal.c \ cal \
cat.c \ cat \
chgrp.c \ chgrp \
chmod.c \ chmod \
chown.c \ chown \
chroot.c \ chroot \
cksum.c \ cksum \
cmp.c \ cmp \
col.c \ col \
cols.c \ cols \
comm.c \ comm \
cp.c \ cp \
csplit.c \ csplit \
cut.c \ cut \
date.c \ date \
dirname.c \ dirname \
du.c \ du \
echo.c \ echo \
env.c \ env \
expand.c \ expand \
expr.c \ expr \
false.c \ false \
fold.c \ fold \
grep.c \ grep \
head.c \ head \
hostname.c \ hostname \
kill.c \ kill \
link.c \ link \
ln.c \ ln \
logname.c \ logname \
ls.c \ ls \
md5sum.c \ md5sum \
mkdir.c \ mkdir \
mkfifo.c \ mkfifo \
mktemp.c \ mktemp \
mv.c \ mv \
nice.c \ nice \
nl.c \ nl \
nohup.c \ nohup \
paste.c \ paste \
printenv.c \ printenv \
printf.c \ printf \
pwd.c \ pwd \
readlink.c \ readlink \
renice.c \ renice \
rm.c \ rm \
rmdir.c \ rmdir \
sleep.c \ sleep \
setsid.c \ setsid \
sort.c \ sort \
split.c \ split \
sponge.c \ sponge \
strings.c \ strings \
sync.c \ sync \
tail.c \ tail \
tar.c \ tar \
tee.c \ tee \
test.c \ test \
touch.c \ touch \
tr.c \ tr \
true.c \ true \
tty.c \ tty \
uudecode.c \ uudecode \
uuencode.c \ uuencode \
uname.c \ uname \
unexpand.c \ unexpand \
uniq.c \ uniq \
unlink.c \ unlink \
seq.c \ seq \
sha1sum.c \ sha1sum \
sha256sum.c\ sha256sum\
sha512sum.c\ sha512sum\
wc.c \ wc \
xargs.c \ xargs \
yes.c yes
OBJ = $(SRC:.c=.o) $(LIB) LIBOBJ = $(LIBSRC:.c=.o)
BIN = $(SRC:.c=) OBJ = $(BIN:=.o) $(LIBOBJ)
MAN = $(SRC:.c=.1) SRC = $(BIN:=.c)
MAN = $(BIN:=.1)
all: binlib all: binlib
binlib: libutil.a binlib: $(LIB)
$(MAKE) bin $(MAKE) bin
bin: $(BIN) bin: $(BIN)
@ -134,12 +136,12 @@ bin: $(BIN)
$(OBJ): $(HDR) config.mk $(OBJ): $(HDR) config.mk
.o: .o:
$(LD) $(LDFLAGS) -o $@ $< libutil.a $(LD) $(LDFLAGS) -o $@ $< $(LIB)
.c.o: .c.o:
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $< $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
libutil.a: $(LIB) $(LIB): $(LIBOBJ)
$(AR) -r -c $@ $? $(AR) -r -c $@ $?
ranlib $@ ranlib $@
@ -162,7 +164,7 @@ dist: clean
gzip sbase-$(VERSION).tar gzip sbase-$(VERSION).tar
rm -rf sbase-$(VERSION) rm -rf sbase-$(VERSION)
sbase-box: libutil.a $(SRC) sbase-box: $(LIB) $(SRC)
mkdir -p build mkdir -p build
cp $(HDR) 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(/`basename $$f .c`_&/" < $$f > build/$$f; done
@ -177,8 +179,8 @@ sbase-box: libutil.a $(SRC)
echo 'else {' >> build/$@.c echo 'else {' >> build/$@.c
for f in $(SRC); do echo "printf(\"`basename $$f .c`\"); putchar(' ');" >> build/$@.c; done for f in $(SRC); do echo "printf(\"`basename $$f .c`\"); putchar(' ');" >> build/$@.c; done
echo "putchar(0xa); }; return 0; }" >> build/$@.c echo "putchar(0xa); }; return 0; }" >> build/$@.c
$(LD) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ build/*.c libutil.a $(LD) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ build/*.c $(LIB)
rm -r build rm -r build
clean: clean:
rm -f $(BIN) $(OBJ) $(LIB) libutil.a sbase-box sbase-$(VERSION).tar.gz rm -f $(BIN) $(OBJ) $(LIBOBJ) $(LIB) sbase-box sbase-$(VERSION).tar.gz