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