compilation

This commit is contained in:
2026-02-14 11:35:08 +01:00
parent 6eb984c3b8
commit eba402dc31
7 changed files with 108 additions and 23 deletions

View File

@@ -1,18 +1,56 @@
#include "parser.h"
#include "util.h"
#include <fstream>
#include <iostream>
#include <sstream>
#include <sys/stat.h>
#include <thread>
int main() {
if (geteuid() != 0) {
std::cerr << "This program needs to be ran as root.\n";
return 1;
}
mkdir("/tmp/shrap", 0777);
std::ifstream file("zlib.shrap");
if (!file) {
std::cerr << "Error opening file\n";
return 1;
}
std::stringstream buffer;
buffer << file.rdbuf();
Expr pkg = Expr::parse(file);
Expr pkg = Expr::parse(buffer.str());
std::cout << pkg.get("name").value << std::endl;
}
Expr src = pkg.get("src").children[0];
std::string src_type = src.children[0].value;
std::string src_url = src.children[1].value;
std::string src_path = "/tmp/shrap/" + src.children[2].value;
if (src_type == "tar") {
std::string archive_path = "/tmp/shrap/" + Util::basename(src_url);
// TODO: replace wget with a library for zero runtime dependencies
Util::shell_command("wget -O " + archive_path + " " + src_url);
// TODO: check archive hash from src.children[3].value
Util::shell_command("tar xf " + archive_path + " -C /tmp/shrap/");
} else {
std::cerr << "ERROR: unrecognized src type: " << src_type << "\n";
return 1;
}
std::string jobs = std::to_string(std::thread::hardware_concurrency());
for (const auto &step : pkg.get("build").children) {
std::string step_type = step.children[0].value;
if (step_type == "configure_make") {
Util::shell_command("./configure --prefix=/usr", src_path);
Util::shell_command("make -j " + jobs, src_path);
Util::shell_command("make install", src_path);
} else {
std::cerr << "ERROR: unrecognized step type: " << step_type << "\n";
return 1;
}
}
}