Makefile问题记录

1、变量错误–PATH

Makefile原文

#!bin/sh
vi24: clean pcie5_0

PATH=/local_vol1_nobackup/xxxxxx/pcie5_0/

pcie5_0:
	$(shell pwd) \
	$(shell cd) ${PATH} 

clean:
	rm -rf Makefile~

Bug打印信息:

srdcws220:~ [ 96 ] --> make clean
rm -rf Makefile~
/bin/sh: rm: command not found
make: *** [Makefile:10: clean] Error 127

Debug

  1. 在terminal中输入命令没有问题。
  2. 问题是出现在加上变量PATH之后。
  3. 通过搜索最后确认是变量PATH的问题,原因是变量PATH与环境变量重名了,更改为HOME_PATH即可。

Makefile更改后

#!bin/sh
vi24: clean pcie5_0

HOME_PATH=/local_vol1_nobackup/xxxxxx/pcie5_0/

pcie5_0:
	$(shell pwd) \
	$(shell cd) ${HOME_PATH} 

clean:
	rm -rf Makefile~

2、"Command not found"问题

Makefile原文

#!bin/sh

bootenv:
	bootenv

clean:
	rm -rf Makefile~

bug

srdcws220:~> [ 78 ] --> make bootenv
bootenv
make: bootenv: Command not found
make: *** [Makefile:4: bootenv] Error 127
srdcws220:~> [ 79 ] --> 

Debug

  1. 请教公司大神的回复:
  2. Unless you’ve told it otherwise, make isn’t using bash, it’s using sh. While sh is probably a symlink to bash, when invoked as “sh” it doesn’t read your .bashrc (nor the system default). You can change this behavior with the SHELL variable in your makefile:
SHELL := /bin/bash

In general, though, it’s better to set everything that you need in the makefile, since relying on your aliases makes your makefile highly non-portable. I usually do something like (using your example):

X := y 

and then using $(X) instead of the alias x in commands. 。

  1. 大体意思是Makefile使用的是sh而不是bash,不过sh可以链接到bash,通过变量SHELL链接到csh,代码如下:
#!/bin/sh
SHELL:=/bin/csh

bootenv:
	source /proj/verif_release_ro/cbwa_bootcore/current/bin/_bootenv.csh

clean:
	rm -rf Makefile~

其中bootenv是alias的内容,需要找到代指的路径。完美!

附在网上搜索的:
今天在编译一个第三方库的时候,按照编译手册,设置完环境变量后,就应该直接make,操作步骤跟原来遇到的一样,没有什么异常,但是却出现了错误,说/bin/sh source not found,这就奇怪了,我在shell下直接source是好用的啊,当时以为Makefile里面的环境变量有问题,就想找到source的绝对路径,直接替换,于是通过"whereis source"查找source命令的路径,却没有找到。
很是奇怪,以为是PATH路径里面没包含,但是在shell下打souce确实可以运行啊。百思不得其解。
于是就开始了网上查找相关资料,发现网上都是介绍source的使用方法的,里面么有一个提source的路径的问题的。倒是有人说用.替换source的,实在没办法,用CTRL_H把source 替换成了“。”,这部分通过了,可又出现了pushd,popd的同样的问题,这就很奇怪了,我在shell下都是可用的,可在Makefile里面就是不行,还有就是同样的在PATH路径下面都没有这几个命令。
只能求助网络,查了很多很多,总算在无意当中顿悟了,这个问题居然出在shell上。sourc/pushd/popd 都是属于shell的内置命令,在PATH里当然找不到了。而只能在shell里面运行。但是这几个命令只在bash shell里面。我们在adduser时是可以选择登陆shell种类的,/bin/sh /bin/bash等等。
我的Linux默认登陆的就是/bin/bash,但是Makefile里面如果不指定,那默认就是/bin/sh,所以会出现上面这个很诡异的问题。w在Makefile中使用SHELL=/bin/bash来指定在Makefile中所使用的shell种类,这个问题就解决了。
这里多说几句就是我们经常在写脚本时,习惯性的第一句都写的是#! /bin/sh或者 #! /bin/bash原来一直以为这个就是个注释,根本没在意,原来这里就是指定的shell解释器种类,一般来讲/bin/sh与/bin/bash都是通用的,二者的命令基本一致。但是涉及到内部命令或者一些命令的细节的时候二者就有区别了,而这种错误又是不容易想到的,以后再遇到类似问题的时候一定要考虑一下有没有可能是shell种类的问题。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值