Makefile中的这个变量是什么?

Clu*_*cat 1 c makefile

所以这里有一个我已经给出的Makefile,我添加了评论.

MF= Makefile_c  #name of the makefile
CC= cc          #compiler to use
CFLAGS= -g      #flags to use
LFLAGS= -lm     #flags to use after the thingy
EXE=    hello   #name to give the executable
INC= \          # ??? What's this for ???
#   No user-defined include files at present - list here if required.
# name of the source file
SRC= \
    hello.c

#delete default suffix
.SUFFIXES:
#define the suffixes we are interested in
.SUFFIXES: .c .o
OBJ=    $(SRC:.c=.o)    # names to give the object files
#The .o files depend on the .c files. Compile the object files.
.c.o:
    $(CC) $(CFLAGS) -c $<

all:    $(EXE)    #The output is the executable

$(OBJ): $(INC)    #The objects depend on whatever INC is

# The executable depends on the object files. build it from the object files.
$(EXE): $(OBJ)
    $(CC) $(CFLAGS) -o $@ $(OBJ) $(LFLAGS)

# ??? the object files depend on the makefile???
$(OBJ): $(MF)

# remove any old executables or object files.
clean:
    rm -f $(OBJ) $(EXE) core
Run Code Online (Sandbox Code Playgroud)

我还在学习makefile,所以如果我错误识别了什么,请纠正我.makefile工作正常但是我想让它适应我的程序,它有多个文件和头文件.我怀疑变量$INC会以某种方式使这成为可能,但到目前为止,我尝试使用它并没有奏效.

现在我想了解这个makefile正在尝试做什么,你知道这$INC是为了什么吗?

小智 5

makefile工作正常但是我想让它适应我的程序,它有多个文件和头文件.我怀疑变量$ INC会以某种方式使这成为可能

很不幸的是,不行.这\只是一个行继续,因此您可以在下一行中为变量写入内容.它在这里是空的.这只是一个非常简单(和古老!)的依赖方法:自己列出它们.目的是列出C源文件中的所有文件#includes,因此make当这些包含文件中的任何文件发生更改时将重建.

有许多高级模式,gcc(和其他编译器)允许自动依赖信息make,但这超出了这个问题的范围.(*)

对于具有多个源文件的构建,此Makefile已经支持它,再次使用"古老"方式,后缀规则.它会自动将.c您目录中的所有文件视为最终程序的一部分.


(*)正如Tormund Giantsbane在评论中所提到的,本文档提供了关于auf自动依赖性主题的很好的信息