makefile与批处理文件基本相同吗?

时间:2022-05-17 02:08:16

I know all about batch files and made them before, but I'm unclear on what a makefile is. It looks like a batch file. What are the similarities and diffferences?

我知道批处理文件的所有内容并且之前已经完成,但我不清楚makefile是什么。它看起来像一个批处理文件。有什么相似之处和差异?

7 个解决方案

#1


13  

No. A makefile has special rules which relate how files depend on each other. It does not necessarily execute in the order it is written.

不。一个makefile有一些特殊的规则,它们涉及文件相互依赖的方式。它不一定按照写入的顺序执行。

A batch file is a sequence of commands and control statements.

批处理文件是一系列命令和控制语句。

Makefiles often contain the same things as batch files, but batch files do not have a direct way of indicating dependencies or provide an inferred method of processing one kind of file into another kind.

Makefile通常包含与批处理文件相同的内容,但批处理文件没有直接指示依赖关系的方法,也没有提供将一种文件处理成另一种文件的推断方法。

#2


12  

Similar, yes, except for the dependencies, the topological sort, the macro processing, and the expert system

If you do nothing but put shell commands in a Makefile then it is in fact a lot like a catalog of "batch files," and it executes each one when its associated named target is specified.

如果你什么都不做,只是把shell命令放在Makefile中,那么它实际上很像“批处理文件”的目录,并且当指定了相关的命名目标时它会执行每个命令。

However, it is more typical to specify a graph of dependencies in a makefile, in which case make does a topological sort of all the dependencies in order to cleverly build everything only once and in the right order starting with the earliest prerequisites.

但是,更典型的是在makefile中指定依赖关系图,在这种情况下,make会对所有依赖关系进行拓扑排序,以便巧妙地从最早的先决条件开始,以正确的顺序构建所有内容。

And to be complete, I should add that make is also a macro processor. It's oriented towards software build systems, so it provides handles on symbolic elements in its problem domain, such as the names of sources and targets.

要完成,我应该补充一点,make也是一个宏处理器。它面向软件构建系统,因此它在其问题域中提供符号元素的句柄,例如源和目标的名称。

Now, make is not a specifically a general purpose expert system,1 but it does do more than just package up shellcode, and technically it does fit the expert system definition.

现在,make并不是一个专门的通用专家系统,1但它确实不仅仅是打包shellcode,技术上它确实适合专家系统定义。

Make contains an inference engine. All versions of make have suffix rules, some versions also implement pattern rules. When combined with your specification (more rules, typically ones defining a software application) the result is an expert system which will decide what needs to be compiled, linked, purchased on eBay, whatever, all depending on the data and commands you have provided.

Make包含一个推理引擎。 make的所有版本都有后缀规则,某些版本也实现了模式规则。当结合您的规范(更多规则,通常是定义软件应用程序的规则)时,结果是一个专家系统,它将决定需要在eBay上编译,链接,购买的内容,这些都取决于您提供的数据和命令。


1. It's an easy-to-use expert system, instead. Skynet will probably not emerge from an accidental typo in a complicated Makefile.

#3


7  

To put a fairly abstract spin on it:

对它进行相当抽象的旋转:

  • Batch files are written in a imperative language.
  • 批处理文件以命令式语言编写。
  • Makefiles are written in a declarative language for file processing (which is intended for and usually used for build control).
  • Makefile是以声明性语言编写的,用于文件处理(用于构建控制,通常用于构建控制)。

#4


6  

Makefiles list commands which are executed, but they're structured differently than a list of sequential commands. Instead they have targets and the commands to 'make' them. make then checks the listed dependencies and sees what targets it needs to update to make what you told it to. There are many implicit rules (given an *.c file make already knows how to compile it to an *.o and even build an executable!) and standard variables (e.g. CFLAGS) so you can use this to your advantage. And, contrary to the man page, you can use these implicit rules without a Makefile.

Makefile列出了执行的命令,但它们的结构与顺序命令列表不同。相反,他们有目标和命令来“制造”它们。然后make会检查列出的依赖项,并查看需要更新的目标,以实现您告诉它的目标。有许多隐式规则(假定* .c文件已经知道如何将其编译为* .o甚至构建可执行文件!)和标准变量(例如CFLAGS),因此您可以使用此优势。而且,与手册页相反,您可以在没有Makefile的情况下使用这些隐式规则。

The simplest way to think about it is the makefile says how to make an 'A' given a 'B', and then you tell make what you want to do (e.g. make all) rather than how to do it. It figures out the individual steps.

考虑它的最简单的方法是makefile说如何给'A'一个'B',然后你告诉make你想做什么(例如make all)而不是怎么做。它计算出各个步骤。

#5


4  

Not at all. They're similar in the sense that all programming languages are similar (even more so since they're both scripting), but they have very different purposes.

一点也不。它们在所有编程语言都相似的意义上是相似的(因为它们都是脚本编写的,因此更加如此),但它们的目的却截然不同。

