]>
Commit | Line | Data |
---|---|---|
36230329 NS |
1 | # Nathan's generic Makefile -*- mode:Makefile -*- |
2 | # Copyright (C) 2019-2020 Nathan Sidwell, nathan@acm.org | |
3 | # License: Apache v2.0 | |
4 | ||
36230329 NS |
5 | srcdir := @srcdir@ |
6 | prefix := @prefix@ | |
7 | exec_prefix := @exec_prefix@ | |
8 | bindir := @bindir@ | |
9 | libdir := @libdir@ | |
10 | includedir := @includedir@ | |
e2aa8a5f NS |
11 | # Linker options |
12 | LDFLAGS := @LDFLAGS@ | |
13 | LIBS := @LIBS@ | |
36230329 NS |
14 | |
15 | # We have to place the -I paths last, so that building will see -I paths to us | |
16 | CXX := $(filter-out -I%,@CXX@) | |
17 | AR := @AR@ | |
626b63d6 | 18 | RANLIB := @RANLIB@ |
36230329 NS |
19 | INSTALL := $(srcdir)/build-aux/install-sh |
20 | ||
21 | # C++ compiler options | |
22 | CXXFLAGS := @CXXFLAGS@ | |
23 | CXXINC := $(filter -I%,@CXX@) | |
d1ad55c4 | 24 | CXXOPTS := $(CXXFLAGS) @PICFLAG@ |
e2aa8a5f | 25 | |
36230329 NS |
26 | ifneq (@EXCEPTIONS@,yes) |
27 | CXXOPTS += -fno-exceptions -fno-rtti | |
28 | endif | |
36230329 NS |
29 | |
30 | # Config | |
31 | CXXOPTS += $(filter-out -DHAVE_CONFIG_H,@DEFS@) -include config.h | |
32 | ||
33 | # Linker options | |
16929214 | 34 | LDFLAGS := @LDFLAGS@ |
36230329 NS |
35 | LIBS := @LIBS@ |
36 | ||
37 | # Per-source & per-directory compile flags (warning: recursive) | |
38 | SRC_CXXFLAGS = $(CXXFLAGS$(patsubst $(srcdir)%,%,$1)) \ | |
39 | $(if $(filter-out $(srcdir)/,$1),\ | |
40 | $(call $0,$(dir $(patsubst %/,%,$1)))) | |
41 | ||
42 | ifneq ($(MAINTAINER),) | |
43 | override MAINTAINER += $1 | |
44 | endif | |
45 | ifeq (@MAINTAINER@,yes) | |
46 | MAINTAINER = $2 | |
47 | else | |
48 | MAINTAINER = \# --enable-maintainer-mode to rebuild $1, or make MAINTAINER=touch | |
49 | endif | |
50 | ||
51 | vpath %.in $(srcdir) | |
52 | vpath %.cc $(srcdir) | |
53 | ||
54 | .SUFFIXES: .o .cc | |
55 | ||
56 | %.o: %.cc | |
57 | @mkdir -p $(dir $@) | |
58 | $(CXX) $(strip $(CXXOPTS) $(call SRC_CXXFLAGS,$<) $(CXXINC)) \ | |
59 | -MMD -MP -MF ${@:.o=.d} -c -o $@ $< | |
60 | ||
e2aa8a5f | 61 | all:: Makefile |
36230329 | 62 | |
e2aa8a5f | 63 | clean:: Makefile |
36230329 | 64 | |
e2aa8a5f NS |
65 | # FIXME: Delete |
66 | revision.stamp: $(srcdir)/. | |
36230329 NS |
67 | @revision=$$(git -C $(srcdir) rev-parse HEAD 2>/dev/null) ;\ |
68 | if test -n "$$revision" ;\ | |
69 | then revision=git-$$revision ;\ | |
70 | if git -C $(srcdir) status --porcelain 2>/dev/null | grep -vq '^ ' ;\ | |
71 | then revision+=M ;\ | |
72 | fi ;\ | |
73 | else revision=unknown ;\ | |
74 | fi ;\ | |
75 | echo $$revision > $@ | |
76 | ||
77 | revision: revision.stamp | |
78 | @cmp -s $< $@ || cp -f $< $@ | |
79 | ||
80 | clean:: | |
81 | rm -f revision.stamp revision | |
82 | ||
83 | distclean:: clean | |
84 | rm -f config.log config.status | |
36230329 | 85 | |
e2aa8a5f | 86 | $(srcdir)/configure: $(srcdir)/configure.ac $(srcdir)/config.m4 |
36230329 NS |
87 | $(call MAINTAINER,$@,cd $(@D) && autoconf -W all,error) |
88 | ||
e2aa8a5f | 89 | $(srcdir)/config.h.in: $(srcdir)/configure.ac $(srcdir)/config.m4 |
36230329 NS |
90 | $(call MAINTAINER,$@,cd $(@D) && autoheader -f -W all,error) |
91 | ||
92 | config.h: config.status config.h.in | |
93 | ./$< --header=$@ | |
94 | touch $@ | |
95 | ||
96 | ifeq ($(filter %clean,$(MAKECMDGOALS)),) | |
e2aa8a5f | 97 | Makefile: config.status Makefile.in |
36230329 NS |
98 | ./$< --file=$@ |
99 | touch $@ | |
100 | endif | |
101 | ||
102 | config.status: $(srcdir)/configure $(srcdir)/config.h.in | |
103 | if test -x $@; then ./$@ -recheck; else $< @configure_args@; fi | |
104 | ||
105 | distclean:: clean | |
106 | rm -f config.h | |
107 | ||
108 | maintainer-clean:: distclean | |
109 | rm -f $(srcdir)/config.h.in | |
110 | ||
111 | clean:: | |
112 | rm -f $(shell find $(srcdir) -name '*~') | |
113 | ||
114 | .PHONY: all check clean distclean maintainer-clean | |
115 | ||
e2aa8a5f NS |
116 | CXXFLAGS/ := -I$(srcdir) |
117 | LIBCODY.O := buffer.o client.o fatal.o netclient.o netserver.o \ | |
118 | resolver.o packet.o server.o | |
119 | ||
120 | all:: libcody.a | |
121 | ||
122 | libcody.a: $(LIBCODY.O) | |
123 | $(AR) -cr $@ $^ | |
124 | $(RANLIB) $@ | |
125 | ||
126 | clean:: | |
127 | rm -f $(LIBCODY.O) $(LIBCODY.O:.o=.d) | |
128 | rm -f libcody.a | |
129 | ||
130 | CXXFLAGS/fatal.cc = -DSRCDIR='"$(srcdir)"' | |
131 | ||
132 | fatal.o: Makefile revision | |
133 | ||
134 | install:: | |
135 | $(INSTALL) -d $(libdir) $(includedir) | |
136 | $(INSTALL) libcody.a $(libdir) | |
137 | $(INSTALL) $(srcdir)/cody.hh $(includedir) | |
36230329 | 138 | |
e2aa8a5f NS |
139 | ifeq ($(filter clean%,$(MAKECMDGOALS)),) |
140 | -include $(LIBCODY.O:.o=.d) | |
36230329 | 141 | endif |