shell与Makefile区别及总结


Makefile与shell脚本区别

 

 

http://blog.csdn.net/absurd/article/details/636418

 

1.通配符不一样

shell:*

Makefile:%

2.引用变量不一样

shell:$var   或者${var}

Makefile:$(var)

 

3.Makefile的target里面才执行shell脚本或者用函数$(shell pwd),其他地方不会

 

4.Makefile的每一行都是开辟一个进程来执行,所有要执行多个shell用\,来认为一行,所以多行设定变量时,里面无法传递变量,见下面例子

 

 

5.变量赋值

shell:不允许有空格

Makefile:允许有空格

 

6.特殊情况

Makefile为了避免和shell的变量冲突,shell的变量以$$开头

PROJECT_ROOT_DIR = $(shell pwd | awk -F'/application|/base_class' '{print $$1}')

        

        

        

        

        

7.make在调用Shell之前先进行预处理,即展开所有Makefile的变量和函数        

shell自己的变量$$GOOD_DIR

Makefile的变量$(GOOD_DIR)

cat Makefile 

GOOD_DIR="you are"

 

all:

    @GOOD_DIR=arm-linux;\

    echo $$GOOD_DIR; echo $(GOOD_DIR)

    @echo $(GOOD_DIR)

zengzhihao@yingyongbu:~/work_place/test/youtest$ make

arm-linux

you are

you are

zengzhihao@yingyongbu:~/work_place/test/youtest$ make GOOD_DIR=outside

arm-linux

outside

outside

    

    

    

        

        

        

条件判断if

shell:

if [ $NOW_VAR == 1 ];then

echo "var is 1"

elif [ $NOW_VAR == 2 ];then

echo "var is 2"

else

echo "var is not 1"

fi

 

 

Makefile:

NOW_DIR=$(shell pwd)

ifeq ($(NOW_VAR), 1)

NOW_DIR="in 1"

else ifeq ($(NOW_VAR), 2)

NOW_DIR="in 2"

else

NOW_DIR="in not 1 or 2"

endif

all:

         echo $(NOW_DIR)

 

 

ifneq ($(NOW_VAR), 1)

endif

 

ifdef V

endif

ifndef V

endif

 

 

 

 

 

for循环

shell:

for pid in ${pids};

do

xxxxx

done

 

 

while循环

shell:

while true

do

xxxx

done        

        

 

Makefile中的for循环,采用shell的for循环

file=1 2 3 4 5

all:

    for name in $(file); \

    do \

    echo $$name;  \

    done

        

        

        

例子        

        两种实现方式

all:

    CC=arm-linux;echo $$CC

    

all:

    @CC=arm-linux;\

    echo $$CC            

    

    

    

    

    


Makefile与shell脚本区别

 

 

http://blog.csdn.net/absurd/article/details/636418

 

1.通配符不一样

shell:*

Makefile:%

2.引用变量不一样

shell:$var   或者${var}

Makefile:$(var)

 

3.Makefile的target里面才执行shell脚本或者用函数$(shell pwd),其他地方不会

 

4.Makefile的每一行都是开辟一个进程来执行,所有要执行多个shell用\,来认为一行,所以多行设定变量时,里面无法传递变量,见下面例子

 

 

5.变量赋值

shell:不允许有空格

Makefile:允许有空格

 

6.特殊情况

Makefile为了避免和shell的变量冲突,shell的变量以$$开头

PROJECT_ROOT_DIR = $(shell pwd | awk -F'/application|/base_class' '{print $$1}')

        

        

        

        

        

7.make在调用Shell之前先进行预处理,即展开所有Makefile的变量和函数        

shell自己的变量$$GOOD_DIR

Makefile的变量$(GOOD_DIR)

cat Makefile 

GOOD_DIR="you are"

 

all:

    @GOOD_DIR=arm-linux;\

    echo $$GOOD_DIR; echo $(GOOD_DIR)

    @echo $(GOOD_DIR)

zengzhihao@yingyongbu:~/work_place/test/youtest$ make

arm-linux

you are

you are

zengzhihao@yingyongbu:~/work_place/test/youtest$ make GOOD_DIR=outside

arm-linux

outside

outside

    

    

    

        

        

        

条件判断if

shell:

if [ $NOW_VAR == 1 ];then

echo "var is 1"

elif [ $NOW_VAR == 2 ];then

echo "var is 2"

else

echo "var is not 1"

fi

 

 

Makefile:

NOW_DIR=$(shell pwd)

ifeq ($(NOW_VAR), 1)

NOW_DIR="in 1"

else ifeq ($(NOW_VAR), 2)

NOW_DIR="in 2"

else

NOW_DIR="in not 1 or 2"

endif

all:

         echo $(NOW_DIR)

 

 

