mgen/README.md

96 lines
3.6 KiB
Markdown
Raw Normal View History

2023-09-18 02:17:42 +00:00
# mgen
2023-09-18 02:50:16 +00:00
Makefile generator for C projects.
## Overview
2023-09-18 02:50:16 +00:00
`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
2023-10-20 20:18:02 +00:00
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
2023-10-20 20:18:02 +00:00
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
2023-09-18 02:50:16 +00:00
- 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)`.
2023-10-21 01:21:43 +00:00
## Why use this tool?
`mgen` offers distinct advantages over other, more complex build systems. These
include:
1. **Simplicity.** There are no special languages to learn, extra configuration
files, and countless features that you won't ever use. Of course, if you need
those things, there are other options available; that is not the space `mgen`
intends to occupy.
1. **Extensibility.** Because `mgen` adds to your existing makefile, you can
write your own build rules in a language you already know: make. Your custom
rules can use the ones generated by `mgen`, or you can just use the generated
ones; it's up to you, `mgen` gives you that option.
1. **Portability.** Once the makefile is generated, it can be run on any machine
that runs `make`. Your users do not have to have `mgen` to compile your
program, they can just use the generated makefile.
## Usage
```
$ mgen --help
2023-10-20 20:18:02 +00:00
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`
2023-10-21 00:55:29 +00:00
Install (must build first) (needs root): `sh install.sh`
2023-10-21 00:55:29 +00:00
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 ?