makemake 0.1.2

Library for building Makefiles programmatically
Documentation
makemake-0.1.2 has been yanked.

makemake

CI CodeFactor

makemake is a rust library for building Makefiles programmatically.

Usage

Run this command in your rust project root:

cargo add makemake

You can find the crate on crates.io.

Example

Let's build a Makefile for a C project.

let mut makefile = Makefile::new();

We'll want variables for the source files, object files, compiler, and flags.

let src = makefile.assign("SRC", Function::wildcard(["src/*.c".into()]));
let obj = makefile.assign("OBJ", Substitution::new(src, ".c", ".o"));
let cc = makefile.assign_without_overwrite(
    "CC",
    Function::shell("which gcc || which clang")
);
let cflags = makefile.append("CFLAGS", "-std=c99 -Wall -Wextra");
let target = makefile.assign("TARGET", "main");

Next, we'll define the rule to create the target.

makefile.rule(target).dep("main.c").dep(obj).cmd(expr!(
    cc,
    cflags,
    "-o",
    makefile.target_var(),
    makefile.deps_var()
));

Finally, we can print the resultant Makefile.

print!("{}", makefile.build());

Indeed, we can use our Makefile to build an example project.

cargo run --example c_project > examples/Makefile
cd examples
make && ./main

The actual example also comes with a make clean!

License

This project is licensed under the MIT License, a copy of which is available in this directory.