ifneq ($(NOW_VAR), 1)

endif

 

ifdef V

endif

ifndef V

endif

 

 

 

 

 

for循环

shell:

for pid in ${pids};

do

xxxxx

done

 

 

while循环

shell:

while true

do

xxxx

done        

        

 

Makefile中的for循环,采用shell的for循环

file=1 2 3 4 5

all:

    for name in $(file); \

    do \

    echo $$name;  \

    done

        

        

        

例子        

        两种实现方式

all:

    CC=arm-linux;echo $$CC

    

all:

    @CC=arm-linux;\

    echo $$CC            

    

    

    

    

    

    

    

    

    

    


Makefile与shell脚本区别

 

 

http://blog.csdn.net/absurd/article/details/636418

 

1.通配符不一样

shell:*

Makefile:%

2.引用变量不一样

shell:$var   或者${var}

Makefile:$(var)

 

3.Makefile的target里面才执行shell脚本或者用函数$(shell pwd),其他地方不会

 

4.Makefile的每一行都是开辟一个进程来执行,所有要执行多个shell用\,来认为一行,所以多行设定变量时,里面无法传递变量,见下面例子

 

 

5.变量赋值

shell:不允许有空格

Makefile:允许有空格

 

6.特殊情况

Makefile为了避免和shell的变量冲突,shell的变量以$$开头

PROJECT_ROOT_DIR = $(shell pwd | awk -F'/application|/base_class' '{print $$1}')

        

        

        

        

        

7.make在调用Shell之前先进行预处理,即展开所有Makefile的变量和函数        

shell自己的变量$$GOOD_DIR

Makefile的变量$(GOOD_DIR)

cat Makefile 

GOOD_DIR="you are"

 

all:

    @GOOD_DIR=arm-linux;\

    echo $$GOOD_DIR; echo $(GOOD_DIR)

    @echo $(GOOD_DIR)

zengzhihao@yingyongbu:~/work_place/test/youtest$ make

arm-linux

you are

you are

zengzhihao@yingyongbu:~/work_place/test/youtest$ make GOOD_DIR=outside

arm-linux

outside

outside

    

    

    

        

        

        

条件判断if

shell:

if [ $NOW_VAR == 1 ];then

echo "var is 1"

elif [ $NOW_VAR == 2 ];then

echo "var is 2"

else

echo "var is not 1"

fi

 

 

Makefile:

NOW_DIR=$(shell pwd)

ifeq ($(NOW_VAR), 1)

NOW_DIR="in 1"

else ifeq ($(NOW_VAR), 2)

NOW_DIR="in 2"

else

NOW_DIR="in not 1 or 2"

endif

all:

         echo $(NOW_DIR)

 

 

ifneq ($(NOW_VAR), 1)

endif

 

ifdef V

endif

ifndef V

endif

 

 

 

 

 

for循环

shell:

for pid in ${pids};

do

xxxxx

done

 

 

while循环

shell:

while true

do

xxxx

done        

        

 

Makefile中的for循环,采用shell的for循环

file=1 2 3 4 5

all:

    for name in $(file); \

    do \

    echo $$name;  \

    done

        

        

        

例子        

        两种实现方式

all:

    CC=arm-linux;echo $$CC

    

all:

    @CC=arm-linux;\

    echo $$CC            

    

    

    

    

    

    

    

    

    

    


Makefile与shell脚本区别

 

 

http://blog.csdn.net/absurd/article/details/636418

 

1.通配符不一样

shell:*

Makefile:%

2.引用变量不一样

shell:$var   或者${var}

Makefile:$(var)

 

3.Makefile的target里面才执行shell脚本或者用函数$(shell pwd),其他地方不会

 

4.Makefile的每一行都是开辟一个进程来执行,所有要执行多个shell用\,来认为一行,所以多行设定变量时,里面无法传递变量,见下面例子

 

 

5.变量赋值

shell:不允许有空格

Makefile:允许有空格

 

6.特殊情况

Makefile为了避免和shell的变量冲突,shell的变量以$$开头

PROJECT_ROOT_DIR = $(shell pwd | awk -F'/application|/base_class' '{print $$1}')

        

        

        

        

        

7.make在调用Shell之前先进行预处理,即展开所有Makefile的变量和函数        

shell自己的变量$$GOOD_DIR

Makefile的变量$(GOOD_DIR)

cat Makefile 

GOOD_DIR="you are"

 

all:

    @GOOD_DIR=arm-linux;\

    echo $$GOOD_DIR; echo $(GOOD_DIR)

    @echo $(GOOD_DIR)

zengzhihao@yingyongbu:~/work_place/test/youtest$ make

arm-linux

you are

you are

zengzhihao@yingyongbu:~/work_place/test/youtest$ make GOOD_DIR=outside

arm-linux

outside

outside

    

    

    

        

        

        

条件判断if

shell:

if [ $NOW_VAR == 1 ];then

echo "var is 1"

elif [ $NOW_VAR == 2 ];then

echo "var is 2"

else

echo "var is not 1"

fi

 

 

Makefile:

NOW_DIR=$(shell pwd)

ifeq ($(NOW_VAR), 1)

NOW_DIR="in 1"

else ifeq ($(NOW_VAR), 2)

NOW_DIR="in 2"

else

NOW_DIR="in not 1 or 2"

endif

all:

         echo $(NOW_DIR)

 

 

ifneq ($(NOW_VAR), 1)

endif

 

ifdef V

endif

ifndef V

endif

 

 

 

 

 

for循环

shell:

for pid in ${pids};

do

xxxxx

done

 

 

while循环

shell:

while true

do

xxxx

done        

        

 

Makefile中的for循环,采用shell的for循环

file=1 2 3 4 5

all:

    for name in $(file); \

    do \

    echo $$name;  \

    done

        

        

        

例子        

        两种实现方式

all:

    CC=arm-linux;echo $$CC

    

all:

    @CC=arm-linux;\

    echo $$CC            

    

    

    

    

    

    

    

    

    

    


Makefile与shell脚本区别

 

 

http://blog.csdn.net/absurd/article/details/636418

 

1.通配符不一样

shell:*

Makefile:%

2.引用变量不一样

shell:$var   或者${var}

Makefile:$(var)

 

3.Makefile的target里面才执行shell脚本或者用函数$(shell pwd),其他地方不会

 

4.Makefile的每一行都是开辟一个进程来执行,所有要执行多个shell用\,来认为一行,所以多行设定变量时,里面无法传递变量,见下面例子

 

 

5.变量赋值

shell:不允许有空格

Makefile:允许有空格

 

6.特殊情况

Makefile为了避免和shell的变量冲突,shell的变量以$$开头

PROJECT_ROOT_DIR = $(shell pwd | awk -F'/application|/base_class' '{print $$1}')

        

        

        

        

        

7.make在调用Shell之前先进行预处理,即展开所有Makefile的变量和函数        

shell自己的变量$$GOOD_DIR

Makefile的变量$(GOOD_DIR)

cat Makefile 

GOOD_DIR="you are"

 

all:

    @GOOD_DIR=arm-linux;\

    echo $$GOOD_DIR; echo $(GOOD_DIR)

    @echo $(GOOD_DIR)

zengzhihao@yingyongbu:~/work_place/test/youtest$ make

arm-linux

you are

you are

zengzhihao@yingyongbu:~/work_place/test/youtest$ make GOOD_DIR=outside

arm-linux

outside

outside

    

    

    

        

        

        

条件判断if

shell:

if [ $NOW_VAR == 1 ];then

echo "var is 1"

elif [ $NOW_VAR == 2 ];then

echo "var is 2"

else

echo "var is not 1"

fi

 

 

Makefile:

NOW_DIR=$(shell pwd)

ifeq ($(NOW_VAR), 1)

NOW_DIR="in 1"

else ifeq ($(NOW_VAR), 2)

NOW_DIR="in 2"

else

NOW_DIR="in not 1 or 2"

endif

all:

         echo $(NOW_DIR)

 

 

ifneq ($(NOW_VAR), 1)

endif

 

ifdef V

endif

ifndef V

endif

 

 

 

 

 

for循环

shell:

for pid in ${pids};

do

xxxxx

done

 

 

while循环

shell:

while true

do

xxxx

done        

        

 

Makefile中的for循环,采用shell的for循环

file=1 2 3 4 5

all:

    for name in $(file); \

    do \

    echo $$name;  \

    done

        

        

        

例子        

        两种实现方式

all:

    CC=arm-linux;echo $$CC

    

all:

    @CC=arm-linux;\

    echo $$CC            

    

    

    

    

    

    

    

    

    

    


Makefile与shell脚本区别

 

 

http://blog.csdn.net/absurd/article/details/636418

 

1.通配符不一样

shell:*

Makefile:%

2.引用变量不一样

shell:$var   或者${var}

Makefile:$(var)

 

3.Makefile的target里面才执行shell脚本或者用函数$(shell pwd),其他地方不会

 

4.Makefile的每一行都是开辟一个进程来执行,所有要执行多个shell用\,来认为一行,所以多行设定变量时,里面无法传递变量,见下面例子

 

 

5.变量赋值

shell:不允许有空格

Makefile:允许有空格

 

6.特殊情况

Makefile为了避免和shell的变量冲突,shell的变量以$$开头

PROJECT_ROOT_DIR = $(shell pwd | awk -F'/application|/base_class' '{print $$1}')

        

        

        

        

        

