-
ArthurSlog
-
SLog-70
-
1 Year,
-
Through China,
-
Sep 11th 2018
-
ArthurSlog Page
-
GitHub
-
NPM Package Page
-
The nuggets home page
-
Jane books home page
-
segmentfault
The sage thinks that the more he has, the more he has
Development Environment MacOS(High Sierra 10.13.5)
Required information and information sources:
-
Tip: The Tab key is used in makefiles as a marker to split between two blocks
-
Complete code -Github portal
-
Make tools
-
Integrated development environment
-
Make tool instruction file Makefile
Start coding
- The previous article wrote a basic Makefile
~/Desktop/makefile_demo/Makefile
.PHONY: all say_hello generate clean
all: say_hello generate
say_hello:
@echo "Hello Malefile"
generate:
@echo "Creating some files..."touch file-{1.. 10}.txtclean:
@echo "Cleaning up..."
rm *.txt
Copy the code
- ~/Desktop/makefile_demo/
cd ~/Desktop/makefile_demo/
make clean
mkdir demo1 demo2
mv Makefile demo1/
cd demo2
-
Create a new file Makefile in the current path (~/Desktop/makefile_demo/demo2/)
-
The current directory structure is as follows:
makefile_demo
| - demo1
| - Makefile
| - demo2
| - Makefile
Copy the code
-
This time, take a look at the “judgment” syntax in makefiles
-
For example, here’s the code:
~/Desktop/makefile_demo/demo2/Makefile
.PHONY: all warning generate clean
all: warning generate
# fun: warning
# if(./README.md)
# do
# @echo "Readme. md is an existing file, you just covered it"
warning : README.md
@echo "Readme. md is an existing file, you just covered it"
generate:
@echo "Creating a file named README.md ..."
touch README.md
clean:
@echo "Cleaning up..."
rm *.md
Copy the code
- In the code above;
# fun: warning
# if(./README.md)
# do
# @echo "Readme. md is an existing file, you just covered it"
warning : README.md
@echo "Readme. md is an existing file, you just covered it"
Copy the code
- It’s broken down into three parts:
/ / the method name
- warning
// Check whether there is a readme. md file in the current path
// The method body, which is the specific execution method, is printed on the console “readme. md is an existing file, 3. @echo “README. Md is an existing file, you just covered it”
- Now, open the command line and execute the generate method in the Makefile in the current path
make generate
Creating a file named README.md ...
touch README.md
Copy the code
- A readme.md file is now generated in the current path
ls
Makefile README.md
Copy the code
- Now, execute the all method in the Makefile. Make executes all by default, so all can be omitted
make
Creating a file named README.md ...
touch README.md
Copy the code
-
The all method contains two methods: Warning and generate
-
Warning executes “Judge module” before executing the method body
-
“Judgment module always takes precedence”
-
Now execute the clean method to clean up the current path
make clean
Cleaning up...
rm *.md
Copy the code
- Viewing the Current Path
ls
Makefile
Copy the code
-
All this is to describe the use of “rules” for makefiles
-
It’s officially called rules.
a rules
The target... : prerequisites... The recipe... ...Copy the code
- This completes the understanding and writing of the “rules” of a basic Makefile.