diff options
| -rwxr-xr-x | bootstrap.sh | 13 | ||||
| -rw-r--r-- | src/bootstrap.cc | 12 | ||||
| -rw-r--r-- | src/configure.cc | 33 | 
3 files changed, 38 insertions, 20 deletions
diff --git a/bootstrap.sh b/bootstrap.sh index a5c11ac..510320a 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,7 +1,14 @@  #!/bin/sh  echo "Bootstrapping..." -g++ -std=c++20 -Wall -O3 -Isrc -pthread src/bootstrap.cc ctor.cc test/ctor.cc -o ctor && \ -./ctor && \ -g++ -std=c++20 -Wall -O3 -Isrc -pthread ctor.cc test/ctor.cc -Lbuild -lctor -o ctor && \ +: ${CXX:=g++} +$CXX -std=c++20 /dev/null -c -o /dev/null 2> /dev/null 1> /dev/null +if [ $? != 0 ] +then +	echo "Set CXX to a compiler supporting c++20." +	exit 1 +fi +$CXX -std=c++20 -Wall -O3 -Isrc -pthread src/bootstrap.cc ctor.cc -o ctor && \ +CXX=`which $CXX` ./ctor && \ +$CXX -std=c++20 -Wall -O3 -Isrc -pthread ctor.cc test/ctor.cc -Lbuild -lctor -o ctor && \  ./ctor configure --ctor-includedir=src --ctor-libdir=build && \  echo "Done. Now run ./ctor to (re)build." diff --git a/src/bootstrap.cc b/src/bootstrap.cc index 08f7b1f..bf597ea 100644 --- a/src/bootstrap.cc +++ b/src/bootstrap.cc @@ -3,6 +3,7 @@  // See accompanying file LICENSE for details.  #include <iostream>  #include <array> +#include <cstdlib>  #define BOOTSTRAP @@ -29,12 +30,23 @@ const Configuration& configuration()  bool hasConfiguration(const std::string& key)  { +	if(key == cfg::host_cxx && std::getenv("CXX")) +	{ +		return true; +	} +  	return false;  }  const std::string& getConfiguration(const std::string& key,                                      const std::string& defaultValue)  { +	if(key == cfg::host_cxx && std::getenv("CXX")) +	{ +		static std::string s = std::getenv("CXX"); +		return s; +	} +  	return defaultValue;  } diff --git a/src/configure.cc b/src/configure.cc index 37bd3cf..60c3ed6 100644 --- a/src/configure.cc +++ b/src/configure.cc @@ -27,18 +27,12 @@ const Configuration& __attribute__((weak)) configuration()  namespace ctor  { -std::optional<std::string> includedir; -std::optional<std::string> libdir; +std::map<std::string, std::string> conf_values;  }  bool hasConfiguration(const std::string& key)  { -	if(key == cfg::ctor_includedir && ctor::includedir) -	{ -		return true; -	} - -	if(key == cfg::ctor_libdir && ctor::libdir) +	if(ctor::conf_values.find(key) != ctor::conf_values.end())  	{  		return true;  	} @@ -50,14 +44,9 @@ bool hasConfiguration(const std::string& key)  const std::string& getConfiguration(const std::string& key,                                      const std::string& defaultValue)  { -	if(key == cfg::ctor_includedir && ctor::includedir) -	{ -		return *ctor::includedir; -	} - -	if(key == cfg::ctor_libdir && ctor::libdir) +	if(ctor::conf_values.find(key) != ctor::conf_values.end())  	{ -		return *ctor::libdir; +		return ctor::conf_values[key];  	}  	const auto& c = configuration(); @@ -335,6 +324,18 @@ int regenerateCache(const Settings& default_settings,  		                       newExternalConfigs.end());  	} +	// Store current values for execution in this execution context. +	if(!ctor_includedir.empty()) +	{ +		ctor::conf_values[cfg::ctor_includedir] = ctor_includedir; +	} +	if(!ctor_libdir.empty()) +	{ +		ctor::conf_values[cfg::ctor_libdir] = ctor_libdir; +	} +	ctor::conf_values[cfg::host_cxx] = host_cxx; +	ctor::conf_values[cfg::build_cxx] = build_cxx; +  	std::cout << "Writing results to: " << configurationFile.string() << "\n";  	{  		std::ofstream istr(configurationFile); @@ -369,12 +370,10 @@ int regenerateCache(const Settings& default_settings,  		if(!ctor_includedir.empty())  		{  			istr << "			{ \"" << cfg::ctor_includedir << "\", \"" << ctor_includedir << "\" },\n"; -			ctor::includedir = ctor_includedir;  		}  		if(!ctor_libdir.empty())  		{  			istr << "			{ \"" << cfg::ctor_libdir << "\", \"" << ctor_libdir << "\" },\n"; -			ctor::libdir = ctor_libdir;  		}  		istr << "		},\n";  | 
