]> git.tdb.fi Git - builder.git/commitdiff
Update the bootstrap to work with recent changes
authorMikko Rasa <tdb@tdb.fi>
Sun, 12 Mar 2023 11:25:46 +0000 (13:25 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 12 Mar 2023 11:34:55 +0000 (13:34 +0200)
There's now a separate, simplified frontend for the stage1 binary.

bootstrap.sh
source/bootstrap/bootstrap.cpp [new file with mode: 0644]
source/bootstrap/bootstrap.h [new file with mode: 0644]

index b8531257a94a68b134cfadb8b4f31acd2b61406c..b8c8a7aec7177f31890aea154f49cf8a48229439 100755 (executable)
@@ -2,13 +2,11 @@
 
 set -e
 
+SOURCEDIRS="source/lib source/bootstrap plugins/base plugins/gnu"
 INCLUDEDIR=temp/bootstrap/include
 REQUIRED="core datafile"
-CFLAGS="-I$INCLUDEDIR `pkg-config --cflags sigc++-2.0`"
+CFLAGS="-std=c++11 -iquote . -I$INCLUDEDIR `pkg-config --cflags sigc++-2.0`"
 LIBS="`pkg-config --libs sigc++-2.0` -lpthread"
-if pkg-config --exists "sigc++-2.0 >= 2.5.1"; then
-       CFLAGS="$CFLAGS -std=c++11"
-fi
 MACHINE="`uname -m`"
 SYSTEM="`uname -s`"
 if [ "$MACHINE" = "x86_64" ]; then
@@ -75,7 +73,10 @@ fi
 rm -rf "$INCLUDEDIR"
 mkdir -p "$INCLUDEDIR/msp"
 
-sources=source/*.cpp
+sources=`find $SOURCEDIRS -name '*.cpp'`
+
+mkdir -p "$INCLUDEDIR/msp/builder"
+ln -sf "$PWD/source/lib"/*.h "$INCLUDEDIR/msp/builder/"
 
 use_overlays="unix generic"
 missing=""
@@ -152,6 +153,6 @@ if [ "$PREFIX" ]; then
        ARGS="$ARGS --prefix='$PREFIX'"
 fi
 if [ "$CUSTOM_COMPILER" = "yes" ]; then
-       ARGS="$ARGS CXX=$COMPILER"
+       ARGS="$ARGS --compiler=$COMPILER"
 fi
 eval "./builder-stage1 $ARGS"
diff --git a/source/bootstrap/bootstrap.cpp b/source/bootstrap/bootstrap.cpp
new file mode 100644 (file)
index 0000000..9374533
--- /dev/null
@@ -0,0 +1,47 @@
+#include "bootstrap.h"
+#include <msp/builder/tool.h>
+#include <msp/core/getopt.h>
+#include <msp/fs/dir.h>
+#include "plugins/base/baseplugin.h"
+#include "plugins/gnu/gnuplugin.h"
+
+using namespace std;
+using namespace Msp;
+
+Bootstrap::Bootstrap(int argc, char **argv)
+{
+       string compiler;
+       string prefix;
+
+       GetOpt getopt;
+       getopt.add_option("compiler", compiler, GetOpt::REQUIRED_ARG).set_help("Use CMD instead of gcc as compiler.", "CMD");
+       getopt.add_option("prefix", prefix, GetOpt::REQUIRED_ARG).set_help("Install things to DIR.", "DIR");
+       getopt(argc, argv);
+
+       logger.enable_channel("tasks");
+       builder.set_logger(&logger);
+       builder.load_plugins<BasePlugin, GnuPlugin>();
+
+       if(!prefix.empty())
+               builder.set_prefix(FS::getcwd()/prefix);
+
+       builder.load_build_file(FS::getcwd()/"builderrc");
+
+       builder.add_default_tools();
+       if(!compiler.empty())
+               builder.get_toolchain().get_tool("CXX").set_command(compiler);
+}
+
+int Bootstrap::main()
+{
+       builder.load_build_file(FS::getcwd()/"Build");
+
+       builder.get_package_manager().get_main_package().prepare();
+       builder.get_build_graph().prepare();
+
+       int exit_code = builder.build();
+
+       builder.save_caches();
+
+       return exit_code;
+}
diff --git a/source/bootstrap/bootstrap.h b/source/bootstrap/bootstrap.h
new file mode 100644 (file)
index 0000000..0b46621
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef BOOTSTRAP_H_
+#define BOOTSTRAP_H_
+
+#include <msp/builder/builder.h>
+#include <msp/core/application.h>
+
+class Bootstrap: public Msp::RegisteredApplication<Bootstrap>
+{
+private:
+       Logger logger;
+       Builder builder;
+
+public:
+       Bootstrap(int, char **);
+
+       int main() override;
+};
+
+#endif