The purpose of makefiles is to describe how to build a project. This usually means creating rules (in a special language) that say things like:

makefile的目的是描述如何构建项目。这通常意味着创建规则(使用特殊语言),例如:

  1. whenever you see a file that ends in .c, run the program "gcc" on it to compile it into a ".o" object file.
  2. 每当您看到以.c结尾的文件时,在其上运行程序“gcc”将其编译为“.o”目标文件。
  3. whenever you have a bunch of ".o"s, link them into a ".exe".
  4. 每当你有一堆“.o”时,将它们链接成“.exe”。

Of course this is a simplistic description.

当然这是一个简单的描述。

The main benefit of using make (the "interpreter" for the makefile language) is that you get a syntax which is purpose-built for these kinds of things. For example, make usually takes care of things like checking whether a file has changed, so that you don't compile a file that doesn't have any changes.

使用make(makefile语言的“解释器”)的主要好处是,您可以获得专门为这些类型构建的语法。例如,make通常负责检查文件是否已更改,以便您不编译没有任何更改的文件。

#6


3  

Very interesting question. With a shell script or batch file, you are providing your computer with a list of instructions to follow in order. It starts at the top, works down until it reaches the end, and then stops. OK, there might be function definitions, loops and gotos which change the exact order in which things happen, but largely speaking the progress through the file is linear.

非常有趣的问题。使用shell脚本或批处理文件,您可以为计算机提供按顺序执行的说明列表。它从顶部开始,向下工作直到它到达终点,然后停止。好的,可能有函数定义,循环和gotos,它们会改变事件发生的确切顺序,但很大程度上说,文件的进度是线性的。

Makefiles, on the other hand, provide a series of instructions on how to make certain things from certain other things. When you call make, you tell it what you want, and it analyses the instructions which it has and decides which of them it needs to execute in order to make your specified target. As a result, what happens when you call a makefile depends not just on the content of the file itself, but on what you asked it to make and what state your files are in at that point.

另一方面,Makefile提供了一系列关于如何从某些其他事物中制作某些东西的说明。当你调用make时,你告诉它你想要什么,它会分析它所拥有的指令,并决定它们为了制定你指定的目标而需要执行哪些指令。因此,调用makefile时会发生什么,不仅取决于文件本身的内容,还取决于您要求它制作的内容以及文件在该点处的状态。

Two different approaches for doing two different things.

做两件不同事情的两种不同方法。

#7


1  

Makefiles are data for the Make program. Think of them as what the old guys did before they had XML :)

Makefile是Make程序的数据。把它们想象成老家伙在拥有XML之前所做的事情:)

#1


13  

No. A makefile has special rules which relate how files depend on each other. It does not necessarily execute in the order it is written.

不。一个makefile有一些特殊的规则,它们涉及文件相互依赖的方式。它不一定按照写入的顺序执行。

A batch file is a sequence of commands and control statements.

批处理文件是一系列命令和控制语句。

Makefiles often contain the same things as batch files, but batch files do not have a direct way of indicating dependencies or provide an inferred method of processing one kind of file into another kind.

Makefile通常包含与批处理文件相同的内容,但批处理文件没有直接指示依赖关系的方法,也没有提供将一种文件处理成另一种文件的推断方法。

#2


12  

Similar, yes, except for the dependencies, the topological sort, the macro processing, and the expert system

If you do nothing but put shell commands in a Makefile then it is in fact a lot like a catalog of "batch files," and it executes each one when its associated named target is specified.

如果你什么都不做,只是把shell命令放在Makefile中,那么它实际上很像“批处理文件”的目录,并且当指定了相关的命名目标时它会执行每个命令。

However, it is more typical to specify a graph of dependencies in a makefile, in which case make does a topological sort of all the dependencies in order to cleverly build everything only once and in the right order starting with the earliest prerequisites.

但是,更典型的是在makefile中指定依赖关系图,在这种情况下,make会对所有依赖关系进行拓扑排序,以便巧妙地从最早的先决条件开始,以正确的顺序构建所有内容。

And to be complete, I should add that make is also a macro processor. It's oriented towards software build systems, so it provides handles on symbolic elements in its problem domain, such as the names of sources and targets.

要完成,我应该补充一点,make也是一个宏处理器。它面向软件构建系统,因此它在其问题域中提供符号元素的句柄,例如源和目标的名称。

Now, make is not a specifically a general purpose expert system,1 but it does do more than just package up shellcode, and technically it does fit the expert system definition.

现在,make并不是一个专门的通用专家系统,1但它确实不仅仅是打包shellcode,技术上它确实适合专家系统定义。

Make contains an inference engine. All versions of make have suffix rules, some versions also implement pattern rules. When combined with your specification (more rules, typically ones defining a software application) the result is an expert system which will decide what needs to be compiled, linked, purchased on eBay, whatever, all depending on the data and commands you have provided.

