Skip to content

demo repository exploring how to auto import bash functions (available in recipes) using a make SHELL wrapper

License

Notifications You must be signed in to change notification settings

lgersman/make-auto-import-bash-library-using-shell-wrapper-demo

Repository files navigation

About

Demo repository exloring how to automatically provide custom bash functions/symbols to

  • make recipes

  • make shell function calls (i.e. $(shell ...))

What is it good for ?

When developing larger Makefile's you will recognize

  • duplicated bash code within make your recipes

  • large bash recipes across many lines (possible thanks to make directive .ONESHELL)

  • longer bash recipe blocks will look very confusing due to the $ escaping issue

Would'nt it be nice to out source such bash code in separate shell script libraries ?

  • easier maintenance

    Makefiles just consist of short recipes just calling your bash functions

    Makefile

    deploy: build
      github::release $(GIT_TAG) $(GITHUB_USER) $(GITHUB_TOKEN)

    your Bash library

    function github::release() {
      ...
    }
    export -f github::release
  • testing

    Your bash scripts can be hardened by tests.

    There exist a bunch of mature shell testing frameworks like https://github.com/kward/shunit2 or bats for testing bash code

  • reusable code

    Your bash functions can now be reused in other slightly different projects.

I think the answer is a clear : Y.E.S. !


This repo contains some working examples implementing automatic configurable provisioning of custom bash libraries in Makefile's.

Depending on your needs you can choose wich variant works best for you.

So if you don't know which one to use ... head over to the GOLD solution - it works in every case.


Is it used somewhere ?

I use some of the ideas implemented here in a generic make framework called pnpmkambrium by myself.

pnpmkambrium goes far beyond the technique described here - it provides

  • a generic Meta Makefile maintaining monorepos for building/uploading

    • docker images

    • npm packages

    • wordpress plugins/themes

    • ...

    out of the box

  • customizable by .env and .secret files.

    In most cases you don't need to write custom Makefile's - just provide .env files (for non-sensitive data) and .secrets files (for sensitive data like credentials).

  • You can even extend it with your own Bash functions and Make targets/rules.

You may also have a look at my Makefile recipes in various languages GitHub repo showing how to use almost any scripting language (instead of bash) to implement Makefile recipes

Prerequisites

  • GNU make

  • Bash

Prior art

About

demo repository exploring how to auto import bash functions (available in recipes) using a make SHELL wrapper

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published