]> git.tuebingen.mpg.de Git - osl.git/blob - Makefile
c52eaea2477e7fb76b32d5638ddb59b39234f5a5
[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 := gcc
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 # The way x, y and z are interpreted depends on the OS.
27 x := 0
28 y := 1
29 z := 3
30 VERSION := $(x).$(y).$(z)
31
32 # common flags
33 CPPFLAGS += -DOSL_VERSION='"$(VERSION)"'
34
35 CFLAGS += -Wno-sign-compare -g -Wunused -Wundef -W
36 CFLAGS += -Wredundant-decls
37 CFLAGS += -Os
38 CFLAGS += -Wall
39 CFLAGS += -Wuninitialized
40 CFLAGS += -Wchar-subscripts
41 CFLAGS += -Wformat-security
42 CFLAGS += -Werror-implicit-function-declaration
43 CFLAGS += -Wmissing-format-attribute
44 CFLAGS += -Wunused-macros
45 CFLAGS += -Wbad-function-cast
46
47 # cflags used only for building library objects
48 LIBCFLAGS += -fPIC
49 LIBCFLAGS += -fvisibility=hidden
50
51 uname_s := $(shell uname -s 2>/dev/null || echo "UNKNOWN_OS")
52
53 libname := osl
54
55 ifeq ($(uname_s),Linux)
56         format := elf
57         LDFLAGS += -Wl,-soname,$(soname)
58         # disallow undefined symbols
59         LDFLAGS += -Wl,-z,defs
60 endif
61 ifeq ($(uname_s),Darwin)
62         # Darwin has its own idea on version numbers:
63         realname := lib$(libname).$(x).dylib
64         soname := $(realname)
65         linkername := lib$(libname).dylib
66         # The minor version number is an incremental number using the format
67         # X[.Y[.Z]]. To set the minor version number of a dynamic library, use
68         # the gcc -current_version option.
69         LDFLAGS += -current_version $(y).$(z)
70         #
71         # The compatibility version number of a library release specifies the
72         # earliest minor version of the clients linked against that release can
73         # use.
74         LDFLAGS += -compatibility_version $(y).0
75         LDFLAGS += -dynamiclib
76 endif
77 ifeq ($(uname_s),SunOS)
78         format := elf
79         # Solaris needs another set of flags
80         LDFLAGS += -z text
81         LDFLAGS += -z defs
82         CPPFLAGS += -I/opt/csw/include
83         LDFLAGS += -lc
84 endif
85
86 ifeq ($(uname_s),NetBSD)
87         format := elf
88         LDFLAGS += -Wl,-soname,$(soname)
89 endif
90
91 ifeq ($(uname_s),FreeBSD)
92         format := elf
93         LDFLAGS += -Wl,-soname,$(soname)
94 endif
95
96 ifeq ($(format),elf)
97         # On ELf-based systems, the following conventions apply (see dhweeler's
98         # Program Library HOWTO):
99         #
100         # The soname has the prefix ``lib'', the name of the library, the
101         # phrase ``.so'', followed by a period and a version number that is
102         # incremented whenever the interface changes.
103         soname := lib$(libname).so.$(x)
104
105         # The real name adds to the soname a period, a minor number, another
106         # period, and the release number.
107         realname := $(soname).$(y).$(z)
108
109         # In addition, there's the name that the compiler uses when requesting
110         # a library, (I'll call it the ``linker name''), which is simply the
111         # soname without any version number.
112         linkername := lib$(libname).so
113         LDFLAGS += --shared
114 endif
115
116 all: $(realname) $(executables) $(man_pages)
117 shared: $(realname)
118
119 ifeq ($(findstring clean, $(MAKECMDGOALS)),)
120 -include $(deps)
121 endif
122 %.o: %.c Makefile errtab.h
123         $(CC) $(CPPFLAGS) -c -MMD -MF $(*F).d -MT $@ $(CFLAGS) $(LIBCFLAGS) $<
124
125 fsck.o: oslfsck.lsg.h
126 oslfsck: $(fsck_objects)
127         $(CC) -o $@ $(fsck_objects) -llopsub
128
129 %.lsg.c: %.suite
130         lopsubgen --gen-c < $<
131
132 %.lsg.h: %.suite
133         lopsubgen --gen-header < $<
134
135 %.1: %.suite
136         lopsubgen --gen-man=$@ < $<
137
138 $(realname): $(objects)
139         $(CC) $(LDFLAGS) -o $@ $(objects)
140
141 $(libname).sym: osl.h.in
142         sed -Ene '/^int|^const/{s/.*(osl_.*)\(.*/\1/; p;}' $< > $@
143 $(libname).ga: $(objects)
144         $(LD) -r -o $@ $(objects)
145 lib$(libname).a: $(libname).ga $(libname).sym
146         $(OBJCOPY) --keep-global-symbols $(libname).sym $(libname).ga $@
147
148 osl_errors.h: errlist
149         echo '/** public error codes of the osl library. */' > $@
150         sed -e 's/\([A-Z_]*\)   .*/     E_OSL_\1/' \
151                 -e '1s/^/enum osl_errors {/1' \
152                 -e '1s/$$/=1/1' \
153                 -e '$$!s/$$/,/g' \
154                 -e '$$s/$$/};/1' $< >> $@
155
156 errtab.h: errlist
157         sed -e 's/^\([A-Z_]*\)\s*\(.*\)/OSL_ERROR(E_OSL_\1, \2)/g' $< > $@
158
159 osl.h: osl.h.in osl_errors.h Makefile
160         echo '#ifndef _OSL_H' > $@
161         echo '#define _OSL_H' >> $@
162         cat osl.h.in osl_errors.h >> $@
163         echo '#endif /* _OSL_H */' >> $@
164 clean:
165         rm -f *.o $(realname) osl.h osl_errors.h errtab.h \
166                 oslfsck *.a *.ga *.sym *.lsg.* *.d
167
168 distclean: clean
169         rm -f web/index.html web/oslfsck.1.html web/osl.png
170         rm -rf web/doxygen
171
172 install-bin: $(executables)
173         $(MKDIR) $(bindir)
174         $(INSTALL) -m 755 $(executables) $(bindir)
175
176 install-man: $(man_pages)
177         $(MKDIR) $(mandir)
178         $(INSTALL) -m 644 $(man_pages) $(mandir)
179
180 install-lib: $(realname) $(headers)
181         $(MKDIR) $(libdir) $(includedir)
182         $(RM) $(libdir)/$(linkername)
183         $(LN) -s $(soname) $(libdir)/$(linkername)
184         $(INSTALL) -m 755 $(realname) $(libdir)
185         $(INSTALL) -m 644 $(headers) $(includedir)
186
187 install: all install-bin install-man install-lib
188 www: web/index.html web/osl.png web/doxygen/index.html
189
190 .PHONY: all shared clean install install-bin install-man install-lib www
191
192 web/osl.png: web/osl.pdf Makefile
193         convert -scale 200x200 $< $@
194
195 web/index.html: oslfsck.1 web/index.html.in INSTALL README
196         sed -e '/@README@/,$$d' web/index.html.in > $@
197         markdown < README >> $@
198         sed -e '1,/@README@/d' -e '/@INSTALL@/,$$d' web/index.html.in >> $@
199         markdown < INSTALL >> $@
200         sed -e '1,/@INSTALL@/d' -e '/@MAN_PAGE@/,$$d' web/index.html.in >> $@
201         groff -m man -Thtml -P -l oslfsck.1 | sed -e '1,/^<body>/d; /^<\/body>/,$$d' >> $@
202         sed -e '1,/@MAN_PAGE@/d' web/index.html.in >> $@
203
204 web/doxygen/index.html: $(wildcard *.c *.h) web/Doxyfile web/header.html \
205                 web/footer.html
206         doxygen web/Doxyfile