This project provides a dynamic Makefile system designed to organize and extend your build processes. Instead of a single monolithic Makefile, Makefiler allows you to define targets and logic in separate, modular .mk files, making your build system more maintainable and scalable.
- Dynamic Target Loading: Automatically discovers and includes targets defined in
.mkfiles within themakefiler/directory. This modular approach keeps your build logic organized and easy to manage. - Help Target (
make help): Provides a self-documenting system. Runningmake helpwill list all available targets and their descriptions, which are extracted directly from your.mkfiles. - Target File Dumping (
make dump target=<target>): A utility for inspecting the contents of individual.mktarget files, which is ideal for debugging or understanding the definition of a specific target. - Optional Variable Overrides: Customize variables used in your targets via an optional
Makefile.variablesfile. This allows you to tailor the build process without modifying the core target definitions. - Debug Mode: Enable debug output by setting the
DEBUGvariable. This outputs extra debug information during make execution, which aids troubleshooting and helps you understand the Makefile’s behavior.
-
Clone Makefiler:
Clone the Makefiler repository into your local workspace.git clone https://github.com/yourusername/makefiler.git
-
Copy the Required Files:
- Copy the main
Makefilefrom the Makefiler repository into the root of your project. - Copy the
makefiler/folder into your project’s root directory.
This setup installs the dynamic Makefiler system into your project, setting the stage for modular target definitions.
- Copy the main
Once installed, follow these steps to use Makefiler in your project:
-
Define Targets in
.mkFiles:
Create or modify.mkfiles in themakefiler/directory. For example, you might have:makefiler/build.mkmakefiler/deploy.mkmakefiler/test.mk
In each
.mkfile, define your Makefile targets using the normal syntax. Be sure to add a comment (starting with#) after each target definition to provide a short description that will be used by thehelptarget.# makefiler/build.mk build: # Compile the application. @echo "Building application..." # ... your build commands ... build-docker: # Build a Docker image. @echo "Building Docker image..." # ... your docker build commands ...
-
Run Targets:
From your project’s root directory, execute make followed by the target name:make build # Runs the 'build' target make build-docker # Runs the 'build-docker' target
-
Get Help (
make help):
To see a formatted list of all available targets and their descriptions, simply run:make helpThe help system will automatically pick up descriptions from the comments in your
.mkfiles. -
Dump a Target File (
make dump target=<target>):
If you need to inspect the contents of a specific.mkfile (for example, to debug or learn its setup), you can run:make dump target=build
This command will display the contents of
makefiler/build.mkin your console.
You can override or customize variables used within your .mk files by creating a Makefile.variables file in the root directory of your project. This step is optional but provides an extra layer of configuration.
-
Create
Makefile.variables:
In the same directory as the mainMakefile, create a file namedMakefile.variables. -
Define Variables:
Add any variables you want to configure. These variables will be available within your.mkfiles. For example:# Makefile.variables BACKEND_BUILD_COMMAND = docker-compose -f docker-compose.backend.yml build DEPLOY_SERVER_ADDRESS = my-production-server.example.com
-
Usage in
.mkFiles:
Your target definitions can now use these variables. For instance:# makefiler/build.mk build-backend: # Build the backend application using the custom command. @echo "Building backend using: $(BACKEND_BUILD_COMMAND)" @$(BACKEND_BUILD_COMMAND) deploy-backend: # Deploy backend to the custom server address. @echo "Deploying backend to: $(DEPLOY_SERVER_ADDRESS)" # ... deployment commands using $(DEPLOY_SERVER_ADDRESS) ...
When Makefile.variables exists, its variables are automatically included, allowing you to easily customize and reuse build commands without modifying core target definitions.
Enable debug output by setting the DEBUG variable to any non-blank value. This can be useful for tracing the execution of your targets or troubleshooting issues.
For example, to enable debug mode when viewing the help output:
DEBUG=1 make helpThis will print extra debug information (like discovered phony targets) during execution. You can also add additional $(if $(DEBUG),$(info ...)) statements in your .mk files or the main Makefile to output variable values or execution traces.
Makefile: The main dynamic Makefile (copied into your project's root).Makefile.variables(optional): File for overriding global user variables (in your project's root).makefiler/: Directory containing.mkfiles that each define a set of related targets (copied into your project's root).
Contributions to improve Makefiler are welcome! Please feel free to submit pull requests or open issues for bug reports, feature requests, or suggestions for improvement.