-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
43 lines (33 loc) · 903 Bytes
/
Makefile
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
LIBSRC = $(wildcard *.c)
LIBOBJ = $(patsubst %.c,%.o,$(LIBSRC))
LIBDEP = $(patsubst %.c,%.d,$(LIBSRC))
LIBDEST = libfasthamming.a
TESTSRC = $(wildcard test/*.c)
TESTDEST = $(patsubst test/%.c,test_%,$(TESTSRC))
CC ?= gcc
LD ?= gcc
AR ?= ar
RANLIB ?= ranlib
.PHONY: all
all: lib test
.PHONY: lib
lib: $(LIBDEST)
%.a: $(LIBOBJ)
$(AR) rc $@ $^ && $(RANLIB) $@
%.o %.d: %.c
$(CC) $(CFLAGS) -MMD -o $*.o -c $<
-include $(LIBDEP)
.PHONY: test
test: $(TESTDEST)
for a in $^; do printf 'Running %s …\n' "$$a"; ./$$a; done
test_%: test/%.c $(LIBDEST)
$(CC) -I. $(CFLAGS) -o $@ $^ $(LFLAGS)
clean:
-find . -type f -name '*.d' -print -delete
-find . -type f -name '*.o' -print -delete
-find . -type f -name '*.a' -print -delete
-find . -type f -name 'test_*' \( -perm -u=x -o -perm -g=x -o -perm -o=x \) -print -delete
-rm -f $(LIBDEP)
-rm -f $(LIBOBJ)
-rm -f $(LIBDEST)
-rm -f $(TESTDEST)