#############################################################################################
#############################################################################################
##
## GET LICENSES
##
#############################################################################################
#############################################################################################

GO_MOD_FILE := $(SOURCE_PATH)go.mod

ifeq ($(shell test -e $(GO_MOD_FILE) && echo -n yes),yes)
    GO_CURRENT_MODULE := $(shell cat $(GO_MOD_FILE) | head -n1 | cut -d" " -f2)
	# go install github.com/google/go-licenses@latest
	EXECUTABLES = $(EXECUTABLES:-) go-licenses;    
endif

.PHONY: go-fetch-licenses
## Fetch licenses for all modules
go-fetch-licenses:
ifeq ($(GO_CURRENT_MODULE),)
	$(QUIET) $(ECHOERRORMARKER) "no go.mod file found, skipping fetching licenses"
else
	$(ECHOMARKER) "Fetch licenses"
	$(QUIET) cd $(SOURCE_PATH); go-licenses save $(GO_CURRENT_MODULE) $(GO_LICENSES_IGNORE_PACKAGES) --force --save_path $(DOCUMENTATION_PATH)licenses/ ; cd -
endif