summaryrefslogtreecommitdiff
path: root/src/bootstrap.cc
blob: 55bd3e00c6dc3f683cc6d295eab1039630822591 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// -*- c++ -*-
// Distributed under the BSD 2-Clause License.
// See accompanying file LICENSE for details.
#include <iostream>
#include <array>
#include <cstdlib>

#define BOOTSTRAP

#include "ctor.h"

#include "util.cc"
#include "rebuild.cc"
#include "task.cc"
#include "task_cc.cc"
#include "task_ar.cc"
#include "execute.cc"
#include "tasks.cc"
#include "build.cc"
#include "tools.cc"

std::filesystem::path configurationFile("configuration.cc");
std::filesystem::path configHeaderFile("config.h");

const ctor::configuration& ctor::get_configuration()
{
	static ctor::configuration cfg;
	static bool initialised{false};
	if(!initialised)
	{
		cfg.build_toolchain = getToolChain(cfg.get(ctor::cfg::build_cxx, "/usr/bin/g++"));
		initialised = true;
	}

	return cfg;
}

bool ctor::configuration::has(const std::string& key) const
{
	return false;
}

const std::string& ctor::configuration::get(const std::string& key, const std::string& default_value) const
{
	if(key == ctor::cfg::build_cxx && std::getenv("CXX"))
	{
		static std::string s = std::getenv("CXX");
		return s;
	}

	if(key == ctor::cfg::build_cc && std::getenv("CC"))
	{
		static std::string s = std::getenv("CC");
		return s;
	}

	if(key == ctor::cfg::build_ld && std::getenv("LD"))
	{
		static std::string s = std::getenv("LD");
		return s;
	}

	if(key == ctor::cfg::build_ar && std::getenv("AR"))
	{
		static std::string s = std::getenv("AR");
		return s;
	}

	if(key == ctor::cfg::builddir && std::getenv("BUILDDIR"))
	{
		static std::string s = std::getenv("BUILDDIR");
		return s;
	}

	return default_value;
}

int main(int argc, char* argv[])
{
	if(argc > 1)
	{
		std::cerr << "This is a minimal bootstrap version of " << argv[0] <<
			" which doesn't support any arguments\n";
		return 1;
	}

	ctor::settings settings{};

	const auto& c = ctor::get_configuration();
	settings.builddir = c.get(ctor::cfg::builddir, settings.builddir);
	settings.parallel_processes =
		std::max(1u, std::thread::hardware_concurrency() * 2 - 1);
	settings.verbose = 0;
	auto all_tasks = getTasks(settings, {}, false);
	for(auto task : all_tasks)
	{
		if(task->registerDepTasks(all_tasks))
		{
			return 1;
		}
	}

	std::vector<Target> non_unittest_targets;
	auto& targets = getTargets(settings);
	for(const auto& target : targets)
	{
		if(target.config.type != ctor::target_type::unit_test &&
		   target.config.type != ctor::target_type::unit_test_library)
		{
			non_unittest_targets.push_back(target);
		}
	}

	auto ret = build(settings, "all", non_unittest_targets, all_tasks);
	if(ret != 0)
	{
		return ret;
	}

	return 0;
}