Skip to content

Commit

Permalink
match version to compiler, new packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
bradjc committed Nov 23, 2023
1 parent 7c4fa54 commit d654848
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 47 deletions.
110 changes: 72 additions & 38 deletions Configuration.mk
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ endif
##
################################################################################



override NEWLIB_BASE_DIR := $(TOCK_USERLAND_BASE_DIR)/lib/libtock-newlib-$(NEWLIB_VERSION)
override LIBCPP_BASE_DIR := $(TOCK_USERLAND_BASE_DIR)/lib/libtock-libc++-$(LIBCPP_VERSION)

Expand Down Expand Up @@ -218,22 +220,23 @@ override CPPFLAGS_PIC += \
# essentially any target. Thus, try a few known names and choose the one for
# which a compiler is found.
ifneq (,$(shell which riscv64-none-elf-gcc 2>/dev/null))
TOOLCHAIN_rv32i := riscv64-none-elf
TOOLCHAIN_rv32 := riscv64-none-elf
else ifneq (,$(shell which riscv32-none-elf-gcc 2>/dev/null))
TOOLCHAIN_rv32i := riscv32-none-elf
TOOLCHAIN_rv32 := riscv32-none-elf
else ifneq (,$(shell which riscv64-elf-gcc 2>/dev/null))
TOOLCHAIN_rv32i := riscv64-elf
TOOLCHAIN_rv32 := riscv64-elf
else ifneq (,$(shell which riscv64-unknown-elf-clang 2>/dev/null))
TOOLCHAIN_rv32i := riscv64-unknown-elf
TOOLCHAIN_rv32 := riscv64-unknown-elf
else ifneq (,$(shell which riscv32-unknown-elf-clang 2>/dev/null))
TOOLCHAIN_rv32i := riscv32-unknown-elf
TOOLCHAIN_rv32 := riscv32-unknown-elf
else
# Fallback option. We don't particularly want to throw an error as this
# configuration makefile can be useful without a proper toolchain.
TOOLCHAIN_rv32i := riscv64-unknown-elf
TOOLCHAIN_rv32 := riscv64-unknown-elf
endif
TOOLCHAIN_rv32imac := $(TOOLCHAIN_rv32i)
TOOLCHAIN_rv32imc := $(TOOLCHAIN_rv32i)
TOOLCHAIN_rv32i := $(TOOLCHAIN_rv32)
TOOLCHAIN_rv32imc := $(TOOLCHAIN_rv32)
TOOLCHAIN_rv32imac := $(TOOLCHAIN_rv32)

# For RISC-V we default to GCC, but can support clang as well. Eventually, one
# or both toolchains might support the PIC we need, at which point we would
Expand All @@ -249,6 +252,23 @@ CC_rv32i := $(CC_rv32)
CC_rv32imc := $(CC_rv32)
CC_rv32imac := $(CC_rv32)

# Determine the version of the RISC-V compiler. This is used to select the
# version of the libgcc library that is compatible.
CC_rv32_version := $(shell $(TOOLCHAIN_rv32)$(CC_rv32) -dumpfullversion)
CC_rv32_version_major := $(shell echo $(CC_rv32_version) | cut -f1 -d.)

# Match compiler version to supported libtock-libc++ versions.
ifeq ($(CC_rv32_version_major),10)
LIBCPP_VERSION_rv32 := 10.5.0
else ifeq ($(CC_rv32_version_major),11)
LIBCPP_VERSION_rv32 := 11.2.0
else ifeq ($(CC_rv32_version_major),12)
LIBCPP_VERSION_rv32 := 12.3.0
else
LIBCPP_VERSION_rv32 := 12.3.0
endif
LIBCPP_BASE_DIR_rv32 := $(TOCK_USERLAND_BASE_DIR)/lib/libtock-libc++-$(LIBCPP_VERSION_rv32)

# Set the toolchain specific flags.
#
# Note: There are no non-gcc, clang-specific flags currently in use, so there is
Expand All @@ -261,8 +281,7 @@ endif

