]> git.tuebingen.mpg.de Git - lopsub.git/blob - Makefile
debian: Final version of 64-bit time_t transition.
[lopsub.git] / Makefile
1 # Implicit rules are implemented in make as suffix rules. The following rule
2 # empties the suffix list to disable the predefined implicit rules. This
3 # increases performance and avoids hard-to-debug behaviour.
4 .SUFFIXES:
5 MAKEFLAGS += -Rr
6 ifeq ("$(origin CC)", "default")
7         CC := cc
8 endif
9 .ONESHELL:
10 .SHELLFLAGS := -ec
11
12 # Recipes which redirect stdout to the target of the rule (i.e., constructs
13 # like cmd > $@) create empty or incomplete output files if the command fails,
14 # for example when cmd was not found. Since the target exists and is uptodate
15 # in this case, this may lead to all sorts of problems. The following target
16 # makes sure that such files are removed.
17 .DELETE_ON_ERROR:
18
19 PREFIX ?= /usr/local
20 M4 := m4
21 LN := ln -f
22 LEX := lex
23 RM := rm -f
24 AR := ar
25 GROFF := groff
26 CP := cp
27 INSTALL := install
28 GZIP := gzip -fn9
29 ZCAT := zcat
30
31 CC += -ffile-prefix-map=$(CURDIR)=.
32
33 dummy != $(M4) /dev/null || printf 'failed'
34 ifeq ($(dummy), failed)
35 $(error m4 is required to build this package)
36 endif
37 dummy != printf '%%%%\n' | $(LEX) -o /dev/null || printf 'failed'
38 ifeq ($(dummy), failed)
39 $(error (f)lex is required to build this package)
40 endif
41
42 DATE_FMT := +%B %Y
43 # To get a reproducible build, we use $(SOURCE_DATE_EPOCH) instead of the
44 # current time if this variable is set.
45 ifdef SOURCE_DATE_EPOCH
46         DATE := $(shell LC_ALL=C date -u -d '@$(SOURCE_DATE_EPOCH)' \
47                 '$(DATE_FMT)' 2>/dev/null || LC_ALL=C date -u '$(DATE_FMT)')
48 else
49         DATE := $(shell date '$(DATE_FMT)')
50 endif
51 GIT_VERSION := $(shell ./version-gen.sh)
52 PLAIN_VERSION := $(firstword $(subst -, , $(GIT_VERSION)))
53 MAJOR_VERSION := $(firstword $(subst ., , $(PLAIN_VERSION)))
54 SONAME := liblopsub.so.$(MAJOR_VERSION)
55 REALNAME := liblopsub.so.$(PLAIN_VERSION)
56 LINKERNAME:=liblopsub.so
57
58 m4_man_pages := lopsub-suite.5.gz lopsub.7.gz
59 all := $(m4_man_pages) $(REALNAME) lopsubgen lopsubgen.1.gz \
60         lopsubex lopsubex.1.gz
61 all: $(all)
62
63 # deps
64 lopsubgen.o: lsg.h
65 lopsub.o lsg.o: lopsub.h lopsub-internal.h
66 lsg.o: lopsubgen.lsg.h lopsub-internal.h
67 lopsubex.o: lopsubex.lsg.h lopsub.h
68 config_file.c: lopsub-internal.h lopsub.h
69 version.o: version.c
70
71 # m4 stuff
72 gendoc := gendoc/gendoc.m4
73 %.h: %.h.m4 $(gendoc)
74         $(M4) -DOUTPUT_MODE=C $(gendoc) $< > $@
75 $(m4_man_pages): %.gz: %.m4 version.c
76         $(M4) -DGIT_VERSION=$(GIT_VERSION) -DDATE="$(DATE)" $< | $(GZIP) > $@
77
78 # flex
79 %.c: %.l
80         $(LEX) -o $@ $<
81
82 # lopsubgen
83 lopsubgen.lsg.c lopsubgen.lsg.h: lopsubgen.suite lopsubgen-stage1 \
84                 lopsub-internal.h
85         ./lopsubgen-stage1 < $<
86 %.lsg.c: %.suite lopsubgen
87         ./lopsubgen --gen-c < $<
88 %.lsg.h: %.suite lopsubgen
89         ./lopsubgen --gen-header < $<
90 %.1.gz: %.suite lopsubgen
91         ./lopsubgen --gen-man=${@:.gz=} --version-string $(GIT_VERSION) < $<
92         $(GZIP) ${@:.gz=}
93
94 # compiling
95 lsg1_objs := lopsubgen.o lsg1.o version.o
96 lsg_objs := lopsubgen.o lsg.o lopsubgen.lsg.o lopsub.o version.o
97 liblopsub_objs := config_file.o lopsub.o version.o
98 lopsubex_objs := lopsubex.o lopsubex.lsg.o $(liblopsub_objs)
99
100 LLS_CFLAGS := -g -fPIC
101 STRICT_CFLAGS := -Wall
102 STRICT_CFLAGS += -Werror-implicit-function-declaration
103
104 $(lsg_objs) $(liblopsub_objs) $(lopsubex_objs): %.o: %.c
105 lopsubgen.o config_file.o:
106         $(CC) $(CPPFLAGS) $(LLS_CFLAGS) $(CFLAGS) -c -o $@ ${@:.o=.c}
107 lsg1.o: lsg.c lsg.h
108         $(CC) $(CPPFLAGS) $(LLS_CFLAGS) $(STRICT_CFLAGS) $(CFLAGS) -DSTAGE1 -c -o $@ $<
109 %.o: %.c
110         $(CC) -I. $(CPPFLAGS) $(LLS_CFLAGS) $(STRICT_CFLAGS) $(CFLAGS) -c -o $@ $<
111
112 # linking
113 lopsubgen-stage1: $(lsg1_objs)
114         $(CC) -Wall -g $(lsg1_objs) -o $@
115 lopsubgen: $(lsg_objs)
116         $(CC) -Wall -g -o $@ $(lsg_objs)
117 $(REALNAME): $(liblopsub_objs)
118         $(CC) --shared -Wl,-soname,liblopsub.so.$(MAJOR_VERSION) -o $@ $^
119 liblopsub.a: $(liblopsub_objs)
120         $(AR) -rcs $@ $^
121
122 lopsubex: $(lopsubex_objs) $(REALNAME)
123         $(CC) -Wall -g -o $@ $(lopsubex_objs)
124
125 # web
126 html := $(addprefix web/, $(addsuffix .html, \
127         index lopsub-api lopsubgen.1 lopsubex.1 $(m4_man_pages:.gz=)))
128 www: $(html)
129 web/lopsub-api.html: lopsub.h.m4 web/header.html web/footer.html
130         $(M4) -DOUTPUT_MODE=HTML web/header.html $(gendoc) \
131                 $< web/footer.html > $@
132 web/index.html: web/lopsub.7.html
133         $(LN) -s $(notdir $<) $@
134 web/%.html: %.gz web/header.html
135         $(CP) web/header.html $@
136         $(ZCAT) $< | $(GROFF) -m man -Thtml | sed -e '1,/^<body>/d' >> $@
137
138 install: $(all)
139         $(INSTALL) -d $(DESTDIR)$(PREFIX)/lib $(DESTDIR)$(PREFIX)/include \
140                 $(DESTDIR)$(PREFIX)/share/man/man1 $(DESTDIR)$(PREFIX)/share/man/man5 \
141                 $(DESTDIR)$(PREFIX)/share/man/man7 $(DESTDIR)$(PREFIX)/bin
142         $(INSTALL) -m 644 $(REALNAME) $(DESTDIR)$(PREFIX)/lib
143         $(LN) -s $(REALNAME) $(DESTDIR)$(PREFIX)/lib/$(SONAME)
144         $(LN) -s $(SONAME) $(DESTDIR)$(PREFIX)/lib/$(LINKERNAME)
145         $(INSTALL) -m 755 lopsubgen $(DESTDIR)$(PREFIX)/bin
146         $(INSTALL) -m 644 lopsub.h $(DESTDIR)$(PREFIX)/include
147         $(INSTALL) -m 644 lopsub-internal.h $(DESTDIR)$(PREFIX)/include
148         $(INSTALL) -m 644 lopsubgen.1.gz $(DESTDIR)$(PREFIX)/share/man/man1
149         $(INSTALL) -m 644 lopsub-suite.5.gz $(DESTDIR)$(PREFIX)/share/man/man5
150         $(INSTALL) -m 644 lopsub.7.gz $(DESTDIR)$(PREFIX)/share/man/man7
151
152 clean:
153         $(RM) $(all) $(html) *.o *.man
154 distclean: clean
155         $(RM) *.lsg.c *.lsg.h lopsubgen.c config_file.c lopsubgen-stage1 \
156                 lopsub.h lopsub.7 lopsub-suite.5 version.c
157 -include Makefile.local