Gnu Make Learning notes 1

The notes are from learning of Gnu Make Manual V0.70 for Gun Make version 3.81, which can be referred to http://www.gnu.org/software/make/manual/make.htm



1. Makefile basic syntax

Rule
target ... : prerequisites ...
    command
    ...
    ...

Usually target is t the object name or executable file name, but it can also be the action name. Make doesn't do anything for the action rule unless you tell it explicitely.
You need to put a tab at the begining of every command line.

By default, the first rule in make file is the DEFAULT GOAL. Only the main goal will be processed.

If the prerequisites files are more recent than target file, or target file doesn't exist, the command needs to be called.

The make process the rules for the files that target depends on firstly.

2. Variables

They are used to simplify the make file.

Definition:

variable = a.o b.o c.o

Usage:   

foo.exe:$(variable)
    cc -o foo.exe $(variable)

It is necessary to use .PHONY to explicitly indicate a phony rule, which can avoid conflict with file of the same name.

.PHONY:clean

3. Not necessary to write source compile command

By default, make can automatically call source compile command for .o targeted rule, and also consider associated .c file into prerequistes.

e.g.

main.o:main.c main.h
    cc -c main.c

equals

main.o:main.h





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值