# Set the toolchain specific `CFLAGS` for RISC-V. We use the same generic
# toolchain flags for each RISC-V variant.
override CFLAGS_rv32 += \
$(CFLAGS_toolchain_rv32)
override CFLAGS_rv32 += $(CFLAGS_toolchain_rv32)

override CFLAGS_rv32i += $(CFLAGS_rv32)
override CFLAGS_rv32imc += $(CFLAGS_rv32)
Expand All @@ -271,8 +290,8 @@ override CFLAGS_rv32imac += $(CFLAGS_rv32)
# Set the base `CPPFLAGS` for all RISC-V variants based on the toolchain family.
override CPPFLAGS_rv32 += \
$(CPPFLAGS_toolchain_rv32) \
-I$(LIBCPP_BASE_DIR)/riscv/headers\
-I$(LIBCPP_BASE_DIR)/riscv/headers/riscv64-unknown-elf
-I$(LIBCPP_BASE_DIR_rv32)/riscv/riscv64-unknown-elf/include/c++/$(LIBCPP_VERSION_rv32) \
-I$(LIBCPP_BASE_DIR_rv32)/riscv/riscv64-unknown-elf/include/c++/$(LIBCPP_VERSION_rv32)/riscv64-unknown-elf

# Set the `CPPFLAGS` for RISC-V. Here we need different flags for different
# variants.
Expand Down Expand Up @@ -301,23 +320,23 @@ override WLFLAGS_rv32imc += $(WLFLAGS_rv32)
override WLFLAGS_rv32imac += $(WLFLAGS_rv32)

override LINK_LIBS_rv32i += \
$(LIBCPP_BASE_DIR)/riscv/rv32i/ilp32/libstdc++-v3/src/.libs/libstdc++.a \
$(LIBCPP_BASE_DIR)/riscv/rv32i/ilp32/libstdc++-v3/libsupc++/.libs/libsupc++.a \
$(LIBCPP_BASE_DIR)/riscv/rv32i/ilp32/libgcc/libgcc.a \
$(LIBCPP_BASE_DIR_rv32)/riscv/riscv64-unknown-elf/lib/rv32i/ilp32/libstdc++.a \
$(LIBCPP_BASE_DIR_rv32)/riscv/riscv64-unknown-elf/lib/rv32i/ilp32/libsupc++.a \
$(LIBCPP_BASE_DIR_rv32)/riscv/lib/gcc/riscv64-unknown-elf/$(LIBCPP_VERSION_rv32)/rv32i/ilp32/libgcc.a \
$(NEWLIB_BASE_DIR)/riscv/rv32i/ilp32/newlib/libc.a \
$(NEWLIB_BASE_DIR)/riscv/rv32i/ilp32/newlib/libm.a

override LINK_LIBS_rv32imc += \
$(LIBCPP_BASE_DIR)/riscv/rv32im/ilp32/libstdc++-v3/src/.libs/libstdc++.a \
$(LIBCPP_BASE_DIR)/riscv/rv32im/ilp32/libstdc++-v3/libsupc++/.libs/libsupc++.a \
$(LIBCPP_BASE_DIR)/riscv/rv32im/ilp32/libgcc/libgcc.a \
$(LIBCPP_BASE_DIR_rv32)/riscv/riscv64-unknown-elf/lib/rv32im/ilp32/libstdc++.a \
$(LIBCPP_BASE_DIR_rv32)/riscv/riscv64-unknown-elf/lib/rv32im/ilp32/libsupc++.a \
$(LIBCPP_BASE_DIR_rv32)/riscv/lib/gcc/riscv64-unknown-elf/$(LIBCPP_VERSION_rv32)/rv32im/ilp32/libgcc.a \
$(NEWLIB_BASE_DIR)/riscv/rv32im/ilp32/newlib/libc.a \
$(NEWLIB_BASE_DIR)/riscv/rv32im/ilp32/newlib/libm.a

