]> git.tuebingen.mpg.de Git - osl.git/blob - Makefile
osl-0.2.0.
[osl.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 CC := $(CC)
7 ifeq ($(strip $(CC)),)
8         CC := cc
9 endif
10
11 # where to install
12 PREFIX ?= /usr/local
13 libdir := $(PREFIX)/lib
14 includedir := $(PREFIX)/include
15 bindir := $(PREFIX)/bin
16 mandir := $(PREFIX)/man/man1
17
18 objects := osl.o util.o rbtree.o sha1.o sha3.o sha256.o
19 fsck_objects := fsck.o osl.o util.o rbtree.o sha1.o sha3.o sha256.o oslfsck.lsg.o
20 deps := $(sort $(objects:.o=.d) $(fsck_objects:.o=.d))
21 headers := osl.h
22 executables := oslfsck
23 man_pages := oslfsck.1
24
25 INSTALL := install
26 MKDIR := mkdir -p
27 RM := rm -f
28 LN := ln
29 LD := ld
30 M4 := m4 -g
31 OBJCOPY := objcopy
32
33 # libosl's versioning consists of three numbers. Let's call them x, y and z.
34 x := 0
35 y := 2
36 z := 0
37 VERSION := $(x).$(y).$(z)
38
39 OSL_CPPFLAGS += -DOSL_VERSION='"$(VERSION)"'
40
41 OSL_CFLAGS += -g -Wunused -Wundef -W
42 OSL_CFLAGS += -Wredundant-decls
43 OSL_CFLAGS += -Os
44 OSL_CFLAGS += -Wall
45 OSL_CFLAGS += -Wuninitialized
46 OSL_CFLAGS += -Wchar-subscripts
47 OSL_CFLAGS += -Wformat-security
48 OSL_CFLAGS += -Werror-implicit-function-declaration
49 OSL_CFLAGS += -Wmissing-format-attribute
50 OSL_CFLAGS += -Wunused-macros
51 OSL_CFLAGS += -Wbad-function-cast
52 OSL_CFLAGS += -fPIC
53 OSL_CFLAGS += -fvisibility=hidden
54
55 OSL_LDFLAGS += -Wl,-soname,$(soname)
56 OSL_LDFLAGS += -Wl,-z,defs
57 OSL_LDFLAGS += --shared
58
59 # On ELf-based systems, the following conventions apply (see dhweeler's
60 # Program Library HOWTO):
61 #
62 # The soname has the prefix ``lib'', the name of the library, the
63 # phrase ``.so'', followed by a period and a version number that is
64 # incremented whenever the interface changes.
65 libname := osl
66 soname := lib$(libname).so.$(x)
67
68 # The real name adds to the soname a period, a minor number, another
69 # period, and the release number.
70 realname := $(soname).$(y).$(z)
71
72 # In addition, there's the name that the compiler uses when requesting
73 # a library, (I'll call it the ``linker name''), which is simply the
74 # soname without any version number.
75 linkername := lib$(libname).so
76
77 all: $(realname) $(executables) $(man_pages) $(headers)
78 shared: $(realname)
79
80 ifeq ($(findstring clean, $(MAKECMDGOALS)),)
81 -include $(deps)
82 endif
83
84 # The files to generate before attempting to run the compiler. These
85 # are the order-only prerequisites in the rule below.
86 pre_deps := osl.h errtab.h oslfsck.lsg.h
87
88 # The .d and .o files are both created from a single cc invocation.
89 define CC_CMD
90         $(CC) $(OSL_CPPFLAGS) $(CPPFLAGS) \
91                 -c -MMD -MF $(*F).d -MT $(*F).o \
92                 $(OSL_CFLAGS) $(CFLAGS) $<
93 endef
94 %.o: %.c Makefile | $(pre_deps)
95         $(CC_CMD)
96 %.d: %.c Makefile | $(pre_deps)
97         $(CC_CMD)
98
99 fsck.o: oslfsck.lsg.h
100 oslfsck: $(fsck_objects)
101         $(CC) -o $@ $(fsck_objects) $(LDFLAGS) -llopsub
102
103 .PRECIOUS: %.lsg.h %.lsg.c
104 %.lsg.c: %.suite
105         lopsubgen --gen-c < $<
106
107 %.lsg.h: %.suite
108         lopsubgen --gen-header < $<
109
110 %.1: %.suite
111         lopsubgen --gen-man=$@ < $<
112
113 $(realname): $(objects)
114         $(CC) $(OSL_LDFLAGS) $(LDFLAGS) -o $@ $(objects)
115
116 errtab.h: errlist
117         sed -e 's/^\([A-Z_]*\)\s*\(.*\)/OSL_ERROR(E_OSL_\1, \2)/g' $< > $@
118
119 osl.h: osl.h.m4 errlist Makefile
120         echo '#ifndef _OSL_H' > $@
121         echo '#define _OSL_H' >> $@
122         $(M4) -DOUTPUT_MODE=C gendoc.m4 $< >> $@
123         echo '/** public error codes of the osl library. */' >> $@
124         sed -e 's/\([A-Z_]*\)   .*/     E_OSL_\1/' \
125                 -e '1s/^/enum osl_errors {/1' \
126                 -e '1s/$$/=1/1' \
127                 -e '$$!s/$$/,/g' \
128                 -e '$$s/$$/};/1' errlist >> $@
129         echo '#endif /* _OSL_H */' >> $@
130 clean:
131         rm -f *.o $(realname) osl.h errtab.h oslfsck *.lsg.* *.d
132
133 distclean: clean
134         rm -f web/index.html web/oslfsck.1.html web/osl.png
135
136 install-bin: $(executables)
137         $(MKDIR) $(bindir)
138         $(INSTALL) -m 755 $(executables) $(bindir)
139
140 install-man: $(man_pages)
141         $(MKDIR) $(mandir)
142         $(INSTALL) -m 644 $(man_pages) $(mandir)
143
144 install-lib: $(realname) $(headers)
145         $(MKDIR) $(libdir) $(includedir)
146         $(RM) $(libdir)/$(linkername)
147         $(LN) -s $(soname) $(libdir)/$(linkername)
148         $(INSTALL) -m 755 $(realname) $(libdir)
149         $(INSTALL) -m 644 $(headers) $(includedir)
150
151 install: all install-bin install-man install-lib
152 www: web/index.html web/osl.png web/api.html
153
154 .PHONY: all shared clean install install-bin install-man install-lib www
155
156 web/osl.png: web/osl.pdf Makefile
157         convert -scale 200x200 $< $@
158
159 web/index.html: oslfsck.1 web/header.html web/index.html.in INSTALL README QUICK_START
160         cat web/header.html > $@
161         sed -e '/@README@/,$$d' web/index.html.in >> $@
162         markdown < README >> $@
163         sed -e '1,/@README@/d' -e '/@INSTALL@/,$$d' web/index.html.in >> $@
164         markdown < INSTALL >> $@
165         sed -e '1,/@INSTALL@/d' -e '/@QUICK_START@/,$$d' web/index.html.in >> $@
166         markdown < QUICK_START >> $@
167         sed -e '1,/@QUICK_START@/d' -e '/@MAN_PAGE@/,$$d' web/index.html.in >> $@
168         groff -m man -Thtml -P -l oslfsck.1 | sed -e '1,/^<body>/d; /^<\/body>/,$$d' >> $@
169         sed -e '1,/@MAN_PAGE@/d' web/index.html.in >> $@
170
171 web/api.html: osl.h.m4 web/header.html web/footer.html
172         cat web/header.html > $@
173         $(M4) -DOUTPUT_MODE=HTML gendoc.m4 $< >> $@
174         cat web/footer.html >> $@