-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
76 lines (60 loc) · 2.07 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
CRYSTAL_ROOT ?= $(shell pwd)/share/crystal-ic/src
CRYSTAL_PATH ?= lib:$(CRYSTAL_ROOT):$(CRYSTAL_ROOT)/../lib
CRYSTAL_CONFIG_PATH ?= '$$ORIGIN/../share/crystal-ic/src'
CRYSTAL_LIB_CONFIG_PATH ?= '$$ORIGIN/../lib/ic/share/crystal-ic/src'
COMPILER ?= crystal
FLAGS ?= -Dpreview_mt --progress
RELEASE_FLAGS ?= -Dpreview_mt --progress --release
ENV ?= CRYSTAL_CONFIG_PATH=$(CRYSTAL_CONFIG_PATH) CRYSTAL_PATH=$(CRYSTAL_PATH)
ENV_LIB ?= CRYSTAL_CONFIG_PATH=$(CRYSTAL_LIB_CONFIG_PATH) CRYSTAL_PATH=$(CRYSTAL_PATH)
SOURCES := $(shell find src -name '*.cr')
O := bin/ic
# LLVM:
LLVM_EXT_DIR := $(CRYSTAL_ROOT)/llvm/ext
LLVM_EXT_OBJ := $(LLVM_EXT_DIR)/llvm_ext.o
LLVM_CONFIG ?= $(shell $(CRYSTAL_ROOT)/llvm/ext/find-llvm-config)
# INSTALL:
DESTDIR ?= /usr/local
BINDIR ?= $(DESTDIR)/bin
DATADIR ?= $(DESTDIR)/share/crystal-ic
INSTALL ?= /usr/bin/install
all: $(O)
$(O): $(LLVM_EXT_OBJ) $(SOURCES)
mkdir -p bin
$(ENV) $(COMPILER) build $(FLAGS) src/ic.cr -o $(O)
.PHONY: release
release: $(LLVM_EXT_OBJ)
mkdir -p bin
$(ENV) $(COMPILER) build $(RELEASE_FLAGS) src/ic.cr -o $(O)
$(LLVM_EXT_OBJ): $(LLVM_EXT_DIR)/llvm_ext.cc
$(CXX) -c $(CXXFLAGS) -o $@ $< $(shell $(LLVM_CONFIG) --cxxflags)
.PHONY: spec
spec: $(LLVM_EXT_OBJ)
mkdir -p bin
$(ENV) $(COMPILER) spec $(FLAGS) --order random
.PHONY: install
install: $(O) ## Install the compiler at DESTDIR
$(INSTALL) -d -m 0755 "$(BINDIR)/"
$(INSTALL) -m 0755 "$(O)" "$(BINDIR)/ic"
$(INSTALL) -d -m 0755 "$(DATADIR)"
cp -av share/crystal-ic/src "$(DATADIR)/"
rm -rf "$(DATADIR)/$(LLVM_EXT_OBJ)" # Don't install llvm_ext.o
$(INSTALL) -d -m 0755 "$(DESTDIR)/share/licenses/ic/"
$(INSTALL) -m 644 LICENSE "$(DESTDIR)/share/licenses/ic/LICENSE"
.PHONY: uninstall
uninstall: ## Uninstall the compiler from DESTDIR
rm -f "$(BINDIR)/ic"
rm -rf "$(DATADIR)/src"
rm -f "$(DESTDIR)/share/licenses/ic/LICENSE"
.PHONY: clean
clean:
rm -f $(LLVM_EXT_OBJ)
rm -f $(O)
.PHONY: lib_build
lib_build: clean $(LLVM_EXT_OBJ)
mkdir -p bin
$(ENV_LIB) $(COMPILER) build $(FLAGS) src/ic.cr -o $(O)
.PHONY: postinstall
postinstall: lib_build
mkdir -p ../../bin
cp $(O) ../../bin/