Skip to content

Commit 2f4d106

Browse files
amstrnadarunthomas
authored andcommitted
Build stuff
1 parent c073def commit 2f4d106

File tree

4 files changed

+127
-0
lines changed

4 files changed

+127
-0
lines changed

Makefile.isp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
.PHONY: all
2+
.PHONY: debug
3+
.PHONY: release
4+
.PHONY: install
5+
.PHONY: clean
6+
7+
export ISP_PREFIX ?= $(HOME)/.local/isp/
8+
9+
ifeq "$(shell isp-support/check_ninja_version)" "System ninja is new enough"
10+
NINJA := ninja
11+
else
12+
NINJA := $(HOME)/.local/bin/ninja
13+
endif
14+
15+
BUILD_TYPE ?= debug
16+
17+
COMMON_CMAKE_FLAGS += -G "Ninja"
18+
COMMON_CMAKE_FLAGS += -DLLVM_ENABLE_PROJECTS="clang"
19+
COMMON_CMAKE_FLAGS += -DCMAKE_MAKE_PROGRAM=$(NINJA)
20+
COMMON_CMAKE_FLAGS += -DCMAKE_INSTALL_PREFIX=$(ISP_PREFIX)
21+
COMMON_CMAKE_FLAGS += -DCMAKE_C_COMPILER=clang
22+
COMMON_CMAKE_FLAGS += -DCMAKE_CXX_COMPILER=clang++
23+
COMMON_CMAKE_FLAGS += -DLLVM_BINUTILS_INCDIR=/usr/include
24+
COMMON_CMAKE_FLAGS += -DBUILD_SHARED_LIBS=True
25+
COMMON_CMAKE_FLAGS += -DLLVM_OPTIMIZED_TABLEGEN=True
26+
COMMON_CMAKE_FLAGS += -DLLVM_BUILD_TESTS=True
27+
COMMON_CMAKE_FLAGS += -DDEFAULT_SYSROOT=$(ISP_PREFIX)/riscv32-unknown-elf
28+
COMMON_CMAKE_FLAGS += -DLLVM_DEFAULT_TARGET_TRIPLE="riscv32-unknown-elf"
29+
COMMON_CMAKE_FLAGS += -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="RISCV"
30+
COMMON_CMAKE_FLAGS += -DLLVM_TARGETS_TO_BUILD=""
31+
32+
DEBUG_CMAKE_FLAGS := -DCMAKE_BUILD_TYPE=Debug
33+
DEBUG_CMAKE_FLAGS += -DLLVM_ENABLE_ASSERTIONS=ON
34+
DEBUG_CMAKE_FLAGS += -DCMAKE_C_FLAGS=-fstandalone-debug
35+
DEBUG_CMAKE_FLAGS += -DCMAKE_CXX_FLAGS=-fstandalone-debug
36+
37+
RELEASE_CMAKE_FLAGS := -DCMAKE_BUILD_TYPE=Release
38+
39+
debug-build/build.ninja: CMAKE_FLAGS := $(COMMON_CMAKE_FLAGS) $(DEBUG_CMAKE_FLAGS)
40+
41+
release-build/build.ninja: CMAKE_FLAGS := $(COMMON_CMAKE_FLAGS) $(RELEASE_CMAKE_FLAGS)
42+
43+
all: $(BUILD_TYPE)
44+
45+
$(BUILD_TYPE): $(BUILD_TYPE)-build/build.ninja
46+
$(NINJA) -C $(BUILD_TYPE)-build
47+
48+
$(BUILD_TYPE)-build/build.ninja:
49+
$(RM) -r $(BUILD_TYPE)-build
50+
mkdir -p $(BUILD_TYPE)-build
51+
cd $(BUILD_TYPE)-build; cmake $(CMAKE_FLAGS) ../llvm
52+
53+
install: $(BUILD_TYPE)-install
54+
55+
debug-install release-install: %-install: $*
56+
$(NINJA) -C $*-build install
57+
58+
clean:
59+
$(RM) -r debug-build
60+
$(RM) -r release-build

isp-support/README

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Best results obtained by using the gold linker. Your ld is likely a symlink,
2+
point it at ld.gold
3+
4+
Be sure to clone recursively
5+
6+
To build the llvm riscv cross compiler first make sure that you have a riscv
7+
toolchain installed. I worked with the instructions here for a clean riscv
8+
toolchain:
9+
10+
https://github.com/lowRISC/riscv-llvm
11+
12+
Then run the configure script. I *strongly* recommend you let it install the
13+
same version of cmake and ninja that I was using (the latest release as of May
14+
22, 2018). It will also ask you for the base path to the riscv toolchain. This
15+
will enable the cross compiler to actually work, and is where the cross compiler
16+
will get installed.
17+
18+
./configure.sh
19+
20+
After that, you can build either the debug or release version. I have been
21+
working with the debug version during development, and strongly recommend it.
22+
The release version is currently *untested* and *unsupported*.
23+
24+
cd debug-build
25+
ninja
26+
ninja install

isp-support/check_ninja_version

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
version=`ninja --version`;
4+
check="1.8.2";
5+
winner=`echo -e "${version}\n${check}" | sort -nr | head -1`;
6+
if [[ "${winner}" = "${version}" ]]; then
7+
echo "System ninja is new enough"
8+
exit 0
9+
else
10+
echo "System ninja is too old"
11+
exit 1
12+
fi

isp-support/install-dependencies

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
apt-get update
6+
7+
apt-get install -y \
8+
binutils-dev \
9+
build-essential \
10+
clang \
11+
cmake \
12+
unzip \
13+
wget \
14+
zlib1g-dev
15+
16+
ninja_check() {
17+
md5sum --quiet -c <<< "540b5a37ac9d822b07179ec1771855ae $HOME/.local/bin/ninja"
18+
}
19+
20+
if [ -f $HOME/.local/bin/ninja ]; then
21+
ninja_check
22+
else
23+
wget https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-linux.zip
24+
unzip -o ninja-linux.zip
25+
mkdir -p $HOME/.local/bin
26+
mv ninja $HOME/.local/bin
27+
rm ninja-linux.zip
28+
ninja_check
29+
fi

0 commit comments

Comments
 (0)