1
2all: help
3
4.PHONY: all help config update
5
6COMPONENTS = all-targets analysis asmparser asmprinter bitreader bitwriter codegen core coroutines debuginfodwarf executionengine instrumentation interpreter ipo irreader linker mc mcjit objcarcopts option profiledata scalaropts support target
7
8VERSION=9.0.0
9VERSION_MAJOR=$(firstword $(subst ., ,$(VERSION)))
10
11SRCDIR=llvm-$(VERSION)
12UNAME_S:=$(shell uname -s)
13
14GOOS := $(shell go env GOOS)
15
16LDFLAGS = $(shell $(CONFIG) --ldflags --libs --system-libs $(COMPONENTS))
17ifeq ($(BUILDDIR),)
18	ifeq ($(UNAME_S),Darwin)
19	CONFIG = /usr/local/Cellar/llvm/$(VERSION)/bin/llvm-config
20	LDFLAGS += -L/usr/local/opt/libffi/lib -lffi
21	else
22	CONFIG = llvm-config-$(VERSION_MAJOR)
23	endif
24else
25CONFIG=$(BUILDDIR)/bin/llvm-config
26endif
27
28help:
29	@echo "Use one of the following commands:"
30	@echo "  config:    update llvm_config_*.go to use a locally installed LLVM version"
31	@echo "  update:    update local .go/.cpp/.h files (see SRCDIR)"
32	@echo "  clean:     remove local .go/.cpp/.h files"
33	@echo "  clean-all: remove all LLVM files, including downloads"
34	@echo ""
35	@echo "Provided flags:"
36	@echo "  VERSION=$(VERSION)"
37	@echo "    LLVM version to use"
38	@echo "  SRCDIR=$(SRCDIR)"
39	@echo "    LLVM sources root"
40	@echo "  BUILDDIR=$(BUILDDIR)"
41	@echo "    LLVM sources root"
42
43config:
44	@echo "// +build !byollvm" > llvm_config_$(GOOS).go
45	@echo "" >> llvm_config_$(GOOS).go
46	@echo "package llvm" >> llvm_config_$(GOOS).go
47	@echo "" >> llvm_config_$(GOOS).go
48	@echo "// Automatically generated by \`make config BUILDDIR=$(BUILDDIR)\`, do not edit." >> llvm_config_$(GOOS).go
49	@echo "" >> llvm_config_$(GOOS).go
50	@echo "// #cgo CPPFLAGS: $(shell $(CONFIG) --cppflags)" >> llvm_config_$(GOOS).go
51	@if [ $(VERSION_MAJOR) -gt 9 ]; then \
52	echo "// #cgo CXXFLAGS: -std=c++14" >> llvm_config_$(GOOS).go; \
53	else \
54	echo "// #cgo CXXFLAGS: -std=c++11" >> llvm_config_$(GOOS).go; \
55	fi
56	@echo "// #cgo LDFLAGS: $(LDFLAGS)" >> llvm_config_$(GOOS).go
57	@echo "import \"C\"" >> llvm_config_$(GOOS).go
58	@echo "" >> llvm_config_$(GOOS).go
59	@echo "type run_build_sh int" >> llvm_config_$(GOOS).go
60
61update: $(SRCDIR) clean
62	@cp -rp "$(SRCDIR)"/bindings/go/llvm/*.go .
63	@cp -rp "$(SRCDIR)"/bindings/go/llvm/*.cpp .
64	@cp -rp "$(SRCDIR)"/bindings/go/llvm/*.h .
65
66clean:
67	@rm -f llvm_config_*.go
68	@rm -f $(sort $(filter-out backport%,$(wildcard *.go)))
69	@rm -f $(sort $(filter-out backport%,$(wildcard *.cpp)))
70	@rm -f $(sort $(filter-out backport%,$(wildcard *.h)))
71
72clean-all: clean
73	@rm -rf llvm-$(VERSION)
74	@rm -f llvm-$(VERSION).src.tar.xz
75
76# Downlaod the given LLVM release.
77llvm-$(VERSION).src.tar.xz:
78	wget -O llvm-$(VERSION).src.tar.xz http://releases.llvm.org/$(VERSION)/llvm-$(VERSION).src.tar.xz
79
80# Extract the given LLVM release to a temporary directory.
81llvm-$(VERSION): llvm-$(VERSION).src.tar.xz
82	mkdir -p $@
83	tar -C $@ --strip-components=1 -xf $< $@.src
84