From 38ba345ff9e07702b54f177ef8cf7aed5cce1b66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Tue, 30 Nov 2021 14:40:50 +0100 Subject: [PATCH 1/5] [Makefile] Check for LLVM_CONFIG only when LLVM is used --- Makefile | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 0770a144f5b1..e6344b039fe8 100644 --- a/Makefile +++ b/Makefile @@ -43,6 +43,7 @@ EXPORTS_BUILD := \ CRYSTAL_CONFIG_LIBRARY_PATH=$(CRYSTAL_CONFIG_LIBRARY_PATH) SHELL = sh LLVM_CONFIG := $(shell src/llvm/ext/find-llvm-config) +LLVM_VERSION := $(shell $(LLVM_CONFIG) --version 2> /dev/null) LLVM_EXT_DIR = src/llvm/ext LLVM_EXT_OBJ = $(LLVM_EXT_DIR)/llvm_ext.o DEPS = $(LLVM_EXT_OBJ) @@ -61,11 +62,12 @@ ifeq ($(shell command -v ld.lld >/dev/null && uname -s),Linux) EXPORT_CC ?= CC="cc -fuse-ld=lld" endif -ifeq (${LLVM_CONFIG},) - $(error Could not locate compatible llvm-config, make sure it is installed and in your PATH, or set LLVM_CONFIG. Compatible versions: $(shell cat src/llvm/ext/llvm-versions.txt)) -else - $(shell echo $(shell printf '\033[33m')Using $(LLVM_CONFIG) [version=$(shell $(LLVM_CONFIG) --version)]$(shell printf '\033[0m') >&2) -endif +colorize = $(shell tput >&2 setaf 3; echo >&2 "$1"; tput >&2 sgr0) +check_llvm_config = $(eval \ + check_llvm_config := $(if $(LLVM_VERSION),\ + $(call colorize,Using $(LLVM_CONFIG) [version=$(LLVM_VERSION)]),\ + $(error "Could not locate compatible llvm-config, make sure it is installed and in your PATH, or set LLVM_CONFIG. Compatible versions: $(shell cat src/llvm/ext/llvm-versions.txt)))\ + ) .PHONY: all all: crystal ## Build all files (currently crystal only) [default] @@ -108,6 +110,7 @@ samples: .PHONY: docs docs: ## Generate standard library documentation + $(call check_llvm_config) ./bin/crystal docs src/docs_main.cr $(DOCS_OPTIONS) --project-name=Crystal --project-version=$(CRYSTAL_VERSION) --source-refname=$(CRYSTAL_CONFIG_BUILD_COMMIT) .PHONY: crystal @@ -156,22 +159,27 @@ uninstall_docs: ## Uninstall docs from DESTDIR rm -rf "$(DATADIR)/examples" $(O)/all_spec: $(DEPS) $(SOURCES) $(SPEC_SOURCES) + $(call check_llvm_config) @mkdir -p $(O) $(EXPORT_CC) $(EXPORTS) ./bin/crystal build $(FLAGS) $(SPEC_WARNINGS_OFF) -o $@ spec/all_spec.cr $(O)/std_spec: $(DEPS) $(SOURCES) $(SPEC_SOURCES) + $(call check_llvm_config) @mkdir -p $(O) $(EXPORT_CC) ./bin/crystal build $(FLAGS) $(SPEC_WARNINGS_OFF) -o $@ spec/std_spec.cr $(O)/compiler_spec: $(DEPS) $(SOURCES) $(SPEC_SOURCES) + $(call check_llvm_config) @mkdir -p $(O) $(EXPORT_CC) $(EXPORTS) ./bin/crystal build $(FLAGS) $(SPEC_WARNINGS_OFF) -o $@ spec/compiler_spec.cr $(O)/crystal: $(DEPS) $(SOURCES) + $(call check_llvm_config) @mkdir -p $(O) $(EXPORTS) $(EXPORTS_BUILD) ./bin/crystal build $(FLAGS) -o $@ src/compiler/crystal.cr -D without_openssl -D without_zlib $(LLVM_EXT_OBJ): $(LLVM_EXT_DIR)/llvm_ext.cc + $(call check_llvm_config) $(CXX) -c $(CXXFLAGS) -o $@ $< $(shell $(LLVM_CONFIG) --cxxflags) man/%.gz: man/% From 76cdbb4e87ba187092e41ce2f3c7b7be6f216573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Wed, 1 Dec 2021 16:03:14 +0100 Subject: [PATCH 2/5] Remove tput --- Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e6344b039fe8..048b5084938f 100644 --- a/Makefile +++ b/Makefile @@ -62,7 +62,12 @@ ifeq ($(shell command -v ld.lld >/dev/null && uname -s),Linux) EXPORT_CC ?= CC="cc -fuse-ld=lld" endif -colorize = $(shell tput >&2 setaf 3; echo >&2 "$1"; tput >&2 sgr0) +ifeq ($(or $(TERM),$(TERM),dumb),dumb) +colorize = $(shell printf >&2 "$1") +else +colorize = $(shell printf >&2 "\033[33m$1\033[0m\n") +endif + check_llvm_config = $(eval \ check_llvm_config := $(if $(LLVM_VERSION),\ $(call colorize,Using $(LLVM_CONFIG) [version=$(LLVM_VERSION)]),\ From 2aef6c7fcf3d15a71a945e7eef47baf909595f88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Wed, 1 Dec 2021 16:54:36 +0100 Subject: [PATCH 3/5] Apply suggestions from code review Co-authored-by: Sijawusz Pur Rahnama --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 048b5084938f..61d86ee0dab7 100644 --- a/Makefile +++ b/Makefile @@ -63,9 +63,9 @@ ifeq ($(shell command -v ld.lld >/dev/null && uname -s),Linux) endif ifeq ($(or $(TERM),$(TERM),dumb),dumb) -colorize = $(shell printf >&2 "$1") + colorize = $(shell printf >&2 "$1") else -colorize = $(shell printf >&2 "\033[33m$1\033[0m\n") + colorize = $(shell printf >&2 "\033[33m$1\033[0m\n") endif check_llvm_config = $(eval \ From 314c2f48b4f868c57f4a0bc0195d5d767d193c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Wed, 1 Dec 2021 17:03:03 +0100 Subject: [PATCH 4/5] Check for empty LLVM_CONFIG --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 61d86ee0dab7..fe0952bde09b 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,9 @@ EXPORTS_BUILD := \ CRYSTAL_CONFIG_LIBRARY_PATH=$(CRYSTAL_CONFIG_LIBRARY_PATH) SHELL = sh LLVM_CONFIG := $(shell src/llvm/ext/find-llvm-config) -LLVM_VERSION := $(shell $(LLVM_CONFIG) --version 2> /dev/null) +ifdef $(LLVM_CONFIG) + LLVM_VERSION := $(shell $(LLVM_CONFIG) --version 2> /dev/null)) +endif LLVM_EXT_DIR = src/llvm/ext LLVM_EXT_OBJ = $(LLVM_EXT_DIR)/llvm_ext.o DEPS = $(LLVM_EXT_OBJ) From 25d3624e2ad30992b42109364ef90a784a79bc31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Thu, 2 Dec 2021 12:20:37 +0100 Subject: [PATCH 5/5] fixup --- Makefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Makefile b/Makefile index fe0952bde09b..7b0f1804111b 100644 --- a/Makefile +++ b/Makefile @@ -43,9 +43,7 @@ EXPORTS_BUILD := \ CRYSTAL_CONFIG_LIBRARY_PATH=$(CRYSTAL_CONFIG_LIBRARY_PATH) SHELL = sh LLVM_CONFIG := $(shell src/llvm/ext/find-llvm-config) -ifdef $(LLVM_CONFIG) - LLVM_VERSION := $(shell $(LLVM_CONFIG) --version 2> /dev/null)) -endif +LLVM_VERSION := $(if $(LLVM_CONFIG), $(shell $(LLVM_CONFIG) --version 2> /dev/null)) LLVM_EXT_DIR = src/llvm/ext LLVM_EXT_OBJ = $(LLVM_EXT_DIR)/llvm_ext.o DEPS = $(LLVM_EXT_OBJ)