From 7b6a7c78d27733732f4c7ffc576e2dacdefee6ea Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Tue, 16 Apr 2024 20:11:01 +0900 Subject: [PATCH] Upgrade Makefile, fix warnings --- .gitignore | 1 + Makefile | 25 +++++++++++++++++++++---- src/main.cpp | 11 +++++------ 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 8b5eb04..fe23302 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ compile_commands.commands.json compile_commands.json .clangd/ .cache/ +/objects/ diff --git a/Makefile b/Makefile index c176d86..a740dd7 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,34 @@ -COMMON_CXXFLAGS = -Wall -Wextra -Wpedantic -std=c++20 +COMMON_CXXFLAGS = -Wall -Wextra -Wpedantic -std=c++20 \ + -Wformat -Wformat=2 -Wconversion -Wimplicit-fallthrough \ + -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 \ + -D_GLIBCXX_ASSERTIONS \ + -fstrict-flex-arrays=3 \ + -fstack-clash-protection -fstack-protector-strong \ + -Wl,-z,nodlopen -Wl,-z,noexecstack \ + -Wl,-z,relro -Wl,-z,now ifdef DEBUG CXXFLAGS = -Og -g ${COMMON_CXXFLAGS} else - CXXFLAGS = -O3 ${COMMON_CXXFLAGS} + CXXFLAGS = -O2 ${COMMON_CXXFLAGS} endif +OBJDIR = objects + +SOURCES = src/main.cpp + +OBJECTS = $(addprefix ${OBJDIR}/,$(patsubst %.cpp,%.cpp.o,${SOURCES})) + all: KoreanNumbers -KoreanNumbers: src/main.o +KoreanNumbers: ${OBJECTS} $(CXX) $(CXXFLAGS) -o KoreanNumbers $^ +${OBJDIR}/%.cpp.o: %.cpp + @mkdir -p $(dir $@) + $(CXX) $(CXXFLAGS) -c -o $@ $< + .PHONY: clean: rm -f KoreanNumbers - rm -f src/*.o + rm -rf ${OBJDIR} diff --git a/src/main.cpp b/src/main.cpp index 5969b3d..c7b050e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -60,7 +59,7 @@ void help() { puts(" [-l | --list] - list \"base\" numbers (can combine with --alt)"); } -const char8_t* digit_to_kword(int n) { +const char8_t* digit_to_kword(unsigned long long n) { switch(n) { case 9: return gu; @@ -252,7 +251,7 @@ void printValue(unsigned long long value) { unsigned char count = 0; while(temp > 0) { ++count; - s.push_back('0' + temp % 10); + s.push_back('0' + (char)(temp % 10)); temp /= 10; if(count == 3 && temp > 0) { s.push_back(','); @@ -280,13 +279,13 @@ unsigned long long clamp_digits(unsigned int digits, unsigned long long value) { } std::ostream& operator<<(std::ostream &os, const std::u8string &str) { - os.write(reinterpret_cast(str.data()), str.size()); + os.write(reinterpret_cast(str.data()), (long)str.size()); return os; } std::ostream& operator<<(std::ostream &os, const char8_t *str8) { const char *cstr = reinterpret_cast(str8); - os.write(cstr, strlen(cstr)); + os.write(cstr, (long)strlen(cstr)); return os; } @@ -401,7 +400,7 @@ int main(int argc, char **argv) { unsigned long long value; { - std::default_random_engine r_eng(std::chrono::steady_clock::now().time_since_epoch().count()); + std::default_random_engine r_eng((unsigned long)std::chrono::steady_clock::now().time_since_epoch().count()); if(!isAlt && randomizeDigits) { unsigned int min_digits = 0; for (unsigned long long min_copy = min; min_copy > 0; min_copy /= 10) {