Skip to content

Instantly share code, notes, and snippets.

@Jamlee
Last active April 10, 2021 21:49
Show Gist options
  • Save Jamlee/51d2b90045f34d138452785355cecde5 to your computer and use it in GitHub Desktop.
Save Jamlee/51d2b90045f34d138452785355cecde5 to your computer and use it in GitHub Desktop.
Makefile
default: all
OUTDIR=out
CFLAGS=-g -Wall
INCLUDES=-I../src
# 测试依赖内容
OBJECTS=main.o adlist.o zmalloc.o
$(foreach i,$(OBJECTS),$(eval "$(OUTDIR)/$(subst .o,,$(i)).o:$(subst .o,,$(i)).c"))
# 在其他目录寻找文件
vpath % ../src
all: app
app: $(addprefix $(OUTDIR)/, $(OBJECTS))
$(CC) $^ -o $(OUTDIR)/$@
$(OUTDIR)/%.o: %.c
$(CC) $(CFLAGS) $^ $(INCLUDES) -c -o $@
clean:
rm -fr out/*
.PHONY: clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment