Makefile向变量添加空格

Makefile adding spaces to variables

我正在尝试使用 makefile 在 LaTex 中编译我的故事。我正在尝试使用一个变量来完成我的故事的文件名。如果我只是 运行 make,它就可以工作。但是,我需要能够 运行 来自 make 的特定命令。

pdflatex "\def\isdraft{1} \input{FMPGC.tex}"

我如何从 PROJ + OBJS 创建一个变量,以便我可以像下面尝试做的那样做一些事情。如果我 运行 下面的 make draft 代码,它会失败并出现在 FMPGC 和 tex 之间添加大量空格。

如何将两个变量与“.”组合起来?这对之间的符号,所以我可以在下面的命令中编译我的故事。我也尝试过不转义 \ 符号,但似乎没有效果。

# This makefile compiles my story using LaTex
# Author:
#

# VARS - Variables to be changed for reuse of my script
PROJ = "FMPGC"          # The name of the project
OBJS = "tex"            # The extension for the content
AUXS = "aux"            # The aux extensions
CHAP = "chapters/"      # The chapters
FOO = $(PROJ) += "."
F002 = $(FOO) += $(OBJS)

# Configuration:
CC = pdflatex   # The compiler

# Rules
all:
    $(CC) $(PROJ).$(OBJS)
draft:
    $(CC) "\def\isdraft{1} \input{$(FOO2)}"

当前错误来自于它现在没有向变量输入任何内容 -

pdflatex     "\def\isdraft{1} \input{}"

下面似乎是确切的问题。

<*> \def\isdraft{1} F
                     MPGC.tex

---------------- 更新生成文件

# This makefile compiles my story using LaTex
# Author:
#

# VARS - Variables to be changed for reuse of my script

# The name of the project
PROJ:=FMPGC
# The extension for the content
OBJS:=tex
# The aux extensions
AUXS:=aux
# The chapters
CHAP:=chapters/

# Configuration:
# The compiler
CC=pdflatex

# Rules
all:
    $(CC) $(PROJ).$(OBJS);
draft:
    $(CC) "\def\isdraft{1} $(PROJ).$(OBJS)";

更新错误----

pdflatex "\def\isdraft{1} FMPGC.tex";
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
LaTeX2e <2014/05/01>
Babel <3.9k> and hyphenation patterns for 21 languages loaded.

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

<*> \def\isdraft{1} F
                     MPGC.tex
? 
! Emergency stop.
 ...                                              

<*> \def\isdraft{1} F
                     MPGC.tex
!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on texput.log.

在 GNU make 手册的 The Two Flavors of Variables 部分,我们发现:

If you put whitespace at the end of a variable value, it is a good idea to put a comment like that at the end of the line to make your intent clear. Conversely, if you do not want any whitespace characters at the end of your variable value, you must remember not to put a random comment on the end of the line after some whitespace, such as this:

dir := /foo/bar    # directory to put the frobs in

Here the value of the variable dir is ‘/foo/bar ’ (with four trailing spaces), which was probably not the intention. (Imagine something like ‘$(dir)/file’ with this definition!)

感谢@Etan Reisner,我在查看文档后能够修复它。

我的 make 文件现在看起来像这样 -

# This makefile compiles my story using LaTex
# Author:
#

# VARS - Variables to be changed for reuse of my script

# The name of the project
PROJ:=FMPGC
# The extension for the content
OBJS:=tex
# The aux extensions
AUXS:=aux
# The chapters
CHAP:=chapters/

# Configuration:
# The compiler
CC=pdflatex

# Rules
all:
    $(CC) $(PROJ).$(OBJS);
draft:
    $(CC) "\def\isdraft{1} \input{$(PROJ).$(OBJS)}";

我现在可以编译我的文档,它会添加我的变量以便在 LaTex 中使用。