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 l,$(LIBS),$(so_pfx)$(l)$(so_sfx))
35 prgfiles := $(foreach p,$(PROGRAMS),$(exe_pfx)$(p)$(exe_sfx))
36 tstfiles := $(foreach t,$(TESTS),$(exe_pfx)$(t)$(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)
55 cp $(libfiles) $(LIBDIR)
60 cp $(prgfiles) $(BINDIR)
65 cp -r $(DATA) $(DATADIR)
70 install-tests:: $(tstfiles)
71 cp $(tstfiles) $(BINDIR)
73 $(BINDIR) $(LIBDIR) $(DATADIR):
76 #############################################################################
81 check:: $(exe_pfx)$(1)$(exe_sfx)
84 vg:: $(exe_pfx)$(1)$(exe_sfx)
88 $(foreach t,$(TESTS),$(eval $(call test_cmd,$(t))))
90 #############################################################################
93 $(1)_all_stems := $$($(1)_STEMS)
94 $(1)_objs := $$(patsubst %,%$(o_sfx),$$($(1)_all_stems))
95 $(1)_deps := $$(patsubst %,%.d,$$($(1)_all_stems))
97 -include $$($(1)_deps)
99 $(1)$(exe_sfx): $$($(1)_objs) $$($(1)_EXTRAS) $(libfiles)
100 $(CXX) -o $$@ $$^ $(LDFLAGS) $(LDLIBS) -L. $(foreach l,$(LIBS),-l$(l))
103 rm -f $(1)$(exe_sfx) $$($(1)_objs) $$($(1)_deps)
106 $(foreach prog,$(PROGRAMS),$(eval $(call link_cmd,$(prog))))
107 $(foreach prog,$(TESTS),$(eval $(call link_cmd,$(prog))))
109 #############################################################################
112 $(1)_all_stems := $$($(1)_STEMS)
113 $(1)_objs := $$(patsubst %,%$(o_sfx),$$($(1)_all_stems))
114 $(1)_deps := $$(patsubst %,%.d,$$($(1)_all_stems))
116 -include $$($(1)_deps)
118 $(so_pfx)$(1)$(so_sfx): $$($(1)_objs)
119 $(CXX) -shared -o $$@ $$^ $(LDFLAGS) $(TARGET_ARCH) $(LOADLIBES) $(LDLIBS)
122 rm -f $(so_pfx)$(1)$(so_sfx) $$($(1)_objs) $$($(1)_deps)
125 $(foreach lib,$(LIBS),$(eval $(call lib_cmd,$(lib))))
127 #############################################################################
133 @echo JAVA_HOME == $(JAVA_HOME)
134 @echo MAKEFILE_LIST == $(MAKEFILE_LIST)
135 @echo .INCLUDE_DIRS == $(.INCLUDE_DIRS)
136 @echo USES == $(USES)
137 @echo PROGRAMS == $(PROGRAMS)
138 @echo LIBS == $(LIBS)
139 @echo TESTS == $(TESTS)
140 @echo CXXFLAGS == $(CXXFLAGS)
141 @echo LDFLAGS == $(LDFLAGS)
146 @echo $(1)_all_stems == $$($(1)_all_stems)
147 @echo $(1)_objs == $$($(1)_objs)
148 @echo $(1)_deps == $$($(1)_deps)
151 $(foreach x,$(PROGRAMS),$(eval $(call dump_template,$(x))))
152 $(foreach x,$(LIBS),$(eval $(call dump_template,$(x))))
153 $(foreach x,$(TESTS),$(eval $(call dump_template,$(x))))
155 .PHONY:: all check dump install install-tests tests