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