1 # -*- Mode: makefile; -*- #
5 uname := $(shell uname)
7 ifneq (,$(findstring CYGWIN_NT,$(uname)))
10 ifneq (,$(findstring MINGW32_NT,$(uname)))
16 # Java is "special" in many ways, doesn't use pkg-config: requires
19 JAVA := $(findstring Java,$(USES))
20 USES := $(filter-out Java,$(USES))
22 current_dir := $(dir $(CURDIR)/$(lastword $(MAKEFILE_LIST)))
23 include $(current_dir)defs.$(TARG)
26 JAVAC ?= $(JAVA_HOME)/bin/javac
30 BINDIR ?= $(PREFIX)/bin
31 LIBDIR ?= $(PREFIX)/lib
32 DATADIR ?= $(PREFIX)/share
34 libfiles := $(foreach x,$(LIBS),$(so_pfx)$(x)$(so_sfx))
35 prgfiles := $(foreach x,$(PROGRAMS),$(exe_pfx)$(x)$(exe_sfx))
36 tstfiles := $(foreach x,$(TESTS),$(exe_pfx)$(x)$(exe_sfx))
38 CXXFLAGS += -std=c++14 -MMD -O3 -Wall
41 CXXFLAGS += $(shell PKG_CONFIG_PATH=$(pkg_config_path) pkg-config --cflags $(USES))
42 LDFLAGS += $(shell PKG_CONFIG_PATH=$(pkg_config_path) pkg-config --libs $(USES))
46 $(CXX) -o $@ -fPIC $(CPPFLAGS) $(CXXFLAGS) -c $<
48 #############################################################################
50 all:: $(libfiles) $(prgfiles)
52 check:: all $(tstfiles)
57 install:: $(libfiles) $(LIBDIR)
58 cp $(libfiles) $(LIBDIR)
62 install:: $(prgfiles) $(BINDIR)
63 cp $(prgfiles) $(BINDIR)
67 install:: $(DATA) $(DATADIR)
68 cp -r $(DATA) $(DATADIR)
72 tests: all $(tstfiles)
74 install-tests:: all $(tstfiles) $(BINDIR)
75 cp $(tstfiles) $(BINDIR)
78 $(BINDIR) $(LIBDIR) $(DATADIR):
81 #############################################################################
86 check:: $(exe_pfx)$(1)$(exe_sfx)
89 vg:: $(exe_pfx)$(1)$(exe_sfx)
90 valgrind $(VGFLAGS) ./$(1) ;
93 $(foreach t,$(TESTS),$(eval $(call test_cmd,$(t))))
95 #############################################################################
98 $(1)_all_stems := $$($(1)_STEMS)
99 $(1)_objs := $$(patsubst %,%$(o_sfx),$$($(1)_all_stems))
100 $(1)_deps := $$(patsubst %,%.d,$$($(1)_all_stems))
102 -include $$($(1)_deps)
104 $(1)$(exe_sfx): $$($(1)_objs) $$($(1)_EXTRAS) $(libfiles)
105 $(CXX) -o $$@ $$^ $(LDFLAGS) $(LDLIBS) -L. $(foreach l,$(LIBS),-l$(l))
108 rm -f $(1)$(exe_sfx) $$($(1)_objs) $$($(1)_deps)
111 $(foreach prog,$(PROGRAMS),$(eval $(call link_cmd,$(prog))))
112 $(foreach prog,$(TESTS),$(eval $(call link_cmd,$(prog))))
114 #############################################################################
117 $(1)_all_stems := $$($(1)_STEMS)
118 $(1)_objs := $$(patsubst %,%$(o_sfx),$$($(1)_all_stems))
119 $(1)_deps := $$(patsubst %,%.d,$$($(1)_all_stems))
121 -include $$($(1)_deps)
123 $(so_pfx)$(1)$(so_sfx): $$($(1)_objs)
124 $(CXX) -shared -o $$@ $$^ $(LDFLAGS) $(TARGET_ARCH) $(LOADLIBES) $(LDLIBS)
127 rm -f $(so_pfx)$(1)$(so_sfx) $$($(1)_objs) $$($(1)_deps)
130 $(foreach lib,$(LIBS),$(eval $(call lib_cmd,$(lib))))
132 #############################################################################
138 @echo JAVA_HOME == $(JAVA_HOME)
139 @echo MAKEFILE_LIST == $(MAKEFILE_LIST)
140 @echo .INCLUDE_DIRS == $(.INCLUDE_DIRS)
141 @echo USES == $(USES)
142 @echo PROGRAMS == $(PROGRAMS)
143 @echo LIBS == $(LIBS)
144 @echo TESTS == $(TESTS)
145 @echo CXXFLAGS == $(CXXFLAGS)
146 @echo LDFLAGS == $(LDFLAGS)
151 @echo $(1)_all_stems == $$($(1)_all_stems)
152 @echo $(1)_objs == $$($(1)_objs)
153 @echo $(1)_deps == $$($(1)_deps)
156 $(foreach x,$(PROGRAMS),$(eval $(call dump_template,$(x))))
157 $(foreach x,$(LIBS),$(eval $(call dump_template,$(x))))
158 $(foreach x,$(TESTS),$(eval $(call dump_template,$(x))))
160 .PHONY:: all check dump install install-tests tests