2005-09-15 21:03:56 +02:00
|
|
|
### The build commands and verbosity
|
|
|
|
|
2006-01-14 09:27:30 +01:00
|
|
|
# Colorize the build.
|
|
|
|
ifdef MAKE_COLOR
|
|
|
|
INFO_COLOR = $(shell tput setaf 5)
|
|
|
|
CC_COLOR = $(shell tput setaf 6)
|
|
|
|
LD_COLOR = $(shell tput setaf 2)
|
|
|
|
PO_COLOR = $(shell tput setaf 6)
|
|
|
|
LINK_COLOR = $(shell tput bold;tput setaf 4)
|
|
|
|
INSTALL_COLOR = $(shell tput setaf 3)
|
2006-09-03 09:27:21 +02:00
|
|
|
UNINSTALL_COLOR = $(shell tput setaf 1)
|
2006-01-14 09:27:30 +01:00
|
|
|
END_COLOR = $(shell tput sgr0)
|
|
|
|
endif
|
|
|
|
|
|
|
|
# sparse is architecture-neutral, which means that we need to tell it
|
|
|
|
# explicitly what architecture to check for. Fix this up for yours..
|
|
|
|
SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__
|
|
|
|
|
2006-01-14 10:28:08 +01:00
|
|
|
|
2006-01-14 09:27:30 +01:00
|
|
|
#############################################################################
|
|
|
|
# Build recipies
|
|
|
|
|
2006-01-14 10:33:38 +01:00
|
|
|
# If we are verbose, we will show the "real" cmds instead of
|
2005-09-15 21:03:56 +02:00
|
|
|
# their quiet versions (which are used in the non-verbose mode).
|
|
|
|
# Inspired by the Linux kernel build system.
|
|
|
|
ifdef V
|
|
|
|
quiet =
|
|
|
|
mquiet = masq_
|
2006-07-10 14:27:40 +02:00
|
|
|
Q =
|
2005-09-15 21:03:56 +02:00
|
|
|
else
|
|
|
|
quiet = quiet_
|
|
|
|
mquiet = quiet_
|
2006-07-10 14:27:40 +02:00
|
|
|
Q = @
|
2005-09-15 21:03:56 +02:00
|
|
|
endif
|
|
|
|
|
|
|
|
# Show the command (quiet or non-quiet version based on the assignment
|
|
|
|
# just above) and then execute it.
|
2005-12-17 01:18:33 +00:00
|
|
|
ncmd = $(if $($(quiet)cmd_$(1)),echo $($(quiet)cmd_$(1)) &&) $(cmd_$(1))
|
|
|
|
cmd = @$(if $($(quiet)cmd_$(1)),echo $($(quiet)cmd_$(1)) &&) $(cmd_$(1))
|
|
|
|
mcmd = @$(if $($(mquiet)cmd_$(1)),echo $($(mquiet)cmd_$(1)) &&) $(cmd_$(1))
|
2005-12-26 19:17:47 +01:00
|
|
|
ecmd = @$(if $($(mquiet)cmd_$(1)),printf "%-38s " $($(mquiet)cmd_$(1)) &&) $(cmd_$(1))
|
2005-09-15 21:03:56 +02:00
|
|
|
|
2005-12-15 02:44:15 -05:00
|
|
|
quiet_cmd_compile = ' [$(CC_COLOR)CC$(END_COLOR)] $(RELPATH)$@'
|
2006-01-06 22:08:49 +01:00
|
|
|
masq_cmd_compile = $(COMPILE) -o $(@) -c $< $(2)
|
|
|
|
cmd_compile = $(COMPILE) -o $(@) -Wp,-MD,.deps/$(*F).pp -c $< $(2)
|
2005-09-15 21:03:56 +02:00
|
|
|
|
2005-09-27 21:38:58 +02:00
|
|
|
# Rule to compile a set of .o files into one .o file
|
2005-12-15 02:44:15 -05:00
|
|
|
quiet_cmd_ld_objs = " [$(LD_COLOR)LD$(END_COLOR)] $(RELPATH)$@"
|
2005-10-20 03:39:59 +02:00
|
|
|
cmd_ld_objs = $(LD) -r -o $@ $(filter $(OBJS), $^) \
|
|
|
|
$(foreach subdir,$(sort $(filter-out src,$(SUBDIRS))), \
|
2006-01-12 19:06:50 +01:00
|
|
|
`test -e $(subdir)/$(LIB_O_NAME) && echo $(subdir)/$(LIB_O_NAME)`)
|
2005-10-21 15:58:36 +02:00
|
|
|
|
2005-12-15 02:44:15 -05:00
|
|
|
quiet_cmd_link = ' [$(LINK_COLOR)LINK$(END_COLOR)] $(RELPATH)$@'
|
2006-01-17 16:53:15 +01:00
|
|
|
cmd_link = $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
|
2005-09-15 21:03:56 +02:00
|
|
|
|
2005-11-24 21:54:49 +01:00
|
|
|
quiet_cmd_sparse = ' [SPARSE] $(RELPATH)$(2)'
|
2006-07-01 14:43:37 +03:00
|
|
|
cmd_sparse = $(SPARSE) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) $(SPARSE_FLAGS) $(2)
|
2005-11-24 13:24:19 +01:00
|
|
|
|
2005-09-15 21:03:56 +02:00
|
|
|
# Recursive make
|
2005-12-15 02:44:15 -05:00
|
|
|
quiet_cmd_recmake = "[$(INFO_COLOR)MAKE $(3)$(END_COLOR)] $(RELPATH)$(2)"
|
2005-12-20 23:21:08 +01:00
|
|
|
cmd_recmake = $(MAKE) -C $(2) $(3)
|
2005-09-15 21:03:56 +02:00
|
|
|
|
2006-12-17 16:21:36 +02:00
|
|
|
quiet_cmd_installdata = " [$(INSTALL_COLOR)INSTALL$(END_COLOR)] $(RELPATH)$(patsubst $(srcdir)%,%,$(2)) -> $(3)"
|
2005-10-01 14:16:19 +02:00
|
|
|
cmd_installdata = $(INSTALL_DATA) $(2) $(3)
|
|
|
|
|
2005-12-15 02:44:15 -05:00
|
|
|
quiet_cmd_installprog = " [$(INSTALL_COLOR)INSTALL$(END_COLOR)] $(RELPATH)$(2) -> $(3)"
|
2005-10-01 14:16:19 +02:00
|
|
|
cmd_installprog = $(INSTALL_PROGRAM) $(2) $(3)
|
|
|
|
|
2007-02-24 12:15:22 +02:00
|
|
|
# $(INSTALL_DATA) in cmd_installdata doesn't use the directory part of
|
|
|
|
# $(2) when it forms the output file name, so don't use it here either.
|
|
|
|
quiet_cmd_uninstall = " [$(UNINSTALL_COLOR)UNINSTALL$(END_COLOR)] $(3)/$(notdir $(2))"
|
|
|
|
cmd_uninstall = $(RM) $(3)/$(notdir $(2))
|
2005-09-15 21:03:56 +02:00
|
|
|
|
2006-01-14 09:27:30 +01:00
|
|
|
#############################################################################
|
|
|
|
# Special handling of conditional variables
|
2005-09-15 21:03:56 +02:00
|
|
|
|
2007-08-28 22:55:26 +02:00
|
|
|
SUBDIRS += $(SUBDIRS-yes) $(SUBDIRS-unlessno) $(SUBDIRS-unless)
|
2007-08-28 23:35:22 +02:00
|
|
|
OBJS += $(OBJS-yes) $(OBJS-unlessno) $(OBJS-unless)
|
2005-09-27 22:49:47 +02:00
|
|
|
|
2007-08-28 22:55:26 +02:00
|
|
|
ALTDIRS = $(SUBDIRS-no) $(SUBDIRS-) $(SUBDIRS-unlessyes)
|
|
|
|
ALTOBJS = $(OBJS-no) $(OBJS-) $(OBJS-unlessyes)
|
2005-09-27 22:49:47 +02:00
|
|
|
|
2005-10-22 13:25:28 +02:00
|
|
|
ifneq ($(findstring cleanall,$(MAKECMDGOALS)),)
|
2005-10-25 23:41:26 +02:00
|
|
|
INCLUDE_ALL=1
|
|
|
|
endif
|
|
|
|
|
2005-10-26 00:34:13 +02:00
|
|
|
ifneq ($(findstring init,$(MAKECMDGOALS)),)
|
2005-10-25 23:41:26 +02:00
|
|
|
INCLUDE_ALL=1
|
2006-01-15 18:37:34 +01:00
|
|
|
ifndef SRC
|
|
|
|
SRC = $(shell cd $(top_srcdir) && pwd)
|
|
|
|
endif
|
2005-10-25 23:41:26 +02:00
|
|
|
endif
|
2005-10-22 13:25:28 +02:00
|
|
|
|
2005-10-25 23:41:26 +02:00
|
|
|
ifdef INCLUDE_ALL
|
2006-01-14 10:28:08 +01:00
|
|
|
SUBDIRS += $(ALTDIRS)
|
|
|
|
OBJS += $(ALTOBJS)
|
2006-01-14 09:27:30 +01:00
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
#############################################################################
|
|
|
|
# Internal build rules
|
|
|
|
|
2006-01-16 23:32:27 +01:00
|
|
|
# All files in $(OBJS) and any $(subdir)/lib.o are linked into lib.o.
|
|
|
|
# Sort them to filter out duplicated and get uniform order.
|
2006-01-14 10:28:08 +01:00
|
|
|
LIB_O_DEPS = \
|
|
|
|
$(sort $(filter-out $(LIB_O_NAME),$(OBJS))) \
|
|
|
|
$(foreach subdir,$(sort $(SUBDIRS)),$(wildcard $(subdir)/$(LIB_O_NAME)))
|
|
|
|
|
|
|
|
$(LIB_O_NAME): $(LIB_O_DEPS)
|
|
|
|
$(call cmd,ld_objs)
|
|
|
|
|
2006-01-14 09:27:30 +01:00
|
|
|
DEP_FILES_1 = $(foreach src,$(OBJS),.deps/$(src))
|
|
|
|
DEP_FILES = $(DEP_FILES_1:%.o=%.P)
|
|
|
|
DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
|
2005-10-22 13:25:28 +02:00
|
|
|
|
2006-01-14 14:46:23 +01:00
|
|
|
ifneq ($(strip $(OBJS)),)
|
2006-01-14 09:27:30 +01:00
|
|
|
-include $(DEP_FILES)
|
2006-01-19 01:23:54 +01:00
|
|
|
ALL_OBJS = $(LIB_O_DEPS) $(LIB_O_NAME)
|
2005-10-22 13:25:28 +02:00
|
|
|
endif
|
|
|
|
|
2006-01-14 09:27:30 +01:00
|
|
|
%.o: $(srcdir)%.c
|
|
|
|
$(call mcmd,compile)
|
2006-01-14 19:48:44 +01:00
|
|
|
@-if test -e .deps/$(*F).pp; then \
|
|
|
|
cp .deps/$(*F).pp .deps/$(*F).P; \
|
2006-01-14 09:27:30 +01:00
|
|
|
tr ' ' '\012' < .deps/$(*F).pp \
|
|
|
|
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
|
|
|
|
>> .deps/$(*F).P; \
|
2006-01-14 19:48:44 +01:00
|
|
|
rm .deps/$(*F).pp; \
|
|
|
|
fi
|
2006-01-14 09:27:30 +01:00
|
|
|
|
2006-07-10 14:27:40 +02:00
|
|
|
CLEAN += $(PROGS) $(OBJS) $(LIB_O_NAME)
|
2005-10-02 23:55:37 +02:00
|
|
|
|
2006-01-14 09:27:30 +01:00
|
|
|
|
|
|
|
#############################################################################
|
|
|
|
# The main default rules
|
|
|
|
|
2006-01-28 05:25:02 +01:00
|
|
|
all-default: $(ALL_OBJS) $(PROGS) $(MAN1) $(MAN5)
|
2005-10-02 23:55:37 +02:00
|
|
|
|
2006-01-03 18:50:26 +01:00
|
|
|
# Ensure that Makefiles in subdirs are created before we recursive into them
|
|
|
|
init-recursive: init-default
|
|
|
|
|
2006-01-28 05:25:02 +01:00
|
|
|
init-default:
|
2005-10-26 00:34:13 +02:00
|
|
|
@$(foreach subdir,$(sort $(SUBDIRS)), \
|
|
|
|
$(MKINSTALLDIRS) $(subdir) >/dev/null; \
|
2006-01-15 18:37:34 +01:00
|
|
|
test -e "$(subdir)/Makefile" \
|
|
|
|
|| echo 'include $(SRC)/$(RELPATH)/$(subdir)/Makefile' > $(subdir)/Makefile;)
|
2005-10-20 03:49:40 +02:00
|
|
|
|
2006-01-14 08:57:42 +01:00
|
|
|
clean-default cleanall-default:
|
2006-07-10 14:27:40 +02:00
|
|
|
$(Q)-test -z "$(CLEAN)" || $(RM) $(CLEAN)
|
2005-10-02 23:55:37 +02:00
|
|
|
|
2005-11-24 13:24:19 +01:00
|
|
|
check-default:
|
|
|
|
ifneq ($(SPARSE),)
|
|
|
|
@$(foreach file, $(wildcard *.c), \
|
|
|
|
$(call ncmd,sparse,$(file));)
|
|
|
|
endif
|
|
|
|
|
2006-01-14 09:27:30 +01:00
|
|
|
install-default: all-default
|
|
|
|
ifdef PROGS
|
|
|
|
@$(MKINSTALLDIRS) $(DESTDIR)$(bindir)
|
|
|
|
@$(foreach file,$(PROGS), \
|
|
|
|
$(call ncmd,installprog,$(file),$(DESTDIR)$(bindir));)
|
|
|
|
endif
|
|
|
|
ifdef MAN1
|
|
|
|
@$(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man1
|
|
|
|
@$(foreach file,$(MAN1), \
|
|
|
|
$(call ncmd,installdata,$(file),$(DESTDIR)$(mandir)/man1);)
|
|
|
|
endif
|
|
|
|
ifdef MAN5
|
|
|
|
@$(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man5
|
|
|
|
@$(foreach file,$(MAN5), \
|
|
|
|
$(call ncmd,installdata,$(file),$(DESTDIR)$(mandir)/man5);)
|
|
|
|
endif
|
|
|
|
|
2006-09-03 09:27:21 +02:00
|
|
|
uninstall-default:
|
|
|
|
ifdef PROGS
|
|
|
|
@$(foreach file,$(PROGS), \
|
|
|
|
$(call ncmd,uninstall,$(file),$(DESTDIR)$(bindir));)
|
|
|
|
endif
|
|
|
|
ifdef MAN1
|
|
|
|
@$(foreach file,$(MAN1), \
|
|
|
|
$(call ncmd,uninstall,$(file),$(DESTDIR)$(mandir)/man1);)
|
|
|
|
endif
|
|
|
|
ifdef MAN5
|
|
|
|
@$(foreach file,$(MAN5), \
|
|
|
|
$(call ncmd,uninstall,$(file),$(DESTDIR)$(mandir)/man5);)
|
|
|
|
endif
|
2006-01-03 00:45:22 +01:00
|
|
|
##############################################################################
|
|
|
|
# Auto-testing infrastructure
|
|
|
|
|
2006-01-03 02:07:51 +01:00
|
|
|
test-default:
|
2006-01-03 00:45:22 +01:00
|
|
|
|
|
|
|
ifdef TEST_PROGS
|
2006-01-06 22:11:45 +01:00
|
|
|
TESTDEPS-$(CONFIG_DEBUG) += $(top_builddir)/src/util/memdebug.o
|
2007-08-29 01:57:01 +02:00
|
|
|
TESTDEPS-unless$(CONFIG_SMALL) += $(top_builddir)/src/util/fastfind.o
|
2007-05-26 14:04:29 +02:00
|
|
|
|
|
|
|
# Add most of the basic utility library to the test dependencies.
|
|
|
|
TESTDEPS += \
|
|
|
|
$(top_builddir)/src/intl/charsets.o \
|
|
|
|
$(top_builddir)/src/osdep/stub.o \
|
|
|
|
$(top_builddir)/src/util/conv.o \
|
|
|
|
$(top_builddir)/src/util/error.o \
|
|
|
|
$(top_builddir)/src/util/file.o \
|
|
|
|
$(top_builddir)/src/util/hash.o \
|
|
|
|
$(top_builddir)/src/util/memory.o \
|
|
|
|
$(top_builddir)/src/util/string.o \
|
|
|
|
$(top_builddir)/src/util/time.o
|
|
|
|
|
2007-08-28 22:55:26 +02:00
|
|
|
TESTDEPS += $(TESTDEPS-yes) $(TESTDEPS-unlessno)
|
2006-01-03 19:04:17 +01:00
|
|
|
|
2006-01-19 02:15:56 +01:00
|
|
|
TEST_LIB=$(top_srcdir)/test/libtest.sh
|
|
|
|
export TEST_LIB
|
|
|
|
|
2006-01-31 19:25:37 +01:00
|
|
|
# This is a very general rule but as long as we don't put test programs in src/
|
|
|
|
# it should work.
|
2006-01-21 08:37:13 +01:00
|
|
|
%: %.o $(TESTDEPS)
|
|
|
|
$(call cmd,link)
|
|
|
|
|
2006-01-17 16:53:15 +01:00
|
|
|
TESTS = $(wildcard $(srcdir)test-*)
|
2006-01-04 14:46:29 +01:00
|
|
|
|
2006-01-31 19:25:37 +01:00
|
|
|
$(TESTS): $(addsuffix .o,$(TEST_PROGS)) $(TEST_PROGS)
|
2006-01-03 19:04:17 +01:00
|
|
|
@echo "*** $(notdir $@) ***"; \
|
|
|
|
$(call shellquote,$(SHELL)) $@ $(TEST_OPTS)
|
2006-01-03 00:45:22 +01:00
|
|
|
|
2006-01-03 02:07:51 +01:00
|
|
|
test-default: $(TESTS)
|
2006-01-03 00:45:22 +01:00
|
|
|
|
|
|
|
clean-test:
|
|
|
|
@rm -fr trash
|
|
|
|
|
2006-01-03 18:54:51 +01:00
|
|
|
CLEAN += $(TEST_PROGS) $(addsuffix .o,$(TEST_PROGS))
|
2006-01-14 08:57:42 +01:00
|
|
|
clean-default: clean-test
|
2006-01-03 00:45:22 +01:00
|
|
|
endif
|
|
|
|
|
|
|
|
.PHONY: $(TESTS)
|
|
|
|
.NOPARALLEL:
|
|
|
|
|
2005-09-15 21:03:56 +02:00
|
|
|
|
2006-01-14 09:27:30 +01:00
|
|
|
#############################################################################
|
|
|
|
# Basic recursion and dependencies setup
|
2005-09-15 21:03:56 +02:00
|
|
|
|
2006-09-03 09:27:21 +02:00
|
|
|
RULES = all install clean cleanall init check test uninstall
|
2006-01-03 18:50:26 +01:00
|
|
|
|
2006-01-14 12:41:27 +01:00
|
|
|
RULES_LOCAL = $(addsuffix -local,$(RULES))
|
|
|
|
RULES_REC = $(addsuffix -recursive,$(RULES))
|
2006-01-12 03:28:23 +01:00
|
|
|
|
2006-01-14 12:41:27 +01:00
|
|
|
.PHONY: $(RULES) $(RULES_LOCAL) $(RULES_REC) $(addsuffix -default,$(RULES))
|
2005-10-21 15:58:36 +02:00
|
|
|
|
2006-05-21 14:55:22 +03:00
|
|
|
# The -recursive rules descend all subdirs.
|
|
|
|
# If make -k was used and a sub-Make fails, then keep building the
|
|
|
|
# remaining subdirectories, but return an error at the end.
|
2006-01-14 12:41:27 +01:00
|
|
|
$(RULES_REC):
|
2006-05-21 14:55:22 +03:00
|
|
|
ifneq (,$(findstring k,$(MAKEFLAGS)))
|
|
|
|
@suberr=0; \
|
|
|
|
$(foreach subdir,$(sort $(SUBDIRS)), \
|
|
|
|
$(call ncmd,recmake,$(subdir),$(subst -recursive,,$@)) || suberr=1;) \
|
|
|
|
exit $$suberr
|
|
|
|
else
|
2005-10-21 15:58:36 +02:00
|
|
|
@$(foreach subdir,$(sort $(SUBDIRS)), \
|
2006-01-14 12:41:27 +01:00
|
|
|
$(call ncmd,recmake,$(subdir),$(subst -recursive,,$@)) || exit 1;)
|
2006-05-21 14:55:22 +03:00
|
|
|
endif
|
2006-01-14 12:41:27 +01:00
|
|
|
|
|
|
|
# Dummy -local rules
|
|
|
|
$(RULES_LOCAL):
|
|
|
|
|
|
|
|
# Default deps
|
|
|
|
rule_deps = $(1)-recursive $(1)-default $(1)-local
|
|
|
|
all: $(call rule_deps,all)
|
|
|
|
install: $(call rule_deps,install)
|
|
|
|
clean: $(call rule_deps,clean)
|
|
|
|
cleanall: $(call rule_deps,cleanall)
|
|
|
|
init: $(call rule_deps,init)
|
|
|
|
check: $(call rule_deps,check)
|
|
|
|
test: $(call rule_deps,test)
|
2006-09-03 09:27:21 +02:00
|
|
|
uninstall: $(call rule_deps,uninstall)
|
2006-01-14 09:27:30 +01:00
|
|
|
|
|
|
|
#############################################################################
|
|
|
|
# Misc
|
|
|
|
|
2005-10-03 00:09:35 +02:00
|
|
|
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
|
|
|
# Otherwise a system limit (for SysV at least) may be exceeded.
|
|
|
|
.NOEXPORT:
|
|
|
|
|
2006-01-03 00:45:22 +01:00
|
|
|
# Shell quote;
|
|
|
|
# Result of this needs to be placed inside ''
|
|
|
|
# XXX: Placed here because Vim cannot highlight things right afterwards
|
|
|
|
shq = $(subst ','\'',$(1))
|
|
|
|
# This has surrounding ''
|
|
|
|
shellquote = '$(call shq,$(1))'
|
|
|
|
|
2005-09-15 21:03:56 +02:00
|
|
|
# vim:syntax=make
|