1、在Makefile中只能在target中调用Shell脚本,其他地方是不能输出的。比如如下代码就是没有任何输出:

VAR="Hello"
echo "$VAR"all:.....

以上代码任何时候都不会输出,没有在target内,如果上述代码改为如下:

VAR="Hello"all:echo "$VAR".....

以上代码,在make all的时候将会执行echo命令。

2、在Makefile中执行shell命令,一行创建一个进程来执行。这也是为什么很多Makefile中有很多行的末尾都是“;  \”,以此来保证代码是一行而不是多行,这样Makefile可以在一个进程中执行,例如:

SUBDIR=src example
all:@for subdir in $(SUBDIR); \do\echo "building "; \done

上述可以看出for循环中每行都是以”; \”结尾的。

3、Makefile中所有以$打头的单词都会被解释成Makefile中的变量。如果你需要调用shell中的变量(或者正则表达式中锚定句位$),都需要加两个$符号($$)。实例如下:

PATH="/data/"all:echo ${PATH}echo $$PATH

例子中的第一个${PATH}引用的是Makefile中的变量,而不是shell中的PATH环境变量,后者引用的事Shell中的PATH环境变量。

以上三点的是Makefile调用shell应该注意的地方,写Makefile一定要注意。

如果make执行的命令前面加了@字符,则不显示命令本身而只显示它的结果; Android中会定义某个变量等于@,例如 hide:= @

通常make执行的命令如果出错(该命令的退出状态非0)就立刻终止,不再执行后续命令,但如果命令前面加了-号,即使这条命令出错,make也会继续执行后续命令。

通常rm命令和mkdir命令前面要加-号,因为rm要删除的文件可能不存在,mkdir要创建的目录可能已存在,这两个命令都有可能出错,但这种错误是应该忽略的。

Stripping shared libraries

Wed 23 December 2009

In linux.

Ian Wienand

So, how to strip a shared library?

--strip-unneeded states that it removes all symbols that are not needed for relocation processing. This is a little cryptic, because one might reasonably assume that a shared library can be "relocated", in that it can be loaded anywhere. However, what this really refers to is object files that are usually built and bundled into a .a archive for static linking. For an object in an static library archive to still be useful, global symbols must be kept, although static symbols can be removed. Take the following small example:

$ cat libtest.c
static int static_var = 100;
int global_var = 100;static int static_function(void) {return static_var;
}int global_function(int i) {return static_function() + global_var + i;
}

Before stripping:

$ gcc -c -fPIC -o libtest.o libtest.c
$ readelf --symbols ./libtest.oSymbol table '.symtab' contains 18 entries:Num:    Value  Size Type    Bind   Vis      Ndx Name
...5: 00000000     4 OBJECT  LOCAL  DEFAULT    5 static_var6: 00000000    22 FUNC    LOCAL  DEFAULT    3 static_function13: 00000004     4 OBJECT  GLOBAL DEFAULT    5 global_var16: 00000016    36 FUNC    GLOBAL DEFAULT    3 global_function

After stripping:

$ strip --strip-unneeded libtest.o
$ readelf --symbols ./libtest.oSymbol table '.symtab' contains 15 entries:Num:    Value  Size Type    Bind   Vis      Ndx Name
...10: 00000004     4 OBJECT  GLOBAL DEFAULT    5 global_var13: 00000016    36 FUNC    GLOBAL DEFAULT    3 global_function

If you --strip-all from this object file, it will remove the entire .symtab section and will be useless for further linking, because you'll never be able to find global_function to call it!.

Shared libraries are different, however. Shared libraries keep global symbols in a separate ELF section called .dynsym. --strip-all will not touch the dynamic symbol entires, and thus it is therefore safe to remove all the "standard" symbols from the output file, without affecting the usability of the shared library. For example, readelf will still show the .dynsym symbols even after stripping:

$ gcc -shared -fPIC -o libtest.so libtest.c
$ strip --strip-all ./libtest.so
$ readelf  --syms ./libtest.soSymbol table '.dynsym' contains 11 entries:Num:    Value  Size Type    Bind   Vis      Ndx Name
...6: 00000452    36 FUNC    GLOBAL DEFAULT   12 global_function10: 000015e0     4 OBJECT  GLOBAL DEFAULT   21 global_var

However, --strip-unneeded is smart enough to realise that a shared-object library doesn't need the .symtab section as well and remove it.

So, conclusions? --strip-all is safe on shared libraries, because global symbols remain in a separate section, but not on objects for inclusion in static libraries (relocatable objects). --strip-unneeded is safe for both, and automatically understands shared objects do not need any .symtab entries to function and removes them; effectively doing the same work as --strip-all. So, --strip-unneeded is essentially the only tool you need for standard stripping needs!

See also



