1 # Implicit rules are implemented in make as suffix rules. The following rule
2 # empties the suffix list to disable the predefined implicit rules. This
3 # increases performance and avoids hard-to-debug behaviour.
6 ifeq ("$(origin CC)", "default")
12 libdir := $(PREFIX)/lib
13 includedir := $(PREFIX)/include
14 bindir := $(PREFIX)/bin
15 mandir := $(PREFIX)/man/man1
17 objects := osl.o util.o rbtree.o sha1.o
18 fsck_objects := fsck.o osl.o util.o rbtree.o sha1.o oslfsck.lsg.o
19 deps := $(sort $(objects:.o=.d) $(fsck_objects:.o=.d))
21 executables := oslfsck
22 man_pages := oslfsck.1
25 ifeq "$(origin CC)" "default"
35 # libosl's versioning consists of three numbers. Let's call them x, y and z.
39 VERSION := $(x).$(y).$(z)
41 OSL_CPPFLAGS += -DOSL_VERSION='"$(VERSION)"'
43 OSL_CFLAGS += -g -Wunused -Wundef -W
44 OSL_CFLAGS += -Wredundant-decls
47 OSL_CFLAGS += -Wuninitialized
48 OSL_CFLAGS += -Wchar-subscripts
49 OSL_CFLAGS += -Wformat-security
50 OSL_CFLAGS += -Werror-implicit-function-declaration
51 OSL_CFLAGS += -Wmissing-format-attribute
52 OSL_CFLAGS += -Wunused-macros
53 OSL_CFLAGS += -Wbad-function-cast
55 OSL_CFLAGS += -fvisibility=hidden
57 OSL_LDFLAGS += -Wl,-soname,$(soname)
58 OSL_LDFLAGS += -Wl,-z,defs
59 OSL_LDFLAGS += --shared
61 # On ELf-based systems, the following conventions apply (see dhweeler's
62 # Program Library HOWTO):
64 # The soname has the prefix ``lib'', the name of the library, the
65 # phrase ``.so'', followed by a period and a version number that is
66 # incremented whenever the interface changes.
68 soname := lib$(libname).so.$(x)
70 # The real name adds to the soname a period, a minor number, another
71 # period, and the release number.
72 realname := $(soname).$(y).$(z)
74 # In addition, there's the name that the compiler uses when requesting
75 # a library, (I'll call it the ``linker name''), which is simply the
76 # soname without any version number.
77 linkername := lib$(libname).so
79 all: $(realname) $(executables) $(man_pages) $(headers)
82 ifeq ($(findstring clean, $(MAKECMDGOALS)),)
86 # List osl.h in the prerequisites to make sure we generate it before attempting
87 # to run the compiler. This matters only when the .d file does not exist.
88 %.o: %.c osl.h Makefile errtab.h
89 $(CC) $(OSL_CPPFLAGS) $(CPPFLAGS) \
90 -c -MMD -MF $(*F).d -MT $@ \
91 $(OSL_CFLAGS) $(CFLAGS) $<
94 oslfsck: $(fsck_objects)
95 $(CC) -o $@ $(fsck_objects) $(LDFLAGS) -llopsub
97 .PRECIOUS: %.lsg.h %.lsg.c
99 lopsubgen --gen-c < $<
102 lopsubgen --gen-header < $<
105 lopsubgen --gen-man=$@ < $<
107 $(realname): $(objects)
108 $(CC) $(OSL_LDFLAGS) $(LDFLAGS) -o $@ $(objects)
111 sed -e 's/^\([A-Z_]*\)\s*\(.*\)/OSL_ERROR(E_OSL_\1, \2)/g' $< > $@
113 osl.h: osl.h.m4 errlist Makefile
114 echo '#ifndef _OSL_H' > $@
115 echo '#define _OSL_H' >> $@
116 $(M4) -DOUTPUT_MODE=C gendoc.m4 $< >> $@
117 echo '/** public error codes of the osl library. */' >> $@
118 sed -e 's/\([A-Z_]*\) .*/ E_OSL_\1/' \
119 -e '1s/^/enum osl_errors {/1' \
122 -e '$$s/$$/};/1' errlist >> $@
123 echo '#endif /* _OSL_H */' >> $@
125 rm -f *.o $(realname) osl.h errtab.h oslfsck *.lsg.* *.d
128 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/api.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/header.html web/index.html.in INSTALL README QUICK_START
154 cat web/header.html > $@
155 sed -e '/@README@/,$$d' web/index.html.in >> $@
156 markdown < README >> $@
157 sed -e '1,/@README@/d' -e '/@INSTALL@/,$$d' web/index.html.in >> $@
158 markdown < INSTALL >> $@
159 sed -e '1,/@INSTALL@/d' -e '/@QUICK_START@/,$$d' web/index.html.in >> $@
160 markdown < QUICK_START >> $@
161 sed -e '1,/@QUICK_START@/d' -e '/@MAN_PAGE@/,$$d' web/index.html.in >> $@
162 groff -m man -Thtml -P -l oslfsck.1 | sed -e '1,/^<body>/d; /^<\/body>/,$$d' >> $@
163 sed -e '1,/@MAN_PAGE@/d' web/index.html.in >> $@
165 web/api.html: osl.h.m4 web/header.html web/footer.html
166 cat web/header.html > $@
167 $(M4) -DOUTPUT_MODE=HTML gendoc.m4 $< >> $@
168 cat web/footer.html >> $@