2005-09-15 15:03:56 -04:00
|
|
|
### The build commands and verbosity
|
|
|
|
|
|
|
|
# If we are verbose, we will show commands prefixed by $(Q) (which acts as
|
|
|
|
# @ in the non-verbose mode), and we will show the "real" cmds instead of
|
|
|
|
# their quiet versions (which are used in the non-verbose mode).
|
|
|
|
# Inspired by the Linux kernel build system.
|
|
|
|
ifdef V
|
|
|
|
Q =
|
|
|
|
quiet =
|
|
|
|
mquiet = masq_
|
|
|
|
else
|
|
|
|
Q = @
|
|
|
|
quiet = quiet_
|
|
|
|
mquiet = quiet_
|
|
|
|
endif
|
|
|
|
|
2005-12-15 02:44:15 -05:00
|
|
|
# Colorize the build.
|
|
|
|
ifdef MAKE_COLOR
|
2005-12-16 20:17:26 -05:00
|
|
|
INFO_COLOR = $(shell tput setaf 5)
|
|
|
|
CC_COLOR = $(shell tput setaf 6)
|
|
|
|
LD_COLOR = $(shell tput setaf 2)
|
2005-12-26 13:17:47 -05:00
|
|
|
PO_COLOR = $(shell tput setaf 6)
|
2005-12-16 20:17:26 -05:00
|
|
|
LINK_COLOR = $(shell tput bold;tput setaf 4)
|
|
|
|
INSTALL_COLOR = $(shell tput setaf 3)
|
|
|
|
END_COLOR = $(shell tput sgr0)
|
2005-12-15 02:44:15 -05:00
|
|
|
endif
|
|
|
|
|
2005-09-15 15:03:56 -04:00
|
|
|
# Show the command (quiet or non-quiet version based on the assignment
|
|
|
|
# just above) and then execute it.
|
2005-12-16 20:18:33 -05: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 13:17:47 -05:00
|
|
|
ecmd = @$(if $($(mquiet)cmd_$(1)),printf "%-38s " $($(mquiet)cmd_$(1)) &&) $(cmd_$(1))
|
2005-09-15 15:03:56 -04:00
|
|
|
|
2005-12-15 02:44:15 -05:00
|
|
|
quiet_cmd_compile = ' [$(CC_COLOR)CC$(END_COLOR)] $(RELPATH)$@'
|
2006-01-06 16:08:49 -05:00
|
|
|
masq_cmd_compile = $(COMPILE) -o $(@) -c $< $(2)
|
|
|
|
cmd_compile = $(COMPILE) -o $(@) -Wp,-MD,.deps/$(*F).pp -c $< $(2)
|
2005-09-15 15:03:56 -04:00
|
|
|
|
2005-09-27 15:38:58 -04: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-19 21:39:59 -04:00
|
|
|
cmd_ld_objs = $(LD) -r -o $@ $(filter $(OBJS), $^) \
|
|
|
|
$(foreach subdir,$(sort $(filter-out src,$(SUBDIRS))), \
|
|
|
|
`test -e $(subdir)/lib.o && echo $(subdir)/lib.o`)
|
2005-10-21 09:58:36 -04:00
|
|
|
|
2005-12-15 02:44:15 -05:00
|
|
|
quiet_cmd_link = ' [$(LINK_COLOR)LINK$(END_COLOR)] $(RELPATH)$@'
|
2006-01-04 08:46:29 -05:00
|
|
|
cmd_link = $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(2) $(LIBS)
|
2005-09-15 15:03:56 -04:00
|
|
|
|
2005-11-24 15:54:49 -05:00
|
|
|
quiet_cmd_sparse = ' [SPARSE] $(RELPATH)$(2)'
|
2005-11-24 07:24:19 -05:00
|
|
|
cmd_sparse = $(SPARSE) $(DEFS) $(INCLUDES) $(AM_CFLAGS) $(CFLAGS) $(SPARSE_FLAGS) $(2)
|
|
|
|
|
2005-09-15 15:03:56 -04: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 17:21:08 -05:00
|
|
|
cmd_recmake = $(MAKE) -C $(2) $(3)
|
2005-09-15 15:03:56 -04:00
|
|
|
|
2005-12-15 02:44:15 -05:00
|
|
|
quiet_cmd_installdata = " [$(INSTALL_COLOR)INSTALL$(END_COLOR)] $(RELPATH)$(2) -> $(3)"
|
2005-10-01 08:16:19 -04: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 08:16:19 -04:00
|
|
|
cmd_installprog = $(INSTALL_PROGRAM) $(2) $(3)
|
|
|
|
|
2005-09-15 15:03:56 -04:00
|
|
|
|
|
|
|
### Internal build rules
|
|
|
|
|
|
|
|
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-09-16 07:48:22 -04:00
|
|
|
ifdef OBJS
|
2005-09-15 15:03:56 -04:00
|
|
|
-include $(DEP_FILES)
|
|
|
|
endif
|
|
|
|
|
2005-10-19 21:49:40 -04:00
|
|
|
%.o: $(srcdir)%.c
|
2005-09-15 15:03:56 -04:00
|
|
|
$(call mcmd,compile)
|
|
|
|
@-cp .deps/$(*F).pp .deps/$(*F).P; \
|
|
|
|
tr ' ' '\012' < .deps/$(*F).pp \
|
|
|
|
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
|
|
|
|
>> .deps/$(*F).P; \
|
|
|
|
rm .deps/$(*F).pp
|
|
|
|
|
2005-09-27 16:49:47 -04:00
|
|
|
ifdef SUBDIRS-yes
|
|
|
|
SUBDIRS += $(SUBDIRS-yes)
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifdef OBJS-yes
|
|
|
|
OBJS += $(OBJS-yes)
|
|
|
|
endif
|
|
|
|
|
2005-10-22 07:25:28 -04:00
|
|
|
ifneq ($(findstring cleanall,$(MAKECMDGOALS)),)
|
2005-10-25 17:41:26 -04:00
|
|
|
INCLUDE_ALL=1
|
|
|
|
endif
|
|
|
|
|
2005-10-25 18:34:13 -04:00
|
|
|
ifneq ($(findstring init,$(MAKECMDGOALS)),)
|
|
|
|
# FIXME: Detect when $(subdir)/Makefile is $(srcdir)/$(subdir)/Makefile
|
|
|
|
# and error out so the user won't overwrite the 'master' Makefiles.
|
2005-10-25 17:41:26 -04:00
|
|
|
INCLUDE_ALL=1
|
|
|
|
endif
|
2005-10-22 07:25:28 -04:00
|
|
|
|
2005-10-25 17:41:26 -04:00
|
|
|
ifdef INCLUDE_ALL
|
2005-10-22 07:25:28 -04:00
|
|
|
ifdef SUBDIRS-no
|
|
|
|
SUBDIRS += $(SUBDIRS-no)
|
|
|
|
endif
|
2005-12-24 20:15:04 -05:00
|
|
|
ifdef SUBDIRS-
|
|
|
|
SUBDIRS += $(SUBDIRS-)
|
|
|
|
endif
|
2005-10-22 07:25:28 -04:00
|
|
|
ifdef OBJS-no
|
|
|
|
OBJS += $(OBJS-no)
|
|
|
|
endif
|
2005-12-24 20:15:04 -05:00
|
|
|
ifdef OBJS-
|
|
|
|
OBJS += $(OBJS-)
|
|
|
|
endif
|
2005-10-22 07:25:28 -04:00
|
|
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
2005-09-16 07:48:22 -04:00
|
|
|
ifdef OBJS
|
2005-10-20 14:18:29 -04:00
|
|
|
lib.o: $(sort $(OBJS)) $(foreach subdir,$(sort $(filter-out src,$(SUBDIRS))), $(wildcard $(subdir)/lib.o))
|
2005-09-27 15:38:58 -04:00
|
|
|
$(call cmd,ld_objs)
|
|
|
|
|
2005-10-02 17:55:37 -04:00
|
|
|
LIB_O = lib.o
|
|
|
|
CLEAN += $(OBJS) $(LIB_O)
|
2005-09-15 17:28:56 -04:00
|
|
|
endif
|
|
|
|
|
2005-10-02 17:55:37 -04:00
|
|
|
CLEAN += $(PROG)
|
|
|
|
|
|
|
|
all-default: $(LIB_O) $(PROGS) $(MAN1) $(MAN5)
|
|
|
|
|
2006-01-03 12:50:26 -05:00
|
|
|
# Ensure that Makefiles in subdirs are created before we recursive into them
|
|
|
|
init-recursive: init-default
|
|
|
|
|
2005-10-25 18:34:13 -04:00
|
|
|
init-default:
|
|
|
|
@$(foreach subdir,$(sort $(SUBDIRS)), \
|
|
|
|
$(MKINSTALLDIRS) $(subdir) >/dev/null; \
|
|
|
|
echo 'include $(SRC)/$(RELPATH)/$(subdir)/Makefile' > $(subdir)/Makefile;)
|
2005-10-19 21:49:40 -04:00
|
|
|
|
2006-01-02 18:45:22 -05:00
|
|
|
clean-default: clean-test
|
2005-12-15 04:04:26 -05:00
|
|
|
@-test -z "$(CLEAN)" || $(RM) $(CLEAN)
|
2005-10-02 17:55:37 -04:00
|
|
|
|
2005-10-22 07:25:28 -04:00
|
|
|
cleanall-default: clean-default
|
|
|
|
|
2005-11-24 07:24:19 -05:00
|
|
|
check-default:
|
|
|
|
ifneq ($(SPARSE),)
|
|
|
|
@$(foreach file, $(wildcard *.c), \
|
|
|
|
$(call ncmd,sparse,$(file));)
|
|
|
|
endif
|
|
|
|
|
2006-01-02 18:45:22 -05:00
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# Auto-testing infrastructure
|
|
|
|
#
|
|
|
|
|
|
|
|
clean-test:
|
2006-01-02 20:07:51 -05:00
|
|
|
test-default:
|
2006-01-02 18:45:22 -05:00
|
|
|
|
|
|
|
ifdef TEST_PROGS
|
2006-01-06 16:11:45 -05:00
|
|
|
TESTDEPS-$(CONFIG_DEBUG) += $(top_builddir)/src/util/memdebug.o
|
2006-01-03 13:04:17 -05:00
|
|
|
TESTDEPS += $(TESTDEPS-yes)
|
|
|
|
|
|
|
|
TESTS = $(wildcard $(srcdir)test-*)
|
2006-01-02 18:45:22 -05:00
|
|
|
|
2006-01-04 08:46:29 -05:00
|
|
|
$(TEST_PROGS): $(TESTDEPS)
|
|
|
|
$(call cmd,link,$@.o)
|
|
|
|
|
|
|
|
# We cannot use $$@.o in the rule above so ensure that all test programs are
|
|
|
|
# built before linking.
|
|
|
|
$(TESTS): $(addsuffix .o,$(TEST_PROGS)) $(TEST_PROGS)
|
2006-01-03 13:04:17 -05:00
|
|
|
@echo "*** $(notdir $@) ***"; \
|
|
|
|
$(call shellquote,$(SHELL)) $@ $(TEST_OPTS)
|
2006-01-02 18:45:22 -05:00
|
|
|
|
2006-01-02 20:07:51 -05:00
|
|
|
test-default: $(TESTS)
|
2006-01-02 18:45:22 -05:00
|
|
|
|
|
|
|
clean-test:
|
|
|
|
@rm -fr trash
|
|
|
|
|
2006-01-03 12:54:51 -05:00
|
|
|
CLEAN += $(TEST_PROGS) $(addsuffix .o,$(TEST_PROGS))
|
2006-01-02 18:45:22 -05:00
|
|
|
endif
|
|
|
|
|
|
|
|
.PHONY: $(TESTS)
|
|
|
|
.NOPARALLEL:
|
|
|
|
|
2005-11-24 07:24:19 -05:00
|
|
|
# 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__
|
2005-10-02 17:55:37 -04:00
|
|
|
install-default: all-default
|
2005-10-01 08:16:19 -04:00
|
|
|
ifdef PROGS
|
2005-10-24 08:06:04 -04:00
|
|
|
@$(MKINSTALLDIRS) $(DESTDIR)$(bindir)
|
|
|
|
@$(foreach file,$(PROGS), \
|
2005-10-17 09:39:40 -04:00
|
|
|
$(call ncmd,installprog,$(file),$(DESTDIR)$(bindir));)
|
2005-10-01 08:16:19 -04:00
|
|
|
endif
|
|
|
|
ifdef MAN1
|
2005-10-24 08:06:04 -04:00
|
|
|
@$(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man1
|
|
|
|
@$(foreach file,$(MAN1), \
|
2005-10-17 09:39:40 -04:00
|
|
|
$(call ncmd,installdata,$(file),$(DESTDIR)$(mandir)/man1);)
|
2005-10-01 08:16:19 -04:00
|
|
|
endif
|
|
|
|
ifdef MAN5
|
2005-10-24 08:06:04 -04:00
|
|
|
@$(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man5
|
|
|
|
@$(foreach file,$(MAN5), \
|
2005-10-17 09:39:40 -04:00
|
|
|
$(call ncmd,installdata,$(file),$(DESTDIR)$(mandir)/man5);)
|
2005-10-01 08:16:19 -04:00
|
|
|
endif
|
2005-09-15 15:03:56 -04:00
|
|
|
|
|
|
|
# Recursion:
|
|
|
|
|
2006-01-03 12:50:26 -05:00
|
|
|
RULES = all install clean cleanall init check test
|
|
|
|
RECRULES = $(addsuffix -recursive,$(RULES))
|
|
|
|
|
|
|
|
.PHONY: $(RECRULES)
|
2005-10-21 09:58:36 -04:00
|
|
|
|
2006-01-03 12:50:26 -05:00
|
|
|
# The -recursive rules decend all subdirs.
|
|
|
|
$(RECRULES):
|
2005-09-27 13:02:09 -04:00
|
|
|
ifdef SUBDIRS
|
2005-10-21 09:58:36 -04:00
|
|
|
@$(foreach subdir,$(sort $(SUBDIRS)), \
|
|
|
|
$(call ncmd,recmake,$(subdir),$(subst -recursive,,$@)) || exit 1;)
|
2005-09-27 13:02:09 -04:00
|
|
|
endif
|
2005-09-15 15:03:56 -04:00
|
|
|
|
2006-01-03 12:50:26 -05:00
|
|
|
# Setup the default sub commands dependency. First decend subdirs then do all
|
|
|
|
# the default stuff and finally do any local hooks.
|
2006-01-04 08:46:29 -05:00
|
|
|
recdeps = $1-recursive $1-default $1-local
|
|
|
|
all: $(call recdeps,all)
|
|
|
|
check: $(call recdeps,check)
|
|
|
|
cleanall: $(call recdeps,cleanall)
|
|
|
|
clean: $(call recdeps,clean)
|
|
|
|
init: $(call recdeps,init)
|
|
|
|
install: $(call recdeps,install)
|
|
|
|
test: $(call recdeps,test)
|
2005-09-15 18:52:54 -04:00
|
|
|
|
2006-01-03 12:50:26 -05:00
|
|
|
# Dummy rules for local hooks
|
|
|
|
$(addsuffix -local,$(RULES)):
|
2005-09-15 17:28:56 -04:00
|
|
|
|
2005-10-02 18:09:35 -04: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-02 18:45:22 -05: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 15:03:56 -04:00
|
|
|
# vim:syntax=make
|