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 fsck.cmdline.o
11 executables := oslfsck
12 man_pages := oslfsck.1
15 ifeq "$(origin CC)" "default"
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.
29 VERSION := $(x).$(y).$(z)
32 CPPFLAGS += -DVERSION='"$(VERSION)"'
34 CFLAGS += -Wno-sign-compare -g -Wunused -Wundef -W
35 CFLAGS += -Wredundant-decls
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
46 # cflags used only for building library objects
48 LIBCFLAGS += -fvisibility=hidden
50 uname_s := $(shell uname -s 2>/dev/null || echo "UNKNOWN_OS")
54 ifeq ($(uname_s),Linux)
56 LDFLAGS += -Wl,-soname,$(soname)
57 # disallow undefined symbols
58 LDFLAGS += -Wl,-z,defs
60 ifeq ($(uname_s),Darwin)
61 # Darwin has its own idea on version numbers:
62 realname := lib$(libname).$(x).dylib
64 linkername := lib$(libname).dylib
65 # The minor version number is an incremental number using the format
66 # X[.Y[.Z]]. To set the minor version number of a dynamic library, use
67 # the gcc -current_version option.
68 LDFLAGS += -current_version $(y).$(z)
70 # The compatibility version number of a library release specifies the
71 # earliest minor version of the clients linked against that release can
73 LDFLAGS += -compatibility_version $(y).0
74 LDFLAGS += -dynamiclib
76 ifeq ($(uname_s),SunOS)
78 # Solaris needs another set of flags
81 CPPFLAGS += -I/opt/csw/include
85 ifeq ($(uname_s),NetBSD)
87 LDFLAGS += -Wl,-soname,$(soname)
90 ifeq ($(uname_s),FreeBSD)
92 LDFLAGS += -Wl,-soname,$(soname)
96 # On ELf-based systems, the following conventions apply (see dhweeler's
97 # Program Library HOWTO):
99 # The soname has the prefix ``lib'', the name of the library, the
100 # phrase ``.so'', followed by a period and a version number that is
101 # incremented whenever the interface changes.
102 soname := lib$(libname).so.$(x)
104 # The real name adds to the soname a period, a minor number, another
105 # period, and the release number.
106 realname := $(soname).$(y).$(z)
108 # In addition, there's the name that the compiler uses when requesting
109 # a library, (I'll call it the ``linker name''), which is simply the
110 # soname without any version number.
111 linkername := lib$(libname).so
115 all: $(realname) $(executables) $(man_pages)
118 Makefile.deps: $(wildcard *.c *.h)
119 $(CC) -MM -MG *.c > $@
122 -include Makefile.deps
124 fsck.cmdline.o: fsck.cmdline.c fsck.cmdline.h
125 $(CC) $(CPPFLAGS) -c $<
127 %.o: %.c Makefile errtab.h
128 $(CC) -c $(CPPFLAGS) $(CFLAGS) $(LIBCFLAGS) $<
130 fsck.cmdline.h fsck.cmdline.c: fsck.ggo Makefile
133 --unamed-opts=table \
134 --no-handle-version \
135 --file-name=fsck.cmdline \
136 --func-name=fsck_cmdline_parser \
137 --set-package="oslfsck" \
138 --arg-struct-name=fsck_args_info \
141 oslfsck: $(fsck_objects)
142 $(CC) -o $@ $(fsck_objects)
145 help2man -h --detailed-help -N ./$< > $@
147 $(realname): $(objects)
148 $(CC) $(LDFLAGS) -o $@ $(objects)
150 $(libname).sym: osl.h.in
151 sed -Ene '/^int|^const/{s/.*(osl_.*)\(.*/\1/; p;}' $< > $@
152 $(libname).ga: $(objects)
153 $(LD) -r -o $@ $(objects)
154 lib$(libname).a: $(libname).ga $(libname).sym
155 $(OBJCOPY) --keep-global-symbols $(libname).sym $(libname).ga $@
157 osl_errors.h: errlist
158 echo '/** public error codes of the osl library. */' > $@
159 sed -e 's/\([A-Z_]*\) .*/ E_OSL_\1/' \
160 -e '1s/^/enum osl_errors {/1' \
163 -e '$$s/$$/};/1' $< >> $@
166 sed -e 's/^\([A-Z_]*\)\s*\(.*\)/OSL_ERROR(E_OSL_\1, \2)/g' $< > $@
168 osl.h: osl.h.in osl_errors.h Makefile
169 echo '#ifndef _OSL_H' > $@
170 echo '#define _OSL_H' >> $@
171 cat osl.h.in osl_errors.h >> $@
172 echo '#endif /* _OSL_H */' >> $@
174 rm -f *.o $(realname) osl.h osl_errors.h errtab.h fsck.cmdline.h \
175 fsck.cmdline.c oslfsck *.a *.ga *.sym
178 rm -f web/index.html web/oslfsck.1.html web/osl.png
181 install-bin: $(executables)
183 $(INSTALL) -m 755 $(executables) $(bindir)
185 install-man: $(man_pages)
187 $(INSTALL) -m 644 $(man_pages) $(mandir)
189 install-lib: $(realname) $(headers)
190 $(MKDIR) $(libdir) $(includedir)
191 $(RM) $(libdir)/$(linkername)
192 $(LN) -s $(soname) $(libdir)/$(linkername)
193 $(INSTALL) -m 755 $(realname) $(libdir)
194 $(INSTALL) -m 644 $(headers) $(includedir)
196 install: all install-bin install-man install-lib
197 www: web/index.html web/osl.png web/doxygen/index.html
199 .PHONY: all shared clean install install-bin install-man install-lib www
201 web/osl.png: web/osl.pdf Makefile
202 convert -scale 200x200 $< $@
204 web/index.html: oslfsck.1 web/index.html.in INSTALL README
205 sed -e '/@README@/,$$d' web/index.html.in > $@
206 markdown < README >> $@
207 sed -e '1,/@README@/d' -e '/@INSTALL@/,$$d' web/index.html.in >> $@
208 markdown < INSTALL >> $@
209 sed -e '1,/@INSTALL@/d' -e '/@MAN_PAGE@/,$$d' web/index.html.in >> $@
210 groff -m man -Thtml -P -l oslfsck.1 | sed -e '1,/^<body>/d; /^<\/body>/,$$d' >> $@
211 sed -e '1,/@MAN_PAGE@/d' web/index.html.in >> $@
213 web/doxygen/index.html: $(wildcard *.c *.h) web/Doxyfile web/header.html \