1:如果在当前目录中直接make的话使用下列代码:
#General Purpose Makefile by guoqingbo
objects := $(patsubst %.c,%.o,$(wildcard *.c))
executables := $(patsubst %.c,%,$(wildcard *.c))
all : $(objects)
$(objects) : %.o: %.c
gcc -c $< -o $@
gcc $< -o $(subst .o, ,$@)
clean :
@rm -rf *.o *~
@rm -rf ${executables}
.PHONY : clean
2:后来发现下列代码也可以有相同效果,难道使用了什么默认规则,还不是很明白,先记录下来:
#General Purpose Makefile by guoqingbo
executables := $(patsubst %.c,%,$(wildcard *.c))
all : $(executables)
clean :
@rm -rf *.o *~
@rm -rf ${executables}
.PHONY : clean