123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- # make reference
- Learn Makefiles - https://makefiletutorial.com/
- $ make
- makefile:2: *** missing separator. Stop.
- $ cat -etv makefile
- [it show line starting by ^I if <tab> is given to that line and it end the line by $]
- Note: makefile must be indented using <tabs> and not <spaces> or 'make' will fail
- # makefile syntax
- targets: prerequisites
- command
- * targets are file names, separated by spaces
- (typically, there is only one per rule)
- * prerequisites are also file names, separated by spaces
- (these files need to exist before the commands for the target are run)
- * commands are a series of steps typically used to make the targets
- (these need to start with a tab character, not spaces)
- # the essence of make
- file:
- echo "This line will print if the file does not exist."
- * we have one target called file
- * target file has no prerequisites
- * target file has one command
- Note: as long as the 'file' does not exist, the command will run
- (if 'file' does exist, no command will run)
- example:
- Let's create a more typical makefile - one that compiles a single C file. But
- before we do, make a file called program.c that has the following contents:
- int main() {
- return 0;
- }
- then create the makefile:
- program:
- cc program.c -o program
- This time, try simply running make. Since there's no target supplied as anargument
- to the make command, the first target is run. In this case, there's only one target
- (program). The first time you run this, program will be created. The second time, you
- will see make: 'program' is up to date. That's because the program file already exists.
- But there a problem: if we modify program.c and then run make, nothing gets recompiled.
- We solve this by adding a prerequisite:
- program: program.c
- cc program.c -o program
- When we run make again, the following set of steps happens:
- * the first target is selected, because the first target is the default target
- * this has a prerequisite of program.c
- * make decides if it should run the program target
- (it will only run if program doesn't exist, or program.c is newer than program)
- The last step is critical, and is the essence of make.
- make -d # trace debug output
- make --debug=b # basic debug
- make -p # print rules and variables
|