2013-11-22 16:45:52 +00:00
|
|
|
default: all
|
|
|
|
|
|
|
|
|
2013-11-22 19:30:24 +00:00
|
|
|
# Include Autoconf variables.
|
|
|
|
Makefile.config: Makefile.config.in
|
2013-11-25 08:55:19 +00:00
|
|
|
./config.status --file $@
|
2013-11-22 19:30:24 +00:00
|
|
|
|
|
|
|
include Makefile.config
|
|
|
|
|
|
|
|
|
2013-11-25 08:55:19 +00:00
|
|
|
# Installing stuff.
|
|
|
|
define install-file-in =
|
|
|
|
|
|
|
|
install:: $(1)/$(notdir $(2))
|
|
|
|
|
|
|
|
$(1)/$(notdir $(2)): $(2)
|
|
|
|
install -d $(1)
|
|
|
|
install -t $(1) $(2)
|
|
|
|
|
|
|
|
endef
|
|
|
|
|
|
|
|
|
2013-11-22 16:45:52 +00:00
|
|
|
# Include all sub-Makefiles.
|
|
|
|
define include_sub_makefile =
|
|
|
|
d := $$(patsubst %/, %, $$(dir $(1)))
|
|
|
|
include $(1)
|
|
|
|
endef
|
|
|
|
|
|
|
|
$(foreach mf, $(SUBS), $(eval $(call include_sub_makefile, $(mf))))
|
|
|
|
|
|
|
|
|
2013-11-22 19:51:18 +00:00
|
|
|
# Initialise some variables.
|
2013-11-22 15:59:09 +00:00
|
|
|
clean_list :=
|
|
|
|
dist_files :=
|
2013-11-22 19:51:18 +00:00
|
|
|
QUIET = @
|
2013-11-22 14:54:18 +00:00
|
|
|
|
|
|
|
|
2013-11-22 19:51:18 +00:00
|
|
|
# Pass -fPIC if we're building dynamic libraries.
|
|
|
|
ifeq ($(BUILD_SHARED_LIBS), 1)
|
2013-11-22 20:56:58 +00:00
|
|
|
GLOBAL_CFLAGS += -fPIC
|
|
|
|
GLOBAL_CXXFLAGS += -fPIC
|
2013-11-23 23:10:00 +00:00
|
|
|
GLOBAL_LDFLAGS += -Wl,--no-copy-dt-needed-entries
|
2013-11-22 19:51:18 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
# Pass -g if we want debug info.
|
|
|
|
ifeq ($(BUILD_DEBUG), 1)
|
2013-11-22 20:56:58 +00:00
|
|
|
GLOBAL_CFLAGS += -g
|
|
|
|
GLOBAL_CXXFLAGS += -g
|
2013-11-22 19:51:18 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
# Pattern rules.
|
2013-11-22 14:54:18 +00:00
|
|
|
|
|
|
|
%.o: %.cc
|
2013-11-22 19:51:18 +00:00
|
|
|
$(QUIET) $(CXX) -o $@ -c $< $(GLOBAL_CXXFLAGS) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(basename $@).dep -MP
|
2013-11-22 14:54:18 +00:00
|
|
|
|
|
|
|
%.o: %.c
|
2013-11-22 19:51:18 +00:00
|
|
|
$(QUIET) $(CC) -o $@ -c $< $(GLOBAL_CFLAGS) $(CFLAGS) $($@_CFLAGS) -MMD -MF $(basename $@).dep -MP
|
2013-11-22 14:54:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Generate Make rules for libraries.
|
|
|
|
libs_list :=
|
|
|
|
|
|
|
|
define LIBS_template =
|
2013-11-23 23:49:34 +00:00
|
|
|
$(1)_NAME ?= $(1)
|
2013-11-23 16:20:15 +00:00
|
|
|
_d := $$(strip $$($(1)_DIR))
|
2013-11-22 16:45:52 +00:00
|
|
|
_srcs := $$(foreach src, $$($(1)_SOURCES), $$(_d)/$$(src))
|
2013-11-23 20:11:02 +00:00
|
|
|
$(1)_OBJS := $$(addsuffix .o, $$(basename $$(_srcs)))
|
2013-11-23 23:15:25 +00:00
|
|
|
_libs := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_PATH))
|
2013-11-22 14:54:18 +00:00
|
|
|
|
2013-11-23 16:20:15 +00:00
|
|
|
$(1)_LDFLAGS_USE :=
|
2013-11-23 19:32:20 +00:00
|
|
|
$(1)_LDFLAGS_USE_INSTALLED :=
|
2013-11-23 16:20:15 +00:00
|
|
|
|
2013-11-22 20:56:58 +00:00
|
|
|
ifeq ($(BUILD_SHARED_LIBS), 1)
|
2013-11-23 19:32:20 +00:00
|
|
|
|
2013-11-23 23:10:00 +00:00
|
|
|
ifndef $(1)_ALLOW_UNDEFINED
|
|
|
|
$(1)_LDFLAGS += -z defs
|
|
|
|
endif
|
|
|
|
|
2013-11-23 23:49:34 +00:00
|
|
|
$(1)_PATH := $$(_d)/$$($(1)_NAME).so
|
2013-11-23 23:15:25 +00:00
|
|
|
|
|
|
|
$$($(1)_PATH): $$($(1)_OBJS) $$(_libs)
|
2013-11-23 23:10:00 +00:00
|
|
|
$(QUIET) $(CXX) -o $$@ -shared $(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$($(1)_LDFLAGS_PROPAGATED) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE))
|
2013-11-23 19:32:20 +00:00
|
|
|
|
2013-11-23 23:49:34 +00:00
|
|
|
$(1)_LDFLAGS_USE += -L$$(_d) -Wl,-rpath,$$(abspath $$(_d)) -l$$(patsubst lib%,%,$$(strip $$($(1)_NAME)))
|
2013-11-23 19:32:20 +00:00
|
|
|
|
2013-11-23 23:56:23 +00:00
|
|
|
$(1)_INSTALL_DIR := $$(libdir)
|
2013-11-23 19:32:20 +00:00
|
|
|
|
2013-11-23 23:49:34 +00:00
|
|
|
$(1)_INSTALL_PATH := $$($(1)_INSTALL_DIR)/$$($(1)_NAME).so
|
2013-11-23 19:32:20 +00:00
|
|
|
|
2013-11-23 20:11:02 +00:00
|
|
|
_libs_final := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_INSTALL_PATH))
|
|
|
|
|
|
|
|
$$($(1)_INSTALL_PATH): $$($(1)_OBJS) $$(_libs_final)
|
2013-11-23 19:32:20 +00:00
|
|
|
install -d $$($(1)_INSTALL_DIR)
|
2013-11-23 23:10:00 +00:00
|
|
|
$(QUIET) $(CXX) -o $$@ -shared $(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$($(1)_LDFLAGS_PROPAGATED) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE_INSTALLED))
|
2013-11-23 19:32:20 +00:00
|
|
|
|
2013-11-23 23:49:34 +00:00
|
|
|
$(1)_LDFLAGS_USE_INSTALLED += -L$$($(1)_INSTALL_DIR) -Wl,-rpath,$$($(1)_INSTALL_DIR) -l$$(patsubst lib%,%,$$(strip $$($(1)_NAME)))
|
2013-11-23 19:32:20 +00:00
|
|
|
|
2013-11-22 20:56:58 +00:00
|
|
|
else
|
2013-11-23 19:32:20 +00:00
|
|
|
|
2013-11-23 23:49:34 +00:00
|
|
|
$(1)_PATH := $$(_d)/$$($(1)_NAME).a
|
2013-11-23 23:15:25 +00:00
|
|
|
|
|
|
|
$$($(1)_PATH): $$($(1)_OBJS)
|
2013-11-22 14:54:18 +00:00
|
|
|
$(QUIET) ar crs $$@ $$?
|
2013-11-23 19:32:20 +00:00
|
|
|
|
2013-11-23 23:15:25 +00:00
|
|
|
$(1)_LDFLAGS_USE += $$($(1)_PATH) $$($(1)_LDFLAGS)
|
2013-11-23 19:32:20 +00:00
|
|
|
|
2013-11-23 23:56:23 +00:00
|
|
|
$(1)_INSTALL_PATH := $$(libdir)/$$($(1)_NAME).a
|
2013-11-23 19:32:20 +00:00
|
|
|
|
2013-11-22 20:56:58 +00:00
|
|
|
endif
|
|
|
|
|
2013-11-23 16:20:15 +00:00
|
|
|
$(1)_LDFLAGS_USE += $$($(1)_LDFLAGS_PROPAGATED)
|
2013-11-23 19:32:20 +00:00
|
|
|
$(1)_LDFLAGS_USE_INSTALLED += $$($(1)_LDFLAGS_PROPAGATED)
|
2013-11-23 23:10:00 +00:00
|
|
|
|
2013-11-22 14:54:18 +00:00
|
|
|
# Propagate CXXFLAGS to the individual object files.
|
2013-11-23 20:11:02 +00:00
|
|
|
$$(foreach obj, $$($(1)_OBJS), $$(eval $$(obj)_CXXFLAGS=$$($(1)_CXXFLAGS)))
|
2013-11-22 14:54:18 +00:00
|
|
|
|
2013-11-22 15:10:33 +00:00
|
|
|
include $$(wildcard $$(_d)/*.dep)
|
|
|
|
|
2013-11-23 23:15:25 +00:00
|
|
|
libs_list += $$($(1)_PATH)
|
2013-11-22 20:56:58 +00:00
|
|
|
clean_list += $$(_d)/*.a $$(_d)/*.so $$(_d)/*.o $$(_d)/*.dep
|
2013-11-22 15:42:25 +00:00
|
|
|
dist_files += $$(_srcs)
|
2013-11-22 14:54:18 +00:00
|
|
|
endef
|
|
|
|
|
2013-11-22 15:59:09 +00:00
|
|
|
$(foreach lib, $(LIBS), $(eval $(call LIBS_template,$(lib))))
|
|
|
|
|
2013-11-22 14:54:18 +00:00
|
|
|
|
|
|
|
# Generate Make rules for programs.
|
|
|
|
programs_list :=
|
|
|
|
|
|
|
|
define PROGRAMS_template =
|
|
|
|
_d := $$($(1)_DIR)
|
2013-11-22 16:45:52 +00:00
|
|
|
_srcs := $$(foreach src, $$($(1)_SOURCES), $$(_d)/$$(src))
|
2013-11-23 16:20:15 +00:00
|
|
|
$(1)_OBJS := $$(addsuffix .o, $$(basename $$(_srcs)))
|
2013-11-23 23:15:25 +00:00
|
|
|
_libs := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_PATH))
|
2013-11-23 17:04:27 +00:00
|
|
|
$(1)_PATH := $$(_d)/$(1)
|
2013-11-22 14:54:18 +00:00
|
|
|
|
2013-11-23 17:04:27 +00:00
|
|
|
$$($(1)_PATH): $$($(1)_OBJS) $$(_libs)
|
2013-11-23 23:10:00 +00:00
|
|
|
$(QUIET) $(CXX) -o $$@ $(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE))
|
2013-11-22 14:54:18 +00:00
|
|
|
|
2013-11-23 17:04:27 +00:00
|
|
|
$(1)_INSTALL_PATH := $$(bindir)/$(1)
|
|
|
|
|
2013-11-23 19:32:20 +00:00
|
|
|
install:: $$($(1)_INSTALL_PATH)
|
|
|
|
|
|
|
|
ifeq ($(BUILD_SHARED_LIBS), 1)
|
|
|
|
|
|
|
|
_libs_final := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_INSTALL_PATH))
|
|
|
|
|
|
|
|
$$($(1)_INSTALL_PATH): $$($(1)_OBJS) $$(_libs_final)
|
|
|
|
install -d $$(dir $$($(1)_INSTALL_PATH))
|
2013-11-23 23:10:00 +00:00
|
|
|
$(QUIET) $(CXX) -o $$($(1)_INSTALL_PATH) $(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE_INSTALLED))
|
2013-11-23 19:32:20 +00:00
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
$$($(1)_INSTALL_PATH): $$($(1)_PATH)
|
|
|
|
install -d $$(dir $$($(1)_INSTALL_PATH))
|
2013-11-23 17:04:27 +00:00
|
|
|
cp $$< $$@
|
|
|
|
|
2013-11-23 19:32:20 +00:00
|
|
|
endif
|
2013-11-23 17:04:27 +00:00
|
|
|
|
2013-11-22 14:54:18 +00:00
|
|
|
# Propagate CXXFLAGS to the individual object files.
|
2013-11-23 16:20:15 +00:00
|
|
|
$$(foreach obj, $$($(1)_OBJS), $$(eval $$(obj)_CXXFLAGS=$$($(1)_CXXFLAGS)))
|
2013-11-22 14:54:18 +00:00
|
|
|
|
2013-11-22 15:42:25 +00:00
|
|
|
include $$(wildcard $$(_d)/*.dep)
|
|
|
|
|
2013-11-23 19:32:20 +00:00
|
|
|
programs_list += $$($(1)_PATH)
|
|
|
|
clean_list += $$($(1)_PATH) $$(_d)/*.o $$(_d)/*.dep
|
2013-11-22 15:42:25 +00:00
|
|
|
dist_files += $$(_srcs)
|
2013-11-22 14:54:18 +00:00
|
|
|
endef
|
|
|
|
|
2013-11-22 15:59:09 +00:00
|
|
|
$(foreach prog, $(PROGRAMS), $(eval $(call PROGRAMS_template,$(prog))))
|
2013-11-22 14:54:18 +00:00
|
|
|
|
2013-11-22 15:42:25 +00:00
|
|
|
|
2013-11-22 15:59:09 +00:00
|
|
|
# Distributing stuff.
|
2013-11-22 15:42:25 +00:00
|
|
|
dist_name = $(PACKAGE_NAME)-$(PACKAGE_VERSION)
|
|
|
|
|
|
|
|
dist:
|
|
|
|
@echo $(dist_files)
|
|
|
|
$(QUIET) tar cvfj $(dist_name).tar.bz2 $(dist_files) --transform 's,^,$(dist_name)/,'
|
|
|
|
|
|
|
|
|
2013-11-22 14:54:18 +00:00
|
|
|
# Cleaning stuff.
|
|
|
|
clean:
|
|
|
|
rm -fv $(clean_list)
|
|
|
|
|
|
|
|
dryclean:
|
|
|
|
@echo $(clean_list)
|
2013-11-22 15:59:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
all: $(programs_list)
|