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