aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2022-12-26 16:34:18 +0100
committerHimbeerserverDE <himbeerserverde@gmail.com>2022-12-26 16:34:18 +0100
commitfe23d1b7e6713f8acc27ee40bf34eb25a724ae18 (patch)
tree8729926d9d199198a2ecd9af48389d6cca2f326b /src/main.rs
parentf47be8483938b232c788f1a3e172faa469fc79e9 (diff)
compile the kernel
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
index 231e55d..ab57954 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,5 +1,7 @@
use anyhow::bail;
+use std::env;
use std::fs::File;
+use std::io::Write;
use std::path::Path;
use std::process::Command;
@@ -22,6 +24,50 @@ fn download_kernel(file_name: &str) -> anyhow::Result<()> {
Ok(())
}
+fn compile() -> anyhow::Result<()> {
+ let mut defconfig = Command::new("make");
+ defconfig.arg("defconfig");
+
+ if !defconfig.spawn()?.wait()?.success() {
+ bail!("make defconfig failed");
+ }
+
+ let mut mod2noconfig = Command::new("make");
+ mod2noconfig.arg("mod2noconfig");
+
+ if !mod2noconfig.spawn()?.wait()?.success() {
+ bail!("make mod2noconfig failed");
+ }
+
+ // Drop and close the file before continuing.
+ {
+ let mut file = File::options()
+ .truncate(false)
+ .append(true)
+ .open(".config")?;
+
+ file.write_all(CONFIG.as_bytes())?;
+ }
+
+ let mut olddefconfig = Command::new("make");
+ olddefconfig.arg("olddefconfig");
+
+ if !olddefconfig.spawn()?.wait()?.success() {
+ bail!("make olddefconfig failed");
+ }
+
+ let mut make = Command::new("make");
+ make.arg("bzImage")
+ .arg("modules")
+ .arg("-j".to_owned() + &num_cpus::get().to_string());
+
+ if !make.spawn()?.wait()?.success() {
+ bail!("make failed");
+ }
+
+ Ok(())
+}
+
fn main() -> anyhow::Result<()> {
let file_name = Path::new(LATEST).file_name().unwrap().to_str().unwrap();
@@ -36,5 +82,11 @@ fn main() -> anyhow::Result<()> {
println!("Kernel source unpacked successfully");
+ env::set_current_dir(file_name.trim_end_matches(".tar.xz"))?;
+
+ println!("Compiling kernel...");
+ compile()?;
+ println!("Kernel compiled successfully");
+
Ok(())
}