This repo illustrates how to organize complex global Makefile targets.
-
Clone this repo into ~/.config/makefiles..
-
To auto load those files add the following to
~/.bashrc
export MAKEFILES_HOME="$HOME/.config/makefiles"
if [ -d ${MAKEFILES_HOME}/public ]; then
# Include all .mk files in ${MAKEFILES_HOME}/public
export MAKEFILES="$(find ${MAKEFILES_HOME}/public -name '*.mk' -print0 | xargs -0 echo)"
fi
The demo shows organizing global make targets into public and internal targets, while using bash functions to run more complex scripts.
-
~/.config/makefiles/public/*.mk
includes public targets likeinstall-jb
andinstall-helm
-
~/.config/makefiles/internal/*.mk
includes internal targets like_install-tool
and_install-archived-tool
It may be desired to have sub-directories under public
to present multiple namespaces. Which should be auto populated as a public target
This setup is fairly complex, Thus I recommend:
- Using global make targets only when the targets are not desired to be associated with a single project is desired.
- Using simple targets as much as possible
- Deferring as much logic to scripts
- Resorting to public/internal split only when reusability between different makefiles is desired which could be a complex scenario enough for such split.
Personal usage recommendations:
- Defining global targets like a
make help
target that parses the comment written on the target line - Defining scoped targets per project, notice that MAKEFILES defined globally would be used everywhere which is not always desired, so MAKEFILES management is desirable in such sitations. Which can be achieved through scripting.
- Before applying the scripts in your env I recommend reading the MAKEFILES manpage first.