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