makefile使用通配符的一个例子

来源:互联网 发布:身边有关大数据的例子 编辑:程序博客网 时间:2024/06/16 01:29

工程路径设置

root

 |------bin

 |------main

 |------objs

 |------source

 |------test



CC = gcc -g -O0



root_path = .
sfix = .c
inc_path = $(root_path)/source


srcs = $(wildcard $(root_path)/source/*.c)
objs = $(patsubst $(root_path)/source/%.c, $(root_path)/objs/%.o, $(wildcard $(root_path)/source/*.c))
# all_srcs = $(foreach x, $(root_path)/source, $(wildcard $(addprefix $(x)/*, $(sfix))))
main_srcs = $(wildcard $(root_path)/main/*.c)
main_objs = $(patsubst $(root_path)/main/%.c, $(root_path)/objs/%.o, $(wildcard $(root_path)/main/*.c))


all: $(objs) $(main_objs)
$(CC) -I$(inc_path) -o $(root_path)/bin/partition  $^


$(objs): $(root_path)/objs/%.o: $(root_path)/source/%.c
$(CC) -I$(inc_path) -c $< -o $@


$(main_objs): $(root_path)/objs/%.o: $(root_path)/main/%.c
$(CC) -I$(inc_path) -c $< -o $@


.PHONY: clean
clean:
rm -rf $(root_path)/objs/*.o $(root_path)/bin/*