-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
52 lines (42 loc) · 1.29 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
49
50
51
CC := mpicc
CFLAGS := -O3 -std=c99 -flto -Wall -Wextra
DEPEND := -MMD
LIBS := -lfftw3 -lm
INCLUDES := -Iinclude
SRCSDIR := src
OBJSDIR := obj
SRCS := $(foreach dir, $(shell find $(SRCSDIR) -type d), $(wildcard $(dir)/*.c))
OBJS := $(addprefix $(OBJSDIR)/, $(subst $(SRCSDIR)/,,$(SRCS:.c=.o)))
DEPS := $(addprefix $(OBJSDIR)/, $(subst $(SRCSDIR)/,,$(SRCS:.c=.d)))
OUTPUTDIR := output
TARGET := a.out
help:
@echo "all : create \"$(TARGET)\""
@echo "clean : remove \"$(TARGET)\" and object files \"$(OBJSDIR)/*.o\""
@echo "output : create \"$(OUTPUTDIR)\" and sub-directories"
@echo "datadel : remove \"$(OUTPUTDIR)\" and sub-directories"
@echo "help : show this help message"
all: $(TARGET)
$(TARGET): $(OBJS)
$(CC) $(CFLAGS) $(DEPEND) -o $@ $^ $(LIBS)
$(OBJSDIR)/%.o: $(SRCSDIR)/%.c
@if [ ! -e `dirname $@` ]; then \
mkdir -p `dirname $@`; \
fi
$(CC) $(CFLAGS) $(DEPEND) $(INCLUDES) -c $< -o $@
clean:
$(RM) -r $(OBJSDIR) $(TARGET)
output:
@if [ ! -e $(OUTPUTDIR)/save ]; then \
mkdir -p $(OUTPUTDIR)/save; \
fi
@if [ ! -e $(OUTPUTDIR)/log ]; then \
mkdir -p $(OUTPUTDIR)/log; \
fi
@if [ ! -e $(OUTPUTDIR)/stat ]; then \
mkdir -p $(OUTPUTDIR)/stat; \
fi
datadel:
$(RM) -r $(OUTPUTDIR)
-include $(DEPS)
.PHONY : help all clean output datadel