2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 19:08:59 +00:00

generalize build rules, add experimental support for manual compilation without libtool

git-svn-id: svn+q:///qpdf/trunk@753 71b93d88-0707-0410-a8cf-f5a4172ac649
This commit is contained in:
Jay Berkenbilt 2009-10-10 14:15:09 +00:00
parent 25e9bdc75b
commit caa397ed15
9 changed files with 166 additions and 79 deletions

View File

@ -63,6 +63,9 @@ $(foreach B,$(BUILD_ITEMS),$(eval \
%.mk: ; %.mk: ;
make/%.mk: ; make/%.mk: ;
#XXX
##BUILDRULES := libtool
BUILDRULES := gcc
include make/rules.mk include make/rules.mk
DUMMY := $(shell mkdir $(foreach B,$(BUILD_ITEMS),$(B)/$(OUTPUT_DIR)) 2>/dev/null) DUMMY := $(shell mkdir $(foreach B,$(BUILD_ITEMS),$(B)/$(OUTPUT_DIR)) 2>/dev/null)

View File

@ -1,7 +1,7 @@
BINS_examples = pdf-bookmarks pdf-mod-info pdf-npages BINS_examples = pdf-bookmarks pdf-mod-info pdf-npages
CBINS_examples = pdf-linearize CBINS_examples = pdf-linearize
TARGETS_examples = $(foreach B,$(BINS_examples) $(CBINS_examples),examples/$(OUTPUT_DIR)/$(B)) TARGETS_examples = $(foreach B,$(BINS_examples) $(CBINS_examples),examples/$(OUTPUT_DIR)/$(call binname,$(B)))
$(TARGETS_examples): $(TARGETS_qpdf) $(TARGETS_examples): $(TARGETS_qpdf)
@ -22,13 +22,13 @@ ifeq ($(GENDEPS),1)
endif endif
$(foreach B,$(BINS_examples),$(eval \ $(foreach B,$(BINS_examples),$(eval \
$(OBJS_$(B)): examples/$(OUTPUT_DIR)/%.o: examples/$(B).cc ; \ $(OBJS_$(B)): examples/$(OUTPUT_DIR)/%.$(OBJ): examples/$(B).cc ; \
$(call compile,examples/$(B).cc,$(INCLUDES_examples)))) $(call compile,examples/$(B).cc,$(INCLUDES_examples))))
$(foreach B,$(CBINS_examples),$(eval \ $(foreach B,$(CBINS_examples),$(eval \
$(OBJS_$(B)): examples/$(OUTPUT_DIR)/%.o: examples/$(B).c ; \ $(OBJS_$(B)): examples/$(OUTPUT_DIR)/%.$(OBJ): examples/$(B).c ; \
$(call c_compile,examples/$(B).c,$(INCLUDES_examples)))) $(call c_compile,examples/$(B).c,$(INCLUDES_examples))))
$(foreach B,$(BINS_examples) $(CBINS_examples),$(eval \ $(foreach B,$(BINS_examples) $(CBINS_examples),$(eval \
examples/$(OUTPUT_DIR)/$(B): $(OBJS_$(B)) ; \ examples/$(OUTPUT_DIR)/$(call binname,$(B)): $(OBJS_$(B)) ; \
$(call makebin,$(OBJS_$(B)),$$@))) $(call makebin,$(OBJS_$(B)),$$@)))

View File

@ -1,5 +1,5 @@
TARGETS_libqpdf = \ TARGETS_libqpdf = \
libqpdf/$(OUTPUT_DIR)/libqpdf.la $(foreach L,$(call libname,qpdf),libqpdf/$(OUTPUT_DIR)/$(L))
INCLUDES_libqpdf = include libqpdf INCLUDES_libqpdf = include libqpdf
@ -54,7 +54,7 @@ ifeq ($(GENDEPS),1)
-include $(call lobj_to_dep,$(OBJS_libqpdf)) -include $(call lobj_to_dep,$(OBJS_libqpdf))
endif endif
$(OBJS_libqpdf): libqpdf/$(OUTPUT_DIR)/%.lo: libqpdf/%.cc $(OBJS_libqpdf): libqpdf/$(OUTPUT_DIR)/%.$(LOBJ): libqpdf/%.cc
$(call libcompile,$<,$(INCLUDES_libqpdf)) $(call libcompile,$<,$(INCLUDES_libqpdf))
# Last three arguments to makelib are CURRENT,REVISION,AGE. # Last three arguments to makelib are CURRENT,REVISION,AGE.
@ -68,6 +68,5 @@ $(OBJS_libqpdf): libqpdf/$(OUTPUT_DIR)/%.lo: libqpdf/%.cc
# #
# * Otherwise, increment REVISION # * Otherwise, increment REVISION
libqpdf/$(OUTPUT_DIR)/libqpdf.la: $(OBJS_libqpdf) $(TARGETS_libqpdf): $(OBJS_libqpdf)
$(call makelib,$(OBJS_libqpdf),$@,3,0,0) $(call makelib,$(OBJS_libqpdf),$@,3,0,0)

View File

@ -12,7 +12,7 @@ BINS_libtests = \
qutil \ qutil \
rc4 rc4
TARGETS_libtests = $(foreach B,$(BINS_libtests),libtests/$(OUTPUT_DIR)/$(B)) TARGETS_libtests = $(foreach B,$(BINS_libtests),libtests/$(OUTPUT_DIR)/$(call binname,$(B)))
$(TARGETS_libtests): $(TARGETS_libqpdf) $(TARGETS_libtests): $(TARGETS_libqpdf)
@ -31,9 +31,9 @@ ifeq ($(GENDEPS),1)
endif endif
$(foreach B,$(BINS_libtests),$(eval \ $(foreach B,$(BINS_libtests),$(eval \
$(OBJS_$(B)): libtests/$(OUTPUT_DIR)/%.o: libtests/$(B).cc ; \ $(OBJS_$(B)): libtests/$(OUTPUT_DIR)/%.$(OBJ): libtests/$(B).cc ; \
$(call compile,libtests/$(B).cc,$(INCLUDES_libtests)))) $(call compile,libtests/$(B).cc,$(INCLUDES_libtests))))
$(foreach B,$(BINS_libtests),$(eval \ $(foreach B,$(BINS_libtests),$(eval \
libtests/$(OUTPUT_DIR)/$(B): $(OBJS_$(B)) ; \ libtests/$(OUTPUT_DIR)/$(call binname,$(B)): $(OBJS_$(B)) ; \
$(call makebin,$(OBJS_$(B)),$$@))) $(call makebin,$(OBJS_$(B)),$$@)))

67
make/gcc-linux.mk Normal file
View File

@ -0,0 +1,67 @@
# --- Required interface definitions ---
OBJ=o
LOBJ=o
# Usage: $(call libname,base)
define libname
lib$(1).a lib$(1).so
endef
# Usage: $(call binname,base)
define binname
$(1)
endef
# --- Required rule definitions ---
# 1 2
# Usage: $(call compile,src,includes)
define compile
$(CXX) $(CPPFLAGS) $(CXXFLAGS) \
$(call depflags,$(basename $(call src_to_obj,$(1)))) \
$(foreach I,$(2),-I$(I)) \
-c $(1) -o $(call src_to_obj,$(1))
endef
# 1 2
# Usage: $(call c_compile,src,includes)
define c_compile
$(CC) $(CPPFLAGS) $(CFLAGS) \
$(call depflags,$(basename $(call src_to_obj,$(1)))) \
$(foreach I,$(2),-I$(I)) \
-c $(1) -o $(call c_src_to_obj,$(1))
endef
define libcompile
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -fpic \
$(call depflags,$(basename $(call src_to_obj,$(1)))) \
$(foreach I,$(2),-I$(I)) \
-c $(1) -o $(call src_to_obj,$(1))
endef
# 1 2 3 4 5
# Usage: $(call makelib,objs,library,current,revision,age)
define makelib
$(RM) $2
if [ "$(findstring .a,$(2))" = ".a" ]; then \
ar cru $(2) $(1); \
ranlib $(2); \
else \
major=$$(( $(3) - $(5))); \
versuffix=$$major.$5.$4; \
$(CXX) $(CXXFLAGS) -shared -o $(2).$$versuffix $(1) \
-Wl,--soname -Wl,`basename $(2)`.$$major \
$(LDFLAGS) $(LIBS); \
ln -s `basename $(2)`.$$versuffix $(2); \
ln -s `basename $(2)`.$$versuffix $(2).$$major; \
fi
endef
# 1 2
# Usage: $(call makebin,objs,binary)
define makebin
$(CXX) $(CXXFLAGS) $(1) -o $(2) $(LDFLAGS) \
-Llibqpdf/$(OUTPUT_DIR) -lqpdf $(LIBS)
endef

74
make/libtool.mk Normal file
View File

@ -0,0 +1,74 @@
# --- Required interface definitions ---
OBJ=o
LOBJ=lo
# Usage: $(call libname,base)
define libname
lib$(1).la
endef
# Usage: $(call binname,base)
define binname
$(1)
endef
# --- Private definitions ---
# Usage: $(call libdepflags,$(basename obj))
# Usage: $(call fixdeps,$(basename obj))
ifeq ($(GENDEPS),1)
libdepflags=-MD -MF $(1).tdep -MP
fixdeps=sed -e 's/\.o:/.lo:/' < $(1).tdep > $(1).dep
else
libdepflags=
fixdeps=
endif
# --- Required rule definitions ---
# 1 2
# Usage: $(call compile,src,includes)
define compile
$(CXX) $(CPPFLAGS) $(CXXFLAGS) \
$(call depflags,$(basename $(call src_to_obj,$(1)))) \
$(foreach I,$(2),-I$(I)) \
-c $(1) -o $(call src_to_obj,$(1))
endef
# 1 2
# Usage: $(call c_compile,src,includes)
define c_compile
$(CC) $(CPPFLAGS) $(CFLAGS) \
$(call depflags,$(basename $(call src_to_obj,$(1)))) \
$(foreach I,$(2),-I$(I)) \
-c $(1) -o $(call c_src_to_obj,$(1))
endef
# 1 2
# Usage: $(call libcompile,src,includes)
define libcompile
$(LIBTOOL) --quiet --mode=compile \
$(CXX) $(CPPFLAGS) $(CXXFLAGS) \
$(call libdepflags,$(basename $(call src_to_obj,$(1)))) \
$(foreach I,$(2),-I$(I)) \
-c $(1) -o $(call src_to_obj,$(1)); \
$(call fixdeps,$(basename $(call src_to_obj,$(1))))
endef
# 1 2 3 4 5
# Usage: $(call makelib,objs,library,current,revision,age)
define makelib
$(LIBTOOL) --mode=link \
$(CXX) $(CXXFLAGS) -o $(2) $(1) $(LDFLAGS) $(LIBS) \
-rpath $(libdir) -version-info $(3):$(4):$(5)
endef
# 1 2
# Usage: $(call makebin,objs,binary)
define makebin
$(LIBTOOL) --mode=link \
$(CXX) $(CXXFLAGS) $(1) -o $(2) $(LDFLAGS) \
-Llibqpdf/$(OUTPUT_DIR) -lqpdf $(LIBS)
endef

View File

@ -1,27 +1,28 @@
include make/$(BUILDRULES).mk
# Usage: $(call src_to_obj,srcs) # Usage: $(call src_to_obj,srcs)
define src_to_obj define src_to_obj
$(foreach F,$(1),$(dir $(F))$(OUTPUT_DIR)/$(patsubst %.cc,%.o,$(notdir $(F)))) $(foreach F,$(1),$(dir $(F))$(OUTPUT_DIR)/$(patsubst %.cc,%.$(OBJ),$(notdir $(F))))
endef endef
# Usage: $(call c_src_to_obj,srcs) # Usage: $(call c_src_to_obj,srcs)
define c_src_to_obj define c_src_to_obj
$(foreach F,$(1),$(dir $(F))$(OUTPUT_DIR)/$(patsubst %.c,%.o,$(notdir $(F)))) $(foreach F,$(1),$(dir $(F))$(OUTPUT_DIR)/$(patsubst %.c,%.$(OBJ),$(notdir $(F))))
endef endef
# Usage: $(call src_to_lobj,srcs) # Usage: $(call src_to_lobj,srcs)
define src_to_lobj define src_to_lobj
$(foreach F,$(1),$(dir $(F))$(OUTPUT_DIR)/$(patsubst %.cc,%.lo,$(notdir $(F)))) $(foreach F,$(1),$(dir $(F))$(OUTPUT_DIR)/$(patsubst %.cc,%.$(LOBJ),$(notdir $(F))))
endef endef
# Usage: $(call obj_to_dep,objs) # Usage: $(call obj_to_dep,objs)
define obj_to_dep define obj_to_dep
$(patsubst %.o,%.dep,$(1)) $(patsubst %.$(OBJ),%.dep,$(1))
endef endef
# Usage: $(call lobj_to_dep,objs) # Usage: $(call lobj_to_dep,objs)
define lobj_to_dep define lobj_to_dep
$(patsubst %.lo,%.dep,$(1)) $(patsubst %.$(LOBJ),%.dep,$(1))
endef endef
# Usage: $(call depflags,$(basename obj)) # Usage: $(call depflags,$(basename obj))
@ -30,60 +31,3 @@ depflags=-MD -MF $(1).dep -MP
else else
depflags= depflags=
endif endif
# Usage: $(call libdepflags,$(basename obj))
# Usage: $(call fixdeps,$(basename obj))
ifeq ($(GENDEPS),1)
libdepflags=-MD -MF $(1).tdep -MP
fixdeps=sed -e 's/\.o:/.lo:/' < $(1).tdep > $(1).dep
else
libdepflags=
fixdeps=
endif
# 1 2
# Usage: $(call compile,src,includes)
define compile
$(CXX) $(CPPFLAGS) $(CXXFLAGS) \
$(call depflags,$(basename $(call src_to_obj,$(1)))) \
$(foreach I,$(2),-I$(I)) \
-c $(1) -o $(call src_to_obj,$(1))
endef
# 1 2
# Usage: $(call c_compile,src,includes)
define c_compile
$(CC) $(CPPFLAGS) $(CFLAGS) \
$(call depflags,$(basename $(call src_to_obj,$(1)))) \
$(foreach I,$(2),-I$(I)) \
-c $(1) -o $(call c_src_to_obj,$(1))
endef
# 1 2
# Usage: $(call libcompile,src,includes)
define libcompile
$(LIBTOOL) --quiet --mode=compile \
$(CXX) $(CPPFLAGS) $(CXXFLAGS) \
$(call libdepflags,$(basename $(call src_to_obj,$(1)))) \
$(foreach I,$(2),-I$(I)) \
-c $(1) -o $(call src_to_obj,$(1)); \
$(call fixdeps,$(basename $(call src_to_obj,$(1))))
endef
# 1 2 3 4 5
# Usage: $(call makelib,objs,library,current,revision,age)
define makelib
$(LIBTOOL) --mode=link \
$(CXX) $(CXXFLAGS) -o $(2) $(1) $(LDFLAGS) $(LIBS) \
-rpath $(libdir) -version-info $(3):$(4):$(5)
endef
# 1 2
# Usage: $(call makebin,objs,binary)
define makebin
$(LIBTOOL) --mode=link \
$(CXX) $(CXXFLAGS) $(1) -o $(2) $(LDFLAGS) \
-Llibqpdf/$(OUTPUT_DIR) -lqpdf $(LIBS)
endef

View File

@ -1,7 +1,7 @@
BINS_qpdf = qpdf test_driver BINS_qpdf = qpdf test_driver
CBINS_qpdf = qpdf-ctest CBINS_qpdf = qpdf-ctest
TARGETS_qpdf = $(foreach B,$(BINS_qpdf) $(CBINS_qpdf),qpdf/$(OUTPUT_DIR)/$(B)) TARGETS_qpdf = $(foreach B,$(BINS_qpdf) $(CBINS_qpdf),qpdf/$(OUTPUT_DIR)/$(call binname,$(B)))
$(TARGETS_qpdf): $(TARGETS_libqpdf) $(TARGETS_qpdf): $(TARGETS_libqpdf)
@ -21,13 +21,13 @@ ifeq ($(GENDEPS),1)
endif endif
$(foreach B,$(BINS_qpdf),$(eval \ $(foreach B,$(BINS_qpdf),$(eval \
$(OBJS_$(B)): qpdf/$(OUTPUT_DIR)/%.o: qpdf/$(B).cc ; \ $(OBJS_$(B)): qpdf/$(OUTPUT_DIR)/%.$(OBJ): qpdf/$(B).cc ; \
$(call compile,qpdf/$(B).cc,$(INCLUDES_qpdf)))) $(call compile,qpdf/$(B).cc,$(INCLUDES_qpdf))))
$(foreach B,$(CBINS_qpdf),$(eval \ $(foreach B,$(CBINS_qpdf),$(eval \
$(OBJS_$(B)): qpdf/$(OUTPUT_DIR)/%.o: qpdf/$(B).c ; \ $(OBJS_$(B)): qpdf/$(OUTPUT_DIR)/%.$(OBJ): qpdf/$(B).c ; \
$(call c_compile,qpdf/$(B).c,$(INCLUDES_qpdf)))) $(call c_compile,qpdf/$(B).c,$(INCLUDES_qpdf))))
$(foreach B,$(BINS_qpdf) $(CBINS_qpdf),$(eval \ $(foreach B,$(BINS_qpdf) $(CBINS_qpdf),$(eval \
qpdf/$(OUTPUT_DIR)/$(B): $(OBJS_$(B)) ; \ qpdf/$(OUTPUT_DIR)/$(call binname,$(B)): $(OBJS_$(B)) ; \
$(call makebin,$(OBJS_$(B)),$$@))) $(call makebin,$(OBJS_$(B)),$$@)))

View File

@ -1,5 +1,5 @@
TARGETS_zlib-flate = \ TARGETS_zlib-flate = \
zlib-flate/$(OUTPUT_DIR)/zlib-flate zlib-flate/$(OUTPUT_DIR)/$(call binname,zlib-flate)
$(TARGETS_zlib-flate): $(TARGETS_libqpdf) $(TARGETS_zlib-flate): $(TARGETS_libqpdf)
@ -18,5 +18,5 @@ endif
$(OBJS_zlib-flate): zlib-flate/$(OUTPUT_DIR)/%.o: zlib-flate/%.cc $(OBJS_zlib-flate): zlib-flate/$(OUTPUT_DIR)/%.o: zlib-flate/%.cc
$(call compile,$<,$(INCLUDES_zlib-flate)) $(call compile,$<,$(INCLUDES_zlib-flate))
zlib-flate/$(OUTPUT_DIR)/zlib-flate: $(OBJS_zlib-flate) zlib-flate/$(OUTPUT_DIR)/$(call binname,zlib-flate): $(OBJS_zlib-flate)
$(call makebin,$(OBJS_zlib-flate),$@) $(call makebin,$(OBJS_zlib-flate),$@)