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 crate::ARGS;
 | 
			
		||||
 | 
			
		||||
use path_clean::PathClean;
 | 
			
		||||
use regex::Regex;
 | 
			
		||||
 | 
			
		||||
use crate::makefile::*;
 | 
			
		||||
use crate::ARGS;
 | 
			
		||||
 | 
			
		||||
#[derive(Debug)]
 | 
			
		||||
#[allow(dead_code)]
 | 
			
		||||
| 
						 | 
				
			
			@ -106,7 +106,15 @@ impl ToString for BuildRuleKind<BuildRule> {
 | 
			
		|||
                command_prefix = "\t@";
 | 
			
		||||
                let verb = match self {
 | 
			
		||||
                    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::Convenience(_) => {
 | 
			
		||||
                        special = true;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										15
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								src/main.rs
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -37,7 +37,14 @@ struct Args {
 | 
			
		|||
thread_local! {static ARGS: Args = Args::parse()}
 | 
			
		||||
 | 
			
		||||
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();
 | 
			
		||||
    ARGS.with(|args| {
 | 
			
		||||
        makefile_name.push_str(&args.makefile);
 | 
			
		||||
| 
						 | 
				
			
			@ -72,7 +79,11 @@ fn main() {
 | 
			
		|||
        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();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,6 +3,7 @@ use std::fs::DirEntry;
 | 
			
		|||
 | 
			
		||||
use crate::build_rule::*;
 | 
			
		||||
use crate::makefile::*;
 | 
			
		||||
use crate::ARGS;
 | 
			
		||||
 | 
			
		||||
#[derive(Debug)]
 | 
			
		||||
pub struct RuleList(pub Vec<BuildRuleKind<BuildRule>>);
 | 
			
		||||
| 
						 | 
				
			
			@ -59,9 +60,18 @@ impl RuleList {
 | 
			
		|||
 | 
			
		||||
    pub fn add_target_rule(&mut self) {
 | 
			
		||||
        let mut objects = self.get_obj_targets();
 | 
			
		||||
        let target_comm = String::from(
 | 
			
		||||
            format!("$(CC) $(LDFLAGS) $(INCS) -o $(BUILDDIR)/$(TARGET) {} $(LDLIBS)", objects.join(" "))
 | 
			
		||||
        );
 | 
			
		||||
        let mut target_comm = String::new();
 | 
			
		||||
        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)"));
 | 
			
		||||
        let prereqs = objects;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue