-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
96 lines (73 loc) · 2.31 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
CC = gcc
ARCH := $(shell getconf LONG_BIT)
LIBPATH32 = ./lib/i386/linux/
LIBPATH64 = ./lib/amd64/linux/
CCLIB := -lm -msse2 -mfpmath=sse -L $(LIBPATH$(ARCH)) -ljpeg -lglut -lGLU -lGL
TARGET = RayTracing.exe
### include current folder (for headers)
CFLAGS = -I ./
SRCS := $(shell ls | grep c$$)
### include folder add
SRCS += $(addprefix include/, $(shell ls include | grep c$$))
DIR_CHECK += include
### include/images folder add
SRCS += $(addprefix include/images/, $(shell ls include/images | grep c$$))
DIR_CHECK += include/images
### naive folder add
SRCS += $(addprefix naive/, $(shell ls naive | grep c$$))
DIR_CHECK += naive
### kdtree folder add
SRCS += $(addprefix kdtree/, $(shell ls kdtree | grep c$$))
DIR_CHECK += kdtree
### shading folder add
SRCS += $(addprefix shading/, $(shell ls shading | grep c$$))
DIR_CHECK += shading
### images folder add
SRCS += $(addprefix images/, $(shell ls images | grep c$$))
DIR_CHECK += images
### interface folder add
SRCS += $(addprefix interface/, $(shell ls interface | grep c$$))
DIR_CHECK += interface
RELEASE_DIR = gcc_release
DEBUG_DIR = gcc_debug
DEPEND_FILE = depend_file
ifeq ($(MAKECMDGOALS), release)
OBJS_DIR = $(RELEASE_DIR)
CCOPT = -O2
else
OBJS_DIR = $(DEBUG_DIR)
CCOPT = -O2 -Wall -DDEBUG
endif
#OBJS = $(addprefix $(OBJS_DIR)/, $(notdir $(SRCS)))
OBJS = $(addprefix $(OBJS_DIR)/, $(SRCS))
OBJS := $(OBJS:%.c=%.o)
.SUFFIXES: .c .o
.PHONY: all release debug clean test
all:
@echo "=========================="
@echo "usage: make release"
@echo " make debug"
@echo " make clean"
@echo " make test [option=\"-cnf\"]"
@echo "=========================="
$(OBJS_DIR)/%.o : %.c
$(CC) $(CFLAGS) $(CCOPT) -c $< -o $@ $(CCLIB)
release: chkdir depend $(OBJS)
$(CC) $(CFLAGS) $(CCOPT) $(OBJS) -o $(TARGET) $(CCLIB)
debug: chkdir depend $(OBJS)
$(CC) $(CFLAGS) $(CCOPT) $(OBJS) -o $(TARGET) $(CCLIB)
clean:
@rm -rf $(DEPEND_FILE) $(DEBUG_DIR) $(RELEASE_DIR) $(TARGET) *.bmp *.nlogn *.nlog2n Debug Release
test:
./$(TARGET) $(option)
chkdir:
@`[ -d $(OBJS_DIR) ] || mkdir $(OBJS_DIR)`
@for DIR in $(DIR_CHECK); do \
[ -d $(OBJS_DIR)/$$DIR ] || mkdir $(OBJS_DIR)/$$DIR; \
done
depend: chkdir
@rm -f $(DEPEND_FILE)
@for FILE in $(SRCS:%.c=%); do \
$(CC) $(CFLAGS) -MM -MT $(OBJS_DIR)/$$FILE.o $$FILE.c >> $(DEPEND_FILE); \
done
-include $(DEPEND_FILE)