Go to file
2023-10-20 15:18:02 -05:00
src wrote readme and added (un)install scripts 2023-10-20 15:15:09 -05:00
.gitignore directory tree parsing done (and its a mess) 2023-09-18 00:06:25 -05:00
Cargo.toml main functionality done, working 2023-09-24 15:53:16 -05:00
install.sh wrote readme and added (un)install scripts 2023-10-20 15:15:09 -05:00
LICENSE Initial commit 2023-09-18 02:17:42 +00:00
README.md removed trailing whitespace 2023-10-20 15:18:02 -05:00
uninstall.sh wrote readme and added (un)install scripts 2023-10-20 15:15:09 -05:00

mgen

Makefile generator for C projects.

Overview

mgen automatically generates build rules for all source files (extension .c) it finds in a recursive search of the directory in which it is run. It places the rules in your existing makefile, meaning you can easily change build options and even write your own rules based on those generated.

mgen will place the generated rules between the strings "#=mgen_start=#" and "#=mgen_end=#" in your makefile. If these lines are not present, it will add them to the end of the file and place the rules there. Anything not between these lines will not be touched by mgen.

mgen utilizes certain common make variables when generating the build rules. These are:

  • CC -> C compiler
  • CFLAGS -> compilation flags
  • LDLIBS -> linker libraries
  • LDFLAGS -> linker flags
  • TARGET -> name of final executable/library

It is therefore recommended that you set these at the beginning of your makefile, unless you want to use the make defaults.

mgen's rules will place all compiled files in the BUILD_DIR specified on the command line (see Usage section of this README). Objects will be placed in the directory BUILD_DIR/obj/, and the TARGET will be placed at BUILD_DIR/$(TARGET).

Usage

$ mgen --help
Usage: mgen [OPTIONS] [BUILD_DIR]

Arguments:
  [BUILD_DIR]  Directory to place build files [default: ./build]

Options:
  -p, --pretty               Replace default make output with nice build messages
  -m, --makefile <MAKEFILE>  Path to makefile [default: ./Makefile]
  -h, --help                 Print help

Starting from a "blank slate," i.e. you have no build system configured in your project, simply run mgen in the root directory and then run make. It's as easy as that.

If you already have a makefile in use, remove any rules to build the target or object files (that what mgen is for). You can keep any other, more complex rules that depend on these things, though. Then, run mgen and make and you are good to go.

Build Instructions

Build: cargo build --release Install (must build first) (needs root): sh install.sh Uninstall (needs root): sh uninstall.sh

Todo

  • Add functionality to generate rules to build a library, as opposed to an executable.
  • Add options to generate convenient rules like clean to remove all build files, run to execute the target, etc.
  • Don't create new makefile if no .c files are found.
  • Add exclude directory(ies) from search
  • Eventually: write man page.
  • Maybe: allow build directory to be specified within the Makefile ?
  • Maybe: figure out a way to only have the user run mgen once, then the makefile itself will call it again if it needs to be regenerated due to a change in project structure ?