Linux Makefile and Shell issues _ server Other

Source: Internet
Author: User

Presumably, anyone who knows makefile knows that makefile can invoke a shell script. But when it's actually used, it's not that simple, and some ambiguous places can make you mad. If you don't believe it, you can take a look at a few examples, imagine what these examples will print, write down what you think, and then run these examples on your computer and check it out.

Example one:

Copy Code code as follows:

If ["$ (build)" = "Debug"]; Then echo "Build Debug"; else echo "Build release"; Fi
All
echo "Done"

Example two:
Copy Code code as follows:

All
@CC =ARM-LINUX-GCC
@echo $ (CC)

Example three:
Copy Code code as follows:

cc=arm-linux-gcc
All
@echo $ (CC)

Example four:
Copy Code code as follows:

SUBDIR=SRC Example
All
@for SubDir in $ (subdir); \
Do\
echo "Building" $ (subdir); \
Done


Description
1. The shell script works in Target and is ignored elsewhere. So in example one, a string like "Build Debug" doesn't print at all. The correct wording for example one is:

Example one:

Copy Code code as follows:

All
If ["$ (build)" = "Debug"]; Then echo "Build Debug"; else echo "Build release"; Fi
echo "Done"

2. Make each line of shell scripts as a separate unit that runs in a separate process. In Example II, two lines of shell script run in two unrelated processes, the first process to set CC to ARM-LINUX-GCC, the second process is not known, so the result of the printing is not ARM-LINUX-GCC. The correct formulation of example two is:

Example two:

Copy Code code as follows:

All
@CC =ARM-LINUX-GCC; echo $ (CC)

Or:
Copy Code code as follows:

All
@CC =ARM-LINUX-GCC; \
echo $ (CC)

3. Make is preprocessed before calling the shell, which expands all makefile variables and functions. These variables and functions begin with $. In example three, the script that the shell takes is actually the echo ARM-LINUX-GCC, so the print results are correct.
4. Make preprocessing, all starting with the $, it will not pass. To refer to the shell's own variables, you should start with $$. Also note that the shell's own variables do not require parentheses. The correct formulation of example four is:

Example four:

Copy Code code as follows:

SUBDIR=SRC Example
All
@for SubDir in $ (subdir); \
Do\
echo "Building" $ $subdir; \
Done

Related Article

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.