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.
6 ifeq ("$(origin CC)", "default")
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.
31 CC += -ffile-prefix-map=$(CURDIR)=.
33 dummy != $(M4) /dev/null || printf 'failed'
34 ifeq ($(dummy), failed)
35 $(error m4 is required to build this package)
37 dummy != printf '%%%%\n' | $(LEX) -o /dev/null || printf 'failed'
38 ifeq ($(dummy), failed)
39 $(error (f)lex is required to build this package)
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)')
49 DATE := $(shell date '$(DATE_FMT)')
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
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
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
72 gendoc := gendoc/gendoc.m4
74 $(M4) -DOUTPUT_MODE=C $(gendoc) $< > $@
75 $(m4_man_pages): %.gz: %.m4 version.c
76 $(M4) -DGIT_VERSION=$(GIT_VERSION) -DDATE="$(DATE)" $< | $(GZIP) > $@
83 lopsubgen.lsg.c lopsubgen.lsg.h: lopsubgen.suite lopsubgen-stage1 \
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) < $<
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)
100 LLS_CFLAGS := -g -fPIC
101 STRICT_CFLAGS := -Wall
102 STRICT_CFLAGS += -Werror-implicit-function-declaration
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}
108 $(CC) $(CPPFLAGS) $(LLS_CFLAGS) $(STRICT_CFLAGS) $(CFLAGS) -DSTAGE1 -c -o $@ $<
110 $(CC) -I. $(CPPFLAGS) $(LLS_CFLAGS) $(STRICT_CFLAGS) $(CFLAGS) -c -o $@ $<
113 lopsubgen-stage1: $(lsg1_objs)
114 $(CC) -Wall -g $(lsg1_objs) -o $@
115 lopsubgen: $(lsg_objs)
116 $(CC) -Wall -g $(LDFLAGS) -o $@ $(lsg_objs)
117 $(REALNAME): $(liblopsub_objs)
118 $(CC) --shared -Wl,-soname,liblopsub.so.$(MAJOR_VERSION) \
120 liblopsub.a: $(liblopsub_objs)
123 lopsubex: $(lopsubex_objs) $(REALNAME)
124 $(CC) -Wall -g -o $@ $(lopsubex_objs)
127 html := $(addprefix web/, $(addsuffix .html, \
128 index lopsub-api lopsubgen.1 lopsubex.1 $(m4_man_pages:.gz=)))
130 web/lopsub-api.html: lopsub.h.m4 web/header.html web/footer.html
131 $(M4) -DOUTPUT_MODE=HTML web/header.html $(gendoc) \
132 $< web/footer.html > $@
133 web/index.html: web/lopsub.7.html
134 $(LN) -s $(notdir $<) $@
135 web/%.html: %.gz web/header.html
136 $(CP) web/header.html $@
137 $(ZCAT) $< | $(GROFF) -m man -Thtml | sed -e '1,/^<body>/d' >> $@
140 $(INSTALL) -d $(DESTDIR)$(PREFIX)/lib $(DESTDIR)$(PREFIX)/include \
141 $(DESTDIR)$(PREFIX)/share/man/man1 $(DESTDIR)$(PREFIX)/share/man/man5 \
142 $(DESTDIR)$(PREFIX)/share/man/man7 $(DESTDIR)$(PREFIX)/bin
143 $(INSTALL) -m 644 $(REALNAME) $(DESTDIR)$(PREFIX)/lib
144 $(LN) -s $(REALNAME) $(DESTDIR)$(PREFIX)/lib/$(SONAME)
145 $(LN) -s $(SONAME) $(DESTDIR)$(PREFIX)/lib/$(LINKERNAME)
146 $(INSTALL) -m 755 lopsubgen $(DESTDIR)$(PREFIX)/bin
147 $(INSTALL) -m 644 lopsub.h $(DESTDIR)$(PREFIX)/include
148 $(INSTALL) -m 644 lopsub-internal.h $(DESTDIR)$(PREFIX)/include
149 $(INSTALL) -m 644 lopsubgen.1.gz $(DESTDIR)$(PREFIX)/share/man/man1
150 $(INSTALL) -m 644 lopsub-suite.5.gz $(DESTDIR)$(PREFIX)/share/man/man5
151 $(INSTALL) -m 644 lopsub.7.gz $(DESTDIR)$(PREFIX)/share/man/man7
154 $(RM) $(all) $(html) *.o *.man
156 $(RM) *.lsg.c *.lsg.h lopsubgen.c config_file.c lopsubgen-stage1 \
157 lopsub.h lopsub.7 lopsub-suite.5 version.c
158 -include Makefile.local