最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【未搞懂】makefile中无法赋值

makefile crifan 2478浏览 0评论

【问题】

在折腾makefile,写了个脚本用于实现自动编译docbook,用xsltproc+fop去生成pdf,期间遇到个很奇怪的,关于makefile无法赋值的问题。

如下方式:

#using tools
XSLT = xsltproc
XSLT_FLAGS_COMMON = --xinclude 

#XSLT_FLAGS_FO = $(XSLT_FLAGS_COMMON) \
#    --stringparam callout.graphics $(CFG_CALLOUT_GRAPHICS) \
#    --stringparam admon.graphics $(CFG_FO_ADMON_GRAPHICS) \

#    --stringparam admon.graphics.path $(ADMON_GRAPHICS_PATH) \
#XSLT_FLAGS_FO = $(XSLT_FLAGS_COMMON)
# callout settings
XSLT_FLAGS_FO = --stringparam callout.graphics $(CFG_CALLOUT_GRAPHICS)
ifeq ($(CFG_CALLOUT_GRAPHICS), 1)
XSLT_FLAGS_FO += --stringparam callout.graphics.path $(CALLOUT_IMG_PATH_LOCAL)
XSLT_FLAGS_FO += --stringparam callout.graphics.number.limit $(CALLOUT_NUM_LIMIT)
endif
# admon settings
XSLT_FLAGS_FO += --stringparam admon.graphics $(CFG_FO_ADMON_GRAPHICS)
ifeq ($(CFG_FO_ADMON_GRAPHICS), 1)
XSLT_FLAGS_FO += --stringparam admon.graphics.extension $(FO_ADMON_GRAPHICS_EXTENSION)
XSLT_FLAGS_FO += --stringparam admon.graphics.path $(FO_ADMON_GRAPHICS_PATH_LOCAL)
endif
XSLT_FLAGS_FO += $(XSLT_FLAGS_COMMON)

################################################################################
# fo
################################################################################
$(OUTPUT_FILE_PO):$(MAIN_SRC_FILE) $(SUB_SRC_FILES)
	@echo "=============================== generating fo =============================="
	export XML_CATALOG_FILES="$(XML_CATALOG_FILES)" && \
	export XML_DEBUG_CATALOG=1 && \
	$(XSLT) $(XSLT_FLAGS_FO) -o $@ $(XSL_NS_FILE_FO) $<

是可以正常实现对于XSLT_FLAGS_FO变量的赋值的,对应的脚本执行结果中,–xinclude能通过XSLT_FLAGS_COMMON传递给XSLT_FLAGS_FO:

xsltproc --stringparam callout.graphics 1 --stringparam callout.graphics.path D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/config/images/system/callouts/ --stringparam callout.graphics.number.limit 30 --stringparam admon.graphics 1 --stringparam admon.graphics.extension .svg --stringparam admon.graphics.path D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/config/images/system/colorsvg/ --xinclude  -o ../output/fo/nand_get_type.fo docbook_fo_crl.xsl nand_get_type.xml

但是对于按照正常逻辑,去这么写:

#using tools
XSLT = xsltproc
XSLT_FLAGS_COMMON = --xinclude 

#XSLT_FLAGS_FO = $(XSLT_FLAGS_COMMON) \
#    --stringparam callout.graphics $(CFG_CALLOUT_GRAPHICS) \
#    --stringparam admon.graphics $(CFG_FO_ADMON_GRAPHICS) \

#    --stringparam admon.graphics.path $(ADMON_GRAPHICS_PATH) \
XSLT_FLAGS_FO = $(XSLT_FLAGS_COMMON)
# callout settings
XSLT_FLAGS_FO += --stringparam callout.graphics $(CFG_CALLOUT_GRAPHICS)
ifeq ($(CFG_CALLOUT_GRAPHICS), 1)
XSLT_FLAGS_FO += --stringparam callout.graphics.path $(CALLOUT_IMG_PATH_LOCAL)
XSLT_FLAGS_FO += --stringparam callout.graphics.number.limit $(CALLOUT_NUM_LIMIT)
endif
# admon settings
XSLT_FLAGS_FO += --stringparam admon.graphics $(CFG_FO_ADMON_GRAPHICS)
ifeq ($(CFG_FO_ADMON_GRAPHICS), 1)
XSLT_FLAGS_FO += --stringparam admon.graphics.extension $(FO_ADMON_GRAPHICS_EXTENSION)
XSLT_FLAGS_FO += --stringparam admon.graphics.path $(FO_ADMON_GRAPHICS_PATH_LOCAL)
endif
#XSLT_FLAGS_FO += $(XSLT_FLAGS_COMMON)

