-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile
122 lines (88 loc) · 2.96 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
srcdir = .
exec_prefix = /usr/local
bindir = $(exec_prefix)/bin
sbindir = $(exec_prefix)/sbin
prefix = /usr/local
includedir = $(prefix)/include
libdir = $(prefix)/lib
mandir = $(prefix)/share/man
SRC_DIRS = $(addprefix $(srcdir)/,src port)
GEN_SRCS = $(sort $(patsubst $(srcdir)/%.y,obj/%.tab.c,$(wildcard $(addsuffix /*.y,$(SRC_DIRS)))) \
$(patsubst $(srcdir)/%.l,obj/%.yy.c,$(wildcard $(addsuffix /*.l,$(SRC_DIRS)))))
SRCS = $(sort $(wildcard $(addsuffix /*.c,$(SRC_DIRS))))
OBJS = $(sort $(patsubst %,%.o,$(basename $(GEN_SRCS))) \
$(addprefix obj/,$(patsubst $(srcdir)/%,%.o,$(basename $(SRCS)))))
PORTS = $(sort $(wildcard $(srcdir)/port/*.c))
TESTS = $(addprefix obj/test/,$(sort $(patsubst $(srcdir)/%,%,$(basename $(PORTS)))))
HEADERS = $(sort $(wildcard $(srcdir)/include/*))
TOOLS = obj/nscd
GENH = obj/include/config.h
LDFLAGS =
CPPFLAGS =
CFLAGS = -Os -pipe
CFLAGS_C99 = -std=c99
CFLAGS_ALL = $(CFLAGS_C99)
CFLAGS_ALL += -D_XOPEN_SOURCE=700 -I$(srcdir)/include -Iobj/include
CFLAGS_ALL += $(CPPFLAGS) $(CFLAGS_AUTO) $(CFLAGS)
LDFLAGS_ALL = $(LDFLAGS_AUTO) $(LDFLAGS)
LDLIBS += $(LDLIBS_AUTO)
INSTALL = $(srcdir)/tools/install.sh
-include config.mak
all: $(TOOLS)
OBJ_DIRS = $(sort $(patsubst %/,%,$(dir $(BINS) $(OBJS) $(TESTS) $(GENH))) obj/src obj/include)
$(TESTS) $(BINS) $(OBJS) $(GENH): | $(OBJ_DIRS)
$(OBJ_DIRS):
mkdir -p $@
obj/include/config.h: $(srcdir)/tools/gen_config.sh $(TESTS)
$(srcdir)/tools/gen_config.sh $(srcdir) >$@
$(OBJS): $(HEADERS)
obj/%.o: obj/%.c $(GENH)
$(CC) $(CFLAGS_ALL) -c -o $@ $<
obj/%.o: $(srcdir)/%.c $(GENH)
$(CC) $(CFLAGS_ALL) -c -o $@ $<
ifdef MODIFY_SRC
$(srcdir)/dist/%.yy.c: $(srcdir)/%.l
$(LEX) -t $< >$@
$(srcdir)/dist/%.tab.c: $(srcdir)/%.y
$(YACC) -b $* $<
$(srcdir)/dist/src:
mkdir -p $@
genfiles: $(srcdir)/dist/src
genfiles: $(patsubst $(srcdir)/%.l,$(srcdir)/dist/%.yy.c,$(wildcard $(add_suffix /*.l,$(SRC_DIRS))))
genfiles: $(patsubst $(srcdir)/%.y,$(srcdir)/dist/%.tab.c,$(wildcard $(add_suffix /*.y,$(SRC_DIRS))))
endif
ifdef LEX
obj/%.yy.c: $(srcdir)/%.l
$(LEX) -t $< >$@
else
obj/%.yy.c: $(srcdir)/dist/%.yy.c
cp $< $@
endif
ifdef YACC
obj/%.tab.c: $(srcdir)/%.y
$(YACC) -b obj/$* $<
else
obj/%.tab.c: $(srcdir)/dist/%.tab.c
cp $< $@
endif
obj/nscd: $(OBJS)
$(CC) $(CFLAGS_ALL) $(LDFLAGS_ALL) $^ $(LDLIBS) -o $@
obj/test/%: $(srcdir)/%.c
$(CC) $(CFLAGS_ALL) -DTEST $(LDFLAGS_ALL) $< $(LDLIBS) -o $@ >/dev/null 2>&1 || cat </dev/null >$@
$(DESTDIR)$(bindir)/%: obj/%
$(INSTALL) -D $< $@
$(DESTDIR)$(sbindir)/%: obj/%
$(INSTALL) -D $< $@
$(DESTDIR)$(includedir)/%: $(srcdir)/include/%
$(INSTALL) -D -m 644 $< $@
$(DESTDIR)$(mandir)/man8/%: %
$(INSTALL) -D -m 644 $< $@
install-headers: $(DESTDIR)$(includedir)/nss.h
install-manpage: $(DESTDIR)$(mandir)/man8/musl-nscd.8
install-tools: $(TOOLS:obj/%=$(DESTDIR)$(sbindir)/%)
install: install-tools install-headers install-manpage
clean:
rm -rf obj
distclean: clean
rm -f config.mak
.PHONY: all install-tools install clean dist-clean genfiles