-
Notifications
You must be signed in to change notification settings - Fork 3
/
GNUmakefile
56 lines (44 loc) · 956 Bytes
/
GNUmakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
NAME=zutil
LIBPREFIX=lib
LIBSUFFIX=.a
RANLIB=ranlib
AR=ar
# CC=g++-3.3
# CC=g++-2.95
# CC=gcc-3.3
# CC=gcc-2.95
# CPPFLAGS=-UNDEBUG -std=c99
# CPPFLAGS=-UNDEBUG
CPPFLAGS=-DNDEBUG
CFLAGS=-Wall -O2
# LDFLAGS += -g
# SRCS=$(wildcard *.c)
SRCS=zutil.c exhaust.c moreassert.c delegate.c
TESTSRCS=test.c
OBJS=$(SRCS:%.c=%.o)
TESTOBJS=$(TESTSRCS:%.c=%.o)
TEST=test
LIB=$(LIBPREFIX)$(NAME)$(LIBSUFFIX)
all: $(LIB) $(TEST)
# .d auto-dependency files
ifneq ($(findstring clean,$(MAKECMDGOALS)),clean)
ifneq (,$(SRCS:%.c=%.d))
-include $(SRCS:%.c=%.d)
endif
ifneq (,$(TESTSRCS:%.c=%.d))
-include $(TESTSRCS:%.c=%.d)
endif
endif
%.d: %.c
@echo remaking $@
@set -e; $(CC) $(CPPFLAGS) $(CFLAGS) -MM $< \
| sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@; \
[ -s $@ ] || rm -f $@
$(LIB): $(OBJS)
$(AR) -r $@ $+
$(RANLIB) $@
$(TEST): $(TESTOBJS) $(LIB)
$(CC) $(LDFLAGS) $+ -o $@
clean:
-rm $(LIB) $(OBJS) $(TEST) $(TESTOBJS) *.d 2>/dev/null
.PHONY: clean all