|
| 1 | +# Include other Makefiles for improved functionality |
| 2 | +INCLUDE_DIR = ../../tools/Makefiles |
| 3 | +MAKEFILES := $(wildcard $(INCLUDE_DIR)/*.mk) |
| 4 | +# We can't guarantee customers will have the include files |
| 5 | +# - prefix to ignore Makefiles when not present |
| 6 | +# https://www.gnu.org/software/make/manual/html_node/Include.html |
| 7 | +-include $(MAKEFILES) |
| 8 | + |
| 9 | +ifneq ($(MAKEFILES),) |
| 10 | + $(info [$(YELLOW)*$(NORMAL)] Use ``make menu`` for available targets) |
| 11 | + $(info [$(YELLOW)*$(NORMAL)] Including available Makefiles: $(MAKEFILES)) |
| 12 | + $(info --) |
| 13 | +else |
| 14 | + $(warning Makefile includes directory not present: $(INCLUDE_DIR)) |
| 15 | +endif |
| 16 | + |
| 17 | +VERSION?=$(shell grep '^version: ' plugin.spec.yaml | sed 's/version: //') |
| 18 | +NAME?=$(shell grep '^name: ' plugin.spec.yaml | sed 's/name: //') |
| 19 | +VENDOR?=$(shell grep '^vendor: ' plugin.spec.yaml | sed 's/vendor: //') |
| 20 | +CWD?=$(shell basename $(PWD)) |
| 21 | +_NAME?=$(shell echo $(NAME) | awk '{ print toupper(substr($$0,1,1)) tolower(substr($$0,2)) }') |
| 22 | +PKG=$(VENDOR)-$(NAME)-$(VERSION).tar.gz |
| 23 | + |
| 24 | +# Set default target explicitly. Make's default behavior is the first target in the Makefile. |
| 25 | +# We don't want that behavior due to includes which are read first |
| 26 | +.DEFAULT_GOAL := default # Make >= v3.80 (make -version) |
| 27 | + |
| 28 | + |
| 29 | +default: image tarball |
| 30 | + |
| 31 | +tarball: |
| 32 | + $(info [$(YELLOW)*$(NORMAL)] Creating plugin tarball) |
| 33 | + rm -rf build |
| 34 | + rm -rf $(PKG) |
| 35 | + tar -cvzf $(PKG) --exclude=$(PKG) --exclude=tests --exclude=run.sh * |
| 36 | + |
| 37 | +image: |
| 38 | + $(info [$(YELLOW)*$(NORMAL)] Building plugin image) |
| 39 | + docker build --pull -t $(VENDOR)/$(NAME):$(VERSION) . |
| 40 | + docker tag $(VENDOR)/$(NAME):$(VERSION) $(VENDOR)/$(NAME):latest |
| 41 | + |
| 42 | +regenerate: |
| 43 | + $(info [$(YELLOW)*$(NORMAL)] Refreshing schema from plugin.spec.yaml) |
| 44 | + insight-plugin refresh |
| 45 | + |
| 46 | +export: image |
| 47 | + $(info [$(YELLOW)*$(NORMAL)] Exporting docker image) |
| 48 | + @printf "\n ---> Exporting Docker image to ./$(VENDOR)_$(NAME)_$(VERSION).tar\n" |
| 49 | + @docker save $(VENDOR)/$(NAME):$(VERSION) | gzip > $(VENDOR)_$(NAME)_$(VERSION).tar |
| 50 | + |
| 51 | +# Make will not run a target if a file of the same name exists unless setting phony targets |
| 52 | +# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html |
| 53 | +.PHONY: default tarball image regenerate |
0 commit comments