1 # Nathan's generic Makefile -*- mode:Makefile -*-
2 # Copyright (C) 2019-2020 Nathan Sidwell, nathan@acm.org
7 $(info Prepending @tools@
/bin to PATH
)
8 PATH
:= @tools@
/bin
:$(PATH
)
12 # Figure out if we should set parallelism
13 ifeq (,$(filter clean%,$(MAKECMDGOALS
)))
14 PARALLELISM
:= @NUM_CPUS@
19 ifeq (00,$(MAKELEVEL
)$(if
$(PARALLELISM
),0,1))
20 # Although Make 4.3 documentation suggests I can set parallelism just
21 # by appending to MAKEFLAGS, it doesn't seem to work. It's also not
22 # possible to figure out the current Make invocation's parallelism,
23 # the -j option doesn't appear in MAKEFLAGS and is magically inserted
24 # when that is expanded in a rule. I can't figure how to get a rule
25 # expansion into a variable to test. Fortunately, Make propagates an
26 # incoming -j option rather than the one you attempted to append
27 $(info Parallelizing
$(PARALLELISM
) ways
)
28 MAKEFLAGS
+= -j
$(PARALLELISM
)
29 ifneq (,$(MAKECMDGOALS
))
30 $(MAKECMDGOALS
): recurse
33 $(MAKE
) -r
$(MAKEFLAGS
) $(MAKECMDGOALS
)
39 exec_prefix := @
exec_prefix@
42 includedir := @
includedir@
44 # autoconf doesn't seem to like setting SHELL
45 SHELL
:= $(shell which zsh
2>/dev
/null
>/dev
/null
&& echo zsh \
46 ||
(echo
"No ZSH, maybe flakey" >&2 && echo sh
))
48 # We have to place the -I paths last, so that building will see -I paths to us
49 CXX
:= $(filter-out -I
%,@CXX@
)
51 INSTALL
:= $(srcdir)/build-aux
/install-sh
53 # C++ compiler options
54 CXXFLAGS
:= @CXXFLAGS@
55 CXXINC
:= $(filter -I
%,@CXX@
)
56 CXXOPTS
:= $(CXXFLAGS
)
57 ifeq ($(notdir $(firstword $(CXX
))),g
++)
58 # It's GCC, or pretending to be it -- so it better smell like it!
60 CXXOPTS
+= -fno-enforce-eh-specs
61 CXXOPTS
+= -fno-stack-protector
-fno-threadsafe-statics
62 ifneq (@EXCEPTIONS@
,yes
)
63 CXXOPTS
+= -fno-exceptions
-fno-rtti
65 ifeq ($(filter -fdebug-prefix-map
=%,$(CXXOPTS
)),)
66 CXXOPTS
+= -fdebug-prefix-map
=${srcdir}/=
71 # just turn off for now
72 CXXOPTS
+= -Woverloaded-virtual
-Wshadow
73 CXXOPTS
+= -Wno-invalid-offsetof
-Wno-unused-variable
74 CXXOPTS
+= -Wno-missing-field-initializers
75 # Diagnostic options, look at controlling terminal so that piping
77 MLEN
:= $(shell stty size
</dev
/tty
2>/dev
/null | cut
-d
' ' -f2
)
79 CXXOPTS
+= -fmessage-length
=$(MLEN
)
81 CXXOPTS
+= -fdiagnostics-color
=always
-fno-diagnostics-show-option
84 ifeq ($(notdir $(firstword $(CXX
))),clang
++)
85 CXXOPTS
+= -fno-stack-protector
-fno-threadsafe-statics
86 ifneq (@EXCEPTIONS@
,yes
)
87 CXXOPTS
+= -fno-exceptions
-fno-rtti
90 CXXOPTS
+= -W
-Wall
-Woverloaded-virtual
-Wshadow
91 CXXOPTS
+= -Wno-invalid-offsetof
-Wno-unused-variable
92 CXXOPTS
+= -Wno-missing-field-initializers
94 # Add different compiler's options here
99 CXXOPTS
+= $(filter-out -DHAVE_CONFIG_H
,@DEFS@
) -include config.h
102 LDFLAGS
:= -L. @LDFLAGS@
105 # Per-source & per-directory compile flags (warning: recursive)
106 SRC_CXXFLAGS
= $(CXXFLAGS
$(patsubst $(srcdir)%,%,$1)) \
107 $(if
$(filter-out $(srcdir)/,$1),\
108 $(call
$0,$(dir $(patsubst %/,%,$1))))
110 ifneq ($(MAINTAINER
),)
111 override MAINTAINER
+= $1
113 ifeq (@MAINTAINER@
,yes
)
116 MAINTAINER
= \
# --enable-maintainer-mode to rebuild $1, or make MAINTAINER=touch
126 $(CXX
) $(strip $(CXXOPTS
) $(call SRC_CXXFLAGS
,$<) $(CXXINC
)) \
127 -MMD
-MP
-MF
${@
:.o
=.d
} -c
-o
$@
$<
129 all:: Makefile
$(addprefix all.
,$(SUBDIRS
))
131 check:: Makefile
$(addprefix check.
,$(SUBDIRS
))
133 clean:: Makefile
$(addprefix clean.
,$(SUBDIRS
))
135 revision.stamp
: $(addprefix $(srcdir)/,.
$(SUBDIRS
))
136 @revision
=$$(git
-C
$(srcdir) rev-parse HEAD
2>/dev
/null
) ;\
137 if
test -n
"$$revision" ;\
138 then revision
=git-
$$revision ;\
139 if git
-C
$(srcdir) status
--porcelain
2>/dev
/null | grep
-vq
'^ ' ;\
142 else revision
=unknown
;\
146 revision
: revision.stamp
147 @cmp
-s
$< $@ || cp
-f
$< $@
150 rm -f revision.stamp revision
153 rm -f config.log config.status
156 $(srcdir)/configure
: $(srcdir)/configure.ac \
157 $(patsubst %,$(srcdir)/%/config.m4
,.
$(SUBDIRS
))
158 $(call MAINTAINER
,$@
,cd
$(@D
) && autoconf
-W
all,error
)
160 $(srcdir)/config.h.in
: $(srcdir)/configure.ac \
161 $(patsubst %,$(srcdir)/%/config.m4
,.
$(SUBDIRS
))
162 $(call MAINTAINER
,$@
,cd
$(@D
) && autoheader
-f
-W
all,error
)
164 config.h
: config.status config.h.in
168 ifeq ($(filter %clean,$(MAKECMDGOALS
)),)
169 @CONFIG_FILES@
: %: config.status
%.in
174 config.status
: $(srcdir)/configure
$(srcdir)/config.h.in
175 if
test -x
$@
; then .
/$@
-recheck
; else $< @configure_args@
; fi
180 maintainer-clean
:: distclean
181 rm -f
$(srcdir)/config.h.in
184 rm -f
$(shell find
$(srcdir) -name
'*~')
186 .PHONY
: all check clean distclean maintainer-clean
188 -include $(addsuffix /Makesub
,.
$(SUBDIRS
))
189 -include $(addsuffix /tests
/Makesub
,.
$(SUBDIRS
))