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")
47 uname_rs := $(shell uname -rs)
51 ifeq ($(uname_s),Linux)
53 LDFLAGS += -Wl,-soname,$(soname)
54 # disallow undefined symbols
55 LDFLAGS += -Wl,-z,defs
57 ifeq ($(uname_s),Darwin)
58 # Darwin has its own idea on version numbers:
59 realname := lib$(libname).$(x).dylib
61 linkername := lib$(libname).dylib
62 # The minor version number is an incremental number using the format
63 # X[.Y[.Z]]. To set the minor version number of a dynamic library, use
64 # the gcc -current_version option.
65 LDFLAGS += -current_version $(y).$(z)
67 # The compatibility version number of a library release specifies the
68 # earliest minor version of the clients linked against that release can
70 LDFLAGS += -compatibility_version $(y).0
71 LDFLAGS += -dynamiclib
73 ifeq ($(uname_s),SunOS)
75 # Solaris needs another set of flags
78 CPPFLAGS += -I/opt/csw/include
82 ifeq ($(uname_s),NetBSD)
84 LDFLAGS += -Wl,-soname,$(soname)
87 ifeq ($(uname_s),FreeBSD)
89 LDFLAGS += -Wl,-soname,$(soname)
93 # On ELf-based systems, the following conventions apply (see dhweeler's
94 # Program Library HOWTO):
96 # The soname has the prefix ``lib'', the name of the library, the
97 # phrase ``.so'', followed by a period and a version number that is
98 # incremented whenever the interface changes.
99 soname := lib$(libname).so.$(x)
101 # The real name adds to the soname a period, a minor number, another
102 # period, and the release number.
103 realname := $(soname).$(y).$(z)
105 # In addition, there's the name that the compiler uses when requesting
106 # a library, (I'll call it the ``linker name''), which is simply the
107 # soname without any version number.
108 linkername := lib$(libname).so
112 all: $(realname) $(executables) $(man_pages)
113 Makefile.deps: $(wildcard *.c *.h)
114 $(CC) -MM -MG *.c > $@
117 -include Makefile.deps
119 fsck.cmdline.o: fsck.cmdline.c fsck.cmdline.h
120 $(CC) -c -DVERSION='"$(VERSION)"' $<
122 %.fsck.o: %.c Makefile fsck.cmdline.c fsck.cmdline.h osl.h errtab.h
123 $(CC) -c -DVERSION='"$(VERSION)"' $(CPPFLAGS) $(CFLAGS) $< -o $@
125 %.o: %.c Makefile errtab.h
126 $(CC) -c $(CPPFLAGS) $(CFLAGS) $(LIBCFLAGS) $<
128 fsck.cmdline.h fsck.cmdline.c: fsck.ggo Makefile
131 --unamed-opts=table \
132 --no-handle-version \
133 --file-name=fsck.cmdline \
134 --func-name=fsck_cmdline_parser \
135 --set-package="oslfsck" \
136 --arg-struct-name=fsck_args_info \
139 oslfsck: $(fsck_objects)
140 $(CC) -o $@ $(fsck_objects) -lcrypto
143 help2man -h --detailed-help -N ./$< > $@
145 $(realname): $(objects)
146 $(CC) $(LDFLAGS) -o $@ $(objects) -lcrypto
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 fsck.cmdline.h \
166 fsck.cmdline.c oslfsck
169 rm -f web/index.html web/oslfsck.1.html web/osl.png
173 $(MKDIR) $(libdir) $(includedir) $(mandir) $(bindir)
174 $(RM) $(libdir)/$(linkername)
175 $(LN) -s $(libdir)/$(soname) $(libdir)/$(linkername)
176 $(INSTALL) -m 755 $(realname) $(libdir)
177 $(INSTALL) -m 644 $(headers) $(includedir)
178 $(INSTALL) -m 755 $(executables) $(bindir)
179 $(INSTALL) -m 644 $(man_pages) $(mandir)
181 .PHONY: all clean install
186 web/osl.png: web/osl.pdf Makefile
187 convert -scale 200x200 $< $@
189 web/index.html: web/oslfsck.1.html web/index.html.in INSTALL README
190 sed -e '/@README@/,$$d' web/index.html.in > $@
191 grutatxt -nb < README >> $@
192 sed -e '1,/@README@/d' -e '/@INSTALL@/,$$d' web/index.html.in >> $@
193 grutatxt -nb < INSTALL >> $@
194 sed -e '1,/@INSTALL@/d' -e '/@MAN_PAGE@/,$$d' web/index.html.in >> $@
195 sed -e '1,/Return to Main Contents/d' -e '/Index/,$$d' web/oslfsck.1.html >> $@
196 sed -e '1,/@MAN_PAGE@/d' web/index.html.in >> $@