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-09-28 15:32:31 -04:00
|
|
|
CURPATH = $(shell pwd)
|
|
|
|
TOPPATH = $(shell cd $(path_to_top) && pwd)
|
2005-10-01 08:16:19 -04:00
|
|
|
RELPATH = $(shell echo '$(CURPATH)' | sed 's,$(TOPPATH),,;s,^/,,;s,\([a-z0-9]\)$$,\1/,')
|
2005-09-28 15:32:31 -04:00
|
|
|
|
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.
|
|
|
|
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-09-28 16:54:30 -04:00
|
|
|
quiet_cmd_compile = ' [CC] $(RELPATH)$<'
|
2005-09-15 15:03:56 -04:00
|
|
|
masq_cmd_compile = $(COMPILE) -c $<
|
|
|
|
cmd_compile = $(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
|
|
|
|
|
2005-09-27 15:38:58 -04:00
|
|
|
# Rule to compile a set of .o files into one .o file
|
2005-09-28 16:54:30 -04:00
|
|
|
quiet_cmd_ld_objs = " [LD] $(RELPATH)$@"
|
2005-09-27 15:38:58 -04:00
|
|
|
cmd_ld_objs = $(LD) -r -o $@ $(filter $(OBJS), $^)
|
|
|
|
|
2005-09-28 16:54:30 -04:00
|
|
|
quiet_cmd_link = ' [LINK] $(RELPATH)$@'
|
2005-10-05 15:42:08 -04:00
|
|
|
cmd_link = $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
|
2005-09-15 15:03:56 -04:00
|
|
|
|
|
|
|
# Recursive make
|
2005-09-28 16:54:30 -04:00
|
|
|
quiet_cmd_recmake = "[MAKE $$target] $(RELPATH)$$subdir"
|
2005-09-15 20:07:36 -04:00
|
|
|
cmd_recmake = $(MAKE) -C $$subdir $$target
|
2005-09-15 15:03:56 -04:00
|
|
|
|
2005-10-01 08:16:19 -04:00
|
|
|
quiet_cmd_installdata = " [INSTALL] $(RELPATH)$(2) -> $(3)"
|
|
|
|
cmd_installdata = $(INSTALL_DATA) $(2) $(3)
|
|
|
|
|
|
|
|
quiet_cmd_installprog = " [INSTALL] $(RELPATH)$(2) -> $(3)"
|
|
|
|
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
|
|
|
|
|
|
|
|
%.o: %.c
|
|
|
|
$(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-09-27 16:38:00 -04:00
|
|
|
ifdef SUBDIRS
|
|
|
|
# Apparently wildcard won't expand *.o files so check if there are any *.c
|
|
|
|
# files and use that to magically add the lib.o file of the subdirectory.
|
2005-09-28 06:11:12 -04:00
|
|
|
subobjs := $(strip $(foreach subdir,$(sort $(filter-out src,$(SUBDIRS))), \
|
|
|
|
$(if $(wildcard $(subdir)/*.c),$(subdir)/lib.o)))
|
2005-09-27 16:38:00 -04:00
|
|
|
endif
|
|
|
|
ifneq ($(subobjs),)
|
|
|
|
OBJS += $(subobjs)
|
|
|
|
endif
|
|
|
|
|
2005-09-16 07:48:22 -04:00
|
|
|
ifdef OBJS
|
2005-09-27 16:49:47 -04:00
|
|
|
lib.o: $(sort $(OBJS))
|
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)
|
|
|
|
|
|
|
|
clean-default:
|
|
|
|
-test -z "$(CLEAN)" || $(RM) $(CLEAN)
|
|
|
|
|
|
|
|
install-default: all-default
|
2005-10-01 08:16:19 -04:00
|
|
|
ifdef PROGS
|
|
|
|
$(MKINSTALLDIRS) $(DESTDIR)$(bindir)
|
2005-10-17 09:39:40 -04:00
|
|
|
$(foreach file,$(PROGS), \
|
|
|
|
$(call ncmd,installprog,$(file),$(DESTDIR)$(bindir));)
|
2005-10-01 08:16:19 -04:00
|
|
|
endif
|
|
|
|
ifdef MAN1
|
|
|
|
$(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man1
|
2005-10-17 09:39:40 -04:00
|
|
|
$(foreach file,$(MAN1), \
|
|
|
|
$(call ncmd,installdata,$(file),$(DESTDIR)$(mandir)/man1);)
|
2005-10-01 08:16:19 -04:00
|
|
|
endif
|
|
|
|
ifdef MAN5
|
|
|
|
$(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man5
|
2005-10-17 09:39:40 -04:00
|
|
|
$(foreach file,$(MAN5), \
|
|
|
|
$(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:
|
|
|
|
|
|
|
|
.PHONY: all-recursive install-recursive clean-recursive
|
|
|
|
all-recursive install-recursive clean-recursive:
|
2005-09-27 13:02:09 -04:00
|
|
|
ifdef SUBDIRS
|
2005-09-15 15:03:56 -04:00
|
|
|
@target=`echo $@ | sed s/-recursive//`; \
|
2005-09-27 16:49:47 -04:00
|
|
|
for subdir in $(sort $(SUBDIRS)); do \
|
2005-09-15 15:03:56 -04:00
|
|
|
$(call ncmd,recmake) || exit 1; \
|
|
|
|
done
|
2005-09-27 13:02:09 -04:00
|
|
|
endif
|
2005-09-15 15:03:56 -04:00
|
|
|
|
2005-10-02 17:55:37 -04:00
|
|
|
all: all-recursive all-default all-local
|
|
|
|
install: install-recursive install-default install-local
|
|
|
|
clean: clean-recursive clean-default clean-local
|
2005-09-15 18:52:54 -04:00
|
|
|
|
2005-09-27 15:11:28 -04:00
|
|
|
all-local:
|
|
|
|
install-local:
|
|
|
|
clean-local:
|
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:
|
|
|
|
|
2005-09-15 15:03:56 -04:00
|
|
|
# vim:syntax=make
|