makefile编写---单个子目录编译自动变量模板ok

1.自动化变量通配符http://blog.sina.com.cn/s/blog_7c95e5850101b38l.html

2.wildcard 使用http://blog.csdn.net/liangkaiming/article/details/6267357

3.srcs=(wildcard:%。o=%。c)说明

http://os.chinaunix.net/a2008/0312/978/000000978004.shtml

4.$(srcs):%.o:%.c说明==$(patsubst %.c,%.o $(wildcard  *.c))==$($(wildcard  *.c):%.c=%.o)

http://bbs.csdn.net/topics/380082064

http://www.linuxsir.org/bbs/thread205437.html

http://guliqun1983.blog.163.com/blog/static/50111685201171842740793/

5.规则http://www.cnblogs.com/pied/archive/2012/11/02/2751476.html

6.bug报错 http://zhidao.baidu.com/link?url=-TFGEM8kQx9O416zeRqcMkpkMP29aIcMYaNC-gteCQ62ydSfk5qJglEkr3h4-K3YofHfKfsDPsoGQr9qBELazq

http://www.baidu.com/#wd=%2Fusr%2Flib%2Fgcc%2Fi486-linux-gnu%2F4.4.3%2F..%2F..%2F..%2F..%2Flib%2Fcrt1.o%3A%20In%20function%20%60_start%27%3A&rsv_spt=1&rsv_bp=1&ie=utf-8&tn=baiduhome_pg&rsv_sug3=7&rsv_sug4=562&rsv_sug2=0&inputT=891&f=8&rsv_sug=1&bs=%25.c%3A%25.o&rsv_n=2

me:

Target  = auto

Cc = gcc
Cflags =  -Wall -O
Lflags = -lpthread
Include = -I
Ar = ar
Libs =

Srcs = $(wildcard *.c)
#$(wildcard,./sub/*.c) qudiao ','
Incs = $(wildcard *.h)
Objects = $(Srcs:%.c=%.o)

.PHONY:clean release install

all: release
print:
  @echo $(Srcs)
  @echo $(Incs)
  @echo $(Objects)
  @echo "why???"
release:$(Target)

$(Target):$(Objects)
 $(Cc)  $^  -o $@
 @echo $@
 @echo "pkf"
$(Objects):%.o:%.c $(Incs)          // this is not need!!!!!
 $(Cc) -c $< -o $@
 @echo $@
 @echo $<
clean:
 -rm *.o
 -rm $(Target)

 

 

 

 

exmple:

==============================================================
Target = TestIni
GCC = gcc
G++ = g++

CInc = $(wildcard *.h)
CSrc = $(wildcard *.c)

Cobjects =$(CSrc:%.c=%.o)
#Cobjects =$(patsubst %.c,%.o,$(CSrc))


release:$(Target)

$(Target): $(Cobjects)
$(GCC) -o $@ $^

 

##################test######################

#CInc += iniparser.h dictionary.h
#CSrc += iniparser.c dictionary.c
#Cobjects += iniparser.o dictionary.o
#CppObejects =
#$(Cobjects):$(Csrc)
# $(GCC) $(CInc) -c $<

#$(Target): iniparser.o dictionary.o
# $(GCC) -o $@ $^

#iniparser.o: iniparser.c
# $(GCC) $(CInc) -c $<
#dictionary.o: dictionary.c
# $(GCC) $(CInc) -c $<


clean:
rm -rf *.o $(Target) *.gch

===================================================

http://blog.csdn.net/liangkaiming/article/details/6267357

wildcard netdir patsubst

make -f makefile release

posted @ 2014-07-22 00:23  midu  阅读(305)  评论(0编辑  收藏  举报