]> git.tuebingen.mpg.de Git - lopsub.git/blobdiff - Makefile
debian: Final version of 64-bit time_t transition.
[lopsub.git] / Makefile
index 408e3a5ac123dff22cd744a1487e18de3ed53c64..89cbc2eeb3abe456e21ee44e69377eb50d4377f5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -9,6 +9,13 @@ endif
 .ONESHELL:
 .SHELLFLAGS := -ec
 
 .ONESHELL:
 .SHELLFLAGS := -ec
 
+# Recipes which redirect stdout to the target of the rule (i.e., constructs
+# like cmd > $@) create empty or incomplete output files if the command fails,
+# for example when cmd was not found. Since the target exists and is uptodate
+# in this case, this may lead to all sorts of problems. The following target
+# makes sure that such files are removed.
+.DELETE_ON_ERROR:
+
 PREFIX ?= /usr/local
 M4 := m4
 LN := ln -f
 PREFIX ?= /usr/local
 M4 := m4
 LN := ln -f
@@ -18,10 +25,29 @@ AR := ar
 GROFF := groff
 CP := cp
 INSTALL := install
 GROFF := groff
 CP := cp
 INSTALL := install
-GZIP := gzip -f9
+GZIP := gzip -fn9
 ZCAT := zcat
 
 ZCAT := zcat
 
-DATE := $(shell date '+%B %Y')
+CC += -ffile-prefix-map=$(CURDIR)=.
+
+dummy != $(M4) /dev/null || printf 'failed'
+ifeq ($(dummy), failed)
+$(error m4 is required to build this package)
+endif
+dummy != printf '%%%%\n' | $(LEX) -o /dev/null || printf 'failed'
+ifeq ($(dummy), failed)
+$(error (f)lex is required to build this package)
+endif
+
+DATE_FMT := +%B %Y
+# To get a reproducible build, we use $(SOURCE_DATE_EPOCH) instead of the
+# current time if this variable is set.
+ifdef SOURCE_DATE_EPOCH
+       DATE := $(shell LC_ALL=C date -u -d '@$(SOURCE_DATE_EPOCH)' \
+               '$(DATE_FMT)' 2>/dev/null || LC_ALL=C date -u '$(DATE_FMT)')
+else
+       DATE := $(shell date '$(DATE_FMT)')
+endif
 GIT_VERSION := $(shell ./version-gen.sh)
 PLAIN_VERSION := $(firstword $(subst -, , $(GIT_VERSION)))
 MAJOR_VERSION := $(firstword $(subst ., , $(PLAIN_VERSION)))
 GIT_VERSION := $(shell ./version-gen.sh)
 PLAIN_VERSION := $(firstword $(subst -, , $(GIT_VERSION)))
 MAJOR_VERSION := $(firstword $(subst ., , $(PLAIN_VERSION)))
@@ -71,13 +97,17 @@ lsg_objs := lopsubgen.o lsg.o lopsubgen.lsg.o lopsub.o version.o
 liblopsub_objs := config_file.o lopsub.o version.o
 lopsubex_objs := lopsubex.o lopsubex.lsg.o $(liblopsub_objs)
 
 liblopsub_objs := config_file.o lopsub.o version.o
 lopsubex_objs := lopsubex.o lopsubex.lsg.o $(liblopsub_objs)
 
+LLS_CFLAGS := -g -fPIC
+STRICT_CFLAGS := -Wall
+STRICT_CFLAGS += -Werror-implicit-function-declaration
+
 $(lsg_objs) $(liblopsub_objs) $(lopsubex_objs): %.o: %.c
 lopsubgen.o config_file.o:
 $(lsg_objs) $(liblopsub_objs) $(lopsubex_objs): %.o: %.c
 lopsubgen.o config_file.o:
-       $(CC) -g -c -fPIC -o $@ ${@:.o=.c}
+       $(CC) $(CPPFLAGS) $(LLS_CFLAGS) $(CFLAGS) -c -o $@ ${@:.o=.c}
 lsg1.o: lsg.c lsg.h
 lsg1.o: lsg.c lsg.h
-       $(CC) -g -DSTAGE1 -Wall -g -c $< -o $@
+       $(CC) $(CPPFLAGS) $(LLS_CFLAGS) $(STRICT_CFLAGS) $(CFLAGS) -DSTAGE1 -c -o $@ $<
 %.o: %.c
 %.o: %.c
-       $(CC) -Wall -I. -g -c -fPIC -o $@ $<
+       $(CC) -I. $(CPPFLAGS) $(LLS_CFLAGS) $(STRICT_CFLAGS) $(CFLAGS) -c -o $@ $<
 
 # linking
 lopsubgen-stage1: $(lsg1_objs)
 
 # linking
 lopsubgen-stage1: $(lsg1_objs)
@@ -86,22 +116,22 @@ lopsubgen: $(lsg_objs)
        $(CC) -Wall -g -o $@ $(lsg_objs)
 $(REALNAME): $(liblopsub_objs)
        $(CC) --shared -Wl,-soname,liblopsub.so.$(MAJOR_VERSION) -o $@ $^
        $(CC) -Wall -g -o $@ $(lsg_objs)
 $(REALNAME): $(liblopsub_objs)
        $(CC) --shared -Wl,-soname,liblopsub.so.$(MAJOR_VERSION) -o $@ $^
+liblopsub.a: $(liblopsub_objs)
+       $(AR) -rcs $@ $^
+
 lopsubex: $(lopsubex_objs) $(REALNAME)
        $(CC) -Wall -g -o $@ $(lopsubex_objs)
 
 # web
 html := $(addprefix web/, $(addsuffix .html, \
 lopsubex: $(lopsubex_objs) $(REALNAME)
        $(CC) -Wall -g -o $@ $(lopsubex_objs)
 
 # web
 html := $(addprefix web/, $(addsuffix .html, \
-       index lopsub-api lopsubgen.1 lopsubex.1 $(m4_man_pages)))
-$(html): $(addprefix web/, $(addsuffix .html, header footer))
-
+       index lopsub-api lopsubgen.1 lopsubex.1 $(m4_man_pages:.gz=)))
 www: $(html)
 www: $(html)
-
-web/lopsub-api.html: lopsub.h.m4
+web/lopsub-api.html: lopsub.h.m4 web/header.html web/footer.html
        $(M4) -DOUTPUT_MODE=HTML web/header.html $(gendoc) \
                $< web/footer.html > $@
 web/index.html: web/lopsub.7.html
        $(LN) -s $(notdir $<) $@
        $(M4) -DOUTPUT_MODE=HTML web/header.html $(gendoc) \
                $< web/footer.html > $@
 web/index.html: web/lopsub.7.html
        $(LN) -s $(notdir $<) $@
-web/%.html: %.gz
+web/%.html: %.gz web/header.html
        $(CP) web/header.html $@
        $(ZCAT) $< | $(GROFF) -m man -Thtml | sed -e '1,/^<body>/d' >> $@
 
        $(CP) web/header.html $@
        $(ZCAT) $< | $(GROFF) -m man -Thtml | sed -e '1,/^<body>/d' >> $@
 
@@ -124,4 +154,4 @@ clean:
 distclean: clean
        $(RM) *.lsg.c *.lsg.h lopsubgen.c config_file.c lopsubgen-stage1 \
                lopsub.h lopsub.7 lopsub-suite.5 version.c
 distclean: clean
        $(RM) *.lsg.c *.lsg.h lopsubgen.c config_file.c lopsubgen-stage1 \
                lopsub.h lopsub.7 lopsub-suite.5 version.c
-
+-include Makefile.local