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