1# This makefile is inspired by abuild (http://www.abuild.org), which
2# was used during the development of qpdf.  The goal here is to have a
3# non-recursive build with all the proper dependencies so we can start
4# the build from anywhere and get the right stuff.  Each directory has
5# a build.mk that is included from here and is written from this
6# directory's perspective.  Each directory also has a proxy Makefile
7# that allows you to start the build from any directory and get
8# reasonable semantics for the all, check, and clean targets.
9
10# Our "build items" are directories.  They are listed here such that
11# no item precedes any item it depends on.  Therefore, each item can
12# safely reference variables set in its predecessors.
13
14# For each build item B, you can run make build_B, make check_B, or
15# make clean_B to build, test, or clean B.  Full dependencies are
16# represented across all the items, so it is possible to start
17# anywhere.  From the top level, the "all", "check", and "clean"
18# targets build, test, or clean everything.
19
20# To run test suites without rebuilding, pass NO_REBUILD=1 to the
21# build. This can be useful for testing binary interface compatibility
22# as it enables you to rebuild libraries and rerun tests without
23# relinking.
24
25# Although this is not a GNU package and does not use automake, you
26# can still run make clean to remove everything that is compiled, make
27# distclean to remove everything that is generated by the end user,
28# and make maintainer-clean to remove everything that is generated
29# including things distributed with the source distribution.  You can
30# pass CLEAN=1 to prevent this Makefile from complaining if
31# ./configure has not been run.
32
33# The install target works as usual and obeys --prefix and so forth
34# passed to ./configure.  You can also pass DESTDIR=/dir to make
35# install to install in a separate location.  This is useful for
36# packagers.
37
38BUILD_ITEMS := manual libqpdf qpdf zlib-flate libtests fuzz examples
39OUTPUT_DIR = build
40ALL_TARGETS =
41
42.PHONY: default
43default: all
44
45CLEAN ?=
46ifneq ($(CLEAN),1)
47ifeq ($(words $(wildcard autoconf.mk)),0)
48DUMMY := $(shell echo 1>&2)
49DUMMY := $(shell echo 1>&2 Please run ./configure before running $(MAKE))
50DUMMY := $(shell echo 1>&2)
51$(error unable to continue with build)
52endif
53
54autoconf.mk:
55
56include autoconf.mk
57
58endif
59
60# Prevent gnu make from trying to rebuild .dep files
61$(foreach B,$(BUILD_ITEMS),$(eval \
62  $(B)/$(OUTPUT_DIR)/%.dep: ;))
63
64# Prevent gnu make from trying to rebuild .mk files
65$(foreach B,$(BUILD_ITEMS),$(eval \
66  $(B)/%.mk: ;))
67%.mk: ;
68make/%.mk: ;
69
70BUILDRULES ?= libtool
71include make/rules.mk
72
73DUMMY := $(shell mkdir $(foreach B,$(BUILD_ITEMS),$(B)/$(OUTPUT_DIR)) 2>/dev/null)
74
75include $(foreach B,$(BUILD_ITEMS),$(B)/build.mk)
76
77ALL_TARGETS = $(foreach B,$(BUILD_ITEMS),$(TARGETS_$(B)))
78
79TEST_ITEMS = $(foreach D,\
80                 $(wildcard $(foreach B,$(BUILD_ITEMS),$(B)/qtest)),\
81                 $(subst /,,$(dir $(D))))
82
83TEST_TARGETS = $(foreach B,$(TEST_ITEMS),check_$(B))
84
85CLEAN_TARGETS = $(foreach B,$(BUILD_ITEMS),clean_$(B))
86
87# For test suites
88export QPDF_BIN = $(abspath qpdf/$(OUTPUT_DIR)/qpdf)
89export QPDF_SKIP_TEST_COMPARE_IMAGES
90export QPDF_LARGE_FILE_TEST_PATH
91
92clean:: $(CLEAN_TARGETS)
93	$(RM) -r appimage/build
94
95.PHONY: $(CLEAN_TARGETS)
96$(foreach B,$(BUILD_ITEMS),$(eval \
97  clean_$(B): ; \
98	$(RM) -r $(B)/$(OUTPUT_DIR)))
99
100distclean: clean
101	$(RM) -r autoconf.mk autom4te.cache config.log config.status libtool
102	$(RM) libqpdf/qpdf/qpdf-config.h
103	$(RM) manual/html.xsl
104	$(RM) manual/print.xsl
105	$(RM) libqpdf.pc libqpdf.map
106
107maintainer-clean: distclean
108	$(RM) -r install-mingw* install-msvc* external-libs
109
110.PHONY: $(TEST_TARGETS)
111
112NO_REBUILD ?=
113ifneq ($(NO_REBUILD),1)
114$(foreach B,$(TEST_ITEMS),$(eval \
115  check_$(B): $(TARGETS_$(B))))
116endif
117
118.PHONY: $(foreach B,$(BUILD_ITEMS),build_$(B))
119$(foreach B,$(BUILD_ITEMS),$(eval \
120  build_$(B): $(TARGETS_$(B))))
121
122.PHONY: all
123all: $(ALL_TARGETS) ;
124
125check: $(TEST_TARGETS)
126
127.PHONY: spell
128# npm install -g cspell; add exceptions to cSpell.json
129spell:
130	cspell **/*.hh include/qpdf/*.h **/*.cc manual/* ChangeLog README* TODO
131
132# Install targets are in the make directory in the rules-specific make
133# fragments.
134
135QTEST=$(abspath qtest/bin/qtest-driver)
136$(TEST_TARGETS):
137	$(call run_qtest,$(subst check_,,$@))
138