Allow macros to work (a) at the very start of a paragraph, and (b)
[sgt/halibut] / Makefile
CommitLineData
d7482997 1# Halibut master makefile
2
73a05796 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
d7482997 12
a4d3c848 13prefix=/usr/local
14exec_prefix=$(prefix)
15bindir=$(exec_prefix)/bin
16INSTALL=install -c
17
574825cf 18ifdef RELEASE
19ifndef VERSION
20VERSION := $(RELEASE)
21endif
22else
23CFLAGS += -g
24endif
25
26ifeq (x$(VERSION)y,xy)
27RELDIR := halibut
28else
29RELDIR := halibut-$(VERSION)
30endif
31
d7482997 32# `make' from top level will build in directory `build'
33# `make BUILDDIR=foo' from top level will build in directory foo
34ifndef REALBUILD
35ifndef BUILDDIR
36ifdef TEST
37BUILDDIR := test
38else
39BUILDDIR := build
40endif
41endif
574825cf 42
a4d3c848 43all install:
d7482997 44 @test -d $(BUILDDIR) || mkdir $(BUILDDIR)
1b7cc907 45 @$(MAKE) -C $(BUILDDIR) -f ../Makefile $@ REALBUILD=yes
574825cf 46
48f8f266 47spotless: topclean
d7482997 48 @test -d $(BUILDDIR) || mkdir $(BUILDDIR)
1b7cc907 49 @$(MAKE) -C $(BUILDDIR) -f ../Makefile spotless REALBUILD=yes
574825cf 50
48f8f266 51clean: topclean
d7482997 52 @test -d $(BUILDDIR) || mkdir $(BUILDDIR)
1b7cc907 53 @$(MAKE) -C $(BUILDDIR) -f ../Makefile clean REALBUILD=yes
574825cf 54
55# Remove Halibut output files in the source directory (may
56# have been created by running, for example, `build/halibut
57# inputs/test.but').
48f8f266 58topclean:
574825cf 59 rm -f *.html output.* *.tar.gz
60
61# Make a release archive. If $(VERSION) is specified, this will
62# also contain a `manifest' file which will be used to decide the
63# version number automatically.
64release:
65 find . -name CVS -prune -o -name build -prune -o -name reltmp -prune \
66 -o -type d -exec mkdir -p reltmp/$(RELDIR)/{} \;
67 find . -name CVS -prune -o -name build -prune -o -name reltmp -prune \
68 -o -name '*.orig' -prune -o -name '*.rej' -prune \
69 -o -name '*.txt' -prune -o -name '*.html' -prune \
70 -o -name '*.1' -prune -o -name '.cvsignore' -prune \
71 -o -name '*.gz' -prune -o -name '.[^.]*' -prune \
72 -o -type f -exec ln -s $(PWD)/{} reltmp/$(RELDIR)/{} \;
73 if test "x$(VERSION)y" != "xy"; then \
74 (cd reltmp/$(RELDIR); \
75 find . -name '*.[ch]' -exec md5sum {} \; \
76 ) > reltmp/$(RELDIR)/manifest; \
77 echo "-DVERSION=\"$(VERSION)\"" > reltmp/$(RELDIR)/version; \
78 fi
75697cf3 79 tar chzvoCf reltmp $(RELDIR).tar.gz $(RELDIR)
574825cf 80 rm -rf reltmp
81
d7482997 82else
83
84# The `real' makefile part.
85
86CFLAGS += -Wall -W
87
88ifdef TEST
89CFLAGS += -DLOGALLOC
90LIBS += -lefence
91endif
92
d7482997 93ifndef VER
94ifdef VERSION
95VER := $(VERSION)
96endif
97endif
98ifdef VER
574825cf 99VDEF = -DVERSION=\"$(VER)\"
100else
101VDEF = `(cd $(SRC); md5sum -c manifest && cat version)`
d7482997 102endif
103
a4d3c848 104all: halibut
05a1519d 105
d7482997 106SRC := ../
107
05a1519d 108LIBCHARSET_SRCDIR = $(SRC)charset/
109LIBCHARSET_OBJDIR = ./#
110LIBCHARSET_OBJPFX = cs-#
111LIBCHARSET_GENPFX = charset-#
112MD = -MD
113CFLAGS += -I$(LIBCHARSET_SRCDIR) -I$(LIBCHARSET_OBJDIR)
114include $(LIBCHARSET_SRCDIR)Makefile
115
d7482997 116MODULES := main malloc ustring error help licence version misc tree234
117MODULES += input keywords contents index style biblio
78c73085 118MODULES += bk_text bk_html bk_whlp bk_man bk_info bk_paper bk_ps bk_pdf
e5cd393f 119MODULES += winhelp psdata wcwidth
d7482997 120
05a1519d 121OBJECTS := $(addsuffix .o,$(MODULES)) $(LIBCHARSET_OBJS)
d7482997 122DEPS := $(addsuffix .d,$(MODULES))
123
124halibut: $(OBJECTS)
125 $(CC) $(LFLAGS) -o halibut $(OBJECTS) $(LIBS)
126
127%.o: $(SRC)%.c
128 $(CC) $(CFLAGS) -MD -c $<
129
130version.o: FORCE
131 $(CC) $(VDEF) -MD -c $(SRC)version.c
132
133spotless:: clean
134 rm -f *.d
135
136clean::
137 rm -f *.o halibut core
138
a4d3c848 139install:
140 $(INSTALL) -m 755 halibut $(bindir)/halibut
141 $(MAKE) -C ../doc install prefix="$(prefix)" INSTALL="$(INSTALL)"
142
d7482997 143FORCE: # phony target to force version.o to be rebuilt every time
144
145-include $(DEPS)
146
147endif