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))
45 #############################################################################
47 all:: $(libfiles) $(prgfiles)
49 check:: all $(tstfiles)
54 install:: $(libfiles) $(LIBDIR)
55 cp $(libfiles) $(LIBDIR)
59 install:: $(prgfiles) $(BINDIR)
60 cp $(prgfiles) $(BINDIR)
64 install:: $(DATA) $(DATADIR)
65 cp -r $(DATA) $(DATADIR)
69 tests: all $(tstfiles)
71 install-tests:: all $(tstfiles) $(BINDIR)
72 cp $(tstfiles) $(BINDIR)
75 $(BINDIR) $(LIBDIR) $(DATADIR):
78 #############################################################################
83 check:: $(exe_pfx)$(1)$(exe_sfx)
86 vg:: $(exe_pfx)$(1)$(exe_sfx)
87 valgrind $(VGFLAGS) ./$(1) ;
90 $(foreach t,$(TESTS),$(eval $(call test_cmd,$(t))))
92 #############################################################################
95 $(1)_all_stems := $$($(1)_STEMS)
96 $(1)_objs := $$(patsubst %,%$(o_sfx),$$($(1)_all_stems))
97 $(1)_deps := $$(patsubst %,%.d,$$($(1)_all_stems))
99 -include $$($(1)_deps)
101 $(1)$(exe_sfx): $$($(1)_objs) $$($(1)_EXTRAS) $(libfiles)
102 $(CXX) -o $$@ $$^ $(LDFLAGS) $(LDLIBS) -L. $(foreach l,$(LIBS),-l$(l))
105 rm -f $(1)$(exe_sfx) $$($(1)_objs) $$($(1)_deps)
108 $(foreach prog,$(PROGRAMS),$(eval $(call link_cmd,$(prog))))
109 $(foreach prog,$(TESTS),$(eval $(call link_cmd,$(prog))))
111 #############################################################################
114 $(1)_all_stems := $$($(1)_STEMS)
115 $(1)_objs := $$(patsubst %,%$(o_sfx),$$($(1)_all_stems))
116 $(1)_deps := $$(patsubst %,%.d,$$($(1)_all_stems))
118 -include $$($(1)_deps)
120 $(so_pfx)$(1)$(so_sfx): $$($(1)_objs) $$($(1)_EXTRA)
121 $(CXX) -shared -o $$@ $$^ $(LDFLAGS) $(TARGET_ARCH) $(LOADLIBES) $(LDLIBS)
124 rm -f $(so_pfx)$(1)$(so_sfx) $$($(1)_objs) $$($(1)_deps)
127 $(foreach lib,$(LIBS),$(eval $(call lib_cmd,$(lib))))
129 #############################################################################
135 @echo JAVA_HOME == $(JAVA_HOME)
136 @echo MAKEFILE_LIST == $(MAKEFILE_LIST)
137 @echo .INCLUDE_DIRS == $(.INCLUDE_DIRS)
138 @echo USES == $(USES)
139 @echo PROGRAMS == $(PROGRAMS)
140 @echo LIBS == $(LIBS)
141 @echo TESTS == $(TESTS)
142 @echo CXXFLAGS == $(CXXFLAGS)
143 @echo LDFLAGS == $(LDFLAGS)
148 @echo $(1)_all_stems == $$($(1)_all_stems)
149 @echo $(1)_objs == $$($(1)_objs)
150 @echo $(1)_deps == $$($(1)_deps)
153 $(foreach x,$(PROGRAMS),$(eval $(call dump_template,$(x))))
154 $(foreach x,$(LIBS),$(eval $(call dump_template,$(x))))
155 $(foreach x,$(TESTS),$(eval $(call dump_template,$(x))))
157 .PHONY:: all check dump install install-tests tests