Commit caa397ed157ada95129dbe784c01c6a1f95b226f
1 parent
25e9bdc7
generalize build rules, add experimental support for manual compilation without libtool
git-svn-id: svn+q:///qpdf/trunk@753 71b93d88-0707-0410-a8cf-f5a4172ac649
Showing
9 changed files
with
166 additions
and
79 deletions
Makefile
examples/build.mk
| 1 | 1 | BINS_examples = pdf-bookmarks pdf-mod-info pdf-npages |
| 2 | 2 | CBINS_examples = pdf-linearize |
| 3 | 3 | |
| 4 | -TARGETS_examples = $(foreach B,$(BINS_examples) $(CBINS_examples),examples/$(OUTPUT_DIR)/$(B)) | |
| 4 | +TARGETS_examples = $(foreach B,$(BINS_examples) $(CBINS_examples),examples/$(OUTPUT_DIR)/$(call binname,$(B))) | |
| 5 | 5 | |
| 6 | 6 | $(TARGETS_examples): $(TARGETS_qpdf) |
| 7 | 7 | |
| ... | ... | @@ -22,13 +22,13 @@ ifeq ($(GENDEPS),1) |
| 22 | 22 | endif |
| 23 | 23 | |
| 24 | 24 | $(foreach B,$(BINS_examples),$(eval \ |
| 25 | - $(OBJS_$(B)): examples/$(OUTPUT_DIR)/%.o: examples/$(B).cc ; \ | |
| 25 | + $(OBJS_$(B)): examples/$(OUTPUT_DIR)/%.$(OBJ): examples/$(B).cc ; \ | |
| 26 | 26 | $(call compile,examples/$(B).cc,$(INCLUDES_examples)))) |
| 27 | 27 | |
| 28 | 28 | $(foreach B,$(CBINS_examples),$(eval \ |
| 29 | - $(OBJS_$(B)): examples/$(OUTPUT_DIR)/%.o: examples/$(B).c ; \ | |
| 29 | + $(OBJS_$(B)): examples/$(OUTPUT_DIR)/%.$(OBJ): examples/$(B).c ; \ | |
| 30 | 30 | $(call c_compile,examples/$(B).c,$(INCLUDES_examples)))) |
| 31 | 31 | |
| 32 | 32 | $(foreach B,$(BINS_examples) $(CBINS_examples),$(eval \ |
| 33 | - examples/$(OUTPUT_DIR)/$(B): $(OBJS_$(B)) ; \ | |
| 33 | + examples/$(OUTPUT_DIR)/$(call binname,$(B)): $(OBJS_$(B)) ; \ | |
| 34 | 34 | $(call makebin,$(OBJS_$(B)),$$@))) | ... | ... |
libqpdf/build.mk
| 1 | 1 | TARGETS_libqpdf = \ |
| 2 | - libqpdf/$(OUTPUT_DIR)/libqpdf.la | |
| 2 | + $(foreach L,$(call libname,qpdf),libqpdf/$(OUTPUT_DIR)/$(L)) | |
| 3 | 3 | |
| 4 | 4 | INCLUDES_libqpdf = include libqpdf |
| 5 | 5 | |
| ... | ... | @@ -54,7 +54,7 @@ ifeq ($(GENDEPS),1) |
| 54 | 54 | -include $(call lobj_to_dep,$(OBJS_libqpdf)) |
| 55 | 55 | endif |
| 56 | 56 | |
| 57 | -$(OBJS_libqpdf): libqpdf/$(OUTPUT_DIR)/%.lo: libqpdf/%.cc | |
| 57 | +$(OBJS_libqpdf): libqpdf/$(OUTPUT_DIR)/%.$(LOBJ): libqpdf/%.cc | |
| 58 | 58 | $(call libcompile,$<,$(INCLUDES_libqpdf)) |
| 59 | 59 | |
| 60 | 60 | # Last three arguments to makelib are CURRENT,REVISION,AGE. |
| ... | ... | @@ -68,6 +68,5 @@ $(OBJS_libqpdf): libqpdf/$(OUTPUT_DIR)/%.lo: libqpdf/%.cc |
| 68 | 68 | # |
| 69 | 69 | # * Otherwise, increment REVISION |
| 70 | 70 | |
| 71 | -libqpdf/$(OUTPUT_DIR)/libqpdf.la: $(OBJS_libqpdf) | |
| 71 | +$(TARGETS_libqpdf): $(OBJS_libqpdf) | |
| 72 | 72 | $(call makelib,$(OBJS_libqpdf),$@,3,0,0) |
| 73 | - | ... | ... |
libtests/build.mk
| ... | ... | @@ -12,7 +12,7 @@ BINS_libtests = \ |
| 12 | 12 | qutil \ |
| 13 | 13 | rc4 |
| 14 | 14 | |
| 15 | -TARGETS_libtests = $(foreach B,$(BINS_libtests),libtests/$(OUTPUT_DIR)/$(B)) | |
| 15 | +TARGETS_libtests = $(foreach B,$(BINS_libtests),libtests/$(OUTPUT_DIR)/$(call binname,$(B))) | |
| 16 | 16 | |
| 17 | 17 | $(TARGETS_libtests): $(TARGETS_libqpdf) |
| 18 | 18 | |
| ... | ... | @@ -31,9 +31,9 @@ ifeq ($(GENDEPS),1) |
| 31 | 31 | endif |
| 32 | 32 | |
| 33 | 33 | $(foreach B,$(BINS_libtests),$(eval \ |
| 34 | - $(OBJS_$(B)): libtests/$(OUTPUT_DIR)/%.o: libtests/$(B).cc ; \ | |
| 34 | + $(OBJS_$(B)): libtests/$(OUTPUT_DIR)/%.$(OBJ): libtests/$(B).cc ; \ | |
| 35 | 35 | $(call compile,libtests/$(B).cc,$(INCLUDES_libtests)))) |
| 36 | 36 | |
| 37 | 37 | $(foreach B,$(BINS_libtests),$(eval \ |
| 38 | - libtests/$(OUTPUT_DIR)/$(B): $(OBJS_$(B)) ; \ | |
| 38 | + libtests/$(OUTPUT_DIR)/$(call binname,$(B)): $(OBJS_$(B)) ; \ | |
| 39 | 39 | $(call makebin,$(OBJS_$(B)),$$@))) | ... | ... |
make/gcc-linux.mk
0 → 100644
| 1 | +# --- Required interface definitions --- | |
| 2 | + | |
| 3 | +OBJ=o | |
| 4 | +LOBJ=o | |
| 5 | + | |
| 6 | +# Usage: $(call libname,base) | |
| 7 | +define libname | |
| 8 | +lib$(1).a lib$(1).so | |
| 9 | +endef | |
| 10 | + | |
| 11 | +# Usage: $(call binname,base) | |
| 12 | +define binname | |
| 13 | +$(1) | |
| 14 | +endef | |
| 15 | + | |
| 16 | +# --- Required rule definitions --- | |
| 17 | + | |
| 18 | +# 1 2 | |
| 19 | +# Usage: $(call compile,src,includes) | |
| 20 | +define compile | |
| 21 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) \ | |
| 22 | + $(call depflags,$(basename $(call src_to_obj,$(1)))) \ | |
| 23 | + $(foreach I,$(2),-I$(I)) \ | |
| 24 | + -c $(1) -o $(call src_to_obj,$(1)) | |
| 25 | +endef | |
| 26 | + | |
| 27 | +# 1 2 | |
| 28 | +# Usage: $(call c_compile,src,includes) | |
| 29 | +define c_compile | |
| 30 | + $(CC) $(CPPFLAGS) $(CFLAGS) \ | |
| 31 | + $(call depflags,$(basename $(call src_to_obj,$(1)))) \ | |
| 32 | + $(foreach I,$(2),-I$(I)) \ | |
| 33 | + -c $(1) -o $(call c_src_to_obj,$(1)) | |
| 34 | +endef | |
| 35 | + | |
| 36 | +define libcompile | |
| 37 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -fpic \ | |
| 38 | + $(call depflags,$(basename $(call src_to_obj,$(1)))) \ | |
| 39 | + $(foreach I,$(2),-I$(I)) \ | |
| 40 | + -c $(1) -o $(call src_to_obj,$(1)) | |
| 41 | +endef | |
| 42 | + | |
| 43 | + | |
| 44 | +# 1 2 3 4 5 | |
| 45 | +# Usage: $(call makelib,objs,library,current,revision,age) | |
| 46 | +define makelib | |
| 47 | + $(RM) $2 | |
| 48 | + if [ "$(findstring .a,$(2))" = ".a" ]; then \ | |
| 49 | + ar cru $(2) $(1); \ | |
| 50 | + ranlib $(2); \ | |
| 51 | + else \ | |
| 52 | + major=$$(( $(3) - $(5))); \ | |
| 53 | + versuffix=$$major.$5.$4; \ | |
| 54 | + $(CXX) $(CXXFLAGS) -shared -o $(2).$$versuffix $(1) \ | |
| 55 | + -Wl,--soname -Wl,`basename $(2)`.$$major \ | |
| 56 | + $(LDFLAGS) $(LIBS); \ | |
| 57 | + ln -s `basename $(2)`.$$versuffix $(2); \ | |
| 58 | + ln -s `basename $(2)`.$$versuffix $(2).$$major; \ | |
| 59 | + fi | |
| 60 | +endef | |
| 61 | + | |
| 62 | +# 1 2 | |
| 63 | +# Usage: $(call makebin,objs,binary) | |
| 64 | +define makebin | |
| 65 | + $(CXX) $(CXXFLAGS) $(1) -o $(2) $(LDFLAGS) \ | |
| 66 | + -Llibqpdf/$(OUTPUT_DIR) -lqpdf $(LIBS) | |
| 67 | +endef | ... | ... |
make/libtool.mk
0 → 100644
| 1 | +# --- Required interface definitions --- | |
| 2 | + | |
| 3 | +OBJ=o | |
| 4 | +LOBJ=lo | |
| 5 | + | |
| 6 | +# Usage: $(call libname,base) | |
| 7 | +define libname | |
| 8 | +lib$(1).la | |
| 9 | +endef | |
| 10 | + | |
| 11 | +# Usage: $(call binname,base) | |
| 12 | +define binname | |
| 13 | +$(1) | |
| 14 | +endef | |
| 15 | + | |
| 16 | +# --- Private definitions --- | |
| 17 | + | |
| 18 | +# Usage: $(call libdepflags,$(basename obj)) | |
| 19 | +# Usage: $(call fixdeps,$(basename obj)) | |
| 20 | +ifeq ($(GENDEPS),1) | |
| 21 | +libdepflags=-MD -MF $(1).tdep -MP | |
| 22 | +fixdeps=sed -e 's/\.o:/.lo:/' < $(1).tdep > $(1).dep | |
| 23 | + | |
| 24 | +else | |
| 25 | +libdepflags= | |
| 26 | +fixdeps= | |
| 27 | +endif | |
| 28 | + | |
| 29 | +# --- Required rule definitions --- | |
| 30 | + | |
| 31 | +# 1 2 | |
| 32 | +# Usage: $(call compile,src,includes) | |
| 33 | +define compile | |
| 34 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) \ | |
| 35 | + $(call depflags,$(basename $(call src_to_obj,$(1)))) \ | |
| 36 | + $(foreach I,$(2),-I$(I)) \ | |
| 37 | + -c $(1) -o $(call src_to_obj,$(1)) | |
| 38 | +endef | |
| 39 | + | |
| 40 | +# 1 2 | |
| 41 | +# Usage: $(call c_compile,src,includes) | |
| 42 | +define c_compile | |
| 43 | + $(CC) $(CPPFLAGS) $(CFLAGS) \ | |
| 44 | + $(call depflags,$(basename $(call src_to_obj,$(1)))) \ | |
| 45 | + $(foreach I,$(2),-I$(I)) \ | |
| 46 | + -c $(1) -o $(call c_src_to_obj,$(1)) | |
| 47 | +endef | |
| 48 | + | |
| 49 | +# 1 2 | |
| 50 | +# Usage: $(call libcompile,src,includes) | |
| 51 | +define libcompile | |
| 52 | + $(LIBTOOL) --quiet --mode=compile \ | |
| 53 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) \ | |
| 54 | + $(call libdepflags,$(basename $(call src_to_obj,$(1)))) \ | |
| 55 | + $(foreach I,$(2),-I$(I)) \ | |
| 56 | + -c $(1) -o $(call src_to_obj,$(1)); \ | |
| 57 | + $(call fixdeps,$(basename $(call src_to_obj,$(1)))) | |
| 58 | +endef | |
| 59 | + | |
| 60 | +# 1 2 3 4 5 | |
| 61 | +# Usage: $(call makelib,objs,library,current,revision,age) | |
| 62 | +define makelib | |
| 63 | + $(LIBTOOL) --mode=link \ | |
| 64 | + $(CXX) $(CXXFLAGS) -o $(2) $(1) $(LDFLAGS) $(LIBS) \ | |
| 65 | + -rpath $(libdir) -version-info $(3):$(4):$(5) | |
| 66 | +endef | |
| 67 | + | |
| 68 | +# 1 2 | |
| 69 | +# Usage: $(call makebin,objs,binary) | |
| 70 | +define makebin | |
| 71 | + $(LIBTOOL) --mode=link \ | |
| 72 | + $(CXX) $(CXXFLAGS) $(1) -o $(2) $(LDFLAGS) \ | |
| 73 | + -Llibqpdf/$(OUTPUT_DIR) -lqpdf $(LIBS) | |
| 74 | +endef | ... | ... |
make/rules.mk
| 1 | +include make/$(BUILDRULES).mk | |
| 1 | 2 | |
| 2 | 3 | # Usage: $(call src_to_obj,srcs) |
| 3 | 4 | define src_to_obj |
| 4 | -$(foreach F,$(1),$(dir $(F))$(OUTPUT_DIR)/$(patsubst %.cc,%.o,$(notdir $(F)))) | |
| 5 | +$(foreach F,$(1),$(dir $(F))$(OUTPUT_DIR)/$(patsubst %.cc,%.$(OBJ),$(notdir $(F)))) | |
| 5 | 6 | endef |
| 6 | 7 | |
| 7 | 8 | # Usage: $(call c_src_to_obj,srcs) |
| 8 | 9 | define c_src_to_obj |
| 9 | -$(foreach F,$(1),$(dir $(F))$(OUTPUT_DIR)/$(patsubst %.c,%.o,$(notdir $(F)))) | |
| 10 | +$(foreach F,$(1),$(dir $(F))$(OUTPUT_DIR)/$(patsubst %.c,%.$(OBJ),$(notdir $(F)))) | |
| 10 | 11 | endef |
| 11 | 12 | |
| 12 | 13 | # Usage: $(call src_to_lobj,srcs) |
| 13 | 14 | define src_to_lobj |
| 14 | -$(foreach F,$(1),$(dir $(F))$(OUTPUT_DIR)/$(patsubst %.cc,%.lo,$(notdir $(F)))) | |
| 15 | +$(foreach F,$(1),$(dir $(F))$(OUTPUT_DIR)/$(patsubst %.cc,%.$(LOBJ),$(notdir $(F)))) | |
| 15 | 16 | endef |
| 16 | 17 | |
| 17 | 18 | # Usage: $(call obj_to_dep,objs) |
| 18 | 19 | define obj_to_dep |
| 19 | -$(patsubst %.o,%.dep,$(1)) | |
| 20 | +$(patsubst %.$(OBJ),%.dep,$(1)) | |
| 20 | 21 | endef |
| 21 | 22 | |
| 22 | 23 | # Usage: $(call lobj_to_dep,objs) |
| 23 | 24 | define lobj_to_dep |
| 24 | -$(patsubst %.lo,%.dep,$(1)) | |
| 25 | +$(patsubst %.$(LOBJ),%.dep,$(1)) | |
| 25 | 26 | endef |
| 26 | 27 | |
| 27 | 28 | # Usage: $(call depflags,$(basename obj)) |
| ... | ... | @@ -30,60 +31,3 @@ depflags=-MD -MF $(1).dep -MP |
| 30 | 31 | else |
| 31 | 32 | depflags= |
| 32 | 33 | endif |
| 33 | - | |
| 34 | -# Usage: $(call libdepflags,$(basename obj)) | |
| 35 | -# Usage: $(call fixdeps,$(basename obj)) | |
| 36 | -ifeq ($(GENDEPS),1) | |
| 37 | -libdepflags=-MD -MF $(1).tdep -MP | |
| 38 | -fixdeps=sed -e 's/\.o:/.lo:/' < $(1).tdep > $(1).dep | |
| 39 | - | |
| 40 | -else | |
| 41 | -libdepflags= | |
| 42 | -fixdeps= | |
| 43 | -endif | |
| 44 | - | |
| 45 | -# 1 2 | |
| 46 | -# Usage: $(call compile,src,includes) | |
| 47 | -define compile | |
| 48 | - $(CXX) $(CPPFLAGS) $(CXXFLAGS) \ | |
| 49 | - $(call depflags,$(basename $(call src_to_obj,$(1)))) \ | |
| 50 | - $(foreach I,$(2),-I$(I)) \ | |
| 51 | - -c $(1) -o $(call src_to_obj,$(1)) | |
| 52 | -endef | |
| 53 | - | |
| 54 | -# 1 2 | |
| 55 | -# Usage: $(call c_compile,src,includes) | |
| 56 | -define c_compile | |
| 57 | - $(CC) $(CPPFLAGS) $(CFLAGS) \ | |
| 58 | - $(call depflags,$(basename $(call src_to_obj,$(1)))) \ | |
| 59 | - $(foreach I,$(2),-I$(I)) \ | |
| 60 | - -c $(1) -o $(call c_src_to_obj,$(1)) | |
| 61 | -endef | |
| 62 | - | |
| 63 | -# 1 2 | |
| 64 | -# Usage: $(call libcompile,src,includes) | |
| 65 | -define libcompile | |
| 66 | - $(LIBTOOL) --quiet --mode=compile \ | |
| 67 | - $(CXX) $(CPPFLAGS) $(CXXFLAGS) \ | |
| 68 | - $(call libdepflags,$(basename $(call src_to_obj,$(1)))) \ | |
| 69 | - $(foreach I,$(2),-I$(I)) \ | |
| 70 | - -c $(1) -o $(call src_to_obj,$(1)); \ | |
| 71 | - $(call fixdeps,$(basename $(call src_to_obj,$(1)))) | |
| 72 | -endef | |
| 73 | - | |
| 74 | -# 1 2 3 4 5 | |
| 75 | -# Usage: $(call makelib,objs,library,current,revision,age) | |
| 76 | -define makelib | |
| 77 | - $(LIBTOOL) --mode=link \ | |
| 78 | - $(CXX) $(CXXFLAGS) -o $(2) $(1) $(LDFLAGS) $(LIBS) \ | |
| 79 | - -rpath $(libdir) -version-info $(3):$(4):$(5) | |
| 80 | -endef | |
| 81 | - | |
| 82 | -# 1 2 | |
| 83 | -# Usage: $(call makebin,objs,binary) | |
| 84 | -define makebin | |
| 85 | - $(LIBTOOL) --mode=link \ | |
| 86 | - $(CXX) $(CXXFLAGS) $(1) -o $(2) $(LDFLAGS) \ | |
| 87 | - -Llibqpdf/$(OUTPUT_DIR) -lqpdf $(LIBS) | |
| 88 | -endef | |
| 89 | - | ... | ... |
qpdf/build.mk
| 1 | 1 | BINS_qpdf = qpdf test_driver |
| 2 | 2 | CBINS_qpdf = qpdf-ctest |
| 3 | 3 | |
| 4 | -TARGETS_qpdf = $(foreach B,$(BINS_qpdf) $(CBINS_qpdf),qpdf/$(OUTPUT_DIR)/$(B)) | |
| 4 | +TARGETS_qpdf = $(foreach B,$(BINS_qpdf) $(CBINS_qpdf),qpdf/$(OUTPUT_DIR)/$(call binname,$(B))) | |
| 5 | 5 | |
| 6 | 6 | $(TARGETS_qpdf): $(TARGETS_libqpdf) |
| 7 | 7 | |
| ... | ... | @@ -21,13 +21,13 @@ ifeq ($(GENDEPS),1) |
| 21 | 21 | endif |
| 22 | 22 | |
| 23 | 23 | $(foreach B,$(BINS_qpdf),$(eval \ |
| 24 | - $(OBJS_$(B)): qpdf/$(OUTPUT_DIR)/%.o: qpdf/$(B).cc ; \ | |
| 24 | + $(OBJS_$(B)): qpdf/$(OUTPUT_DIR)/%.$(OBJ): qpdf/$(B).cc ; \ | |
| 25 | 25 | $(call compile,qpdf/$(B).cc,$(INCLUDES_qpdf)))) |
| 26 | 26 | |
| 27 | 27 | $(foreach B,$(CBINS_qpdf),$(eval \ |
| 28 | - $(OBJS_$(B)): qpdf/$(OUTPUT_DIR)/%.o: qpdf/$(B).c ; \ | |
| 28 | + $(OBJS_$(B)): qpdf/$(OUTPUT_DIR)/%.$(OBJ): qpdf/$(B).c ; \ | |
| 29 | 29 | $(call c_compile,qpdf/$(B).c,$(INCLUDES_qpdf)))) |
| 30 | 30 | |
| 31 | 31 | $(foreach B,$(BINS_qpdf) $(CBINS_qpdf),$(eval \ |
| 32 | - qpdf/$(OUTPUT_DIR)/$(B): $(OBJS_$(B)) ; \ | |
| 32 | + qpdf/$(OUTPUT_DIR)/$(call binname,$(B)): $(OBJS_$(B)) ; \ | |
| 33 | 33 | $(call makebin,$(OBJS_$(B)),$$@))) | ... | ... |
zlib-flate/build.mk
| 1 | 1 | TARGETS_zlib-flate = \ |
| 2 | - zlib-flate/$(OUTPUT_DIR)/zlib-flate | |
| 2 | + zlib-flate/$(OUTPUT_DIR)/$(call binname,zlib-flate) | |
| 3 | 3 | |
| 4 | 4 | $(TARGETS_zlib-flate): $(TARGETS_libqpdf) |
| 5 | 5 | |
| ... | ... | @@ -18,5 +18,5 @@ endif |
| 18 | 18 | $(OBJS_zlib-flate): zlib-flate/$(OUTPUT_DIR)/%.o: zlib-flate/%.cc |
| 19 | 19 | $(call compile,$<,$(INCLUDES_zlib-flate)) |
| 20 | 20 | |
| 21 | -zlib-flate/$(OUTPUT_DIR)/zlib-flate: $(OBJS_zlib-flate) | |
| 21 | +zlib-flate/$(OUTPUT_DIR)/$(call binname,zlib-flate): $(OBJS_zlib-flate) | |
| 22 | 22 | $(call makebin,$(OBJS_zlib-flate),$@) | ... | ... |