Core functions for makefiles (module management, help)
Makefile technology has some drawbacks but it is reliable, language agnostic and available by default on most platform.
This project aims to standardize most common functionalities. Simply copy and include core.mk
in your project and start building your project !
- 📦 Simple dependency manager (using git submodule)
- ✓ No extra dependency
- ✓ Lightweight implementation
- ✓ Compatible dependency maintainer bot (Renovate)
- ℹ️ Automatic help generator, based on comments
- ⚒️ Everything is customizable using
Makefile.local
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/w5s/makefile-core/main/install.sh)"
1. Copy core.mk
to your project
my-project/
├─ .modules/
│ ├─ core.mk <- COPY https://raw.githubusercontent.com/w5s/makefile-core/main/core.mk
├─ Makefile
2. Include .modules/core.mk
in your Makefile
# At the start of Makefile
include .modules/core.mk
3. Test that everything is working
> make help
Display all available targets and flags
Tip
Help command output is automatically generated by reading annotations in the Makefiles.
Here is an example of annotated Makefile
# For a target, add a comment at the end of line
my_target: ## Do something
# For a variable, add a comment on the line before and declare using ?=
## This is a variable
MY_VARIABLE ?= my-value
Will display
> make help
...
Targets :
...
my_target Do something
...
Flags:
...
MY_VARIABLE This is a variable
...
Add a makefile module (as git submodule). If a ./module.mk
is found it will be automatically included.
Example :
> make self-add url=https://github.com/ianstormtaylor/makefile-assert
# It will add /.modules/makefile-assert git submodule
Note
Running this command will create a folder inside .modules/
using git subtree and a module.json
file.
All modification should be versioned in git.
Update all makefile modules
Example :
> make self-update
Display all env variables exported by make. This is useful for debugging. Another use is for dumping environment and use it in Makefile.local
to be loaded elsewhere.
Example :
> make print-env > Makefile.local
# This will create a Makefile.local that can be used to initialize all environment variables used by the environment
Print every declared variables (often for debugging)
Example :
> make print-variables
Print a given variable
Example :
> make print-VAR
# This will display the value of $(VAR)
Override any variables/targets by creating Makefile.local
/ Makefile.config
my-project/
├─ .modules/
│ ├─ ...
├─ Makefile
├─ Makefile.config <- Will override (versioned)
├─ Makefile.local <- Will override (not versioned)
Note
Including .modules/core.mk
will also include files in the following order
<projectDir>/Makefile.local
(not versioned file)<projectDir>/Makefile.config
(versioned file)<projectDir>/.modules/core.mk
(default values)<projectDir>/.modules/*/module.mk
TODO
This repository is a copy of Captive-Studio/makefile-core . jpolo was the author of both, but Captive-Studio team will keep on maintaining their copy.
These repository were inspirations to build makefile-core :
MIT © Julien Polo