7.make在调用Shell之前先进行预处理,即展开所有Makefile的变量和函数        

shell自己的变量$$GOOD_DIR

Makefile的变量$(GOOD_DIR)

cat Makefile 

GOOD_DIR="you are"

 

all:

    @GOOD_DIR=arm-linux;\

    echo $$GOOD_DIR; echo $(GOOD_DIR)

    @echo $(GOOD_DIR)

zengzhihao@yingyongbu:~/work_place/test/youtest$ make

arm-linux

you are

you are

zengzhihao@yingyongbu:~/work_place/test/youtest$ make GOOD_DIR=outside

arm-linux

outside

outside

    

    

    

        

        

        

条件判断if

shell:

if [ $NOW_VAR == 1 ];then

echo "var is 1"

elif [ $NOW_VAR == 2 ];then

echo "var is 2"

else

echo "var is not 1"

fi

 

 

Makefile:

NOW_DIR=$(shell pwd)

ifeq ($(NOW_VAR), 1)

NOW_DIR="in 1"

else ifeq ($(NOW_VAR), 2)

NOW_DIR="in 2"

else

NOW_DIR="in not 1 or 2"

endif

all:

         echo $(NOW_DIR)

 

 

ifneq ($(NOW_VAR), 1)

endif

 

ifdef V

endif

ifndef V

endif

 

 

 

 

 

for循环

shell:

for pid in ${pids};

do

xxxxx

done

 

 

while循环

shell:

while true

do

xxxx

done        

        

 

Makefile中的for循环,采用shell的for循环

file=1 2 3 4 5

all:

    for name in $(file); \

    do \

    echo $$name;  \

    done

        

        

        

例子        

        两种实现方式

all:

    CC=arm-linux;echo $$CC

    

all:

    @CC=arm-linux;\

    echo $$CC            

    

    

    

    

    


Makefile与shell脚本区别

 

 

http://blog.csdn.net/absurd/article/details/636418

 

1.通配符不一样

shell:*

Makefile:%

2.引用变量不一样

shell:$var   或者${var}

Makefile:$(var)

 

3.Makefile的target里面才执行shell脚本或者用函数$(shell pwd),其他地方不会

 

4.Makefile的每一行都是开辟一个进程来执行,所有要执行多个shell用\,来认为一行,所以多行设定变量时,里面无法传递变量,见下面例子

 

 

5.变量赋值

shell:不允许有空格

Makefile:允许有空格

 

6.特殊情况

Makefile为了避免和shell的变量冲突,shell的变量以$$开头

PROJECT_ROOT_DIR = $(shell pwd | awk -F'/application|/base_class' '{print $$1}')

        

        

        

        

        

7.make在调用Shell之前先进行预处理,即展开所有Makefile的变量和函数        

shell自己的变量$$GOOD_DIR

Makefile的变量$(GOOD_DIR)

cat Makefile 

GOOD_DIR="you are"

 

all:

    @GOOD_DIR=arm-linux;\

    echo $$GOOD_DIR; echo $(GOOD_DIR)

    @echo $(GOOD_DIR)

zengzhihao@yingyongbu:~/work_place/test/youtest$ make

arm-linux

you are

you are

zengzhihao@yingyongbu:~/work_place/test/youtest$ make GOOD_DIR=outside

arm-linux

outside

outside

    

    

    

        

        

        

条件判断if

shell:

if [ $NOW_VAR == 1 ];then

echo "var is 1"

elif [ $NOW_VAR == 2 ];then

echo "var is 2"

else

echo "var is not 1"

fi

 

 

Makefile:

NOW_DIR=$(shell pwd)

ifeq ($(NOW_VAR), 1)

NOW_DIR="in 1"

else ifeq ($(NOW_VAR), 2)

NOW_DIR="in 2"

else

NOW_DIR="in not 1 or 2"

endif

all:

         echo $(NOW_DIR)

 

 

ifneq ($(NOW_VAR), 1)

endif

 

ifdef V

endif

ifndef V

endif

 

 

 

 

 

for循环

shell:

for pid in ${pids};

do

xxxxx

done

 

 

while循环

shell:

while true

do

xxxx

done        

        

 

Makefile中的for循环,采用shell的for循环

file=1 2 3 4 5

all:

    for name in $(file); \

    do \

    echo $$name;  \

    done

        

        

        

例子        

        两种实现方式

all:

    CC=arm-linux;echo $$CC

    

all:

    @CC=arm-linux;\

    echo $$CC            

    

    

    

    

    

    

 

1.通配符
2.引用的变量
3.赋值
4.makefile的一行
5.makefile调用shell
6.判断和循环语句

 

 

    

    

    

    
 

    

    

    

    

    
 

    

    

    

    

    
 

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值