Ensure required cmd in Makefile targets

To conditionally install the swag command required for my openapi-generate target, I find this approach to be both easy and portable. It works well because swag is a Go binary, so I have a way to install it regardless of the user's platform, using go install:

GOPATH ?= $(HOME)/go/bin
SWAG = $(GOPATH)/swag
openapi-generate:
    test -x $(SWAG) || go install github.com/swaggo/swag/cmd/swag
    $(SWAG) init
    $(SWAG) fmt

It's important to note, the variables must be set outside the target, openapi-generate.


~ /home 🏠 ~ talks 💬 ~ bash ~ craftsmanship ~ db ~ dongxi ~ emacs ~ escenic ~ iam ~ java ~ js ~ language ~ latex ~ ldap ~ life ~ linux ~ llm ~ mac-os-x ~ mt-foo ~ network ~ norsk ~ python ~ quotes ~ running ~ security ~ travel ~ unix ~ various ~ vcs ~ webdesign ~ windows ~ discoveries ~ cv 🧙 ~

Licensed under CC BY Creative Commons License ~ 📡 RSS feed ~ ✉ torstein.k.johansen @ gmail ~ 🐘 @skybert@hachyderm.io ~ 🎥 youtube.com/@skybert