]> git.tuebingen.mpg.de Git - osl.git/blob - Makefile
92e66c1e4e10889a68e5ebf517f3b7aa22cedce1
[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 libname := osl
49
50 LDFLAGS += -Wl,-soname,$(soname)
51 # disallow undefined symbols
52 LDFLAGS += -Wl,-z,defs
53
54 # On ELf-based systems, the following conventions apply (see dhweeler's
55 # Program Library HOWTO):
56 #
57 # The soname has the prefix ``lib'', the name of the library, the
58 # phrase ``.so'', followed by a period and a version number that is
59 # incremented whenever the interface changes.
60 soname := lib$(libname).so.$(x)
61
62 # The real name adds to the soname a period, a minor number, another
63 # period, and the release number.
64 realname := $(soname).$(y).$(z)
65
66 # In addition, there's the name that the compiler uses when requesting
67 # a library, (I'll call it the ``linker name''), which is simply the
68 # soname without any version number.
69 linkername := lib$(libname).so
70 LDFLAGS += --shared
71
72 all: $(realname) $(executables) $(man_pages)
73 shared: $(realname)
74
75 ifeq ($(findstring clean, $(MAKECMDGOALS)),)
76 -include $(deps)
77 endif
78 %.o: %.c Makefile errtab.h
79         $(CC) $(CPPFLAGS) -c -MMD -MF $(*F).d -MT $@ $(CFLAGS) $<
80
81 fsck.o: oslfsck.lsg.h
82 oslfsck: $(fsck_objects)
83         $(CC) -o $@ $(fsck_objects) -llopsub
84
85 %.lsg.c: %.suite
86         lopsubgen --gen-c < $<
87
88 %.lsg.h: %.suite
89         lopsubgen --gen-header < $<
90
91 %.1: %.suite
92         lopsubgen --gen-man=$@ < $<
93
94 $(realname): $(objects)
95         $(CC) $(LDFLAGS) -o $@ $(objects)
96
97 $(libname).sym: osl.h.in
98         sed -Ene '/^int|^const/{s/.*(osl_.*)\(.*/\1/; p;}' $< > $@
99 $(libname).ga: $(objects)
100         $(LD) -r -o $@ $(objects)
101 lib$(libname).a: $(libname).ga $(libname).sym
102         $(OBJCOPY) --keep-global-symbols $(libname).sym $(libname).ga $@
103
104 osl_errors.h: errlist
105         echo '/** public error codes of the osl library. */' > $@
106         sed -e 's/\([A-Z_]*\)   .*/     E_OSL_\1/' \
107                 -e '1s/^/enum osl_errors {/1' \
108                 -e '1s/$$/=1/1' \
109                 -e '$$!s/$$/,/g' \
110                 -e '$$s/$$/};/1' $< >> $@
111
112 errtab.h: errlist
113         sed -e 's/^\([A-Z_]*\)\s*\(.*\)/OSL_ERROR(E_OSL_\1, \2)/g' $< > $@
114
115 osl.h: osl.h.in osl_errors.h Makefile
116         echo '#ifndef _OSL_H' > $@
117         echo '#define _OSL_H' >> $@
118         cat osl.h.in osl_errors.h >> $@
119         echo '#endif /* _OSL_H */' >> $@
120 clean:
121         rm -f *.o $(realname) osl.h osl_errors.h errtab.h \
122                 oslfsck *.a *.ga *.sym *.lsg.* *.d
123
124 distclean: clean
125         rm -f web/index.html web/oslfsck.1.html web/osl.png
126         rm -rf web/doxygen
127
128 install-bin: $(executables)
129         $(MKDIR) $(bindir)
130         $(INSTALL) -m 755 $(executables) $(bindir)
131
132 install-man: $(man_pages)
133         $(MKDIR) $(mandir)
134         $(INSTALL) -m 644 $(man_pages) $(mandir)
135
136 install-lib: $(realname) $(headers)
137         $(MKDIR) $(libdir) $(includedir)
138         $(RM) $(libdir)/$(linkername)
139         $(LN) -s $(soname) $(libdir)/$(linkername)
140         $(INSTALL) -m 755 $(realname) $(libdir)
141         $(INSTALL) -m 644 $(headers) $(includedir)
142
143 install: all install-bin install-man install-lib
144 www: web/index.html web/osl.png web/doxygen/index.html
145
146 .PHONY: all shared clean install install-bin install-man install-lib www
147
148 web/osl.png: web/osl.pdf Makefile
149         convert -scale 200x200 $< $@
150
151 web/index.html: oslfsck.1 web/index.html.in INSTALL README
152         sed -e '/@README@/,$$d' web/index.html.in > $@
153         markdown < README >> $@
154         sed -e '1,/@README@/d' -e '/@INSTALL@/,$$d' web/index.html.in >> $@
155         markdown < INSTALL >> $@
156         sed -e '1,/@INSTALL@/d' -e '/@MAN_PAGE@/,$$d' web/index.html.in >> $@
157         groff -m man -Thtml -P -l oslfsck.1 | sed -e '1,/^<body>/d; /^<\/body>/,$$d' >> $@
158         sed -e '1,/@MAN_PAGE@/d' web/index.html.in >> $@
159
160 web/doxygen/index.html: $(wildcard *.c *.h) web/Doxyfile web/header.html \
161                 web/footer.html
162         doxygen web/Doxyfile