diff --git a/src/code_templates/mod.rs b/src/code_templates/mod.rs index 3f89b914a0d59af91b848e4d2d18a810d7ad320b..46120c306ee41a8bee6f142522d5b9c90403e99a 100644 --- a/src/code_templates/mod.rs +++ b/src/code_templates/mod.rs @@ -66,46 +66,86 @@ pub fn template_for_examfile() -> CodeBuffer { return buffer; } -pub fn template_for_makefile_algo(mut hfile_name: String, mut main_name: String) -> CodeBuffer { +// pub fn template_for_makefile_algo(mut hfile_name: String, mut main_name: String) -> CodeBuffer { +// let mut buffer = CodeBuffer::new(4); + +// // Removing extensions +// for _ in 0..2 { +// hfile_name.pop(); +// main_name.pop(); +// } + +// buffer.println("# This file was automatically generated by `create-prog-app`"); +// buffer.println("CC:=gcc"); +// buffer.println("CFLAGS:=-Wall -Wextra -g -pedantic -fsanitize=address -fsanitize=leak"); +// buffer.println("LIBS:=-lm"); +// buffer.println("VPATH:=struct"); +// buffer.println("# Due to the oddity of MAKE and the fact you cannot generate \"true\" tabs,"); +// buffer.println("# the \"tab\" character is replaced by spaces."); +// buffer.println("# `create-prog-app` STRONGLY advises you not to change/modify the line below"); +// buffer.println(".RECIPEPREFIX:=$(.RECIPEPREFIX) "); +// buffer.println(""); +// buffer.println( +// format!( +// "{}: {}.o {}.o", +// main_name.to_lowercase(), +// main_name.to_lowercase(), +// hfile_name.to_lowercase() +// ) +// .as_str(), +// ); +// buffer.println_right("$(CC) $(CFLAGS) $(LIBS) $^ -o $@"); +// buffer.println_left(""); +// buffer.println(format!("{0}.o: {0}.c", main_name.to_lowercase()).as_str()); +// buffer.println_right("$(CC) $(CFLAGS) $(LIBS) -c $<"); +// buffer.println_left(""); +// buffer.println(format!("{0}.o: {0}.c {0}.h", hfile_name.to_lowercase()).as_str()); +// buffer.println_right("$(CC) $(CFLAGS) $(LIBS) -c $<"); +// buffer.println_left(""); +// buffer.println("clean:"); +// buffer.println_right(format!("rm -f *.o {}", main_name.to_lowercase()).as_str()); +// buffer.println_left(""); +// buffer.println(format!("rebuild: clean {}", main_name.to_lowercase()).as_str()); + +// return buffer; +// } + +pub fn template_for_makefile_algo_v2(impl_name: String, mut main_name: String) -> CodeBuffer { let mut buffer = CodeBuffer::new(4); - // Removing extensions + buffer.println("# This file was automatically generated by `create-prog-app`"); + buffer.println("CC := gcc"); + buffer.println("CFLAGS := -Wall -Wextra -g -pedantic -fsanitize=address -fsanitize=leak"); + buffer.println("LDFLAGS := -lm"); + buffer.println("VPATH := struct"); + buffer.println(""); + buffer.println( + format!( + "SOURCES := {} {}", + main_name.to_lowercase(), + impl_name.to_lowercase() + ) + .as_str(), + ); + for _ in 0..2 { - hfile_name.pop(); main_name.pop(); } - buffer.println("# This file was automatically generated by `create-prog-app`"); - buffer.println("CC:=gcc"); - buffer.println("CFLAGS:=-Wall -Wextra -g -pedantic -fsanitize=address -fsanitize=leak"); - buffer.println("LIBS:=-lm"); - buffer.println("VPATH:=struct"); + buffer.println("OBJECTS := $(patsubst %.c, %.o, $(SOURCES))"); + buffer.println(format!("TARGET := {}", main_name).as_str()); buffer.println("# Due to the oddity of MAKE and the fact you cannot generate \"true\" tabs,"); buffer.println("# the \"tab\" character is replaced by spaces."); buffer.println("# `create-prog-app` STRONGLY advises you not to change/modify the line below"); buffer.println(".RECIPEPREFIX:=$(.RECIPEPREFIX) "); buffer.println(""); - buffer.println( - format!( - "{}: {}.o {}.o", - main_name.to_lowercase(), - main_name.to_lowercase(), - hfile_name.to_lowercase() - ) - .as_str(), - ); - buffer.println_right("$(CC) $(CFLAGS) $(LIBS) $^ -o $@"); - buffer.println_left(""); - buffer.println(format!("{0}.o: {0}.c", main_name.to_lowercase()).as_str()); - buffer.println_right("$(CC) $(CFLAGS) $(LIBS) -c $<"); - buffer.println_left(""); - buffer.println(format!("{0}.o: {0}.c {0}.h", hfile_name.to_lowercase()).as_str()); - buffer.println_right("$(CC) $(CFLAGS) $(LIBS) -c $<"); + buffer.println("$(TARGET): $(OBJECTS)"); + buffer.println_right("$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)"); buffer.println_left(""); + buffer.println(".PHONY: clean"); + buffer.println(""); buffer.println("clean:"); - buffer.println_right(format!("rm -f *.o {}", main_name.to_lowercase()).as_str()); - buffer.println_left(""); - buffer.println(format!("rebuild: clean {}", main_name.to_lowercase()).as_str()); + buffer.println_right("rm -f $(OBJECTS) $(TARGET)"); return buffer; } diff --git a/src/main.rs b/src/main.rs index 4a7482b524d35844020f1cda6e7b8893db953c80..c9954b9cf8854eadd445d45f2230975f54c152d7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,8 +49,12 @@ fn algo_template() { File::create(&(root.to_owned().into_os_string().into_string().unwrap() + "Makefile")) .expect("Cannot create Makefile!"); + // let makefile_template = + // code_templates::template_for_makefile_algo(header_filename.clone(), main_filename.clone()) + // .to_string(); + let makefile_template = - code_templates::template_for_makefile_algo(header_filename.clone(), main_filename.clone()) + code_templates::template_for_makefile_algo_v2(impl_filename.clone(), main_filename.clone()) .to_string(); makefile