override LINK_LIBS_rv32imac += \
$(LIBCPP_BASE_DIR)/riscv/rv32imac/ilp32/libstdc++-v3/src/.libs/libstdc++.a \
$(LIBCPP_BASE_DIR)/riscv/rv32imac/ilp32/libstdc++-v3/libsupc++/.libs/libsupc++.a \
$(LIBCPP_BASE_DIR)/riscv/rv32imac/ilp32/libgcc/libgcc.a \
$(LIBCPP_BASE_DIR_rv32)/riscv/riscv64-unknown-elf/lib/rv32imac/ilp32/libstdc++.a \
$(LIBCPP_BASE_DIR_rv32)/riscv/riscv64-unknown-elf/lib/rv32imac/ilp32/libsupc++.a \
$(LIBCPP_BASE_DIR_rv32)/riscv/lib/gcc/riscv64-unknown-elf/$(LIBCPP_VERSION_rv32)/rv32imac/ilp32/libgcc.a \
$(NEWLIB_BASE_DIR)/riscv/rv32imac/ilp32/newlib/libc.a \
$(NEWLIB_BASE_DIR)/riscv/rv32imac/ilp32/newlib/libm.a

Expand All @@ -344,16 +363,31 @@ CC_cortex-m3 := $(CC_cortex-m)
CC_cortex-m4 := $(CC_cortex-m)
CC_cortex-m7 := $(CC_cortex-m)

# Determine the version of the ARM compiler. This is used to select the version
# of the libgcc library that is compatible.
CC_cortex-m_version := $(shell $(TOOLCHAIN_cortex-m)$(CC_cortex-m) -dumpfullversion)
CC_cortex-m_version_major := $(shell echo $(CC_cortex-m_version) | cut -f1 -d.)

# Match compiler version to supported libtock-libc++ versions.
ifeq ($(CC_cortex-m_version_major),10)
LIBCPP_VERSION_cortex-m := 10.5.0
else ifeq ($(CC_cortex-m_version_major),11)
LIBCPP_VERSION_cortex-m := 11.2.0
else ifeq ($(CC_cortex-m_version_major),12)
LIBCPP_VERSION_cortex-m := 12.3.0
else
LIBCPP_VERSION_cortex-m := 12.3.0
endif
LIBCPP_BASE_DIR_cortex-m := $(TOCK_USERLAND_BASE_DIR)/lib/libtock-libc++-$(LIBCPP_VERSION_cortex-m)

# Based on the toolchain used by each architecture, add in toolchain-specific
# flags. We assume that each architecture family uses the same toolchain.
ifeq ($(findstring -gcc,$(CC_cortex-m)),-gcc)
override CPPFLAGS_toolchain_cortex-m += $(CPPFLAGS_gcc)
override CFLAGS_toolchain_cortex-m += $(CFLAGS_gcc)
endif

override CFLAGS_cortex-m += \
$(CFLAGS_toolchain_cortex-m)

override CFLAGS_cortex-m += $(CFLAGS_toolchain_cortex-m)
override CFLAGS_cortex-m0 += $(CFLAGS_cortex-m)
override CFLAGS_cortex-m3 += $(CFLAGS_cortex-m)
override CFLAGS_cortex-m4 += $(CFLAGS_cortex-m)
Expand All @@ -367,8 +401,8 @@ override CPPFLAGS_cortex-m += \
-msingle-pic-base\
-mpic-register=r9\
-mno-pic-data-is-text-relative\
-I$(LIBCPP_BASE_DIR)/thumb/headers\
-I$(LIBCPP_BASE_DIR)/thumb/headers/arm-none-eabi
-I$(LIBCPP_BASE_DIR_cortex-m)/arm/arm-none-eabi/include/c++/$(LIBCPP_VERSION_cortex-m)\
-I$(LIBCPP_BASE_DIR_cortex-m)/arm/arm-none-eabi/include/c++/$(LIBCPP_VERSION_cortex-m)/arm-none-eabi

# Work around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85606
override CPPFLAGS_cortex-m0 += $(CPPFLAGS_cortex-m) \
Expand All @@ -385,30 +419,30 @@ override CPPFLAGS_cortex-m7 += $(CPPFLAGS_cortex-m) \
-mcpu=cortex-m7

