Make static mode

Source: Internet
Author: User

MakeStatic Mode

The static mode makes it easier to define rules with multiple targets and makes our rules more flexible and flexible. Let's take a look at the Syntax:

<Targets... >:< target-pattern >:< prereq-patterns...>

<Commands>

...

Targets defines a series of target files with wildcards. Is a set of targets.

Target-pattern indicates the targets mode, that is, the target set mode.

Prereq-patterns is the dependency mode of the target. It defines the dependency mode of the target again.

The three things may not be clearly described in this way. Let's give an example. If <target-pattern> is defined as "%. O ", which means that all of our <target> sets are". O ", and if our <prereq-patterns> is defined as" %. C ", which means to perform a second definition of the target set formed by <target-pattern>. The calculation method is, take "%" in the <target-pattern> mode (that is, remove [. o]), and add [. c] A new set formed at the end.

Therefore, the "Target mode" or "dependency mode" must contain the character "%, if your file name contains "%", you can use the Backslash "\" to escape it to indicate the true "%" character.

Let's look at an example:

Objects = Foo. O Bar. o

ALL: $ (objects)

$ (Objects): %. O: %. c

$ (CC)-C $ (cflags) $ <-o $ @

In the above example, we specify that our target is obtained from $ object, "%. O "indicates that all o. O Bar. "O", that is, the mode of the variable $ object set, and the dependency mode "%. c. The format is "%. O "" % ", that is," foo bar ", and add". c, so our dependency target is "foo. c bar. C ". In the command, "$ <" and "$ @" are automation variables. "$ <" indicates all dependent target sets (that is, "foo. c bar. c), "$ @" indicates the target set (that is, "Foo. O Bar. O "). As a result, the above rules are equivalent to the following rules:

Foo. O: Foo. c

$ (CC)-C $ (cflags) Foo. C-o Foo. o

Bar. O: bar. c

$ (CC)-C $ (cflags) bar. C-o Bar. o

Imagine that if we have hundreds of "%. O", it would be too efficient to write a bunch of rules as long as we use this simple "static mode rule. The usage of "static mode rules" is flexible. If used well, it will be very powerful. Let's look at another example:

Files = Foo. ELC bar. O lose. o

$ (Filter %. O, $ (Files): %. O: %. c

$ (CC)-C $ (cflags) $ <-o $ @

$ (Filter %. ELC, $ (Files): %. ELC: %. El

Emacs-F batch-byte-compile $ <

$ (Filter %. O, $ (Files) indicates that the filter function of makefile is called to filter the "$ Files" set, as long as the mode is "%. O. I don't have to say much about its content. This example shows more elasticity in makefile.

Original

Http://wiki.ubuntu.org.cn/index.php? Title = % E8 % B7 % 9f % E6 % 88% 91% E4 % B8 % 80% E8 % B5 % B7 % E5 % 86% 99 makefile: % E4 % B9 % a6 % E5 % 86% 99% E8 % A7 % 84% E5 % 88% 99 & variant = ZH-HANT

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.