Chinaunix首页 | 论坛 | 博客
  • 博客访问: 61520
  • 博文数量: 25
  • 博客积分: 1899
  • 博客等级: 上尉
  • 技术积分: 250
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-29 23:45
文章分类

全部博文(25)

文章存档

2012年(22)

2010年(3)

我的朋友

分类: LINUX

2012-05-18 22:39:26

*每个文件一个可执行文件*

还是觉得使用.hello.exe 这种写法有点怪,最新的版本

(1)
不要用
%:%.o
$(CC) -o $@ $< $(LDFLAGS)
这样的规则,因为make 会使用内部隐含规则如:
gcc -g -lrt -lpthread mutex.c -o mutex
那么-lpthread 不是在规则最后时,大量告警就出来了:
undefined reference to `pthread_create'


(2)
你可以用 .exe 代替
OBJS := $(SRCS:%.c=%.exe)
%.exe:%.o

(3)
或是直接写一句来覆盖隐含规则:
%:%.c
@echo "----------linking $@------"
$(CC) -o $@ $< $(CFLAGS) $(LDFLAGS)


(4)
.hello.exe 版本
OBJS := $(SRCS:%.c=.%.exe)
.%.exe: %.o
$(LD) -o $@ $< $(LDFLAGS)
%.o: %.c
$(CC) -o $@ -c $< $(CFLAGS)

(5) 最终版本
CC := gcc

SRCS := $(wildcard *.c)
OBJS := $(SRCS:%.c=%)

CFLAGS := -g
LDFLAGS := -lrt -lpthread

all: $(OBJS)

clean c:
rm -f a.out $(OBJS) $(OBJS:%=%.o)

%:%.c
@echo "----------linking $@------"
$(CC) -o $@ $< $(CFLAGS) $(LDFLAGS)

.PHONY: all clean c

(1) make-doc

# apt-get install make-doc
# pinfo make
/Text Func

src=$(wildcard *.c ./sub/*.c)
dir=$(notdir $(src))
obj=$(patsubst %.c,%.o,$(dir)) # obj=$(dir:%.c=%.o)

(2) 内核Makefile
* Doc *
Documentation/kbuild/makefiles.txt

* Trace *
# make -d menuconfig
Reading makefile `Makefile'...
Reading makefile `/usr/src/linux-2.6.35.13/scripts/Kbuild.include'
Reading makefile `/usr/src/linux-2.6.35.13/arch/x86/Makefile'

ARCH为空时,读取当前PC平台(arch/x86)之Makefile.生成文件
.config

* reference *
八、KBuild MakeFile介绍

* chinaunix *

chinaunix.net 中想查看同一类的文章,请点击标题下左边的分类链接


* 解决方案 * use virtualbox: has modification time 3.2e+07 s in the future 
(0) ntpdate
(1) svn根目录下
find . -exec touch {} \;
(2) 最上层Makefile下
make clean
(3) 最上层Makefile下
make

* 如果写了很多小文件,每个文件一个使用一个.out的通用Makefile *




阅读(780) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~