1 # -*- Mode: makefile; -*- #
3 # This file is part of MKUltra - Gene's ultimate make include files.
5 # Copyright © 2016-2017 Gene Hightower <gene@digilicious.com>
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, version 3.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. See the file LICENSE. If not, see
18 # <http://www.gnu.org/licenses/>.
22 uname := $(shell uname)
24 ifneq (,$(findstring CYGWIN_NT,$(uname)))
27 ifneq (,$(findstring MINGW32_NT,$(uname)))
33 # Java is "special" in many ways, doesn't use pkg-config: requires
36 JAVA := $(findstring Java,$(USES))
37 USES := $(filter-out Java,$(USES))
39 current_dir := $(dir $(CURDIR)/$(lastword $(MAKEFILE_LIST)))
40 include $(current_dir)defs.$(TARG)
43 JAVAC ?= $(JAVA_HOME)/bin/javac
47 BINDIR ?= $(PREFIX)/bin
48 LIBDIR ?= $(PREFIX)/lib
49 DATADIR ?= $(PREFIX)/share
51 libfiles := $(foreach x,$(LIBS),$(so_pfx)$(x)$(so_sfx))
52 prgfiles := $(foreach x,$(PROGRAMS),$(x)$(exe_sfx))
53 tstfiles := $(foreach x,$(TESTS),$(x)$(exe_sfx))
55 ifeq (clang,$(notdir $(CXX)))
60 -Wno-c++98-compat-pedantic \
61 -Wno-disabled-macro-expansion \
62 -Wno-exit-time-destructors \
64 -Wno-global-constructors \
65 -Wno-missing-field-initializers \
66 -Wno-missing-prototypes \
70 -Wno-sign-conversion \
71 -Wno-undefined-func-template \
72 -Wno-unused-const-variable \
73 -Wno-unused-exception-parameter \
74 -Wno-unused-parameter \
75 -Wno-zero-length-array
81 -Wno-missing-field-initializers \
83 -Wno-unused-const-variable \
89 -Woverloaded-virtual \
93 CFLAGS += $(warnings_c) -MMD -O3 -flto -fvisibility=hidden -fstack-check
94 CXXFLAGS += -std=c++1z $(warnings_cpp) -MMD -O3 -flto -fvisibility=hidden -fstack-check
99 CFLAGS += $(shell PKG_CONFIG_PATH=$(pkg_config_path) pkg-config --cflags $(USES))
100 CXXFLAGS += $(shell PKG_CONFIG_PATH=$(pkg_config_path) pkg-config --cflags $(USES))
101 LDFLAGS += $(shell PKG_CONFIG_PATH=$(pkg_config_path) pkg-config --libs $(USES))
104 #############################################################################
107 $(CXX) -o $@ -fPIC $(CPPFLAGS) $(CXXFLAGS) -c $<
110 $(CC) -o $@ -fPIC $(CPPFLAGS) $(CFLAGS) -c $<
112 #############################################################################
114 ifneq (,$(BUNDLE_PREFIX))
115 # Bundle for NeXTSTEP, OPENSTEP, GNUstep, and their lineal descendants
118 bundle_dir = $(BUNDLE_PREFIX)/Contents
119 bundle_bin_dir = $(bundle_dir)/MacOS
120 bundle_lib_dir = $(bundle_dir)/lib
121 bundle_dat_dir = $(bundle_dir)/share
123 bundle_all_dirs = $(bundle_bin_dir) $(bundle_lib_dir) $(bundle_dat_dir)
131 #############################################################################
133 all:: $(libfiles) $(prgfiles)
135 check:: all $(tstfiles)
140 install:: $(libfiles) $(LIBDIR)
141 cp $(libfiles) $(LIBDIR)
142 ifneq (,$(bundle_lib_dir))
143 cp $(libfiles) $(bundle_lib_dir)
148 install:: $(prgfiles) $(BINDIR)
149 cp $(prgfiles) $(BINDIR)
150 ifneq (,$(bundle_bin_dir))
151 cp $(prgfiles) $(bundle_bin_dir)
156 install:: $(DATA) $(DATADIR)
157 cp -r $(DATA) $(DATADIR)
158 ifneq (,$(bundle_dat_dir))
159 cp -r $(DATA) $(bundle_dat_dir)
164 tests: all $(tstfiles)
166 install-tests:: all $(tstfiles) $(BINDIR)
167 cp $(tstfiles) $(BINDIR)
170 $(BINDIR) $(LIBDIR) $(DATADIR):
173 #############################################################################
178 check:: $(1)$(exe_sfx)
182 valgrind $(VGFLAGS) ./$(1) ;
185 $(foreach t,$(TESTS),$(eval $(call test_cmd,$(t))))
187 #############################################################################
190 $(1)_all_stems := $$($(1)_STEMS)
191 $(1)_objs := $$(patsubst %,%$(o_sfx),$$($(1)_all_stems))
192 $(1)_deps := $$(patsubst %,%.d,$$($(1)_all_stems))
194 -include $$($(1)_deps)
196 $(1)$(exe_sfx): $$($(1)_objs) $$($(1)_EXTRAS) $(libfiles)
197 $(CXX) -o $$@ $$^ $(LDFLAGS) $(LDLIBS) -L. $(foreach l,$(LIBS),-l$(l))
200 rm -f $(1)$(exe_sfx) $$($(1)_objs) $$($(1)_deps)
203 $(foreach prog,$(PROGRAMS),$(eval $(call link_cmd,$(prog))))
204 $(foreach prog,$(TESTS),$(eval $(call link_cmd,$(prog))))
206 #############################################################################
209 $(1)_all_stems := $$($(1)_STEMS)
210 $(1)_objs := $$(patsubst %,%$(o_sfx),$$($(1)_all_stems))
211 $(1)_deps := $$(patsubst %,%.d,$$($(1)_all_stems))
213 -include $$($(1)_deps)
215 $(so_pfx)$(1)$(so_sfx): $$($(1)_objs)
216 $(CXX) -shared -o $$@ $$^ $(LDFLAGS) $(TARGET_ARCH) $(LOADLIBES) $(LDLIBS)
219 rm -f $(so_pfx)$(1)$(so_sfx) $$($(1)_objs) $$($(1)_deps)
222 $(foreach lib,$(LIBS),$(eval $(call lib_cmd,$(lib))))
224 #############################################################################
230 @echo JAVA_HOME == $(JAVA_HOME)
231 @echo MAKEFILE_LIST == $(MAKEFILE_LIST)
232 @echo .INCLUDE_DIRS == $(.INCLUDE_DIRS)
233 @echo USES == $(USES)
234 @echo PROGRAMS == $(PROGRAMS)
235 @echo LIBS == $(LIBS)
236 @echo TESTS == $(TESTS)
237 @echo CFLAGS == $(CFLAGS)
238 @echo CXXFLAGS == $(CXXFLAGS)
239 @echo LDFLAGS == $(LDFLAGS)
244 @echo $(1)_all_stems == $$($(1)_all_stems)
245 @echo $(1)_objs == $$($(1)_objs)
246 @echo $(1)_deps == $$($(1)_deps)
249 $(foreach x,$(PROGRAMS),$(eval $(call dump_template,$(x))))
250 $(foreach x,$(LIBS),$(eval $(call dump_template,$(x))))
251 $(foreach x,$(TESTS),$(eval $(call dump_template,$(x))))
253 .PHONY:: all check dump install install-tests tests