-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
139 lines (115 loc) · 3.41 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
CC = g++
CLANG = clang++
CFLAGS = -g -std=c++11 -std=c++0x -Wall -Wextra
OBJCFLAGS := -framework Cocoa
MAIN := main
SOURCEDIR := src
INCLUDEDIR := src
BUILDDIR := build
DLLDIR := bin
SAMPLEDIR := $(SOURCEDIR)/sample
SAMPLESRCS := $(wildcard $(addprefix $(SAMPLEDIR)/, *.cpp))
SAMPLEOBJS := $(addprefix $(BUILDDIR)/, $(notdir $(SAMPLESRCS:.cpp=.o)))
PLATDIR := $(SOURCEDIR)/platform
SOURCES := $(wildcard $(addprefix $(SOURCEDIR)/, *.cpp))
OBJECTS := $(addprefix $(BUILDDIR)/, $(notdir $(SOURCES:.cpp=.o))) $(SAMPLEOBJS)
INCLUDES := -I$(INCLUDEDIR)
HEADERS := $(wildcard $(addprefix $(INCLUDEDIR)/, *.hpp)) $(PLATDIR)/platform.hpp $(SAMPLEDIR)/sample.hpp
# MacOS Compile
MACSOURCES := $(SOURCEDIR)/macos.mm
MACOBJECTS := $(filter-out build/$(MAIN).o, $(OBJECTS))
# DLL Compile
DLLOBJECTS := $(filter-out build/$(MAIN).o, $(OBJECTS))
TARGET = viewer
SAMPLE = sample
DLLTARGET = $(DLLDIR)/lurdr.dll
RM := rm -f
RMDIR := rm -f
MD := mkdir -p
# reference : https://stackoverflow.com/questions/714100/os-detecting-makefile
ifeq ($(OS),Windows_NT)
MD := mkdir
RM := del /s /q
RMDIR := rmdir /s /q
TARGET := viewer.exe
CFLAGS += -fopenmp
ifeq ($(PROCESSOR_ARCHITEW6432),AMD64)
CFLAGS += -D AMD64
else
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
CFLAGS += -D AMD64
endif
ifeq ($(PROCESSOR_ARCHITECTURE),x86)
CFLAGS += -D IA32
endif
endif
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
CFLAGS += -D LINUX
endif
ifeq ($(UNAME_S),Darwin)
CFLAGS += -D OSX
endif
UNAME_P := $(shell uname -p)
ifeq ($(UNAME_P),x86_64)
CFLAGS += -D AMD64
endif
ifneq ($(filter %86,$(UNAME_P)),)
CFLAGS += -D IA32
endif
ifneq ($(filter arm%,$(UNAME_P)),)
CFLAGS += -D ARM
endif
endif
# all is set to default compile for MacOS
all: macos
win32_prepare:
@if not exist $(BUILDDIR) $(MD) $(BUILDDIR)
macos_prepare:
@$(MD) $(BUILDDIR)
$(TARGET): $(OBJECTS)
@$(CC) $(CFLAGS) $(INCLUDES) -o $@ $^
$(BUILDDIR)/%.o: $(SAMPLEDIR)/%.cpp $(HEADERS)
@$(CC) $(CFLAGS) $(INCLUDES) -o $@ -c $<
$(BUILDDIR)/%.o: $(SOURCEDIR)/%.cpp $(HEADERS)
@$(CC) $(CFLAGS) $(INCLUDES) -o $@ -c $<
# Debug option
debug: CFLAGS += -DDEBUG
# help option
help:
@echo --- MAKEFILE OPTIONS -----------
@echo "macos : compile for MacOS App"
@echo "win32 : compile for Win32 App"
@echo " dll : compile for DLL"
@echo " sample : compile for sample script $(SAMPLESOURCE)"
@echo " help : show makefile options"
@echo "debug : add '#define DEBUG'"
@echo "clean : clean target, bin/ and build/"
show:
@echo $(SAMPLESRCS)
@echo $(SAMPLEOBJS)
.PHONY: clean
clean:
@if exist $(TARGET) $(RM) $(TARGET)
@if exist $(BUILDDIR) $(RMDIR) $(BUILDDIR)
@echo --- CLEAN COMPLETE -------------
# MacOS compile options
macos: macos_prepare macos_compile
macos_compile: $(OBJECTS)
@$(CLANG) -o $(TARGET) $(OBJCFLAGS) $(CFLAGS) $(PLATDIR)/macos.mm $(OBJECTS)
# Win32 compile options
win32: win32_prepare win32_compile
win32_compile: $(OBJECTS)
@$(CC) -o $(TARGET) $(CFLAGS) $(PLATDIR)/win32.cpp $(OBJECTS) -lgdi32
run:
@$(TARGET)
# DLL compile options
dll: clean dll_compile
dll_compile: CFLAGS += -DBDLL
dll_compile: $(DLLTARGET)
$(DLLTARGET): $(DLLOBJECTS)
@$(MD) $(dir $@)
@$(CC) $(CFLAGS) $(INCLUDES) -shared -o $@ $^
sample: dll_compile
@$(CC) $(CFLAGS) -o $(SAMPLE) $(SAMPLESOURCE) $(DLLTARGET)