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.fsck.o osl.fsck.o util.fsck.o rbtree.fsck.o sha1.fsck.o fsck.cmdline.o
11 executables := oslfsck
12 man_pages := oslfsck.1
15 ifeq "$(origin CC)" "default"
22 # libosl's versioning consists of three numbers. Let's call them x, y and z.
23 # The way x, y and z are interpreted depends on the OS.
27 VERSION := $(x).$(y).$(z)
30 CFLAGS += -Wno-sign-compare -g -Wunused -Wundef -W
31 CFLAGS += -Wredundant-decls
34 CFLAGS += -Wuninitialized
35 CFLAGS += -Wchar-subscripts
36 CFLAGS += -Wformat-security
37 CFLAGS += -Werror-implicit-function-declaration
38 CFLAGS += -Wmissing-format-attribute
39 CFLAGS += -Wunused-macros
40 CFLAGS += -Wbad-function-cast
42 # cflags used only for building library objects
44 LIBCFLAGS += -fvisibility=hidden
46 uname_s := $(shell uname -s 2>/dev/null || echo "UNKNOWN_OS")
50 ifeq ($(uname_s),Linux)
52 LDFLAGS += -Wl,-soname,$(soname)
53 # disallow undefined symbols
54 LDFLAGS += -Wl,-z,defs
56 ifeq ($(uname_s),Darwin)
57 # Darwin has its own idea on version numbers:
58 realname := lib$(libname).$(x).dylib
60 linkername := lib$(libname).dylib
61 # The minor version number is an incremental number using the format
62 # X[.Y[.Z]]. To set the minor version number of a dynamic library, use
63 # the gcc -current_version option.
64 LDFLAGS += -current_version $(y).$(z)
66 # The compatibility version number of a library release specifies the
67 # earliest minor version of the clients linked against that release can
69 LDFLAGS += -compatibility_version $(y).0
70 LDFLAGS += -dynamiclib
72 ifeq ($(uname_s),SunOS)
74 # Solaris needs another set of flags
77 CPPFLAGS += -I/opt/csw/include
81 ifeq ($(uname_s),NetBSD)
83 LDFLAGS += -Wl,-soname,$(soname)
86 ifeq ($(uname_s),FreeBSD)
88 LDFLAGS += -Wl,-soname,$(soname)
92 # On ELf-based systems, the following conventions apply (see dhweeler's
93 # Program Library HOWTO):
95 # The soname has the prefix ``lib'', the name of the library, the
96 # phrase ``.so'', followed by a period and a version number that is
97 # incremented whenever the interface changes.
98 soname := lib$(libname).so.$(x)
100 # The real name adds to the soname a period, a minor number, another
101 # period, and the release number.
102 realname := $(soname).$(y).$(z)
104 # In addition, there's the name that the compiler uses when requesting
105 # a library, (I'll call it the ``linker name''), which is simply the
106 # soname without any version number.
107 linkername := lib$(libname).so
111 all: $(realname) $(executables) $(man_pages)
112 Makefile.deps: $(wildcard *.c *.h)
113 $(CC) -MM -MG *.c > $@
116 -include Makefile.deps
118 fsck.cmdline.o: fsck.cmdline.c fsck.cmdline.h
119 $(CC) -c -DVERSION='"$(VERSION)"' $<
121 %.fsck.o: %.c Makefile fsck.cmdline.c fsck.cmdline.h osl.h errtab.h
122 $(CC) -c -DVERSION='"$(VERSION)"' $(CPPFLAGS) $(CFLAGS) $< -o $@
124 %.o: %.c Makefile errtab.h
125 $(CC) -c $(CPPFLAGS) $(CFLAGS) $(LIBCFLAGS) $<
127 fsck.cmdline.h fsck.cmdline.c: fsck.ggo Makefile
130 --unamed-opts=table \
131 --no-handle-version \
132 --file-name=fsck.cmdline \
133 --func-name=fsck_cmdline_parser \
134 --set-package="oslfsck" \
135 --arg-struct-name=fsck_args_info \
138 oslfsck: $(fsck_objects)
139 $(CC) -o $@ $(fsck_objects)
142 help2man -h --detailed-help -N ./$< > $@
144 $(realname): $(objects)
145 $(CC) $(LDFLAGS) -o $@ $(objects)
147 osl_errors.h: errlist
148 echo '/** public error codes of the osl library. */' > $@
149 sed -e 's/\([A-Z_]*\) .*/ E_OSL_\1/' \
150 -e '1s/^/enum osl_errors {/1' \
153 -e '$$s/$$/};/1' $< >> $@
156 sed -e 's/^\([A-Z_]*\)\s*\(.*\)/OSL_ERROR(E_OSL_\1, \2)/g' $< > $@
158 osl.h: osl.h.in osl_errors.h Makefile
159 echo '#ifndef _OSL_H' > $@
160 echo '#define _OSL_H' >> $@
161 cat osl.h.in osl_errors.h >> $@
162 echo '#endif /* _OSL_H */' >> $@
164 rm -f *.o $(realname) osl.h osl_errors.h errtab.h fsck.cmdline.h \
165 fsck.cmdline.c oslfsck
168 rm -f web/index.html web/oslfsck.1.html web/osl.png
171 install-bin: $(executables)
173 $(INSTALL) -m 755 $(executables) $(bindir)
175 install-man: $(man_pages)
177 $(INSTALL) -m 644 $(man_pages) $(mandir)
179 install-lib: $(realname) $(headers)
180 $(MKDIR) $(libdir) $(includedir)
181 $(RM) $(libdir)/$(linkername)
182 $(LN) -s $(libdir)/$(soname) $(libdir)/$(linkername)
183 $(INSTALL) -m 755 $(realname) $(libdir)
184 $(INSTALL) -m 644 $(headers) $(includedir)
186 install: all install-bin install-man install-lib
188 .PHONY: all clean install install-bin install-man install-lib
193 web/osl.png: web/osl.pdf Makefile
194 convert -scale 200x200 $< $@
196 web/index.html: web/oslfsck.1.html web/index.html.in INSTALL README
197 sed -e '/@README@/,$$d' web/index.html.in > $@
198 grutatxt -nb < README >> $@
199 sed -e '1,/@README@/d' -e '/@INSTALL@/,$$d' web/index.html.in >> $@
200 grutatxt -nb < INSTALL >> $@
201 sed -e '1,/@INSTALL@/d' -e '/@MAN_PAGE@/,$$d' web/index.html.in >> $@
202 sed -e '1,/Return to Main Contents/d' -e '/Index/,$$d' web/oslfsck.1.html >> $@
203 sed -e '1,/@MAN_PAGE@/d' web/index.html.in >> $@