Makefile文件和shell脚本相关推荐

  1. Linux 金字塔 的shell命令,linux下保留文件系统下剩余指定数目文件的shell脚本

    原文出处: http://www.jbxue.com/article/13808.html (原创文章,转载请注明出处) 本节内容: 保留文件系统下剩余指定数目的文件 例子: #!/bin/bash ...

  2. linux 循环显示所有的sh.*文件.,利用shell脚本遍历文件夹内所有的文件并作整理统计的方法...

    环境: Ubuntu下采用shell脚本实现 案例简述:文件夹内有许多子文件夹,这里需要自动读取所有的文件,包括他们的地址和文件名.通过观察文件名的规律,按照一定的规则裁剪出文件名的某一部分,该部分为 ...

  3. xml文件、jsp文件、sql文件、shell脚本文件注释

    一,各种文件如何注释: 1.xml文件注释 注释以 <!-- 开始并以 --> 结束, 例如 <!--注释内容-->. 2.jsp文件注释 2. 1. html注释:      ...

  4. php批量替换文件内容,Shell脚本实现批量替换文件内容

    Shell脚本实现批量替换文件内容 今天同事发现内部服务器的硬盘空间不够了,上面有很多备份,我又不能删除,重新找了个320g的硬盘挂载了上,想以后shell脚本下的备份都转移到新硬盘上,给老硬盘腾出空 ...

  5. linux遍历目录删除指定文件,利用shell脚本遍历文件夹内所有的文件并作整理统计的方法-linux删除文件夹...

    本篇文章扣丁学堂Linux培训小编给读者们分享一下利用shell脚本遍历文件夹内所有的文件并作整理统计的方法,文章具有很好的参考价值,感兴趣的小伙伴就随小编来了解一下吧. 环境: Ubuntu下采用s ...

  6. linux递归删除空文件夹,Shell脚本实现递归删除空文件夹

    有时我们需要递归删除空文件夹,网上找了一下,没有发现比较好的Shell脚本,于是自己动手写了一个 脚本 #!/bin/bash # author: 十年后的卢哥哥 # des: delete empt ...

  7. linux sh文件case,Shell脚本case语句简明教程

    Shell case语句为多选择语句.可以用case语句匹配一个值与一个模式,如果匹配成功,执行相匹配的命令.case语句格式如下: case 值 in 模式1) command1 command2 ...

  8. ue 编写linux脚本,UltraEdit23 sh文件 (shell脚本)着色

    网上有UltraEdit早期版本的添加方法: 但是这新版本有点不同: 方法如下: 安装后,到AppData\Roaming\IDMComp\UltraEdit\wordfiles 目录下添加UnixS ...

  9. linux while read文件,linux shell脚本用while read逐行读取文本的问题

    问题: 我现在是想用一个脚本获取一定列表服务器的运行时间.首先我建立一个名字为ip.txt的IP列表(一个IP一行),再建好密钥实现不用密码直接登录.然后写脚本如下:#!/bin/bashwhile ...

最新文章

  1. 反转字符串/列表、改变递归次数限制、else用法...Python 冷知识(四)
  2. GitHub超4.4k星:程序员求职,一个算法模板就够了
  3. eclipse中anroid adk添加
  4. SpringBoot在项目中基本配置设置
  5. SharePoint 2013 Nintex Workflow 工作流帮助(六)
  6. 中文路径读取乱码,json乱码
  7. 算法笔记_面试题_13.二叉树的最近公共祖先
  8. 【实用工具】原型图绘画工具推荐
  9. 小米路由器3g改无线打印机服务器,小米路由器3G怎么设置?
  10. 关于几种获取iOS设备UDID典型方式的技术探讨
  11. oracle数据投毒,Oracle Database Server TNS Listener远程数据投毒漏洞(CVE-2012-1675)的完美解决方法...
  12. 天气预报API接口大全
  13. mysql 语句 面试题
  14. 硬件:Nand Flash、Nor Flash
  15. 蓝牙耳机选什么好?5款主打高性价比的蓝牙耳机推荐
  16. 移动端H5的js操作
  17. math_@多元函数求导@全微分@偏导数@复合偏导
  18. 桌面云服务器联想,联想云桌面系统助力四川大学搭建智慧课堂
  19. WINCE TCPMP应用一:TCPMP概述
  20. 远距离无线音视频传输方案,物联网技术应用,无线远距离WiFi通信技术

热门文章

  1. zabbix 自动发现和注册
  2. Jenkins 安装简记录
  3. JAVA 读取图片储存至本地
  4. Java学习之注解Annotation实现原理
  5. php 一次性替换多个关键词
  6. shell高级视频答学生while循环问题
  7. linux 命令详解 二十二
  8. [转]中国CIO的空前机会和空前责任
  9. Guava RateLimiter限流源码解析和实例应用
  10. apache ab压力测试工具-批量压测脚本