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.
29 VERSION := $(x).$(y).$(z)
32 CPPFLAGS += -DOSL_VERSION='"$(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
52 ifeq ($(uname_s),Linux)
54 LDFLAGS += -Wl,-soname,$(soname)
55 # disallow undefined symbols
56 LDFLAGS += -Wl,-z,defs
58 ifeq ($(uname_s),NetBSD)
60 LDFLAGS += -Wl,-soname,$(soname)
63 ifeq ($(uname_s),FreeBSD)
65 LDFLAGS += -Wl,-soname,$(soname)
69 # On ELf-based systems, the following conventions apply (see dhweeler's
70 # Program Library HOWTO):
72 # The soname has the prefix ``lib'', the name of the library, the
73 # phrase ``.so'', followed by a period and a version number that is
74 # incremented whenever the interface changes.
75 soname := lib$(libname).so.$(x)
77 # The real name adds to the soname a period, a minor number, another
78 # period, and the release number.
79 realname := $(soname).$(y).$(z)
81 # In addition, there's the name that the compiler uses when requesting
82 # a library, (I'll call it the ``linker name''), which is simply the
83 # soname without any version number.
84 linkername := lib$(libname).so
88 all: $(realname) $(executables) $(man_pages)
91 ifeq ($(findstring clean, $(MAKECMDGOALS)),)
94 %.o: %.c Makefile errtab.h
95 $(CC) $(CPPFLAGS) -c -MMD -MF $(*F).d -MT $@ $(CFLAGS) $(LIBCFLAGS) $<
98 oslfsck: $(fsck_objects)
99 $(CC) -o $@ $(fsck_objects) -llopsub
102 lopsubgen --gen-c < $<
105 lopsubgen --gen-header < $<
108 lopsubgen --gen-man=$@ < $<
110 $(realname): $(objects)
111 $(CC) $(LDFLAGS) -o $@ $(objects)
113 $(libname).sym: osl.h.in
114 sed -Ene '/^int|^const/{s/.*(osl_.*)\(.*/\1/; p;}' $< > $@
115 $(libname).ga: $(objects)
116 $(LD) -r -o $@ $(objects)
117 lib$(libname).a: $(libname).ga $(libname).sym
118 $(OBJCOPY) --keep-global-symbols $(libname).sym $(libname).ga $@
120 osl_errors.h: errlist
121 echo '/** public error codes of the osl library. */' > $@
122 sed -e 's/\([A-Z_]*\) .*/ E_OSL_\1/' \
123 -e '1s/^/enum osl_errors {/1' \
126 -e '$$s/$$/};/1' $< >> $@
129 sed -e 's/^\([A-Z_]*\)\s*\(.*\)/OSL_ERROR(E_OSL_\1, \2)/g' $< > $@
131 osl.h: osl.h.in osl_errors.h Makefile
132 echo '#ifndef _OSL_H' > $@
133 echo '#define _OSL_H' >> $@
134 cat osl.h.in osl_errors.h >> $@
135 echo '#endif /* _OSL_H */' >> $@
137 rm -f *.o $(realname) osl.h osl_errors.h errtab.h \
138 oslfsck *.a *.ga *.sym *.lsg.* *.d
141 rm -f web/index.html web/oslfsck.1.html web/osl.png
144 install-bin: $(executables)
146 $(INSTALL) -m 755 $(executables) $(bindir)
148 install-man: $(man_pages)
150 $(INSTALL) -m 644 $(man_pages) $(mandir)
152 install-lib: $(realname) $(headers)
153 $(MKDIR) $(libdir) $(includedir)
154 $(RM) $(libdir)/$(linkername)
155 $(LN) -s $(soname) $(libdir)/$(linkername)
156 $(INSTALL) -m 755 $(realname) $(libdir)
157 $(INSTALL) -m 644 $(headers) $(includedir)
159 install: all install-bin install-man install-lib
160 www: web/index.html web/osl.png web/doxygen/index.html
162 .PHONY: all shared clean install install-bin install-man install-lib www
164 web/osl.png: web/osl.pdf Makefile
165 convert -scale 200x200 $< $@
167 web/index.html: oslfsck.1 web/index.html.in INSTALL README
168 sed -e '/@README@/,$$d' web/index.html.in > $@
169 markdown < README >> $@
170 sed -e '1,/@README@/d' -e '/@INSTALL@/,$$d' web/index.html.in >> $@
171 markdown < INSTALL >> $@
172 sed -e '1,/@INSTALL@/d' -e '/@MAN_PAGE@/,$$d' web/index.html.in >> $@
173 groff -m man -Thtml -P -l oslfsck.1 | sed -e '1,/^<body>/d; /^<\/body>/,$$d' >> $@
174 sed -e '1,/@MAN_PAGE@/d' web/index.html.in >> $@
176 web/doxygen/index.html: $(wildcard *.c *.h) web/Doxyfile web/header.html \