@ -5,17 +5,9 @@ tgo: build/tgo
.PHONY : all tgo run -test run -blinky run -blinky 2 clean fmt gen -device gen -device -nrf
.PHONY : all tgo run -test run -blinky run -blinky 2 clean fmt gen -device gen -device -nrf
# Custom LLVM toolchain.
CFLAGS = -Wall -Werror -Os -fno-exceptions -ffunction-sections -fdata-sections $( LLFLAGS)
LLVM := $( shell go env GOPATH) /src/github.com/aykevl/llvm/bindings/go/llvm/workdir/llvm_build/bin/
LINK = $( LLVM) llvm-link
LLAS = $( LLVM) llvm-as
OPT = $( LLVM) opt
CFLAGS = -Wall -Werror -Os -fno-exceptions -flto -ffunction-sections -fdata-sections $( LLFLAGS)
CFLAGS += -fno-exceptions -fno-unwind-tables # Avoid .ARM.exidx etc.
CFLAGS += -fno-exceptions -fno-unwind-tables # Avoid .ARM.exidx etc.
RUNTIME_PARTS = build/runtime.bc
TARGET ?= unix
TARGET ?= unix
i f e q ( $( TARGET ) , u n i x )
i f e q ( $( TARGET ) , u n i x )
@ -30,13 +22,10 @@ SIZE = arm-none-eabi-size
OBJCOPY = arm-none-eabi-objcopy
OBJCOPY = arm-none-eabi-objcopy
LLFLAGS += -target armv7m-none-eabi
LLFLAGS += -target armv7m-none-eabi
TGOFLAGS += -target $( TARGET)
TGOFLAGS += -target $( TARGET)
CFLAGS += -I$( CURDIR) /src/runtime
CFLAGS += -I$( CURDIR) /lib/nrfx
CFLAGS += -I$( CURDIR) /lib/nrfx/mdk
CFLAGS += -I$( CURDIR) /lib/CMSIS/CMSIS/Include
CFLAGS += -I$( CURDIR) /lib/CMSIS/CMSIS/Include
CFLAGS += -DNRF52832_XXAA
CFLAGS += -DNRF52832_XXAA
CFLAGS += -Wno-uninitialized
CFLAGS += -Wno-uninitialized
RUNTIME_PARTS += build/nrfx_system_nrf52.bc
OBJ += build/nrfx_system_nrf52.o
OBJ += build/nrfx_startup_nrf51.o # TODO nrf52, see https://bugs.llvm.org/show_bug.cgi?id=31601
OBJ += build/nrfx_startup_nrf51.o # TODO nrf52, see https://bugs.llvm.org/show_bug.cgi?id=31601
e l s e i f e q ( $( TARGET ) , a r d u i n o )
e l s e i f e q ( $( TARGET ) , a r d u i n o )
@ -94,15 +83,11 @@ build/tgo: *.go
go build -o build/tgo -i .
go build -o build/tgo -i .
# Build IR with the Go compiler.
# Build IR with the Go compiler.
build/%.o : src /examples /% src /examples /%/*.go build /tgo src /runtime /*.go build /runtime -$( TARGET ) -combined .bc
build/%.o : src /examples /% src /examples /%/*.go build /tgo src /runtime /*.go
./build/tgo build $( TGOFLAGS) -runtime build/runtime-$( TARGET) -combined.bc -o $@ $( subst src/,,$<)
./build/tgo build $( TGOFLAGS) -o $@ $( subst src/,,$<)
# Compile LLVM bitcode from LLVM source.
build/%.bc : src /runtime /%.ll
$( LLAS) -o $@ $<
# Compile system_* file for the nRF.
# Compile system_* file for the nRF.
build/nrfx_%.bc : lib /nrfx /mdk /%.c
build/nrfx_%.o : lib /nrfx /mdk /%.c
@mkdir -p build
@mkdir -p build
clang $( CFLAGS) -c -o $@ $^
clang $( CFLAGS) -c -o $@ $^
@ -114,10 +99,6 @@ build/nrfx_%.o: lib/nrfx/mdk/gcc_%.S
build/%.o : %.S
build/%.o : %.S
$( AS) -o $@ $^
$( AS) -o $@ $^
# Merge all runtime LLVM files together in a single bitcode file.
build/runtime-$(TARGET)-combined.bc : $( RUNTIME_PARTS )
$( LINK) -o $@ $^
# Generate output ELF executable.
# Generate output ELF executable.
build/% : build /%.o $( OBJ )
build/% : build /%.o $( OBJ )
$( LD) -o $@ $^
$( LD) -o $@ $^