-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
175 lines (144 loc) · 4.93 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
MAKEFLAGS += --jobs=$(shell nproc)
# make \
compile program
# make all \
compile and run program
# make clean \
removes executable, object files, saves, and docs
# developer commands:
# make docs \
generates the html docs using Doxygen
# make fix \
formats the code using clang-format, commits, and pushes the changes
# make goto \
proceed several rounds automatically and print the price history graph
# make msvc \
compile the program using the Microsoft Visual C++ compiler
# make format-check \
check the code for formatting and static analysis issues
# make input-check \
Run the program with various inputs to check for errors
CXX = g++
INCLUDES = -Iinclude
OUTPUT = stocksim
CXXFLAGS += -Wall -Wextra -pedantic -std=c++17 -Werror -g \
-Wcast-qual -Wundef -Wswitch -Wshadow -Wold-style-cast
# -Wconversion -Wfloat-equal
# -fsanitize=address -fsanitize=undefined
# MinGW does not support -static-pie
ifeq ($(OS),Windows_NT)
# -pthread needed for clang++ on Windows
ifeq ($(CXX),clang++)
CXXFLAGS += -pthread
endif
CXXFLAGS += -static
else ifeq ($(CXX),g++)
ifeq ($(shell uname),Linux)
CXXFLAGS += -static-pie -fPIE
endif
endif
# Security flags for Linux
ifeq ($(shell uname),Linux)
ifneq ($(CXX),cosmoc++)
CXXFLAGS += -z noexecstack -z relro -z now
endif
endif
# Clang will warn about unused command line arguments.
ifeq ($(CXX),clang++)
CXXFLAGS += -Wno-error=unused-command-line-argument
endif
default: stocksim
random_price.o: src/random_price.cpp \
include/random_price.h include/events.h include/stock.h
$(CXX) $(INCLUDES) $(CXXFLAGS) -c $< -o $@
file_io.o: src/file_io.cpp \
include/file_io.h include/stock.h
$(CXX) $(INCLUDES) $(CXXFLAGS) -c $< -o $@
stock.o: src/stock.cpp \
include/stock.h include/names.h include/random_price.h \
include/events.h include/format.h
$(CXX) $(INCLUDES) $(CXXFLAGS) -c $< -o $@
events.o: src/events.cpp \
include/events.h include/random_price.h
$(CXX) $(INCLUDES) $(CXXFLAGS) -c $< -o $@
names.o: src/names.cpp \
include/names.h
$(CXX) $(INCLUDES) $(CXXFLAGS) -c $< -o $@
format.o: src/format.cpp \
include/format.h
$(CXX) $(INCLUDES) $(CXXFLAGS) -c $< -o $@
draw.o: src/draw.cpp \
include/draw.h include/format.h
$(CXX) $(INCLUDES) $(CXXFLAGS) -c $< -o $@
graph.o: src/graph.cpp \
include/graph.h
$(CXX) $(INCLUDES) $(CXXFLAGS) -c $< -o $@
controls.o: src/controls.cpp \
include/controls.h include/draw.h include/format.h include/stock.h
$(CXX) $(INCLUDES) $(CXXFLAGS) -c $< -o $@
main.o: src/main.cpp \
include/*.h include/nonstdlibs/*.h
$(CXX) $(INCLUDES) $(CXXFLAGS) -c $< -o $@
stocksim: main.o stock.o random_price.o events.o names.o \
graph.o format.o draw.o file_io.o controls.o
$(CXX) $(INCLUDES) $(CXXFLAGS) $^ -o $(OUTPUT)
all: clean
$(MAKE) stocksim OUTPUT=$(OUTPUT)
./$(OUTPUT)
goto: stocksim
rm -r saves/ 2>/dev/null || true
echo -e "0\nsave\nN\nY\nN\nY\nN\nY\nN\nY\nN\nY\nN\nY\nN\nY\nN\nY" \
"\nN\nY\nN\nY\nN\nY\nN\nY\nN\nY\nN\nY\nN\nY\nN\nY\nN\nY\nN\nY" \
"\nN\nY\nN\nY\nN\nY\nN\nY\nN\nY\nN\nY\nN\nY\nN\nY\nN\nY\nN\nY" \
"\nN\nY\nN\nY\nN\nY\nN\nY\nN\nY\nN\nY\nN\nY\nN\nY\nN\nY\nX\nY" | ./$(OUTPUT)
echo -e "1\nsave\nT\n0\nX\nY\n" | ./$(OUTPUT)
echo -e "2\nsave\nY\n3" | ./$(OUTPUT)
clean:
rm *.o stocksim* -r saves/ html/ latex/ *.obj *.pdb *.ilk *.dSYM/ 2>/dev/null || true
# Used for github pages doxygen
docs: .github/Doxyfile src/*.cpp include/*.h
cp .github/Doxyfile Doxyfile.temp
echo PROJECT_NUMBER = $$(git branch --show-current) $$(git log -n1 --format="%h") >> Doxyfile.temp
doxygen Doxyfile.temp
rm Doxyfile.temp
fix:
git pull
clang-format --verbose -i src/*.cpp include/*.h
git commit -a -m "Formatting: Run clang-format" -m "From Makefile: make fix"
git push
ifeq ($(MAKECMDGOALS),msvc)
ifeq ($(OUTPUT),stocksim)
OUTPUT = stocksim-msvc.exe
endif
endif
msvc: src/*.cpp include/*.h clean
cl -std:c++17 -utf-8 -Iinclude -W1 -WX -sdl -O1 -Oy- -guard:cf -MP \
src/*.cpp -Fe:$(OUTPUT) -MD -GL -D_HAS_EXCEPTIONS=0 -GR-
rm *.obj || true
format-check:
clang-format --dry-run --Werror src/*.cpp include/*.h
clang-tidy src/*.cpp --checks=performance-*,-performance-avoid-endl,readability-*,bugprone-*,portability-*,cert-* \
--fix-errors --fix-notes --format-style=file -- -Iinclude
input-check:
echo -e "1\ntest\nX\nY\n" | ./$(OUTPUT)
echo -e "0\n saves\nsaves\nB\n1\n1\nN\nY\nN\nY\nN\nY\nT\n0\nT\n1\nT\n2\nE\nT\nX\nY\n" | ./$(OUTPUT)
echo -e "1\nsaves\nN\nY\nN\nY\nN\nY\nN\nY\nT\n0\nT\nT\n3\nT\n4\nT\nS\n1\n1\nX\nY\n" | ./$(OUTPUT)
echo -e "2\nsaves\nY\n3\n" | ./$(OUTPUT)
# cosmopolitan c++ compiler does not support -flto and stack protector
ifeq ($(MAKECMDGOALS),release)
ifneq ($(CXX),cosmoc++)
CXXFLAGS += -fstack-protector-strong
ifneq ($(CXX),clang++)
CXXFLAGS += -flto
else ifneq ($(OS),Windows_NT)
CXXFLAGS += -flto
endif
endif
endif
release: clean
# this should put after default target
"$(MAKE)" stocksim \
CXXFLAGS="$(CXXFLAGS) -O3 -D_FORTIFY_SOURCE=2" \
OUTPUT="stocksim-release" \
CXX="$(CXX)"
.PHONY: all clean docs fix goto msvc format-check release input-check