Linux shell 之Makefile
cat Makefile
c_src := $(shell ls *.c)
dirs := a b c d
files := $(foreach dir, $(dirs), $(wildcard $(dir)/*))
target:test.c
gcc -o hell test.c
@echo -e $(subst ee,EE, feet on the street)
@echo -e $(patsubst %.c, %.o, x.c.c bar.c)
@echo $(strip a b c)
@echo $(findstring a, a b c)
@echo $(findstring a, b c)
@echo $(filter %c %s, foo.c bar.c baz.s ugh.h)
@echo $(filter-out %c %s, foo.c bar.c baz.s ugh.h)
@echo $(sort foo bar lose)
@echo $(dir src/fooc hacks)
@echo $(notdir src/fooc hacks)
@echo $(suffix src/foo.c src-1.0/bar.c hacks)
@echo $(basename src/foo.c src-1.0/bar.c hacks)
@echo $(addsuffix .c, src/bar hacks)
@echo $(addprefix src/, foo bar)
@echo $(wildcard *.c)
@echo ${files}
@echo $(files)
@echo ${c_src}
@echo $(origin c_src)
@echo $(origin cheng)
clean:
rm -f hello
daheng@ubuntu:~/test_program$ cat Makefile
c_src := $(shell ls *.c)
dirs := a b c d
files := $(foreach dir, $(dirs), $(wildcard $(dir)/*))
target:test.c
gcc -o hell test.c
@echo -e $(subst ee,EE, feet on the street)
@echo -e $(patsubst %.c, %.o, x.c.c bar.c)
@echo $(strip a b c)
@echo $(findstring a, a b c)
@echo $(findstring a, b c)
@echo $(filter %c %s, foo.c bar.c baz.s ugh.h)
@echo $(filter-out %c %s, foo.c bar.c baz.s ugh.h)
@echo $(sort foo bar lose)
@echo $(dir src/fooc hacks)
@echo $(notdir src/fooc hacks)
@echo $(suffix src/foo.c src-1.0/bar.c hacks)
@echo $(basename src/foo.c src-1.0/bar.c hacks)
@echo $(addsuffix .c, src/bar hacks)
@echo $(addprefix src/, foo bar)
@echo $(wildcard *.c)
@echo ${files}
@echo $(files)
@echo ${c_src}
@echo $(origin c_src)
@echo $(origin cheng)
clean:
rm -f hello
执行make
gcc -o hell test.c
fEEt on the strEEt
x.c.o bar.o
a b c
a
foo.c bar.c baz.s
ugh.h
bar foo lose
src/ ./
fooc hacks
.c .c
src/foo src-1.0/bar hacks
src/bar.c hacks.c
src/foo src/bar
timer2.c traverseFile.c sever.c timer1.c test1.c color_script.sh.x.c testNet.c test.c mysql_test.c test_sockpair.c
a/3 a/2 a/1 b/6 b/5 b/4 c/9 c/8 c/7
a/3 a/2 a/1 b/6 b/5 b/4 c/9 c/8 c/7
color_script.sh.x.c mysql_test.c sever.c test1.c test.c testNet.c test_sockpair.c timer1.c timer2.c traverseFile.c
file
undefined
此外:
makefile常见的四种赋值有
"=",普通等号
":=",会把之前的赋值覆盖掉
"?=",若没有赋值,则赋予等号后的值。
"+=":普通+=,字符串内容相加
浙公网安备 33010602011771号