Make包含一个推理引擎。 make的所有版本都有后缀规则,某些版本也实现了模式规则。当结合您的规范(更多规则,通常是定义软件应用程序的规则)时,结果是一个专家系统,它将决定需要在eBay上编译,链接,购买的内容,这些都取决于您提供的数据和命令。


1. It's an easy-to-use expert system, instead. Skynet will probably not emerge from an accidental typo in a complicated Makefile.

#3


7  

To put a fairly abstract spin on it:

对它进行相当抽象的旋转:

  • Batch files are written in a imperative language.
  • 批处理文件以命令式语言编写。
  • Makefiles are written in a declarative language for file processing (which is intended for and usually used for build control).
  • Makefile是以声明性语言编写的,用于文件处理(用于构建控制,通常用于构建控制)。

#4


6  

Makefiles list commands which are executed, but they're structured differently than a list of sequential commands. Instead they have targets and the commands to 'make' them. make then checks the listed dependencies and sees what targets it needs to update to make what you told it to. There are many implicit rules (given an *.c file make already knows how to compile it to an *.o and even build an executable!) and standard variables (e.g. CFLAGS) so you can use this to your advantage. And, contrary to the man page, you can use these implicit rules without a Makefile.

Makefile列出了执行的命令,但它们的结构与顺序命令列表不同。相反,他们有目标和命令来“制造”它们。然后make会检查列出的依赖项,并查看需要更新的目标,以实现您告诉它的目标。有许多隐式规则(假定* .c文件已经知道如何将其编译为* .o甚至构建可执行文件!)和标准变量(例如CFLAGS),因此您可以使用此优势。而且,与手册页相反,您可以在没有Makefile的情况下使用这些隐式规则。

The simplest way to think about it is the makefile says how to make an 'A' given a 'B', and then you tell make what you want to do (e.g. make all) rather than how to do it. It figures out the individual steps.

考虑它的最简单的方法是makefile说如何给'A'一个'B',然后你告诉make你想做什么(例如make all)而不是怎么做。它计算出各个步骤。

#5


4  

Not at all. They're similar in the sense that all programming languages are similar (even more so since they're both scripting), but they have very different purposes.

一点也不。它们在所有编程语言都相似的意义上是相似的(因为它们都是脚本编写的,因此更加如此),但它们的目的却截然不同。

The purpose of makefiles is to describe how to build a project. This usually means creating rules (in a special language) that say things like:

makefile的目的是描述如何构建项目。这通常意味着创建规则(使用特殊语言),例如:

  1. whenever you see a file that ends in .c, run the program "gcc" on it to compile it into a ".o" object file.
  2. 每当您看到以.c结尾的文件时,在其上运行程序“gcc”将其编译为“.o”目标文件。
  3. whenever you have a bunch of ".o"s, link them into a ".exe".
  4. 每当你有一堆“.o”时,将它们链接成“.exe”。

Of course this is a simplistic description.

当然这是一个简单的描述。

The main benefit of using make (the "interpreter" for the makefile language) is that you get a syntax which is purpose-built for these kinds of things. For example, make usually takes care of things like checking whether a file has changed, so that you don't compile a file that doesn't have any changes.

使用make(makefile语言的“解释器”)的主要好处是,您可以获得专门为这些类型构建的语法。例如,make通常负责检查文件是否已更改,以便您不编译没有任何更改的文件。

#6


3  

Very interesting question. With a shell script or batch file, you are providing your computer with a list of instructions to follow in order. It starts at the top, works down until it reaches the end, and then stops. OK, there might be function definitions, loops and gotos which change the exact order in which things happen, but largely speaking the progress through the file is linear.

非常有趣的问题。使用shell脚本或批处理文件,您可以为计算机提供按顺序执行的说明列表。它从顶部开始,向下工作直到它到达终点,然后停止。好的,可能有函数定义,循环和gotos,它们会改变事件发生的确切顺序,但很大程度上说,文件的进度是线性的。

Makefiles, on the other hand, provide a series of instructions on how to make certain things from certain other things. When you call make, you tell it what you want, and it analyses the instructions which it has and decides which of them it needs to execute in order to make your specified target. As a result, what happens when you call a makefile depends not just on the content of the file itself, but on what you asked it to make and what state your files are in at that point.

另一方面,Makefile提供了一系列关于如何从某些其他事物中制作某些东西的说明。当你调用make时,你告诉它你想要什么,它会分析它所拥有的指令,并决定它们为了制定你指定的目标而需要执行哪些指令。因此,调用makefile时会发生什么,不仅取决于文件本身的内容,还取决于您要求它制作的内容以及文件在该点处的状态。

Two different approaches for doing two different things.

做两件不同事情的两种不同方法。

#7


1  

Makefiles are data for the Make program. Think of them as what the old guys did before they had XML :)

Makefile是Make程序的数据。把它们想象成老家伙在拥有XML之前所做的事情:)