2013-11-22 18:45:52 +02:00
|
|
|
default: all
|
|
|
|
|
|
|
|
|
2013-11-22 21:30:24 +02:00
|
|
|
# Include Autoconf variables.
|
|
|
|
Makefile.config: Makefile.config.in
|
|
|
|
./config.status
|
|
|
|
|
|
|
|
include Makefile.config
|
|
|
|
|
|
|
|
|
2013-11-22 18:45:52 +02: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 21:51:18 +02:00
|
|
|
# Initialise some variables.
|
2013-11-22 17:59:09 +02:00
|
|
|
clean_list :=
|
|
|
|
dist_files :=
|
2013-11-22 21:51:18 +02:00
|
|
|
QUIET = @
|
2013-11-22 16:54:18 +02:00
|
|
|
|
|
|
|
|
2013-11-22 21:51:18 +02:00
|
|
|
# Pass -fPIC if we're building dynamic libraries.
|
|
|
|
ifeq ($(BUILD_SHARED_LIBS), 1)
|
|
|
|
GLOBAL_CFLAGS += -fPIC
|
|
|
|
GLOBAL_CXXFLAGS += -fPIC
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
# Pass -g if we want debug info.
|
|
|
|
ifeq ($(BUILD_DEBUG), 1)
|
|
|
|
GLOBAL_CFLAGS += -g
|
|
|
|
GLOBAL_CXXFLAGS += -g
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
# Pattern rules.
|
2013-11-22 16:54:18 +02:00
|
|
|
|
|
|
|
%.o: %.cc
|
2013-11-22 21:51:18 +02:00
|
|
|
$(QUIET) $(CXX) -o $@ -c $< $(GLOBAL_CXXFLAGS) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(basename $@).dep -MP
|
2013-11-22 16:54:18 +02:00
|
|
|
|
|
|
|
%.o: %.c
|
2013-11-22 21:51:18 +02:00
|
|
|
$(QUIET) $(CC) -o $@ -c $< $(GLOBAL_CFLAGS) $(CFLAGS) $($@_CFLAGS) -MMD -MF $(basename $@).dep -MP
|
2013-11-22 16:54:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Generate Make rules for libraries.
|
|
|
|
libs_list :=
|
|
|
|
|
|
|
|
define LIBS_template =
|
|
|
|
_d := $$($(1)_DIR)
|
2013-11-22 18:45:52 +02:00
|
|
|
_srcs := $$(foreach src, $$($(1)_SOURCES), $$(_d)/$$(src))
|
2013-11-22 17:42:25 +02:00
|
|
|
_objs := $$(addsuffix .o, $$(basename $$(_srcs)))
|
2013-11-22 16:54:18 +02:00
|
|
|
_libs := $$(foreach lib, $$($(1)_LIBS), $$(lib).a)
|
2013-11-22 18:45:52 +02:00
|
|
|
_lib := $$(_d)/$(1).a
|
2013-11-22 16:54:18 +02:00
|
|
|
|
|
|
|
$$(_lib): $$(_objs)
|
|
|
|
$(QUIET) ar crs $$@ $$?
|
|
|
|
|
|
|
|
# Propagate CXXFLAGS to the individual object files.
|
|
|
|
$$(foreach obj, $$(_objs), $$(eval $$(obj)_CXXFLAGS=$$($(1)_CXXFLAGS)))
|
|
|
|
|
2013-11-22 17:10:33 +02:00
|
|
|
include $$(wildcard $$(_d)/*.dep)
|
|
|
|
|
2013-11-22 16:54:18 +02:00
|
|
|
libs_list += $$(_lib)
|
2013-11-22 18:45:52 +02:00
|
|
|
clean_list += $$(_d)/*.a $$(_d)/*.o $$(_d)/*.dep
|
2013-11-22 17:42:25 +02:00
|
|
|
dist_files += $$(_srcs)
|
2013-11-22 16:54:18 +02:00
|
|
|
endef
|
|
|
|
|
2013-11-22 17:59:09 +02:00
|
|
|
$(foreach lib, $(LIBS), $(eval $(call LIBS_template,$(lib))))
|
|
|
|
|
2013-11-22 16:54:18 +02:00
|
|
|
|
|
|
|
# Generate Make rules for programs.
|
|
|
|
programs_list :=
|
|
|
|
|
|
|
|
define PROGRAMS_template =
|
|
|
|
_d := $$($(1)_DIR)
|
2013-11-22 18:45:52 +02:00
|
|
|
_srcs := $$(foreach src, $$($(1)_SOURCES), $$(_d)/$$(src))
|
2013-11-22 17:42:25 +02:00
|
|
|
_objs := $$(addsuffix .o, $$(basename $$(_srcs)))
|
2013-11-22 18:45:52 +02:00
|
|
|
_libs := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_DIR)/$$(lib).a)
|
|
|
|
_prog := $$(_d)/$(1)
|
2013-11-22 16:54:18 +02:00
|
|
|
|
|
|
|
$$(_prog): $$(_objs) $$(_libs)
|
|
|
|
$(QUIET) g++ -o $$@ $$^ $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS))
|
|
|
|
|
|
|
|
# Propagate CXXFLAGS to the individual object files.
|
|
|
|
$$(foreach obj, $$(_objs), $$(eval $$(obj)_CXXFLAGS=$$($(1)_CXXFLAGS)))
|
|
|
|
|
2013-11-22 17:42:25 +02:00
|
|
|
include $$(wildcard $$(_d)/*.dep)
|
|
|
|
|
2013-11-22 16:54:18 +02:00
|
|
|
programs_list += $$(_prog)
|
2013-11-22 18:45:52 +02:00
|
|
|
clean_list += $$(_prog) $$(_d)/*.o $$(_d)/*.dep
|
2013-11-22 17:42:25 +02:00
|
|
|
dist_files += $$(_srcs)
|
2013-11-22 16:54:18 +02:00
|
|
|
endef
|
|
|
|
|
2013-11-22 17:59:09 +02:00
|
|
|
$(foreach prog, $(PROGRAMS), $(eval $(call PROGRAMS_template,$(prog))))
|
2013-11-22 16:54:18 +02:00
|
|
|
|
2013-11-22 17:42:25 +02:00
|
|
|
|
2013-11-22 17:59:09 +02:00
|
|
|
# Distributing stuff.
|
2013-11-22 17:42:25 +02: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 16:54:18 +02:00
|
|
|
# Cleaning stuff.
|
|
|
|
clean:
|
|
|
|
rm -fv $(clean_list)
|
|
|
|
|
|
|
|
dryclean:
|
|
|
|
@echo $(clean_list)
|
2013-11-22 17:59:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
all: $(programs_list)
|