pass non-cppipe options to the compiler

This commit is contained in:
vrd
2025-06-06 18:00:38 +03:00
parent 370995978c
commit 7f3794e742
3 changed files with 18 additions and 7 deletions
+2 -1
View File
@@ -13,7 +13,8 @@ const char* CXX = "c++";
#define DEBUG_FLAGS "-g" #define DEBUG_FLAGS "-g"
// ...when not debugging // ...when not debugging
#define RELEASE_FLAGS "-Ofast", "-s" // -O2 seems to work best for both execution and compilation speed
#define RELEASE_FLAGS "-O2", "-s"
// ...for both C and C++ // ...for both C and C++
#define CPPFLAGS "-fwhole-program", "-march=native", "-Wall", "-Wextra", "-pipe" #define CPPFLAGS "-fwhole-program", "-march=native", "-Wall", "-Wextra", "-pipe"
+16 -5
View File
@@ -72,6 +72,7 @@ bool debug = false;
bool quick = false; bool quick = false;
// Just compile, don't run // Just compile, don't run
bool dont_run = false; bool dont_run = false;
vector<const char*> additional_compiler_args;
} }
@@ -135,6 +136,10 @@ int parse_args_until_src(int argc, char* argv[])
"-g debug the binary, asserts are also enabled\n" "-g debug the binary, asserts are also enabled\n"
"-q quicker, just compare source and binary time stamps, if included files were updated a recompile WON'T occur!\n" "-q quicker, just compare source and binary time stamps, if included files were updated a recompile WON'T occur!\n"
"-n don't run, just compile the file without running it\n\n" "-n don't run, just compile the file without running it\n\n"
"Any other argument that begins with '-' is passed to the compiler e.g.:\n"
" cppipe -O0 file.cpp\n\n"
"Environment variables:\n" "Environment variables:\n"
"CPPIPEPATH - ':'-separated list of directories to prepend to the FILE search path\n"; "CPPIPEPATH - ':'-separated list of directories to prepend to the FILE search path\n";
exit(0); exit(0);
@@ -151,6 +156,10 @@ int parse_args_until_src(int argc, char* argv[])
{ {
dont_run = true; dont_run = true;
} }
else if( !arg.empty() && arg[0] == '-') // if it's an unknown option pass it to the compiler
{
additional_compiler_args.push_back(argv[i]);
}
else // Then treat it as the src_arg else // Then treat it as the src_arg
{ {
src_arg = i; src_arg = i;
@@ -303,10 +312,8 @@ bool preprocess_and_compare()
// Result of preprocessing as string // Result of preprocessing as string
string new_pp = read_to_end(preprocessing.out); string new_pp = read_to_end(preprocessing.out);
// TODO: decide what to do here, #! causes inevitavble non-fatal errors if( !wait(preprocessing) ) // preprocessing failed
// maybe warn that preproccessing failed exit(1);
// if( !wait(preprocessing) ) // preprocessing failed
// exit(1);
if( fs::exists(preprocessed_file) ) // todo: clean up if else blocks if( fs::exists(preprocessed_file) ) // todo: clean up if else blocks
{ {
@@ -371,11 +378,15 @@ void compile_src_file()
compile.append_args({ CXXFLAGS }); compile.append_args({ CXXFLAGS });
// Remap the debug source file since we compile from stdin
string debug_remap = "-fdebug-prefix-map=<stdin>=" + src_file.string();
if(debug) if(debug)
compile.append_args({ DEBUG_FLAGS }); compile.append_args({ DEBUG_FLAGS, debug_remap.c_str() });
else else
compile.append_args({ RELEASE_FLAGS }); compile.append_args({ RELEASE_FLAGS });
for(const char* arg: additional_compiler_args)
compile += arg;
if( !compile() ) // if failed to compile if( !compile() ) // if failed to compile
{ {
-1
View File
@@ -1,4 +1,3 @@
fix debug
many points in name - rc.local.start many points in name - rc.local.start
example #!/usr/bin/cppipe example #!/usr/bin/cppipe
description - advantages over manual compile description - advantages over manual compile