3 libdir := $(PREFIX)/lib
4 includedir := $(PREFIX)/include
5 bindir := $(PREFIX)/bin
6 mandir := $(PREFIX)/man/man1
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))
12 executables := oslfsck
13 man_pages := oslfsck.1
16 ifeq "$(origin CC)" "default"
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.
30 VERSION := $(x).$(y).$(z)
33 CPPFLAGS += -DOSL_VERSION='"$(VERSION)"'
35 CFLAGS += -Wno-sign-compare -g -Wunused -Wundef -W
36 CFLAGS += -Wredundant-decls
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
47 # cflags used only for building library objects
49 LIBCFLAGS += -fvisibility=hidden
51 uname_s := $(shell uname -s 2>/dev/null || echo "UNKNOWN_OS")
55 ifeq ($(uname_s),Linux)
57 LDFLAGS += -Wl,-soname,$(soname)
58 # disallow undefined symbols
59 LDFLAGS += -Wl,-z,defs
61 ifeq ($(uname_s),Darwin)
62 # Darwin has its own idea on version numbers:
63 realname := lib$(libname).$(x).dylib
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)
71 # The compatibility version number of a library release specifies the
72 # earliest minor version of the clients linked against that release can
74 LDFLAGS += -compatibility_version $(y).0
75 LDFLAGS += -dynamiclib
77 ifeq ($(uname_s),SunOS)
79 # Solaris needs another set of flags
82 CPPFLAGS += -I/opt/csw/include
86 ifeq ($(uname_s),NetBSD)
88 LDFLAGS += -Wl,-soname,$(soname)
91 ifeq ($(uname_s),FreeBSD)
93 LDFLAGS += -Wl,-soname,$(soname)
97 # On ELf-based systems, the following conventions apply (see dhweeler's
98 # Program Library HOWTO):
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)
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)
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
116 all: $(realname) $(executables) $(man_pages)
119 ifeq ($(findstring clean, $(MAKECMDGOALS)),)
122 %.o: %.c Makefile errtab.h
123 $(CC) $(CPPFLAGS) -c -MMD -MF $(*F).d -MT $@ $(CFLAGS) $(LIBCFLAGS) $<
125 fsck.o: oslfsck.lsg.h
126 oslfsck: $(fsck_objects)
127 $(CC) -o $@ $(fsck_objects) -llopsub
130 lopsubgen --gen-c < $<
133 lopsubgen --gen-header < $<
136 lopsubgen --gen-man=$@ < $<
138 $(realname): $(objects)
139 $(CC) $(LDFLAGS) -o $@ $(objects)
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 $@
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' \
154 -e '$$s/$$/};/1' $< >> $@
157 sed -e 's/^\([A-Z_]*\)\s*\(.*\)/OSL_ERROR(E_OSL_\1, \2)/g' $< > $@
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 */' >> $@
165 rm -f *.o $(realname) osl.h osl_errors.h errtab.h \
166 oslfsck *.a *.ga *.sym *.lsg.* *.d
169 rm -f web/index.html web/oslfsck.1.html web/osl.png
172 install-bin: $(executables)
174 $(INSTALL) -m 755 $(executables) $(bindir)
176 install-man: $(man_pages)
178 $(INSTALL) -m 644 $(man_pages) $(mandir)
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)
187 install: all install-bin install-man install-lib
188 www: web/index.html web/osl.png web/doxygen/index.html
190 .PHONY: all shared clean install install-bin install-man install-lib www
192 web/osl.png: web/osl.pdf Makefile
193 convert -scale 200x200 $< $@
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 >> $@
204 web/doxygen/index.html: $(wildcard *.c *.h) web/Doxyfile web/header.html \