override LINK_LIBS_cortex-m0 += \
$(LIBCPP_BASE_DIR)/thumb/v6-m/nofp/libstdc++-v3/src/.libs/libstdc++.a \
$(LIBCPP_BASE_DIR)/thumb/v6-m/nofp/libstdc++-v3/libsupc++/.libs/libsupc++.a \
$(LIBCPP_BASE_DIR)/thumb/v6-m/nofp/libgcc/libgcc.a \
$(LIBCPP_BASE_DIR_cortex-m)/arm/arm-none-eabi/lib/v6-m/nofp/libstdc++.a \
$(LIBCPP_BASE_DIR_cortex-m)/arm/arm-none-eabi/lib/v6-m/nofp/libsupc++.a \
$(LIBCPP_BASE_DIR_cortex-m)/arm/lib/gcc/arm-none-eabi/$(LIBCPP_VERSION_cortex-m)/v6-m/nofp/libgcc.a \
$(NEWLIB_BASE_DIR)/thumb/v6-m/nofp/newlib/libc.a \
$(NEWLIB_BASE_DIR)/thumb/v6-m/nofp/newlib/libm.a

override LINK_LIBS_cortex-m3 += \
$(LIBCPP_BASE_DIR)/thumb/v7-m/nofp/libstdc++-v3/src/.libs/libstdc++.a \
$(LIBCPP_BASE_DIR)/thumb/v7-m/nofp/libstdc++-v3/libsupc++/.libs/libsupc++.a \
$(LIBCPP_BASE_DIR)/thumb/v7-m/nofp/libgcc/libgcc.a \
$(LIBCPP_BASE_DIR_cortex-m)/arm/arm-none-eabi/lib/v7-m/nofp/libstdc++.a \
$(LIBCPP_BASE_DIR_cortex-m)/arm/arm-none-eabi/lib/v7-m/nofp/libsupc++.a \
$(LIBCPP_BASE_DIR_cortex-m)/arm/lib/gcc/arm-none-eabi/$(LIBCPP_VERSION_cortex-m)/v7-m/nofp/libgcc.a \
$(NEWLIB_BASE_DIR)/thumb/v7-m/nofp/newlib/libc.a \
$(NEWLIB_BASE_DIR)/thumb/v7-m/nofp/newlib/libm.a

override LINK_LIBS_cortex-m4 += \
$(LIBCPP_BASE_DIR)/thumb/v7e-m/nofp/libstdc++-v3/src/.libs/libstdc++.a \
$(LIBCPP_BASE_DIR)/thumb/v7e-m/nofp/libstdc++-v3/libsupc++/.libs/libsupc++.a \
$(LIBCPP_BASE_DIR)/thumb/v7e-m/nofp/libgcc/libgcc.a \
$(LIBCPP_BASE_DIR_cortex-m)/arm/arm-none-eabi/lib/v7e-m/nofp/libstdc++.a \
$(LIBCPP_BASE_DIR_cortex-m)/arm/arm-none-eabi/lib/v7e-m/nofp/libsupc++.a \
$(LIBCPP_BASE_DIR_cortex-m)/arm/lib/gcc/arm-none-eabi/$(LIBCPP_VERSION_cortex-m)/v7e-m/nofp/libgcc.a \
$(NEWLIB_BASE_DIR)/thumb/v7e-m/nofp/newlib/libc.a \
$(NEWLIB_BASE_DIR)/thumb/v7e-m/nofp/newlib/libm.a

override LINK_LIBS_cortex-m7 += \
$(LIBCPP_BASE_DIR)/thumb/v7e-m/nofp/libstdc++-v3/src/.libs/libstdc++.a \
$(LIBCPP_BASE_DIR)/thumb/v7e-m/nofp/libstdc++-v3/libsupc++/.libs/libsupc++.a \
$(LIBCPP_BASE_DIR)/thumb/v7e-m/nofp/libgcc/libgcc.a \
$(LIBCPP_BASE_DIR_cortex-m)/arm/arm-none-eabi/lib/v7e-m/nofp/libstdc++.a \
$(LIBCPP_BASE_DIR_cortex-m)/arm/arm-none-eabi/lib/v7e-m/nofp/libsupc++.a \
$(LIBCPP_BASE_DIR_cortex-m)/arm/lib/gcc/arm-none-eabi/$(LIBCPP_VERSION_cortex-m)/v7e-m/nofp/libgcc.a \
$(NEWLIB_BASE_DIR)/thumb/v7e-m/nofp/newlib/libc.a \
$(NEWLIB_BASE_DIR)/thumb/v7e-m/nofp/newlib/libm.a

