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