| 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 | SRC := ../ |
| 100 | |
| 101 | MODULES := main malloc ustring error help licence version misc tree234 |
| 102 | MODULES += input keywords contents index style biblio |
| 103 | MODULES += bk_text bk_xhtml bk_whlp bk_man bk_info bk_paper bk_ps bk_pdf |
| 104 | MODULES += winhelp psdata |
| 105 | |
| 106 | OBJECTS := $(addsuffix .o,$(MODULES)) |
| 107 | DEPS := $(addsuffix .d,$(MODULES)) |
| 108 | |
| 109 | halibut: $(OBJECTS) |
| 110 | $(CC) $(LFLAGS) -o halibut $(OBJECTS) $(LIBS) |
| 111 | |
| 112 | %.o: $(SRC)%.c |
| 113 | $(CC) $(CFLAGS) -MD -c $< |
| 114 | |
| 115 | version.o: FORCE |
| 116 | $(CC) $(VDEF) -MD -c $(SRC)version.c |
| 117 | |
| 118 | spotless:: clean |
| 119 | rm -f *.d |
| 120 | |
| 121 | clean:: |
| 122 | rm -f *.o halibut core |
| 123 | |
| 124 | FORCE: # phony target to force version.o to be rebuilt every time |
| 125 | |
| 126 | -include $(DEPS) |
| 127 | |
| 128 | endif |