################################################################################
# fo
################################################################################
$(OUTPUT_FILE_PO):$(MAIN_SRC_FILE) $(SUB_SRC_FILES)
	@echo "=============================== generating fo =============================="
	export XML_CATALOG_FILES="$(XML_CATALOG_FILES)" && \
	export XML_DEBUG_CATALOG=1 && \
	$(XSLT) $(XSLT_FLAGS_FO) -o $@ $(XSL_NS_FILE_FO) $<

结果–xinclude就无法传递给XSLT_FLAGS_FO了,结果变成:

xsltproc --stringparam callout.graphics 1 --stringparam callout.graphics.path D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/config/images/system/callouts/ --stringparam callout.graphics.number.limit 30 --stringparam admon.graphics 1 --stringparam admon.graphics.extension .svg --stringparam admon.graphics.path D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/config/images/system/colorsvg/ -o ../output/fo/nand_get_type.fo docbook_fo_crl.xsl nand_get_type.xml

然后就导致之前就遇到过的错误:

Element include in namespace 'http://www.w3.org/2001/XInclude' encountered in book, but no template matches.

了。搞得很是无语。

【解决过程】

1.后来试了另外一种写法:

#using tools
XSLT = xsltproc
XSLT_FLAGS_COMMON = --xinclude 

XSLT_FLAGS_FO = $(XSLT_FLAGS_COMMON) \
    --stringparam callout.graphics $(CFG_CALLOUT_GRAPHICS) \
    --stringparam admon.graphics $(CFG_FO_ADMON_GRAPHICS) \

#    --stringparam admon.graphics.path $(ADMON_GRAPHICS_PATH) \
#XSLT_FLAGS_FO = $(XSLT_FLAGS_COMMON)
# callout settings
#XSLT_FLAGS_FO = --stringparam callout.graphics $(CFG_CALLOUT_GRAPHICS)
ifeq ($(CFG_CALLOUT_GRAPHICS), 1)
XSLT_FLAGS_FO += --stringparam callout.graphics.path $(CALLOUT_IMG_PATH_LOCAL)
XSLT_FLAGS_FO += --stringparam callout.graphics.number.limit $(CALLOUT_NUM_LIMIT)
endif
# admon settings
#XSLT_FLAGS_FO += --stringparam admon.graphics $(CFG_FO_ADMON_GRAPHICS)
ifeq ($(CFG_FO_ADMON_GRAPHICS), 1)
XSLT_FLAGS_FO += --stringparam admon.graphics.extension $(FO_ADMON_GRAPHICS_EXTENSION)
XSLT_FLAGS_FO += --stringparam admon.graphics.path $(FO_ADMON_GRAPHICS_PATH_LOCAL)
endif
#XSLT_FLAGS_FO += $(XSLT_FLAGS_COMMON)

################################################################################
# fo
################################################################################
$(OUTPUT_FILE_PO):$(MAIN_SRC_FILE) $(SUB_SRC_FILES)
	@echo "=============================== generating fo =============================="
	export XML_CATALOG_FILES="$(XML_CATALOG_FILES)" && \
	export XML_DEBUG_CATALOG=1 && \
	$(XSLT) $(XSLT_FLAGS_FO) -o $@ $(XSL_NS_FILE_FO) $<

则也是可以正常地实现将–xinclude传递给XSLT_FLAGS_FO的:

xsltproc --xinclude   --stringparam callout.graphics 1  --stringparam admon.graphics 1   --stringparam callout.graphics.path D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/config/images/system/callouts/ --stringparam callout.graphics.number.limit 30 --stringparam admon.graphics.extension .svg --stringparam admon.graphics.path D:/tmp/tmp_dev_root/cgwin/home/CLi/develop/docbook/config/images/system/colorsvg/ -o ../output/fo/nand_get_type.fo docbook_fo_crl.xsl nand_get_type.xml

但是对于开始直接用:

XSLT_FLAGS_FO = $(XSLT_FLAGS_COMMON)

却无法实现参数赋值,还是没搞懂是啥原因。觉得很是诡异。不符合常理。

期待有高人指点指点。

转载请注明:在路上 » 【未搞懂】makefile中无法赋值

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.161 seconds, using 22.19MB memory