Shell in makefile

Source: Internet
Author: User

Extract a section in makefile that calls shell.

Install:
-If [! -E xxx]; then sudo mkdir xxx; FI

Note: To write the above if statement to a row, you must add a semicolon before fi; otherwise, the following error will occur.
Unexpected end of File

The following is a related article.

Makefile


And
Shell


Problems


 

As long as you know
Makefile

Everyone knows
Makefile

Yes
Shell

Script. But in actual use, it is not that simple, and some ambiguity may make you crazy. If you don't believe it, let's take a look at several examples. Imagine what these examples will print, write down the results you think, and run these examples on the computer. Let's take a look at them.

 

 

Example 1:

If ["$ (build)" = "debug"]; then
Echo "build debug"; else echo "build release"; FI

ALL:


Echo "done"

Example 2:

ALL:


@ Cc = arm-Linux-gcc


@ Echo $ (cc)

Example 3:

Cc = arm-Linux-gcc

ALL:


@ Echo $ (cc)

Example 4:

Subdir = SRC example

ALL:


@ For subdir in $ (subdir );/


Do/


Echo "building" $ (subdir );/


Done

 

 

Note:


1.


Shell


Script in
Target

And is ignored elsewhere. So in Example 1,
"Build debug"

Such strings cannot be printed at all. Example 1 is written as follows:

 

Example 1:

ALL:


If ["$ (build)" = "debug"]; then
Echo "build debug"; else echo "build release"; FI


Echo "done"

 

2.


Make


Set each row
Shell

Scripts are used as independent units and run in separate processes. Example 2: two rows
Shell

The script runs in two unrelated processes. The first Process
CC

Set
Arm-Linux-gcc

The second process is unknown, so the printed result is naturally not
Arm-Linux-gcc

. Example 2 is written as follows:

 

Example 2:

ALL:


@ Cc = arm-Linux-GCC; echo $ (cc)

Or:

ALL:

@ Cc = arm-Linux-GCC ;/

Echo $ (cc)

 

3.


Make


Before calling
Shell

Perform preprocessing before, that is, expand all
Makefile

. These variables and functions both use
$

. Example 3,
Shell

The script is actually
Echo arm-Linux-gcc

, So the print result is correct.

 

4.


Make


During preprocessing, all
$

It will not be missed. To reference
Shell

Your own variables should be
$

. Note that,
Shell

You do not need parentheses for your own variables. Example 4 is written correctly:

 

Example 4:

Subdir = SRC example

ALL:


@ For subdir in $ (subdir );/


Do/


Echo "building" $ subdir ;/


Done

Thanks, thanks!

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.