免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: ljoolj
打印 上一主题 下一主题

[NetBSD] 请教:如何去掉make给的gcc 加上的-O2 选项 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2006-03-24 15:16 |只看该作者
原帖由 ljoolj 于 2006-3-24 14:04 发表
明白了,gcc 里面 -O2 -O0 可以同时存在
最后一个有效是这个意思吧。
那可以直接在Makefile里面改,不用在/etc/mk.conf改,这样改影响面太大了。


刚才看了一下讲awk的书以及我们前段时间翻译的《FreeBSD系统编程》中的make部分,找出了另外一个挺有意思的解决办法:

在你自己的Makefile文件的开头加上这样两句话:

  1. TMP_CFLAGS = $(CFLAGS)
  2. CFLAGS != awk 'BEGIN {"echo $(TMP_CFLAGS)" | getline ; sub("-O2", "") ; print $0}'
复制代码


这样一来,不管之前给CFLAGS赋了什么值,通过这两句话,就能把其中的-O2选项给去掉。同理,只需替换第二行中的"-O2",即可去除或修改之前赋给CFLAGS的任何选项。

这样你也不必去动系统makefile里的东西了。

论坛徽章:
1
寅虎
日期:2013-09-29 23:15:15
12 [报告]
发表于 2006-03-24 15:22 |只看该作者
呵~awk还可以这样用.真有趣!

论坛徽章:
0
13 [报告]
发表于 2006-03-24 15:46 |只看该作者
原帖由 congli 于 2006-3-24 15:22 发表
呵~awk还可以这样用.真有趣!


俺也是现学现用,纯属为了练习awk,

论坛徽章:
1
寅虎
日期:2013-09-29 23:15:15
14 [报告]
发表于 2006-03-24 15:53 |只看该作者
原帖由 雨丝风片 于 2006-3-24 15:46 发表


俺也是现学现用,纯属为了练习awk,

家里那本<sed与awk>还闲放着,没时间看.
不过这几天用awk解决了几个小问题.感觉挺不错!

论坛徽章:
0
15 [报告]
发表于 2006-03-24 16:14 |只看该作者
原帖由 雨丝风片 于 2006-3-24 15:16 发表


刚才看了一下讲awk的书以及我们前段时间翻译的《FreeBSD系统编程》中的make部分,找出了另外一个挺有意思的解决办法:

在你自己的Makefile文件的开头加上这样两句话:

[code]TMP_CFLAGS = $(CFLAGS)
CFLAGS != awk 'BEGIN {"echo $(TMP_CFLAGS)" | getline ; sub("-O2", "") ; print $0}'


刚才测试过了,虽然多敲几个字,不过感觉巧妙一些哈:)

论坛徽章:
0
16 [报告]
发表于 2006-03-24 16:33 |只看该作者
原帖由 ljoolj 于 2006-3-24 16:14 发表
刚才测试过了,虽然多敲几个字,不过感觉巧妙一些哈:)


跟我们写代码一样,一种“普适”的解决方案看上去一般都要复杂一些,

不过扩展方法也很简单:
sub("被替换选项", "替换后的内容" )

论坛徽章:
2
亥猪
日期:2014-03-19 16:36:35午马
日期:2014-11-23 23:48:46
17 [报告]
发表于 2006-03-24 16:41 |只看该作者
pmake 有这个功能阿。在man make : variable modifiers那里
${CFLAGS:C/-O./-O0/:u}
不过不知道是不是只能pmake这样搞。
我记得gmake有替换函数。

论坛徽章:
0
18 [报告]
发表于 2006-03-24 17:00 |只看该作者
原帖由 gvim 于 2006-3-24 16:41 发表
pmake 有这个功能阿。在man make : variable modifiers那里
${CFLAGS:C/-O./-O0/:u}
不过不知道是不是只能pmake这样搞。
我记得gmake有替换函数。


哈哈,不错!把该看的书都看遍了,就是没去man make,结果绕了个大弯子!
俺今天是对pmake刮目相看了!

论坛徽章:
0
19 [报告]
发表于 2006-03-24 17:04 |只看该作者
gmake的“替换引用”也可以达到这个目的:

6.3.1 Substitution References
A substitution reference substitutes the value of a variable with alterations that you specify. It has the form `$(var:a=b)' (or `${var:a=b}') and its meaning is to take the value of the variable var, replace every a at the end of a word with b in that value, and substitute the resulting string.

When we say "at the end of a word", we mean that a must appear either followed by whitespace or at the end of the value in order to be replaced; other occurrences of a in the value are unaltered. For example:

  foo := a.o b.o c.o
bar := $(foo:.o=.c)


原来看过这里的,今天没有想起来,
回去再仔细看看pmake的man,免得以后又走弯路了,

[ 本帖最后由 雨丝风片 于 2006-3-24 17:07 编辑 ]

论坛徽章:
2
亥猪
日期:2014-03-19 16:36:35午马
日期:2014-11-23 23:48:46
20 [报告]
发表于 2006-03-24 22:10 |只看该作者
挖到这个东西,来源 http://www.home.unix-ag.org/bmeurer/NetBSD/tips.html

What to put in /etc/mk.conf
  1. In order to get a sane build environment and to build sane packages out of your environment, you should consider overriding some default values in your /etc/mk.conf. For example, if you are running NetBSD/alpha, you shouldn't use any optimizations to cc(1), because gcc is still buggy on Alpha. And in general you should think twice before setting the optimization level above 2, because this might cause several programs to segfault frequently or not run at all. Here are some lines from my mk.conf, which might help you (they will honor all default values but -O*):

  2. COMMONCFLAGS?=-O2 -pipe
  3. COPTS:=${COMMONCFLAGS} ${COPTS:C/-O[0-9]*//g}
  4. CFLAGS:=${COMMONCFLAGS} ${CFLAGS:C/-O[0-9]*//g}
  5. CXXFLAGS:=${COMMONCFLAGS} ${CXXFLAGS:C/-O[0-9]*//g}
  6.           When trying to fix bugs in packages, it is helpful to append -Wall -Werror to COMMONCFLAGS, but beware: This might break a lot of configure scripts (so, you have the chance to fix them too ;-). Another needful thing to have in your mk.conf is support for sudo instead of the default su(1), so you may need not to type the root password everytime you install a package as a user. Here are the lines from my mk.conf:

  7. .if exists(/usr/pkg/bin/sudo)
  8. SU_CMD=/usr/pkg/bin/sudo /bin/sh -c
  9. .endif
  10.           Another helpful thing to do, is to override the default MASTER_SITE with faster (local) mirrors. E.g. I have a local NetBSD mirror (thats the tatooine.kosmos.all line, so don't simply copy&paste to your mk.conf :-), from where pkgsrc should try to fetch the needed distfiles first and after that fails, it will try several other mirrors, and only if a distfile cannot be found there, it'll try to fetch it from the MASTER_SITEs specified for the package. Here are the lines from my mk.conf:

  11. MASTER_SITE_OVERRIDE+= \
  12. ftp://tatooine.kosmos.all/pub/NetBSD/packages/distfiles/ \
  13. ftp://ftp.de.netbsd.org/pub/NetBSD/packages/distfiles/ \
  14. ftp://ftp2.de.netbsd.org/pub/NetBSD/packages/distfiles/ \
  15. ftp://ftp.at.netbsd.org/pub/NetBSD/packages/distfiles/ \
  16. ftp://ftp.netbsd.org/pub/NetBSD/packages/distfiles/
复制代码

[ 本帖最后由 gvim 于 2006-3-24 22:17 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP