diff --git a/agb/Cargo.toml b/agb/Cargo.toml index 7a5cc959..b688335a 100644 --- a/agb/Cargo.toml +++ b/agb/Cargo.toml @@ -10,6 +10,7 @@ repository = "https://github.com/agbrs/agb" [features] default = ["testing"] testing = [] +multiboot = [] [dependencies] bitflags = "2" diff --git a/agb/build.rs b/agb/build.rs index 3b627607..4e34db7b 100644 --- a/agb/build.rs +++ b/agb/build.rs @@ -1,5 +1,19 @@ -fn main() { +use std::{env, error::Error, fs, path::PathBuf}; + +fn main() -> Result<(), Box> { + let out = &PathBuf::from(env::var("OUT_DIR").unwrap()); + let linker_script = if env::var("CARGO_FEATURE_MULTIBOOT").is_ok() { + include_bytes!("gba_mb.ld").as_slice() + } else { + include_bytes!("gba.ld").as_slice() + }; + + fs::write(out.join("gba.ld"), linker_script)?; + println!("cargo:rustc-link-search={}", out.display()); + println!("cargo:rerun-if-changed=gba.ld"); println!("cargo:rerun-if-changed=gba_mb.ld"); println!("cargo:rerun-if-changed=build.rs"); + + Ok(()) }