INSTALL_PROGRAM ?= $(INSTALL)
INSTALL_DATA ?= $(INSTALL) -m 644
MKDIR_P := mkdir -p
-VERSION := $(shell ./version-gen.sh $(PACKAGE) version.c)
+B := build
+VERSION := $(shell $(MKDIR_P) $(B) && ./version-gen.sh $(PACKAGE) $(B)/version.c)
RM := rm -f
LSG := lopsubgen
GROFF := groff -m man -Thtml -P -l -P -r
GZIP := gzip -cfn9
-units := $(PACKAGE) $(PACKAGE).lsg str file exec sig daemon df tv snap ipc version
M4 := m4 \
-D "AUTHOR=$(AUTHOR)" \
-D "PACKAGE=$(PACKAGE)" \
-D "DESCRIPTION1=$(DESCRIPTION1)" \
-D "DESCRIPTION2=$(DESCRIPTION2)" \
-D "DESCRIPTION3=$(DESCRIPTION3)"
-objs := $(addsuffix .o, $(units))
-deps := $(addsuffix .d, $(units))
+c_source := $(PACKAGE) str file exec sig daemon df tv snap ipc
+c_generated := $(B)/$(PACKAGE).lsg $(B)/version
+objs := $(addsuffix .o, $(c_generated) $(addprefix $(B)/, $(c_source)))
+deps := $(objs:.o=.d)
all := $(PACKAGE) $(PACKAGE).1.gz
all: $(all)
man: $(PACKAGE).1.gz
-$(objs): $(PACKAGE).lsg.h Makefile
+$(objs): $(B)/$(PACKAGE).lsg.h Makefile
-include $(deps)
DSS_CPPFLAGS += -Wunused-macros
+DSS_CPPFLAGS += -I$(B)
DSS_CFLAGS := -Wno-sign-compare -g -Wunused -Wundef
DSS_CFLAGS += -Wredundant-decls
DSS_CFLAGS += -Wbad-function-cast
DSS_CFLAGS += -Wshadow
+CC_CMD = $(CC) -c -o $@ $(DSS_CPPFLAGS) $(CPPFLAGS) $(DSS_CFLAGS) $(CFLAGS) \
+ -MMD -MF $(B)/$(*F).d -MT $@ $<
+
.ONESHELL:
.SHELLFLAGS := -ec
ifeq ("$(origin V)", "command line")
else
SAY = @printf '%s\n' '$(strip $(1))'
endif
-version.c:
+$(B)/version.c:
$(call SAY, VG $@)
./version-gen.sh $(PACKAGE) version.c > /dev/null
$(PACKAGE): $(objs)
$(call SAY, LD $@)
$(CC) -o $@ $(objs) $(LDFLAGS) -llopsub
-%.o: %.c
+$(B)/%.o: $(B)/%.c
+ $(call SAY, CC $<)
+ $(CC_CMD)
+$(B)/%.o: %.c
$(call SAY, CC $<)
- $(CC) -c -o $@ $(DSS_CPPFLAGS) $(CPPFLAGS) $(DSS_CFLAGS) $(CFLAGS) \
- -MMD -MF $(*F).d -MT $@ $<
+ $(CC_CMD)
+
.PHONY: all clean install README
-.PRECIOUS: %.lsg.c %.lsg.h %.suite %.1
-$(PACKAGE).suite: $(PACKAGE).suite.m4 Makefile
+.PRECIOUS: $(B)/%.lsg.c $(B)/%.lsg.h $(B)/%.suite $(B)/%.1
+$(B)/$(PACKAGE).suite: $(PACKAGE).suite.m4 Makefile
$(call SAY, M4 $<)
$(M4) $< > $@
-%.lsg.h: %.suite
+$(B)/%.lsg.h: $(B)/%.suite
$(call SAY, LSGH $<)
$(LSG) --gen-h=$@ < $<
-%.lsg.c: %.suite
+$(B)/%.lsg.c: $(B)/%.suite
$(call SAY, LSGC $<)
$(LSG) --gen-c=$@ < $<
-%.1: %.suite
+$(B)/%.1: $(B)/%.suite
$(call SAY, LSGM $<)
$(LSG) --gen-man=$@ --version-string=$(VERSION) < $<
-%.1.gz: %.1
+%.1.gz: $(B)/%.1
$(call SAY, GZIP $<)
$(GZIP) < $< > $@
-%.1.html: %.1
+$(B)/%.1.html: $(B)/%.1
$(call SAY, GROFF $<)
$(GROFF) $< > $@
clean:
$(call SAY, CLEAN)
- $(RM) *.[od] $(all) *.html $(PACKAGE).1 $(PACKAGE).suite \
- $(PACKAGE).lsg.[ch] version.c
+ $(RM) -r $(B) $(all)
ifneq ($(findstring strip, $(MAKECMDGOALS)),)
strip_option := -s
README:
@printf '%s\n' "$(README)"
-index.html: index.html.m4 Makefile
+$(B)/index.html: index.html.m4 Makefile
$(call SAY, M4 $@)
$(M4) $< > $@