2020-09-04 00:36:19 +00:00
|
|
|
# Copyright (c) 2019-2020 Status Research & Development GmbH. Licensed under
|
2019-12-15 23:21:43 +00:00
|
|
|
# either of:
|
|
|
|
# - Apache License, version 2.0
|
|
|
|
# - MIT license
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except
|
|
|
|
# according to those terms.
|
|
|
|
|
|
|
|
SHELL := bash # the shell used internally by Make
|
|
|
|
|
2020-09-04 00:36:19 +00:00
|
|
|
NIM_PARAMS := -f --outdir:build --skipParentCfg:on --skipUserCfg:on $(NIMFLAGS)
|
2021-09-09 12:12:58 +00:00
|
|
|
BUILD_MSG := "\\x1B[92mBuilding:\\x1B[39m"
|
2021-05-12 22:21:59 +00:00
|
|
|
CMAKE := cmake
|
2021-09-01 14:45:13 +00:00
|
|
|
CMAKE_MISSING_MSG := "CMake not installed. Aborting."
|
2019-12-15 23:21:43 +00:00
|
|
|
|
|
|
|
# verbosity level
|
|
|
|
V := 0
|
|
|
|
NIM_PARAMS := $(NIM_PARAMS) --verbosity:$(V)
|
|
|
|
HANDLE_OUTPUT :=
|
|
|
|
SILENT_TARGET_PREFIX := disabled
|
|
|
|
ifeq ($(V), 0)
|
2020-09-04 00:36:19 +00:00
|
|
|
NIM_PARAMS := $(NIM_PARAMS) --hints:off
|
2019-12-15 23:21:43 +00:00
|
|
|
HANDLE_OUTPUT := &>/dev/null
|
|
|
|
SILENT_TARGET_PREFIX :=
|
|
|
|
endif
|
|
|
|
|
|
|
|
USE_SYSTEM_LIBS := 0
|
|
|
|
ifneq ($(USE_SYSTEM_LIBS), 0)
|
|
|
|
NIM_PARAMS := $(NIM_PARAMS) -d:libbacktraceUseSystemLibs
|
|
|
|
endif
|
|
|
|
|
|
|
|
ECHO_AND_RUN = echo -e "\n$(CMD)\n"; $(CMD) $(MACOS_DEBUG_SYMBOLS) && ./build/$@
|
2019-12-19 20:14:59 +00:00
|
|
|
LIBDIR := install/usr/lib
|
|
|
|
INCLUDEDIR := install/usr/include
|
2020-02-11 01:06:10 +00:00
|
|
|
CFLAGS += -g -O3 -std=gnu11 -pipe -Wall -Wextra -fPIC
|
2020-02-10 23:48:31 +00:00
|
|
|
CXXFLAGS += -g -O3 -std=gnu++11 -pipe -Wall -Wextra -fPIC
|
2019-12-19 20:14:59 +00:00
|
|
|
CPPFLAGS := -I"$(CURDIR)/$(INCLUDEDIR)"
|
|
|
|
LDLIBS := -L"$(CURDIR)/$(LIBDIR)"
|
|
|
|
AR := ar
|
|
|
|
# for Mingw-w64
|
|
|
|
CC := gcc
|
|
|
|
CXX := g++
|
2019-12-15 23:21:43 +00:00
|
|
|
|
2020-09-04 00:36:19 +00:00
|
|
|
TESTS := test1 \
|
|
|
|
test2
|
2019-12-15 23:21:43 +00:00
|
|
|
|
2020-09-04 00:36:19 +00:00
|
|
|
.PHONY: all \
|
|
|
|
clean \
|
|
|
|
test \
|
|
|
|
$(TESTS)
|
2019-12-15 23:21:43 +00:00
|
|
|
|
|
|
|
ifeq ($(USE_SYSTEM_LIBS), 0)
|
2019-12-19 20:14:59 +00:00
|
|
|
LIBBACKTRACE_DEP := $(LIBDIR)/libbacktrace.a
|
2019-12-15 23:21:43 +00:00
|
|
|
else
|
2019-12-19 20:14:59 +00:00
|
|
|
LIBBACKTRACE_DEP :=
|
2019-12-15 23:21:43 +00:00
|
|
|
endif
|
|
|
|
|
2020-02-15 11:56:55 +00:00
|
|
|
all: $(LIBBACKTRACE_DEP) $(LIBDIR)/libbacktracenim.a
|
|
|
|
|
|
|
|
BUILD_CXX_LIB := 1
|
|
|
|
ifeq ($(BUILD_CXX_LIB), 1)
|
|
|
|
all: $(LIBDIR)/libbacktracenimcpp.a
|
|
|
|
endif
|
2019-12-19 20:14:59 +00:00
|
|
|
|
|
|
|
$(LIBDIR)/libbacktracenim.a: libbacktrace_wrapper.o | $(LIBDIR)
|
|
|
|
echo -e $(BUILD_MSG) "$@" && \
|
|
|
|
rm -f $@ && \
|
|
|
|
$(AR) rcs $@ $<
|
|
|
|
|
|
|
|
# it doesn't link to libbacktrace.a, but it needs the headers installed by that target
|
2019-12-20 18:06:29 +00:00
|
|
|
libbacktrace_wrapper.o: libbacktrace_wrapper.c libbacktrace_wrapper.h $(LIBBACKTRACE_DEP)
|
2019-12-15 23:21:43 +00:00
|
|
|
|
2019-12-19 20:14:59 +00:00
|
|
|
$(LIBDIR)/libbacktracenimcpp.a: libbacktrace_wrapper_cpp.o | $(LIBDIR)
|
|
|
|
echo -e $(BUILD_MSG) "$@" && \
|
|
|
|
rm -f $@ && \
|
|
|
|
$(AR) rcs $@ $<
|
|
|
|
|
|
|
|
# implicit rule doesn't kick in
|
2019-12-20 18:06:29 +00:00
|
|
|
libbacktrace_wrapper_cpp.o: libbacktrace_wrapper.cpp libbacktrace_wrapper.c libbacktrace_wrapper.h $(LIBBACKTRACE_DEP)
|
2019-12-19 20:14:59 +00:00
|
|
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
|
|
|
|
|
|
|
|
$(LIBDIR):
|
|
|
|
mkdir -p $@
|
2019-12-15 23:21:43 +00:00
|
|
|
|
|
|
|
#########
|
|
|
|
# macOS #
|
|
|
|
#########
|
|
|
|
ifeq ($(shell uname), Darwin)
|
|
|
|
# TODO: disable when this issue is fixed: https://github.com/nim-lang/Nim/issues/12735
|
|
|
|
MACOS_DEBUG_SYMBOLS = && dsymutil build/$@
|
|
|
|
|
|
|
|
BUILD_MSG := "Building:"
|
2021-09-01 14:45:13 +00:00
|
|
|
CMAKE_MISSING_MSG := "CMake not installed. Please run 'brew install cmake'. Aborting."
|
2019-12-15 23:21:43 +00:00
|
|
|
|
|
|
|
#- macOS Clang needs the LLVM libunwind variant
|
|
|
|
# (GCC comes with its own, in libgcc_s.so.1, used even by Clang itself, on other platforms)
|
2019-12-19 20:14:59 +00:00
|
|
|
USE_VENDORED_LIBUNWIND := 1
|
|
|
|
endif # macOS
|
|
|
|
|
|
|
|
###########
|
|
|
|
# Windows #
|
|
|
|
###########
|
|
|
|
ifeq ($(OS), Windows_NT)
|
|
|
|
BUILD_MSG := "Building:"
|
|
|
|
CPPFLAGS += -D__STDC_FORMAT_MACROS -D_WIN32_WINNT=0x0600
|
|
|
|
CMAKE_ARGS := -G "MinGW Makefiles" -DCMAKE_SH="CMAKE_SH-NOTFOUND"
|
|
|
|
|
|
|
|
# the GCC one doesn't seem to work on 64 bit Windows
|
|
|
|
USE_VENDORED_LIBUNWIND := 1
|
|
|
|
|
|
|
|
LIBBACKTRACE_SED := sed -i 's/\$$[({]SHELL[)}]/"$$(SHELL)"/g' Makefile
|
|
|
|
else
|
|
|
|
LIBBACKTRACE_SED := true
|
|
|
|
endif # Windows
|
|
|
|
|
|
|
|
ifeq ($(USE_VENDORED_LIBUNWIND), 1)
|
|
|
|
# libbacktrace needs to find libunwind during compilation
|
|
|
|
export CPPFLAGS
|
|
|
|
export LDLIBS
|
|
|
|
|
|
|
|
# CMake ignores CPPFLAGS in the environment
|
|
|
|
export CFLAGS += $(CPPFLAGS)
|
|
|
|
export CXXFLAGS += $(CPPFLAGS)
|
|
|
|
|
2019-12-15 23:21:43 +00:00
|
|
|
#- this library doesn't support parallel builds, hence the "-j1"
|
2019-12-19 20:14:59 +00:00
|
|
|
#- the "Git for Windows" Bash is usually installed in a path with spaces, which messes up the Makefile. Add quotes.
|
|
|
|
$(LIBDIR)/libbacktrace.a: $(LIBDIR)/libunwind.a
|
2021-03-14 02:02:11 +00:00
|
|
|
else # USE_VENDORED_LIBUNWIND
|
2020-02-11 01:06:10 +00:00
|
|
|
export CFLAGS
|
|
|
|
export CXXFLAGS
|
2021-03-14 02:02:11 +00:00
|
|
|
endif # USE_VENDORED_LIBUNWIND
|
2020-02-11 01:06:10 +00:00
|
|
|
|
2021-03-14 02:02:11 +00:00
|
|
|
# We need to enable cross-compilation here, by passing "--build" and "--host"
|
|
|
|
# to "./configure". We already set CC in the environment, so it doesn't matter
|
|
|
|
# what the target host is, as long as it's a valid one.
|
2019-12-19 20:14:59 +00:00
|
|
|
$(LIBDIR)/libbacktrace.a:
|
2021-03-14 02:02:11 +00:00
|
|
|
+ echo -e $(BUILD_MSG) "$@" && \
|
|
|
|
cd vendor/libbacktrace-upstream && \
|
|
|
|
./configure --prefix="/usr" --libdir="/usr/lib" --disable-shared --enable-static \
|
|
|
|
--with-pic --build=$(./config.guess) --host=arm MAKE="$(MAKE)" $(HANDLE_OUTPUT) && \
|
2019-12-19 20:14:59 +00:00
|
|
|
$(LIBBACKTRACE_SED) && \
|
|
|
|
$(MAKE) -j1 DESTDIR="$(CURDIR)/install" clean all install $(HANDLE_OUTPUT)
|
2019-12-15 23:21:43 +00:00
|
|
|
|
2019-12-19 20:14:59 +00:00
|
|
|
# DESTDIR does not work on Windows for a CMake-generated Makefile
|
|
|
|
$(LIBDIR)/libunwind.a:
|
2020-04-17 23:55:02 +00:00
|
|
|
+ echo -e $(BUILD_MSG) "$@"; \
|
2021-09-01 14:45:13 +00:00
|
|
|
which $(CMAKE) &>/dev/null || { echo $(CMAKE_MISSING_MSG); exit 1; }; \
|
2020-04-17 23:55:02 +00:00
|
|
|
cd vendor/libunwind && \
|
2019-12-15 23:21:43 +00:00
|
|
|
rm -f CMakeCache.txt && \
|
2021-05-12 22:21:59 +00:00
|
|
|
$(CMAKE) -DLIBUNWIND_ENABLE_SHARED=OFF -DLIBUNWIND_ENABLE_STATIC=ON -DLIBUNWIND_INCLUDE_DOCS=OFF \
|
2021-03-14 02:02:11 +00:00
|
|
|
-DLIBUNWIND_LIBDIR_SUFFIX="" -DCMAKE_INSTALL_PREFIX="$(CURDIR)/install/usr" -DCMAKE_CROSSCOMPILING=1 \
|
|
|
|
$(CMAKE_ARGS) . $(HANDLE_OUTPUT) && \
|
2019-12-19 20:14:59 +00:00
|
|
|
$(MAKE) VERBOSE=$(V) clean install $(HANDLE_OUTPUT) && \
|
2019-12-15 23:21:43 +00:00
|
|
|
cp -a include "$(CURDIR)/install/usr/"
|
|
|
|
|
|
|
|
test: $(TESTS)
|
|
|
|
|
2019-12-19 20:14:59 +00:00
|
|
|
$(TESTS): all
|
2019-12-15 23:21:43 +00:00
|
|
|
$(eval CMD := nim c $(NIM_PARAMS) tests/$@.nim) $(ECHO_AND_RUN)
|
|
|
|
$(eval CMD := nim c $(NIM_PARAMS) --debugger:native tests/$@.nim) $(ECHO_AND_RUN)
|
|
|
|
$(eval CMD := nim c $(NIM_PARAMS) --debugger:native --stackTrace:off tests/$@.nim) $(ECHO_AND_RUN)
|
|
|
|
$(eval CMD := nim c $(NIM_PARAMS) --debugger:native -d:debug tests/$@.nim) $(ECHO_AND_RUN)
|
|
|
|
$(eval CMD := nim c $(NIM_PARAMS) --debugger:native -d:release tests/$@.nim) $(ECHO_AND_RUN)
|
2020-09-04 00:36:19 +00:00
|
|
|
$(eval CMD := nim c $(NIM_PARAMS) --debugger:native -d:release -d:nimStackTraceOverride tests/$@.nim) $(ECHO_AND_RUN)
|
2021-04-29 00:18:27 +00:00
|
|
|
$(eval CMD := nim c $(NIM_PARAMS) --debugger:native -d:danger tests/$@.nim) $(ECHO_AND_RUN)
|
|
|
|
$(eval CMD := nim c $(NIM_PARAMS) --debugger:native -d:danger -d:nimStackTraceOverride tests/$@.nim) $(ECHO_AND_RUN)
|
2021-05-25 20:37:36 +00:00
|
|
|
$(eval CMD := nim c $(NIM_PARAMS) --debugger:native -d:release --gcc.options.debug:'-g1' -d:nimStackTraceOverride tests/$@.nim) $(ECHO_AND_RUN)
|
2020-09-28 15:49:48 +00:00
|
|
|
ifeq ($(shell uname), Darwin)
|
|
|
|
$(eval CMD := nim c $(NIM_PARAMS) --debugger:native -d:release --passC:-flto=thin --passL:"-flto=thin -Wl,-object_path_lto,build/$@.lto" tests/$@.nim) $(ECHO_AND_RUN)
|
2021-04-29 00:18:27 +00:00
|
|
|
$(eval CMD := nim c $(NIM_PARAMS) --debugger:native -d:release -d:nimStackTraceOverride --passC:-flto=thin --passL:"-flto=thin -Wl,-object_path_lto,build/$@.lto" tests/$@.nim) $(ECHO_AND_RUN)
|
2020-09-28 15:49:48 +00:00
|
|
|
else
|
|
|
|
$(eval CMD := nim c $(NIM_PARAMS) --debugger:native -d:release --passC:-flto=auto --passL:-flto=auto tests/$@.nim) $(ECHO_AND_RUN)
|
2021-04-29 00:18:27 +00:00
|
|
|
$(eval CMD := nim c $(NIM_PARAMS) --debugger:native -d:release -d:nimStackTraceOverride --passC:-flto=auto --passL:-flto=auto tests/$@.nim) $(ECHO_AND_RUN)
|
2020-09-28 15:49:48 +00:00
|
|
|
endif
|
2020-02-15 11:56:55 +00:00
|
|
|
ifeq ($(BUILD_CXX_LIB), 1)
|
2020-09-07 19:01:58 +00:00
|
|
|
# for the C++ backend:
|
2019-12-15 23:21:43 +00:00
|
|
|
$(eval CMD := nim cpp $(NIM_PARAMS) --debugger:native tests/$@.nim) $(ECHO_AND_RUN)
|
2020-09-07 19:01:58 +00:00
|
|
|
$(eval CMD := nim cpp $(NIM_PARAMS) --debugger:native -d:release -d:nimStackTraceOverride tests/$@.nim) $(ECHO_AND_RUN)
|
2021-05-25 20:37:36 +00:00
|
|
|
$(eval CMD := nim cpp $(NIM_PARAMS) --debugger:native -d:release --gcc.cpp.options.debug:'-g1' -d:nimStackTraceOverride tests/$@.nim) $(ECHO_AND_RUN)
|
2020-02-15 11:56:55 +00:00
|
|
|
endif
|
2019-12-15 23:21:43 +00:00
|
|
|
|
|
|
|
clean:
|
2019-12-19 20:14:59 +00:00
|
|
|
rm -rf install build *.o
|
2020-09-28 15:49:48 +00:00
|
|
|
cd vendor/libbacktrace-upstream && \
|
2020-02-15 11:56:55 +00:00
|
|
|
{ [[ -e Makefile ]] && $(MAKE) clean $(HANDLE_OUTPUT) || true; }
|
2021-04-29 00:18:27 +00:00
|
|
|
cd vendor/libunwind && \
|
2022-03-23 01:14:28 +00:00
|
|
|
{ [[ -e Makefile ]] && $(MAKE) clean $(HANDLE_OUTPUT) || true; } && \
|
|
|
|
rm -rf CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt Makefile
|
2019-12-19 20:14:59 +00:00
|
|
|
|
|
|
|
$(SILENT_TARGET_PREFIX).SILENT:
|
2019-12-15 23:21:43 +00:00
|
|
|
|