From cf3663b3482a39069fb85bcc35f38d1f2510872e Mon Sep 17 00:00:00 2001 From: Venelin Date: Mon, 27 May 2024 10:26:30 +0300 Subject: [PATCH] support clang and other compilers --- config.h | 9 ++++++--- install.sh | 5 +++-- src/cppipe.cpp | 10 ++++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/config.h b/config.h index 94e63e4..216dd6b 100644 --- a/config.h +++ b/config.h @@ -1,10 +1,13 @@ // C compiler -const char* CC = "gcc"; +const char* CC = "cc"; // C++ compiler -const char* CXX = "g++"; +const char* CXX = "c++"; +// The compilation options are chosen with gcc in mind, but clang should also work +// Other compilers are not tested, but may work // You can read about gcc options by running "man gcc" + // Compiler options to use... // ...when debugging @@ -14,7 +17,7 @@ const char* CXX = "g++"; #define RELEASE_FLAGS "-Ofast", "-s" // ...for both C and C++ -#define CPPFLAGS "--whole-program", "-march=native", "-Wall", "-Wextra", "-pipe" +#define CPPFLAGS "-fwhole-program", "-march=native", "-Wall", "-Wextra", "-pipe" // ...for C #define CFLAGS CPPFLAGS diff --git a/install.sh b/install.sh index 7df856c..1c9248d 100755 --- a/install.sh +++ b/install.sh @@ -7,9 +7,10 @@ PREFIX=/usr/local # Compile cppipe -options="-std=c++17 -Ofast --whole-program -march=native -DNDEBUG -Wall -Wextra -Wno-parentheses -Wno-unused-result -s -pipe" +# The options are with gcc in mind, but should work with clang and maybe other compilers +options="-std=c++17 -Ofast -fwhole-program -march=native -DNDEBUG -Wall -Wextra -Wno-parentheses -Wno-unused-result -s -pipe" # options="-std=c++17 -g" -g++ -o cppipe $options cppipe.cpp +c++ -o cppipe $options cppipe.cpp chmod 755 cppipe mv cppipe ${PREFIX}/bin diff --git a/src/cppipe.cpp b/src/cppipe.cpp index 9f5a50f..da8912b 100644 --- a/src/cppipe.cpp +++ b/src/cppipe.cpp @@ -14,6 +14,9 @@ using namespace std; namespace fs = std::filesystem; +namespace +{ + struct MappedFile // todo: move to utils { // ~MappedFile() @@ -55,6 +58,8 @@ fs::path src_file; fs::path cache_dir; fs::path bin; // cache bins to avoid recompiles +} + int main(int argc, char* argv[]) { int src_arg = parse_args_until_src(argc, argv); @@ -81,6 +86,9 @@ int main(int argc, char* argv[]) exec(run); } +namespace +{ + int parse_args_until_src(int argc, char* argv[]) { if(argc < 2) @@ -285,3 +293,5 @@ bool is_src_file(const string_view p) else return false; } + +}