Expand Down
4 changes: 3 additions & 1 deletion libc++/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ RUN git clone https://github.com/tock/libtock-c --depth 1 -b make-precompiled
RUN cd libtock-c && git fetch && git checkout 69e338ba54857c100365a815aa5e7942c7e282c8

# Actually build the toolchain
RUN cd libtock-c/libc++ && make
RUN cd libtock-c/libc++ && make GCC_VERSION=10.5.0
RUN cd libtock-c/libc++ && make GCC_VERSION=11.4.0
RUN cd libtock-c/libc++ && make GCC_VERSION=12.3.0
17 changes: 9 additions & 8 deletions libc++/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
GCC_VERSION ?= 10.5.0
NEWLIB_VERSION ?= 4.2.0.20211231

all: rebuild-gcc

ifeq ($(GCC_VERSION),)
$(error Need to set the GCC_VERSION variable to choose which to build.)
else

# Determine which RISC-V toolchain is installed.
ifneq (,$(shell which riscv64-none-elf-gcc 2>/dev/null))
TOOLCHAIN_rv32i := riscv64-none-elf
Expand Down Expand Up @@ -57,14 +60,12 @@ rebuild-gcc: gcc-$(GCC_VERSION)
@echo ""
@echo "=== PACKAGING LIBC++ ARTIFACTS ==================="
@echo ""
@mkdir -p libtock-libc++-$(GCC_VERSION)/thumb
@mkdir -p libtock-libc++-$(GCC_VERSION)/arm
@cp -r gcc-arm-$(GCC_VERSION)-install/lib libtock-libc++-$(GCC_VERSION)/arm
@cp -r gcc-arm-$(GCC_VERSION)-install/arm-none-eabi libtock-libc++-$(GCC_VERSION)/arm
@mkdir -p libtock-libc++-$(GCC_VERSION)/riscv
@cp -r gcc-arm-$(GCC_VERSION)-install/arm-none-eabi/include/c++/$(GCC_VERSION) libtock-libc++-$(GCC_VERSION)/thumb/headers
@cp -r gcc-riscv-$(GCC_VERSION)-install/$(TOOLCHAIN_rv32i)/include/c++/$(GCC_VERSION) libtock-libc++-$(GCC_VERSION)/riscv/headers
@rsync -ram --include='libgcc.a' --include='*/' --exclude='*' gcc-arm-$(GCC_VERSION)-out/arm-none-eabi/thumb/ libtock-libc++-$(GCC_VERSION)/thumb/
@rsync -ram --include='libstdc++.a' --include='libsupc++.a' --include='*/' --exclude='*' gcc-arm-$(GCC_VERSION)-out/arm-none-eabi/thumb/ libtock-libc++-$(GCC_VERSION)/thumb/
@rsync -ram --include='libgcc.a' --include='*/' --exclude='*' gcc-riscv-$(GCC_VERSION)-out/$(TOOLCHAIN_rv32i)/ libtock-libc++-$(GCC_VERSION)/riscv/
@rsync -ram --include='libstdc++.a' --include='libsupc++.a' --include='*/' --exclude='*' gcc-riscv-$(GCC_VERSION)-out/$(TOOLCHAIN_rv32i)/ libtock-libc++-$(GCC_VERSION)/riscv/
@cp -r gcc-riscv-$(GCC_VERSION)-install/lib libtock-libc++-$(GCC_VERSION)/riscv
@cp -r gcc-riscv-$(GCC_VERSION)-install/$(TOOLCHAIN_rv32i) libtock-libc++-$(GCC_VERSION)/riscv
@zip -r libtock-libc++-$(GCC_VERSION).zip libtock-libc++-$(GCC_VERSION)


Expand Down

0 comments on commit d654848

Please sign in to comment.