Skip to content

Commit

Permalink
Makefile flags cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
eric15342335 committed Jun 18, 2024
1 parent 97bb929 commit 370cf1b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
26 changes: 10 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,27 @@ CXX = g++
INCLUDES = -Iinclude
OUTPUT = stocksim
CXXFLAGS += -Wall -Wextra -pedantic -std=c++17 -Werror -g \
-Wcast-qual -Wundef -Wswitch -Wshadow -Wold-style-cast
-Wcast-qual -Wundef -Wswitch -Wshadow
# -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
CXXFLAGS += -pthread
endif
CXXFLAGS += -static
endif

# Security flags for Linux
ifeq ($(shell uname),Linux)
ifneq ($(CXX),cosmoc++)
CXXFLAGS += -z noexecstack -z relro -z now
CXXFLAGS += -z relro -z now -static-pie -fPIE
endif
endif

# Clang will warn about unused command line arguments.
ifeq ($(CXX),clang++)
CXXFLAGS += -Wno-error=unused-command-line-argument
CXXFLAGS += -Wno-error=unused-command-line-argument
endif

default: stocksim
Expand Down Expand Up @@ -139,14 +133,14 @@ endif

# -GL can further reduce size, but more likely to flag as malicious
msvc: src/*.cpp include/*.h clean
cl -std:c++17 -EHsc -utf-8 -Iinclude -W1 -WX -O1 -guard:cf -MP \
cl -std:c++17 -EHsc -utf-8 $(INCLUDES) -W1 -WX -O1 -guard:cf -MP \
src/*.cpp -Fe:$(OUTPUT)
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
--fix-errors --fix-notes --format-style=file -- $(INCLUDES)

input-check:
echo -e "1\ntest\nX\nY\n" | ./$(OUTPUT)
Expand All @@ -157,11 +151,11 @@ input-check:
# cosmopolitan c++ compiler does not support -flto and stack protector
ifeq ($(MAKECMDGOALS),release)
ifneq ($(CXX),cosmoc++)
CXXFLAGS += -fstack-protector-strong
CXXFLAGS += -fstack-protector-strong
ifneq ($(CXX),clang++)
CXXFLAGS += -flto
CXXFLAGS += -flto
else ifneq ($(OS),Windows_NT)
CXXFLAGS += -flto
CXXFLAGS += -flto
endif
endif
endif
Expand Down
10 changes: 1 addition & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,10 @@ program. If not, see <https://www.gnu.org/licenses/>.
#include "file_io.h"
#include "format.h"
#include "graph.h"
#include "nonstdlibs/VariadicTable.h"
#include "random_price.h"
#include "stock.h"

#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
#include "nonstdlibs/VariadicTable.h"
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif

#include <cmath>
#include <fstream>
#include <numeric>
Expand Down

0 comments on commit 370cf1b

Please sign in to comment.