Skip to content

Commit

Permalink
Improve Makefile to hack crystal
Browse files Browse the repository at this point in the history
- Use spaces instead of tab as an indent of no command line
- Add "optional variables" and "recipes" section for help outputs
- Output colored llvm-config information (this is same color of
  ./bin/crystal's "Using compiled compiler at" information)
  • Loading branch information
makenowjust authored and Ary Borenszweig committed Dec 13, 2016
1 parent 4336aab commit 2d86bd1
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
-include Makefile.local # for optional local options e.g. threads

# Recipes for this Makefile

## Build the compiler
## $ make
## Clean up built files then build the compiler
## $ make clean crystal
## Build the compiler in release mode
## $ make crystal release=1
## Run all specs in verbose mode
## $ make specs verbose=1

LLVM_CONFIG ?= ## llvm-config command path to use

release ?= ## Compile in release mode
stats ?= ## Enable statistics output
threads ?= ## Maximum number of threads to use
debug ?= ## Add symbolic debug info
verbose ?= ## Run specs in verbose mode

O := .build
SOURCES := $(shell find src -name '*.cr')
SPEC_SOURCES := $(shell find spec -name '*.cr')
Expand All @@ -8,12 +27,14 @@ VERBOSE := $(if $(verbose),-v )
EXPORTS := $(if $(release),,CRYSTAL_CONFIG_PATH=`pwd`/src)
SHELL = bash
LLVM_CONFIG_FINDER := \
[ -n "$(LLVM_CONFIG)" ] && command -v "$(LLVM_CONFIG)" || \
command -v llvm-config-3.9 || command -v llvm-config39 || (command -v llvm-config > /dev/null && (case "$(llvm-config --version)" in 3.9*) command -v llvm-config;; *) false;; esac)) || \
command -v llvm-config-3.8 || command -v llvm-config38 || (command -v llvm-config > /dev/null && (case "$(llvm-config --version)" in 3.8*) command -v llvm-config;; *) false;; esac)) || \
command -v llvm-config-3.6 || command -v llvm-config36 || \
command -v llvm-config-3.5 || command -v llvm-config35 || \
command -v llvm-config
[ -n "$(LLVM_CONFIG)" ] && command -v "$(LLVM_CONFIG)" || \
command -v llvm-config-3.9 || command -v llvm-config39 || \
(command -v llvm-config > /dev/null && (case "$(llvm-config --version)" in 3.9*) command -v llvm-config;; *) false;; esac)) || \
command -v llvm-config-3.8 || command -v llvm-config38 || \
(command -v llvm-config > /dev/null && (case "$(llvm-config --version)" in 3.8*) command -v llvm-config;; *) false;; esac)) || \
command -v llvm-config-3.6 || command -v llvm-config36 || \
command -v llvm-config-3.5 || command -v llvm-config35 || \
command -v llvm-config
LLVM_CONFIG := $(shell $(LLVM_CONFIG_FINDER))
LLVM_EXT_DIR = src/llvm/ext
LLVM_EXT_OBJ = $(LLVM_EXT_DIR)/llvm_ext.o
Expand All @@ -26,18 +47,28 @@ CXXFLAGS += $(if $(debug),-g -O0)
ifeq (${LLVM_CONFIG},)
$(error Could not locate llvm-config, make sure it is installed and in your PATH, or set LLVM_CONFIG)
else
$(info Using $(LLVM_CONFIG) [version=$(shell $(LLVM_CONFIG) --version)])
$(info $(shell printf '\033[33m')Using $(LLVM_CONFIG) [version=$(shell $(LLVM_CONFIG) --version)]$(shell printf '\033[0m'))
endif

.PHONY: all
all: crystal
all: crystal ## Build all files (currently crystal only) [default]

.PHONY: help
help: ## Show this help
@echo
@printf '\033[34mtargets:\033[0m\n'
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) |\
sort |\
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
@echo
@printf '\033[34moptional variables:\033[0m\n'
@grep -E '^[a-zA-Z_-]+ \?=.*?## .*$$' $(MAKEFILE_LIST) |\
sort |\
awk 'BEGIN {FS = " \\?=.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
@echo
@printf '\033[34mrecipes:\033[0m\n'
@grep -E '^##.*$$' $(MAKEFILE_LIST) |\
awk 'BEGIN {FS = "## "}; /^## [a-zA-Z_-]/ {printf " \033[36m%s\033[0m\n", $$2}; /^## / {printf " %s\n", $$2}'

.PHONY: spec
spec: all_spec ## Run all specs
Expand Down

0 comments on commit 2d86bd1

Please sign in to comment.