[YUNIKORN-280] Fix Makefile multi line echo (#23)
Fix multiline echo in Makefile. The current implementation generates
unexpanded newline characters in certain build systems.
Fixes: #23
diff --git a/Makefile b/Makefile
index 384c415..ac5ef54 100644
--- a/Makefile
+++ b/Makefile
@@ -32,14 +32,25 @@
COMMON_LIB := $(LIB_DIR)/common
CONSTANTS_GO := $(COMMON_LIB)/constants.go
-GENERATED_HEADER := "// **** DO NOT EDIT\n// **** This code is generated by the build process.\n// **** DO NOT EDIT"
+define GENERATED_HEADER
+
+// Code generated by make build. DO NOT EDIT
+
+endef
+export GENERATED_HEADER
+
+define PACKAGE_DEF
+package common
+
+endef
+export PACKAGE_DEF
all:
$(MAKE) -C $(dir $(BASE_DIR)) build
# Generate the proto file from the spec, leave proto untouched if there are no changes
$(SI_PROTO).tmp: $(SI_SPEC)
- @echo $(GENERATED_HEADER) > $@
+ @echo "$$GENERATED_HEADER" > $@
cat $< | sed -n -e '/```protobuf$$/,/^```$$/ p' | sed '/^```/d' >> $@
awk '{ if (length > 200) print NR, $$0 }' $@ | diff - /dev/null
(diff $@ $(SI_PROTO) > /dev/null 2>&1 || mv -f $@ $(SI_PROTO)) && \
@@ -47,24 +58,24 @@
$(CONSTANTS_GO).tmp: $(SI_SPEC)
test -d $(COMMON_LIB) || mkdir -p $(COMMON_LIB)
- @echo $(GENERATED_HEADER) > $@
- @echo "\npackage common\n" >> $@
+ @echo "$$GENERATED_HEADER" > $@
+ @echo "$$PACKAGE_DEF" >> $@
cat $< | sed -n -e '/``constants$$/,/^```$$/ p' | sed '/^```/d' >> $@
(diff $@ $(CONSTANTS_GO) > /dev/null 2>&1 || mv -f $@ $(CONSTANTS_GO)) && \
- rm -f $@
+ rm -f $@
# Build the go language bindings from the spec via a generated proto
build: $(SI_PROTO).tmp $(CONSTANTS_GO).tmp
$(MAKE) -C $(LIB_DIR)
-# Set a empty recipe used in the internal build
+# Set a empty recipe
.PHONY: test
test:
@echo ""
# Check for missing license headers
-.PHONY: check-license
-check-license:
+.PHONY: license-check
+license-check:
@echo "checking license header"
@licRes=$$(grep -Lr --exclude-dir=lib --include=*.{go,sh,md,yaml,mod} "Licensed to the Apache Software Foundation" .) ; \
if [ -n "$${licRes}" ]; then \