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 LDFLAGS += -Wl,-soname,$(soname)
53 # disallow undefined symbols
54 LDFLAGS += -Wl,-z,defs
56 # On ELf-based systems, the following conventions apply (see dhweeler's
57 # Program Library HOWTO):
59 # The soname has the prefix ``lib'', the name of the library, the
60 # phrase ``.so'', followed by a period and a version number that is
61 # incremented whenever the interface changes.
62 soname := lib$(libname).so.$(x)
64 # The real name adds to the soname a period, a minor number, another
65 # period, and the release number.
66 realname := $(soname).$(y).$(z)
68 # In addition, there's the name that the compiler uses when requesting
69 # a library, (I'll call it the ``linker name''), which is simply the
70 # soname without any version number.
71 linkername := lib$(libname).so
74 all: $(realname) $(executables) $(man_pages)
77 ifeq ($(findstring clean, $(MAKECMDGOALS)),)
80 %.o: %.c Makefile errtab.h
81 $(CC) $(CPPFLAGS) -c -MMD -MF $(*F).d -MT $@ $(CFLAGS) $(LIBCFLAGS) $<
84 oslfsck: $(fsck_objects)
85 $(CC) -o $@ $(fsck_objects) -llopsub
88 lopsubgen --gen-c < $<
91 lopsubgen --gen-header < $<
94 lopsubgen --gen-man=$@ < $<
96 $(realname): $(objects)
97 $(CC) $(LDFLAGS) -o $@ $(objects)
99 $(libname).sym: osl.h.in
100 sed -Ene '/^int|^const/{s/.*(osl_.*)\(.*/\1/; p;}' $< > $@
101 $(libname).ga: $(objects)
102 $(LD) -r -o $@ $(objects)
103 lib$(libname).a: $(libname).ga $(libname).sym
104 $(OBJCOPY) --keep-global-symbols $(libname).sym $(libname).ga $@
106 osl_errors.h: errlist
107 echo '/** public error codes of the osl library. */' > $@
108 sed -e 's/\([A-Z_]*\) .*/ E_OSL_\1/' \
109 -e '1s/^/enum osl_errors {/1' \
112 -e '$$s/$$/};/1' $< >> $@
115 sed -e 's/^\([A-Z_]*\)\s*\(.*\)/OSL_ERROR(E_OSL_\1, \2)/g' $< > $@
117 osl.h: osl.h.in osl_errors.h Makefile
118 echo '#ifndef _OSL_H' > $@
119 echo '#define _OSL_H' >> $@
120 cat osl.h.in osl_errors.h >> $@
121 echo '#endif /* _OSL_H */' >> $@
123 rm -f *.o $(realname) osl.h osl_errors.h errtab.h \
124 oslfsck *.a *.ga *.sym *.lsg.* *.d
127 rm -f web/index.html web/oslfsck.1.html web/osl.png
130 install-bin: $(executables)
132 $(INSTALL) -m 755 $(executables) $(bindir)
134 install-man: $(man_pages)
136 $(INSTALL) -m 644 $(man_pages) $(mandir)
138 install-lib: $(realname) $(headers)
139 $(MKDIR) $(libdir) $(includedir)
140 $(RM) $(libdir)/$(linkername)
141 $(LN) -s $(soname) $(libdir)/$(linkername)
142 $(INSTALL) -m 755 $(realname) $(libdir)
143 $(INSTALL) -m 644 $(headers) $(includedir)
145 install: all install-bin install-man install-lib
146 www: web/index.html web/osl.png web/doxygen/index.html
148 .PHONY: all shared clean install install-bin install-man install-lib www
150 web/osl.png: web/osl.pdf Makefile
151 convert -scale 200x200 $< $@
153 web/index.html: oslfsck.1 web/index.html.in INSTALL README
154 sed -e '/@README@/,$$d' web/index.html.in > $@
155 markdown < README >> $@
156 sed -e '1,/@README@/d' -e '/@INSTALL@/,$$d' web/index.html.in >> $@
157 markdown < INSTALL >> $@
158 sed -e '1,/@INSTALL@/d' -e '/@MAN_PAGE@/,$$d' web/index.html.in >> $@
159 groff -m man -Thtml -P -l oslfsck.1 | sed -e '1,/^<body>/d; /^<\/body>/,$$d' >> $@
160 sed -e '1,/@MAN_PAGE@/d' web/index.html.in >> $@
162 web/doxygen/index.html: $(wildcard *.c *.h) web/Doxyfile web/header.html \