From ed68b5f0570f5df054cdfd4b863afd0cb2f20628 Mon Sep 17 00:00:00 2001 From: Victor Fusco <1221933+vfusco@users.noreply.github.com> Date: Thu, 7 Dec 2023 02:14:10 -0300 Subject: [PATCH] refactor: cross-compile sys-utils --- .github/workflows/main.yml | 33 +----------- Dockerfile | 84 ++++++++++++------------------ Makefile | 43 ++++++++++----- sys-utils/Makefile | 36 +++++++++++++ sys-utils/ioctl-echo-loop/Makefile | 24 +++++---- sys-utils/rollup/Makefile | 24 +++++---- sys-utils/xhalt/Makefile | 24 +++++---- sys-utils/yield/Makefile | 24 +++++---- 8 files changed, 152 insertions(+), 140 deletions(-) create mode 100644 sys-utils/Makefile diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 06f0163c..849f6391 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,8 +1,5 @@ name: Build on: [push] -env: - TOOLCHAIN_IMAGE: ${{ github.repository_owner }}/toolchain - TOOLCHAIN_TAG: 0.16.0 jobs: tools: runs-on: ubuntu-latest-8-cores @@ -100,41 +97,13 @@ jobs: ${{ env.TOOLS_ROOTFS }} ${{ env.TOOLS_ROOTFS }}.sha512 - build: + test-rollup-http-server: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 with: submodules: recursive - - name: Login to GHCR - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Login to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Build yield tool - run: cd sys-utils/yield && make toolchain-exec CONTAINER_COMMAND="/usr/bin/make yield.toolchain" - - - name: Build ioctl-echo-loop tool - run: cd sys-utils/ioctl-echo-loop && make toolchain-exec CONTAINER_COMMAND="/usr/bin/make ioctl-echo-loop.toolchain" - - - name: Build rollup tool - run: cd sys-utils/rollup && make toolchain-exec CONTAINER_COMMAND="/usr/bin/make rollup.toolchain" - - - name: Build rollup http server - run: cd rollup-http/rollup-http-server && ./build.sh - - - name: Build echo dapp - run: cd rollup-http/echo-dapp && ./build.sh - - name: Test rollup-http-server and echo-dapp client run: | cd rollup-http/rollup-http-server diff --git a/Dockerfile b/Dockerfile index 745c2c55..8f1e7a8f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,15 +14,15 @@ # limitations under the License. # -FROM --platform=linux/riscv64 riscv64/ubuntu:22.04 as tools-env +FROM ubuntu:22.04 as tools-env ARG IMAGE_KERNEL_VERSION=v0.19.1 ARG LINUX_VERSION=6.5.9-ctsi-1 -ARG LINUX_HEADERS_URLPATH=https://github.com/cartesi/image-kernel/releases/download/${IMAGE_KERNEL_VERSION}/linux-libc-dev-${LINUX_VERSION}-${IMAGE_KERNEL_VERSION}.deb +ARG LINUX_HEADERS_URLPATH=https://github.com/cartesi/image-kernel/releases/download/${IMAGE_KERNEL_VERSION}/linux-libc-dev-riscv64-cross-${LINUX_VERSION}-${IMAGE_KERNEL_VERSION}.deb ARG BUILD_BASE=/opt/cartesi # Install dependencies # ------------------------------------------------------------------------------ -ENV LINUX_HEADERS_FILEPATH=/tmp/linux-libc-dev-${LINUX_VERSION}-${IMAGE_KERNEL_VERSION}.deb +ENV LINUX_HEADERS_FILEPATH=/tmp/linux-libc-dev-riscv64-cross-${LINUX_VERSION}-${IMAGE_KERNEL_VERSION}.deb RUN DEBIAN_FRONTEND=noninteractive apt-get update && \ apt-get upgrade -y && \ @@ -30,54 +30,43 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && \ build-essential \ ca-certificates \ git \ - rsync \ wget \ + crossbuild-essential-riscv64 \ + gcc-12-riscv64-linux-gnu \ + g++-12-riscv64-linux-gnu \ && \ wget -O ${LINUX_HEADERS_FILEPATH} ${LINUX_HEADERS_URLPATH} && \ - echo "aace918b830ee2d682c329b3361a3458ebc42ba5193ccb821fd0b2071ac821b3 ${LINUX_HEADERS_FILEPATH}" | sha256sum --check && \ + echo "efdb2243d9b6828e90c826be0f178110f0cc590cb00e8fa588cb20723126c2a4 ${LINUX_HEADERS_FILEPATH}" | sha256sum --check && \ apt-get install -y --no-install-recommends ${LINUX_HEADERS_FILEPATH} && \ - mkdir -p ${BUILD_BASE} && \ + adduser developer -u 499 --gecos ",,," --disabled-password && \ + mkdir -p ${BUILD_BASE}/tools && chown -R developer:developer ${BUILD_BASE}/tools && \ rm -rf /var/lib/apt/lists/* ${LINUX_HEADERS_FILEPATH} +#ENV CC="riscv64-linux-gnu-gcc-12" +#ENV CXX="riscv64-linux-gnu-g++-12" +ENV RISCV_ARCH="rv64gc" +ENV RISCV_ABI="lp64d" +ENV CFLAGS="-march=$RISCV_ARCH -mabi=$RISCV_ABI" +ENV TOOLCHAIN_PREFIX="riscv64-linux-gnu-" +ENV TOOLCHAIN_SUFFIX="-12" + FROM tools-env as builder -COPY sys-utils/ ${BUILD_BASE}/tools/sys-utils/ +COPY --chown=developer:developer sys-utils/ ${BUILD_BASE}/tools/sys-utils/ # build C/C++ tools # ------------------------------------------------------------------------------ FROM builder as c-builder -RUN make -C ${BUILD_BASE}/tools/sys-utils/xhalt/ CROSS_COMPILE="" xhalt.toolchain -RUN make -C ${BUILD_BASE}/tools/sys-utils/yield/ CROSS_COMPILE="" yield.toolchain -RUN make -C ${BUILD_BASE}/tools/sys-utils/ioctl-echo-loop/ CROSS_COMPILE="" ioctl-echo-loop.toolchain -RUN make -C ${BUILD_BASE}/tools/sys-utils/rollup/ CROSS_COMPILE="" rollup.toolchain +USER developer +RUN make -C ${BUILD_BASE}/tools/sys-utils/ -j$(nproc) all # build rust tools # ------------------------------------------------------------------------------ -FROM --platform=${BUILDPLATFORM} ubuntu:22.04 as rust-builder -ARG IMAGE_KERNEL_VERSION=v0.19.1 -ARG LINUX_VERSION=6.5.9-ctsi-1 -ARG BUILD_BASE=/opt/cartesi -ENV LINUX_HEADERS_FILEPATH=/tmp/linux-libc-dev-riscv64-cross-${LINUX_VERSION}-${IMAGE_KERNEL_VERSION}.deb - -RUN DEBIAN_FRONTEND=noninteractive apt-get update && \ - apt-get upgrade -y && \ - apt-get install -y --no-install-recommends \ - build-essential \ - ca-certificates \ - git \ - wget \ - crossbuild-essential-riscv64 \ - gcc-12-riscv64-linux-gnu \ - && \ - wget -O ${LINUX_HEADERS_FILEPATH} https://github.com/cartesi/image-kernel/releases/download/${IMAGE_KERNEL_VERSION}/linux-libc-dev-riscv64-cross-${LINUX_VERSION}-${IMAGE_KERNEL_VERSION}.deb && \ - echo "efdb2243d9b6828e90c826be0f178110f0cc590cb00e8fa588cb20723126c2a4 ${LINUX_HEADERS_FILEPATH}" | sha256sum --check && \ - apt-get install -y --no-install-recommends ${LINUX_HEADERS_FILEPATH} && \ - adduser developer -u 499 --gecos ",,," --disabled-password && \ - mkdir -p ${BUILD_BASE}/tools && chown -R developer:developer ${BUILD_BASE}/tools && \ - rm -rf /var/lib/apt/lists/* ${LINUX_HEADERS_FILEPATH} +FROM tools-env as rust-env +ENV PATH="/home/developer/.cargo/bin:${PATH}" USER developer -RUN \ - cd && \ + +RUN cd && \ wget https://github.com/rust-lang/rustup/archive/refs/tags/1.26.0.tar.gz && \ echo "6f20ff98f2f1dbde6886f8d133fe0d7aed24bc76c670ea1fca18eb33baadd808 1.26.0.tar.gz" | sha256sum --check && \ tar -xzf 1.26.0.tar.gz && \ @@ -88,14 +77,7 @@ RUN \ --target riscv64gc-unknown-linux-gnu && \ rm -rf rustup-1.26.0 1.26.0.tar.gz - -ENV PATH="/home/developer/.cargo/bin:${PATH}" -ENV CC="riscv64-linux-gnu-gcc-12" -ENV CXX="riscv64-linux-gnu-g++-12" -ENV RISCV_ARCH="rv64gc" -ENV RISCV_ABI="lp64d" -ENV CFLAGS="-march=$RISCV_ARCH -mabi=$RISCV_ABI" - +FROM rust-env as rust-builder COPY --chown=developer:developer rollup-http/rollup-init ${BUILD_BASE}/tools/rollup-http/rollup-init COPY --chown=developer:developer rollup-http/rollup-http-client ${BUILD_BASE}/tools/rollup-http/rollup-http-client COPY --chown=developer:developer rollup-http/.cargo ${BUILD_BASE}/tools/rollup-http/.cargo @@ -131,7 +113,7 @@ RUN cd ${BUILD_BASE}/tools/rollup-http/echo-dapp && \ # pack tools (deb) # ------------------------------------------------------------------------------ -FROM c-builder as packer +FROM tools-env as packer ARG TOOLS_DEB=machine-emulator-tools.deb ARG STAGING_BASE=${BUILD_BASE}/_install ARG STAGING_DEBIAN=${STAGING_BASE}/DEBIAN @@ -139,16 +121,16 @@ ARG STAGING_SBIN=${STAGING_BASE}/usr/sbin ARG STAGING_BIN=${STAGING_BASE}/usr/bin RUN mkdir -p ${STAGING_DEBIAN} ${STAGING_SBIN} ${STAGING_BIN} ${STAGING_BASE}/etc && \ - echo "cartesi-machine" > ${staging_base}/etc/hostname && \ - cp ${BUILD_BASE}/tools/sys-utils/system-init/system-init ${STAGING_SBIN} && \ - cp ${BUILD_BASE}/tools/sys-utils/xhalt/xhalt ${STAGING_SBIN} && \ - cp ${BUILD_BASE}/tools/sys-utils/yield/yield ${STAGING_SBIN} && \ - cp ${BUILD_BASE}/tools/sys-utils/rollup/rollup ${STAGING_SBIN} && \ - cp ${BUILD_BASE}/tools/sys-utils/ioctl-echo-loop/ioctl-echo-loop ${STAGING_BIN} && \ - cp ${BUILD_BASE}/tools/sys-utils/misc/* ${STAGING_BIN} + echo "cartesi-machine" > ${staging_base}/etc/hostname COPY control ${STAGING_DEBIAN}/control +COPY --from=builder ${BUILD_BASE}/tools/sys-utils/cartesi-init/cartesi-init ${STAGING_SBIN} +COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/xhalt/xhalt ${STAGING_SBIN} +COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/yield/yield ${STAGING_SBIN} +COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/rollup/rollup ${STAGING_SBIN} +COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/ioctl-echo-loop/ioctl-echo-loop ${STAGING_BIN} +COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/misc/* ${STAGING_BIN} COPY --from=rust-builder ${BUILD_BASE}/tools/rollup-http/rollup-init/rollup-init ${STAGING_SBIN} COPY --from=http-server-builder ${BUILD_BASE}/tools/rollup-http/rollup-http-server/target/riscv64gc-unknown-linux-gnu/release/rollup-http-server ${STAGING_BIN} COPY --from=echo-dapp-builder ${BUILD_BASE}/tools/rollup-http/echo-dapp/target/riscv64gc-unknown-linux-gnu/release/echo-dapp ${STAGING_BIN} diff --git a/Makefile b/Makefile index 21cb2cd8..fae1a09a 100644 --- a/Makefile +++ b/Makefile @@ -26,24 +26,24 @@ TOOLS_ROOTFS := rootfs-tools-v$(VERSION).ext2 IMAGE_KERNEL_VERSION ?= v0.19.1 LINUX_VERSION ?= 6.5.9-ctsi-1 -LINUX_HEADERS_URLPATH := https://github.com/cartesi/image-kernel/releases/download/${IMAGE_KERNEL_VERSION}/linux-libc-dev-${LINUX_VERSION}-${IMAGE_KERNEL_VERSION}.deb +LINUX_HEADERS_URLPATH := https://github.com/cartesi/image-kernel/releases/download/${IMAGE_KERNEL_VERSION}/linux-libc-dev-riscv64-cross-${LINUX_VERSION}-${IMAGE_KERNEL_VERSION}.deb all: fs build: control - @docker buildx build --platform=linux/riscv64 --load \ + @docker buildx build --load \ --build-arg TOOLS_DEB=$(TOOLS_DEB) \ --build-arg IMAGE_KERNEL_VERSION=$(IMAGE_KERNEL_VERSION) \ --build-arg LINUX_VERSION=$(LINUX_VERSION) \ --build-arg LINUX_HEADERS_URLPATH=$(LINUX_HEADERS_URLPATH) \ -t $(TOOLS_IMAGE) \ -f Dockerfile \ - . ; \ + . ; $(MAKE) copy copy: - @ID=`docker create --platform=linux/riscv64 $(TOOLS_IMAGE)` && \ - docker cp $$ID:/opt/cartesi/$(TOOLS_DEB) . && \ + @ID=`docker create $(TOOLS_IMAGE)` && \ + docker cp $$ID:/opt/cartesi/$(TOOLS_DEB) . && \ docker rm $$ID $(TOOLS_DEB) deb: build @@ -76,9 +76,23 @@ setup: setup-required: @echo 'riscv64 buildx setup required:' `docker buildx ls | grep -q riscv64 && echo no || echo yes` +build-tools-env: + docker build --target tools-env -t $(TOOLS_IMAGE)-tools-env -f Dockerfile . + build-rust-builder-env: docker build --target rust-builder -t $(TOOLS_IMAGE)-rust-builder -f Dockerfile . +tools-env: + @docker run --hostname rust-builder -it --rm \ + -e USER=$$(id -u -n) \ + -e GROUP=$$(id -g -n) \ + -e UID=$$(id -u) \ + -e GID=$$(id -g) \ + -v `pwd`:/opt/cartesi/machine-emulator-tools \ + -w /opt/cartesi/machine-emulator-tools \ + $(TOOLS_IMAGE)-tools-env /bin/bash + + rust-builder-env: @docker run --hostname rust-builder -it --rm \ -e USER=$$(id -u -n) \ @@ -89,6 +103,17 @@ rust-builder-env: -w /opt/cartesi/machine-emulator-tools \ $(TOOLS_IMAGE)-rust-builder /bin/bash +clean-image: + @(docker rmi $(TOOLS_IMAGE) > /dev/null 2>&1 || true) + +clean: + @rm -f $(TOOLS_DEB) control rootfs* + @$(MAKE) -C sys-utils clean + +distclean: clean clean-image + +sys-utils: + @$(MAKE) -C sys-utils help: @echo 'available commands:' @@ -100,12 +125,4 @@ help: @echo ' env - print useful Makefile variables as a KEY=VALUE list' @echo ' clean - remove the generated artifacts' -clean-image: - @(docker rmi $(TOOLS_IMAGE) > /dev/null 2>&1 || true) - -clean: - @rm -f $(TOOLS_DEB) control rootfs* - -distclean: clean clean-image - .PHONY: build fs deb env setup setup-required help distclean diff --git a/sys-utils/Makefile b/sys-utils/Makefile new file mode 100644 index 00000000..510b60c2 --- /dev/null +++ b/sys-utils/Makefile @@ -0,0 +1,36 @@ +# Copyright Cartesi and individual authors (see AUTHORS) +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +UTILITIES := xhalt yield rollup ioctl-echo-loop +UTILITIES_WITH_TOOLCHAIN := $(addsuffix -with-toolchain,$(UTILITIES)) + +all: $(UTILITIES) + +$(UTILITIES): + @$(MAKE) -C $@ + +with-toolchain: + @$(MAKE) $(UTILITIES_WITH_TOOLCHAIN) + +$(UTILITIES_WITH_TOOLCHAIN): + @$(MAKE) -C $@ with-toolchain + +clean: + @$(foreach utility,$(UTILITIES),$(MAKE) -C $(utility) clean;) + + +.PHONY: all with-toolchain $(UTILITIES) $(UTILITIES_WITH_TOOLCHAIN) diff --git a/sys-utils/ioctl-echo-loop/Makefile b/sys-utils/ioctl-echo-loop/Makefile index 3c883b7e..be73ff91 100644 --- a/sys-utils/ioctl-echo-loop/Makefile +++ b/sys-utils/ioctl-echo-loop/Makefile @@ -21,12 +21,14 @@ TOOLCHAIN_TAG ?= 0.16.0 RISCV_ARCH ?= rv64gc RISCV_ABI ?= lp64d -CROSS_COMPILE = riscv64-cartesi-linux-gnu- -RVCC = $(CROSS_COMPILE)gcc -RVCXX = $(CROSS_COMPILE)g++ -RVCOPY = $(CROSS_COMPILE)objcopy -RVDUMP = $(CROSS_COMPILE)objdump -STRIP = $(CROSS_COMPILE)strip +TOOLCHAIN_PREFIX ?= riscv64-cartesi-linux-gnu- +TOOLCHAIN_SUFFIX ?= + +RVCC = $(TOOLCHAIN_PREFIX)gcc$(TOOLCHAIN_SUFFIX) +RVCXX = $(TOOLCHAIN_PREFIX)g++$(TOOLCHAIN_SUFFIX) +RVCOPY = $(TOOLCHAIN_PREFIX)objcopy$(TOOLCHAIN_SUFFIX) +RVDUMP = $(TOOLCHAIN_PREFIX)objdump$(TOOLCHAIN_SUFFIX) +STRIP = $(TOOLCHAIN_PREFIX)strip CFLAGS :=-Wall -pedantic -O2 -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) CONTAINER_MAKE := /usr/bin/make @@ -35,17 +37,17 @@ KERNEL_HEADERS_PATH := /opt/riscv/usr/include all: ioctl-echo-loop -ioctl-echo-loop: ioctl-echo-loop.c +ioctl-echo-loop.with-toolchain with-toolchain: $(MAKE) toolchain-exec CONTAINER_COMMAND="$(CONTAINER_MAKE) $@.toolchain" -extra.ext2: ioctl-echo-loop +extra.ext2.with-toolchain: $(MAKE) toolchain-exec CONTAINER_COMMAND="$(CONTAINER_MAKE) $@.toolchain" -ioctl-echo-loop.toolchain: +ioctl-echo-loop: ioctl-echo-loop.c $(RVCC) $(CFLAGS) -o ioctl-echo-loop ioctl-echo-loop.c $(STRIP) ioctl-echo-loop -extra.ext2.toolchain: +extra.ext2: ioctl-echo-loop mkdir -m 0755 ./extra cp ./ioctl-echo-loop ./extra/ioctl-echo-loop xgenext2fs -i 512 -b 8192 -d extra $(basename $@) @@ -72,6 +74,6 @@ toolchain-env: $(TOOLCHAIN_IMAGE):$(TOOLCHAIN_TAG) clean: - \rm -rf ioctl-echo-loop extra.ext2 extra + @rm -rf ioctl-echo-loop extra.ext2 extra .PHONY: toolchain-exec toolchain-env diff --git a/sys-utils/rollup/Makefile b/sys-utils/rollup/Makefile index 020dc685..2b81d6ed 100644 --- a/sys-utils/rollup/Makefile +++ b/sys-utils/rollup/Makefile @@ -21,12 +21,14 @@ TOOLCHAIN_TAG ?= 0.16.0 RISCV_ARCH ?= rv64gc RISCV_ABI ?= lp64d -CROSS_COMPILE = riscv64-cartesi-linux-gnu- -RVCC = $(CROSS_COMPILE)gcc -RVCXX = $(CROSS_COMPILE)g++ -RVCOPY = $(CROSS_COMPILE)objcopy -RVDUMP = $(CROSS_COMPILE)objdump -STRIP = $(CROSS_COMPILE)strip +TOOLCHAIN_PREFIX ?= riscv64-cartesi-linux-gnu- +TOOLCHAIN_SUFFIX ?= + +RVCC = $(TOOLCHAIN_PREFIX)gcc$(TOOLCHAIN_SUFFIX) +RVCXX = $(TOOLCHAIN_PREFIX)g++$(TOOLCHAIN_SUFFIX) +RVCOPY = $(TOOLCHAIN_PREFIX)objcopy$(TOOLCHAIN_SUFFIX) +RVDUMP = $(TOOLCHAIN_PREFIX)objdump$(TOOLCHAIN_SUFFIX) +STRIP = $(TOOLCHAIN_PREFIX)strip RISCV_CFLAGS :=-march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) CONTAINER_MAKE := /usr/bin/make @@ -35,17 +37,17 @@ KERNEL_HEADERS_PATH := /opt/riscv/usr/include all: rollup -rollup: rollup.cpp +rollup.with-toolchain with-toolchain: $(MAKE) toolchain-exec CONTAINER_COMMAND="$(CONTAINER_MAKE) $@.toolchain" -extra.ext2: rollup +extra.ext2.with-toolchain: $(MAKE) toolchain-exec CONTAINER_COMMAND="$(CONTAINER_MAKE) $@.toolchain" -rollup.toolchain: +rollup: rollup.cpp $(RVCXX) -std=c++17 -O2 -o rollup rollup.cpp $(STRIP) rollup -extra.ext2.toolchain: +extra.ext2: rollup mkdir -m 0755 ./extra cp ./rollup ./extra/rollup xgenext2fs -i 512 -b 8192 -d extra $(basename $@) @@ -72,6 +74,6 @@ toolchain-env: $(TOOLCHAIN_IMAGE):$(TOOLCHAIN_TAG) clean: - \rm -rf rollup extra.ext2 extra + @rm -rf rollup extra.ext2 extra .PHONY: toolchain-exec toolchain-env diff --git a/sys-utils/xhalt/Makefile b/sys-utils/xhalt/Makefile index 0b50052a..7d77156f 100644 --- a/sys-utils/xhalt/Makefile +++ b/sys-utils/xhalt/Makefile @@ -21,12 +21,14 @@ TOOLCHAIN_TAG ?= 0.16.0 RISCV_ARCH ?= rv64gc RISCV_ABI ?= lp64d -CROSS_COMPILE = riscv64-cartesi-linux-gnu- -RVCC = $(CROSS_COMPILE)gcc -RVCXX = $(CROSS_COMPILE)g++ -RVCOPY = $(CROSS_COMPILE)objcopy -RVDUMP = $(CROSS_COMPILE)objdump -STRIP = $(CROSS_COMPILE)strip +TOOLCHAIN_PREFIX ?= riscv64-cartesi-linux-gnu- +TOOLCHAIN_SUFFIX ?= + +RVCC = $(TOOLCHAIN_PREFIX)gcc$(TOOLCHAIN_SUFFIX) +RVCXX = $(TOOLCHAIN_PREFIX)g++$(TOOLCHAIN_SUFFIX) +RVCOPY = $(TOOLCHAIN_PREFIX)objcopy$(TOOLCHAIN_SUFFIX) +RVDUMP = $(TOOLCHAIN_PREFIX)objdump$(TOOLCHAIN_SUFFIX) +STRIP = $(TOOLCHAIN_PREFIX)strip RISCV_CFLAGS :=-march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) CONTAINER_MAKE := /usr/bin/make @@ -35,17 +37,17 @@ KERNEL_HEADERS_PATH := /opt/riscv/usr/include all: xhalt -xhalt: xhalt.c +xhalt.with-toolchain with-toolchain: $(MAKE) toolchain-exec CONTAINER_COMMAND="$(CONTAINER_MAKE) $@.toolchain" -extra.ext2: xhalt +extra.ext2.with-toolchain: $(MAKE) toolchain-exec CONTAINER_COMMAND="$(CONTAINER_MAKE) $@.toolchain" -xhalt.toolchain: +xhalt: xhalt.c $(RVCC) -O2 -o xhalt xhalt.c $(STRIP) xhalt -extra.ext2.toolchain: +extra.ext2: xhalt mkdir -m 0755 ./extra cp ./xhalt ./extra/xhalt xgenext2fs -i 512 -b 8192 -d extra $(basename $@) @@ -72,6 +74,6 @@ toolchain-env: $(TOOLCHAIN_IMAGE):$(TOOLCHAIN_TAG) clean: - \rm -rf xhalt extra.ext2 extra + @rm -rf xhalt extra.ext2 extra .PHONY: toolchain-exec toolchain-env diff --git a/sys-utils/yield/Makefile b/sys-utils/yield/Makefile index 85b16e55..18e756ae 100644 --- a/sys-utils/yield/Makefile +++ b/sys-utils/yield/Makefile @@ -21,12 +21,14 @@ TOOLCHAIN_TAG ?= 0.16.0 RISCV_ARCH ?= rv64gc RISCV_ABI ?= lp64d -CROSS_COMPILE = riscv64-cartesi-linux-gnu- -RVCC = $(CROSS_COMPILE)gcc -RVCXX = $(CROSS_COMPILE)g++ -RVCOPY = $(CROSS_COMPILE)objcopy -RVDUMP = $(CROSS_COMPILE)objdump -STRIP = $(CROSS_COMPILE)strip +TOOLCHAIN_PREFIX ?= riscv64-cartesi-linux-gnu- +TOOLCHAIN_SUFFIX ?= + +RVCC = $(TOOLCHAIN_PREFIX)gcc$(TOOLCHAIN_SUFFIX) +RVCXX = $(TOOLCHAIN_PREFIX)g++$(TOOLCHAIN_SUFFIX) +RVCOPY = $(TOOLCHAIN_PREFIX)objcopy$(TOOLCHAIN_SUFFIX) +RVDUMP = $(TOOLCHAIN_PREFIX)objdump$(TOOLCHAIN_SUFFIX) +STRIP = $(TOOLCHAIN_PREFIX)strip RISCV_CFLAGS :=-march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) CONTAINER_MAKE := /usr/bin/make @@ -35,17 +37,17 @@ KERNEL_HEADERS_PATH := /opt/riscv/usr/include all: yield -yield: yield.c +yield.with-toolchain with-toolchain: $(MAKE) toolchain-exec CONTAINER_COMMAND="$(CONTAINER_MAKE) $@.toolchain" -extra.ext2: yield +extra.ext2.with-toolchain: $(MAKE) toolchain-exec CONTAINER_COMMAND="$(CONTAINER_MAKE) $@.toolchain" -yield.toolchain: +yield: yield.c $(RVCC) -O2 -o yield yield.c $(STRIP) yield -extra.ext2.toolchain: +extra.ext2: yield mkdir -m 0755 ./extra cp ./yield ./extra/yield xgenext2fs -i 512 -b 8192 -d extra $(basename $@) @@ -72,6 +74,6 @@ toolchain-env: $(TOOLCHAIN_IMAGE):$(TOOLCHAIN_TAG) clean: - \rm -rf yield extra.ext2 extra + @rm -rf yield extra.ext2 extra .PHONY: toolchain-exec toolchain-env