-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
49 lines (39 loc) · 1.04 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
CC := cc
CFLAG := -std=c99 -Wall -Wextra -Werror -O3 $(ARG_CFLAG)
INC := -Iinclude
LIB := -lm
SRCDIR := src
OBJDIR := obj
SRCS := $(shell find $(SRCDIR) -type f -name "*.c")
OBJS := $(patsubst %.c,$(OBJDIR)/%.o,$(SRCS))
DEPS := $(patsubst %.c,$(OBJDIR)/%.d,$(SRCS))
OUTDIR := output
TARGET := a.out
help:
@echo "all : create \"$(TARGET)\""
@echo "clean : remove \"$(TARGET)\" and object files under \"$(OBJDIR)\""
@echo "output : create \"$(OUTDIR)\" to store output"
@echo "datadel : clean-up \"$(OUTDIR)\""
@echo "help : show this message"
all: $(TARGET)
$(TARGET): $(OBJS)
$(CC) $(CFLAG) -o $@ $^ $(LIB)
$(OBJDIR)/%.o: %.c
@if [ ! -e $(dir $@) ]; then \
mkdir -p $(dir $@); \
fi
$(CC) $(CFLAG) -MMD $(INC) -c $< -o $@
clean:
$(RM) -r $(OBJDIR) $(TARGET)
output:
@if [ ! -e $(OUTDIR)/log ]; then \
mkdir -p $(OUTDIR)/log; \
fi
@if [ ! -e $(OUTDIR)/save ]; then \
mkdir -p $(OUTDIR)/save; \
fi
datadel:
$(RM) -r $(OUTDIR)/log/*
$(RM) -r $(OUTDIR)/save/*
-include $(DEPS)
.PHONY : all clean output datadel help