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!