# 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 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 ?