added library (static and dynamic) capability
This commit is contained in:
parent
4412b08a45
commit
e0ce61ab14
3 changed files with 36 additions and 7 deletions
|
@ -1,10 +1,10 @@
|
||||||
use std::{path::PathBuf, fs};
|
use std::{path::PathBuf, fs};
|
||||||
use crate::ARGS;
|
|
||||||
|
|
||||||
use path_clean::PathClean;
|
use path_clean::PathClean;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
use crate::makefile::*;
|
use crate::makefile::*;
|
||||||
|
use crate::ARGS;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
@ -106,7 +106,15 @@ impl ToString for BuildRuleKind<BuildRule> {
|
||||||
command_prefix = "\t@";
|
command_prefix = "\t@";
|
||||||
let verb = match self {
|
let verb = match self {
|
||||||
BuildRuleKind::Object(_) => "Building",
|
BuildRuleKind::Object(_) => "Building",
|
||||||
BuildRuleKind::Target(_) => "Linking",
|
BuildRuleKind::Target(_) => {
|
||||||
|
if args.static_library {
|
||||||
|
"Creating static library"
|
||||||
|
} else if args.dynamic_library {
|
||||||
|
"Creating dynamic library"
|
||||||
|
} else {
|
||||||
|
"Linking"
|
||||||
|
}
|
||||||
|
},
|
||||||
BuildRuleKind::Directory(_) => "Creating directory",
|
BuildRuleKind::Directory(_) => "Creating directory",
|
||||||
BuildRuleKind::Convenience(_) => {
|
BuildRuleKind::Convenience(_) => {
|
||||||
special = true;
|
special = true;
|
||||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -37,7 +37,14 @@ struct Args {
|
||||||
thread_local! {static ARGS: Args = Args::parse()}
|
thread_local! {static ARGS: Args = Args::parse()}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
ARGS.with(|args| {
|
||||||
|
if args.dynamic_library && args.static_library {
|
||||||
|
panic!("error: you must either a static library or a dynamic library, not both");
|
||||||
|
}
|
||||||
|
if args.run && (args.dynamic_library || args.static_library) {
|
||||||
|
panic!("error: you cannot run a library");
|
||||||
|
}
|
||||||
|
});
|
||||||
let mut makefile_name = String::new();
|
let mut makefile_name = String::new();
|
||||||
ARGS.with(|args| {
|
ARGS.with(|args| {
|
||||||
makefile_name.push_str(&args.makefile);
|
makefile_name.push_str(&args.makefile);
|
||||||
|
@ -72,7 +79,11 @@ fn main() {
|
||||||
generated_content.push_str("\n");
|
generated_content.push_str("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ARGS.with(|args| {
|
||||||
|
if args.dynamic_library {
|
||||||
|
generated_content.push_str("# dynamic library\nCFLAGS += -fPIC\nLDFLAGS += -shared\n\n");
|
||||||
|
} else {}
|
||||||
|
});
|
||||||
|
|
||||||
rule_list.add_target_rule();
|
rule_list.add_target_rule();
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ use std::fs::DirEntry;
|
||||||
|
|
||||||
use crate::build_rule::*;
|
use crate::build_rule::*;
|
||||||
use crate::makefile::*;
|
use crate::makefile::*;
|
||||||
|
use crate::ARGS;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct RuleList(pub Vec<BuildRuleKind<BuildRule>>);
|
pub struct RuleList(pub Vec<BuildRuleKind<BuildRule>>);
|
||||||
|
@ -59,9 +60,18 @@ impl RuleList {
|
||||||
|
|
||||||
pub fn add_target_rule(&mut self) {
|
pub fn add_target_rule(&mut self) {
|
||||||
let mut objects = self.get_obj_targets();
|
let mut objects = self.get_obj_targets();
|
||||||
let target_comm = String::from(
|
let mut target_comm = String::new();
|
||||||
format!("$(CC) $(LDFLAGS) $(INCS) -o $(BUILDDIR)/$(TARGET) {} $(LDLIBS)", objects.join(" "))
|
ARGS.with(|args| {
|
||||||
);
|
if args.static_library {
|
||||||
|
target_comm = String::from(
|
||||||
|
format!("$(AR) $(ARFLAGS) $(BUILDDIR)/$(TARGET) {}", objects.join(" "))
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
target_comm = String::from(
|
||||||
|
format!("$(CC) $(LDFLAGS) $(INCS) -o $(BUILDDIR)/$(TARGET) {} $(LDLIBS)", objects.join(" "))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
objects.push(String::from("| $(OBJDIR) $(BUILDDIR)"));
|
objects.push(String::from("| $(OBJDIR) $(BUILDDIR)"));
|
||||||
let prereqs = objects;
|
let prereqs = objects;
|
||||||
|
|
Loading…
Reference in a new issue