Skip to content

Commit

Permalink
Makefile cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
eric15342335 committed Jun 18, 2024
1 parent 97bb929 commit c78bf3b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 32 deletions.
35 changes: 10 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MAKEFLAGS += --jobs=$(shell nproc)
MAKEFLAGS += -j
# make \
compile program
# make all \
Expand All @@ -20,39 +20,25 @@ 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
-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
CXXFLAGS += -static
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
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 += -pthread -Wno-error=unused-command-line-argument
endif

default: stocksim
Expand Down Expand Up @@ -128,7 +114,7 @@ docs: .github/Doxyfile src/*.cpp include/*.h
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 commit -a -m "Format code using clang-format" -m "Shortcut to run: make fix"
git push

ifeq ($(MAKECMDGOALS),msvc)
Expand All @@ -137,9 +123,8 @@ OUTPUT = stocksim-msvc.exe
endif
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 -Iinclude -W1 -WX -O1 -guard:cf -MP -GL \
src/*.cpp -Fe:$(OUTPUT)
rm *.obj || true

Expand All @@ -166,8 +151,8 @@ endif
endif
endif

# this should put after default target
release: clean
# this should put after default target
"$(MAKE)" stocksim \
CXXFLAGS="$(CXXFLAGS) -O3 -D_FORTIFY_SOURCE=2" \
OUTPUT="stocksim-release" \
Expand Down
7 changes: 0 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,7 @@ program. If not, see <https://www.gnu.org/licenses/>.
#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>
Expand Down

0 comments on commit c78bf3b

Please sign in to comment.