ifeq ("$(origin CC)", "default")
CC := cc
endif
+ifeq ($(CC_FOR_BUILD),)
+ CC_FOR_BUILD := $(CC)
+endif
.ONESHELL:
.SHELLFLAGS := -ec
else
DATE := $(shell date '$(DATE_FMT)')
endif
-GIT_VERSION := $(shell ./version-gen.sh)
+
+B := build
+GIT_VERSION := $(shell mkdir -p $(B) && ./version-gen.sh)
PLAIN_VERSION := $(firstword $(subst -, , $(GIT_VERSION)))
MAJOR_VERSION := $(firstword $(subst ., , $(PLAIN_VERSION)))
SONAME := liblopsub.so.$(MAJOR_VERSION)
LINKERNAME:=liblopsub.so
m4_man_pages := lopsub-suite.5.gz lopsub.7.gz
-all := $(m4_man_pages) $(REALNAME) lopsubgen lopsubgen.1.gz \
+all := $(m4_man_pages) $(REALNAME) lopsubgen $(B)/lopsubgen lopsubgen.1.gz \
lopsubex lopsubex.1.gz
all: $(all)
$(LEX) -o $@ $<
# lopsubgen
-lopsubgen.lsg.c lopsubgen.lsg.h: lopsubgen.suite lopsubgen-stage1 \
+lopsubgen.lsg.c lopsubgen.lsg.h: lopsubgen.suite $(B)/lopsubgen-stage1 \
lopsub-internal.h
- ./lopsubgen-stage1 < $<
+ $(B)/lopsubgen-stage1 < $<
%.lsg.c: %.suite lopsubgen
- ./lopsubgen --gen-c < $<
+ $(B)/./lopsubgen --gen-c < $<
%.lsg.h: %.suite lopsubgen
- ./lopsubgen --gen-header < $<
+ $(B)/./lopsubgen --gen-header < $<
%.1.gz: %.suite lopsubgen
- ./lopsubgen --gen-man=${@:.gz=} --version-string $(GIT_VERSION) < $<
+ $(B)/./lopsubgen --gen-man=${@:.gz=} --version-string $(GIT_VERSION) < $<
$(GZIP) ${@:.gz=}
-# compiling
-lsg1_objs := lopsubgen.o lsg1.o version.o
+lsg1_objs := $(addprefix $(B)/, lopsubgen.o lsg1.o version.o)
lsg_objs := lopsubgen.o lsg.o lopsubgen.lsg.o lopsub.o version.o
+blsg_objs := $(addprefix $(B)/, $(lsg_objs))
liblopsub_objs := config_file.o lopsub.o version.o
lopsubex_objs := lopsubex.o lopsubex.lsg.o $(liblopsub_objs)
STRICT_CFLAGS += -Werror-implicit-function-declaration
$(lsg_objs) $(liblopsub_objs) $(lopsubex_objs): %.o: %.c
+$(blsg_objs): $(B)/%.o: %.c
lopsubgen.o config_file.o:
$(CC) $(CPPFLAGS) $(LLS_CFLAGS) $(CFLAGS) -c -o $@ ${@:.o=.c}
-lsg1.o: lsg.c lsg.h
- $(CC) $(CPPFLAGS) $(LLS_CFLAGS) $(STRICT_CFLAGS) $(CFLAGS) -DSTAGE1 -c -o $@ $<
+$(B)/lopsubgen.o: lopsubgen.c
+ $(CC_FOR_BUILD) $(CPPFLAGS) $(LLS_CFLAGS) $(CFLAGS) -c -o $@ $<
+$(B)/lsg1.o: lsg.c lsg.h
+ $(CC_FOR_BUILD) $(CPPFLAGS) $(LLS_CFLAGS) $(STRICT_CFLAGS) $(CFLAGS) -DSTAGE1 -c -o $@ $<
%.o: %.c
$(CC) -I. $(CPPFLAGS) $(LLS_CFLAGS) $(STRICT_CFLAGS) $(CFLAGS) -c -o $@ $<
-
-# linking
-lopsubgen-stage1: $(lsg1_objs)
- $(CC) -Wall -g $(lsg1_objs) -o $@
+$(B)/%.o: %.c
+ $(CC_FOR_BUILD) -I. $(CPPFLAGS) $(LLS_CFLAGS) $(STRICT_CFLAGS) $(CFLAGS) -c -o $@ $<
+$(B)/lopsubgen-stage1: $(lsg1_objs)
+ $(CC_FOR_BUILD) -Wall -g $(lsg1_objs) -o $@
lopsubgen: $(lsg_objs)
$(CC) -Wall -g $(LDFLAGS) -o $@ $(lsg_objs)
+$(B)/lopsubgen: $(blsg_objs)
+ $(CC_FOR_BUILD) -Wall -g $(LDFLAGS) -o $@ $(blsg_objs)
+
$(REALNAME): $(liblopsub_objs)
$(CC) --shared -Wl,-soname,liblopsub.so.$(MAJOR_VERSION) \
$(LDFLAGS) -o $@ $^
$(INSTALL) -m 644 lopsub.7.gz $(DESTDIR)$(PREFIX)/share/man/man7
clean:
- $(RM) $(all) $(html) *.o *.man
+ $(RM) $(all) $(html) *.o *.man $(B)/*.o
distclean: clean
$(RM) *.lsg.c *.lsg.h lopsubgen.c config_file.c lopsubgen-stage1 \
lopsub.h lopsub.7 lopsub-suite.5 version.c
+ $(RM) -r $(B)
-include Makefile.local