bk_text and bk_info both need to know the on-screen width of
[sgt/halibut] / Makefile
1 # Halibut master makefile
2
3 # Currently depends on gcc, because:
4 # - the dependency tracking uses -MD in order to avoid needing an
5 # explicit `make depend' step
6 # - the definition of CFLAGS includes the gcc-specific flag
7 # `-Wall'
8 #
9 # Currently depends on GNU make, because:
10 # - the Makefile uses GNU ifdef / ifndef commands and GNU make `%'
11 # pattern rules
12
13 ifdef RELEASE
14 ifndef VERSION
15 VERSION := $(RELEASE)
16 endif
17 else
18 CFLAGS += -g
19 endif
20
21 ifeq (x$(VERSION)y,xy)
22 RELDIR := halibut
23 else
24 RELDIR := halibut-$(VERSION)
25 endif
26
27 # `make' from top level will build in directory `build'
28 # `make BUILDDIR=foo' from top level will build in directory foo
29 ifndef REALBUILD
30 ifndef BUILDDIR
31 ifdef TEST
32 BUILDDIR := test
33 else
34 BUILDDIR := build
35 endif
36 endif
37
38 all:
39 @test -d $(BUILDDIR) || mkdir $(BUILDDIR)
40 @make -C $(BUILDDIR) -f ../Makefile REALBUILD=yes
41
42 spotless: topclean
43 @test -d $(BUILDDIR) || mkdir $(BUILDDIR)
44 @make -C $(BUILDDIR) -f ../Makefile spotless REALBUILD=yes
45
46 clean: topclean
47 @test -d $(BUILDDIR) || mkdir $(BUILDDIR)
48 @make -C $(BUILDDIR) -f ../Makefile clean REALBUILD=yes
49
50 # Remove Halibut output files in the source directory (may
51 # have been created by running, for example, `build/halibut
52 # inputs/test.but').
53 topclean:
54 rm -f *.html output.* *.tar.gz
55
56 # Make a release archive. If $(VERSION) is specified, this will
57 # also contain a `manifest' file which will be used to decide the
58 # version number automatically.
59 release:
60 find . -name CVS -prune -o -name build -prune -o -name reltmp -prune \
61 -o -type d -exec mkdir -p reltmp/$(RELDIR)/{} \;
62 find . -name CVS -prune -o -name build -prune -o -name reltmp -prune \
63 -o -name '*.orig' -prune -o -name '*.rej' -prune \
64 -o -name '*.txt' -prune -o -name '*.html' -prune \
65 -o -name '*.1' -prune -o -name '.cvsignore' -prune \
66 -o -name '*.gz' -prune -o -name '.[^.]*' -prune \
67 -o -type f -exec ln -s $(PWD)/{} reltmp/$(RELDIR)/{} \;
68 if test "x$(VERSION)y" != "xy"; then \
69 (cd reltmp/$(RELDIR); \
70 find . -name '*.[ch]' -exec md5sum {} \; \
71 ) > reltmp/$(RELDIR)/manifest; \
72 echo "-DVERSION=\"$(VERSION)\"" > reltmp/$(RELDIR)/version; \
73 fi
74 tar chzvCf reltmp - $(RELDIR) > $(RELDIR).tar.gz
75 rm -rf reltmp
76
77 else
78
79 # The `real' makefile part.
80
81 CFLAGS += -Wall -W
82
83 ifdef TEST
84 CFLAGS += -DLOGALLOC
85 LIBS += -lefence
86 endif
87
88 ifndef VER
89 ifdef VERSION
90 VER := $(VERSION)
91 endif
92 endif
93 ifdef VER
94 VDEF = -DVERSION=\"$(VER)\"
95 else
96 VDEF = `(cd $(SRC); md5sum -c manifest && cat version)`
97 endif
98
99 halibut:
100
101 SRC := ../
102
103 LIBCHARSET_SRCDIR = $(SRC)charset/
104 LIBCHARSET_OBJDIR = ./#
105 LIBCHARSET_OBJPFX = cs-#
106 LIBCHARSET_GENPFX = charset-#
107 MD = -MD
108 CFLAGS += -I$(LIBCHARSET_SRCDIR) -I$(LIBCHARSET_OBJDIR)
109 include $(LIBCHARSET_SRCDIR)Makefile
110
111 MODULES := main malloc ustring error help licence version misc tree234
112 MODULES += input keywords contents index style biblio
113 MODULES += bk_text bk_xhtml bk_whlp bk_man bk_info bk_paper bk_ps bk_pdf
114 MODULES += winhelp psdata wcwidth
115
116 OBJECTS := $(addsuffix .o,$(MODULES)) $(LIBCHARSET_OBJS)
117 DEPS := $(addsuffix .d,$(MODULES))
118
119 halibut: $(OBJECTS)
120 $(CC) $(LFLAGS) -o halibut $(OBJECTS) $(LIBS)
121
122 %.o: $(SRC)%.c
123 $(CC) $(CFLAGS) -MD -c $<
124
125 version.o: FORCE
126 $(CC) $(VDEF) -MD -c $(SRC)version.c
127
128 spotless:: clean
129 rm -f *.d
130
131 clean::
132 rm -f *.o halibut core
133
134 FORCE: # phony target to force version.o to be rebuilt every time
135
136 -include $(DEPS)
137
138 endif