Add crosscompiling support with sys/zig.sh ##build

This commit is contained in:
pancake 2022-11-05 23:33:31 +01:00 committed by GitHub
parent 64620755d8
commit 5d07b40478
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 173 additions and 17 deletions

View File

@ -8,8 +8,12 @@
LANG=C
LC_ALL=C
LOADLIBS=1
EXT=so
[ "`uname`" = Darwin ] && EXT=dylib
if [ -z "$EXT_SO" ]; then
EXT=so
[ "`uname`" = Darwin ] && EXT=dylib
else
EXT="${EXT_SO}"
fi
export LANG
export LC_ALL

View File

@ -1,5 +1,8 @@
ifeq ($(uname -m),arm64)
ARCH=arm64
else
ARCH=amd64
# ARCH=arm64
endif
DOCKER_IMAGE=r2docker
DOCKERFLAGS+=--privileged
@ -13,4 +16,4 @@ endif
all:
docker build $(DOCKER_PLATFORM) -t $(DOCKER_IMAGE) .
docker run $(DOCKER_PLATFORM) -v $(shell pwd)/../..:/r $(DOCKERFLAGS) -i -t r2
docker run $(DOCKER_PLATFORM) -v $(shell pwd)/../..:/r -v /tmp:/tmp $(DOCKERFLAGS) -i -t ${DOCKER_IMAGE}

View File

@ -69,7 +69,6 @@ anal.propeller
arch.null
arch.jdh8
arch.i4004
arch.amd29k
esil.dummy
asm.arm
asm.null

View File

@ -35,10 +35,6 @@ LINK+=$(shell echo ${R2DEPS} | sed -e 's:r_\([^ ]\+\):$(LIBR)/\1/libr_\1.${EXT_A
endif
endif
# Debug
ifneq ($(OSTYPE),mingw32)
CFLAGS+=-g
endif
CFLAGS+=-Wall
# libgmp
@ -61,6 +57,7 @@ endif
# XXX do it in configure stage
OSTYPE?=gnulinux
ifeq (${OSTYPE},auto)
_UNAME=$(shell uname)
ifeq ($(_UNAME),Darwin)
@ -93,6 +90,9 @@ OSTYPE=bsd
endif
# Output
ifneq ($(OSTYPE),mingw32)
CFLAGS+=-g
endif
ifeq (${OSTYPE},windows)
CFLAGS+=-D__WINDOWS__=1
EXT_AR=lib

View File

@ -27,7 +27,7 @@ ifeq (${BUILD_OS},dragonfly)
endif
.PHONY: pre pos
pre: libr_io.${EXT_SO} libr_io.${EXT_AR}
pre: libr_io.$(EXT_SO) libr_io.$(EXT_AR)
@$(MAKE) -C p
$(MAKE) pos

View File

@ -1,13 +1,163 @@
#!/bin/sh
export CC="zig cc -std=c11"
export LD="zig cc"
ARG="$1"
# cross compile to linux-arm64
#export CC="zig cc -std=c11 -target aarch64-linux"
#export LD="zig cc -target aarch64-linux"
TARGETS="
native
clean
arm-linux
arm64-linux
amd64-linux
riscv64-linux
mips-linux
sparcv9-linux
ppc-linux
ppc64-linux
wasm32-wasi
Experimental:
arm64-macos
amd64-macos
amd64-netbsd
i386-windows
amd64-windows
arm64-windows
See \`zig targets\` for more details.
"
if [ -z "$ARG" ]; then
echo "Usage: sys/zig.sh [target]"
echo "Environment:"
echo " STATIC=0|1 # build r2 statically"
echo "Targets:$TARGETS"
#echo "CPUS: x86_64 arm aarch64 i386 riscv64 wasm32"
#echo "OSS: linux macos windows freebsd netbsd dragonfly UEFI"
exit 1
fi
TARGET="$ARG"
OSTYPE=gnulinux
#export CC="zig cc -std=c11"
#export LD="zig cc"
CFGFLAGS=""
case "$TARGET" in
clean)
make clean > /dev/null
exit 0
;;
amd64-darwin|x86_64-darwin|amd64-macos|x86_64-macos)
TARGET="x86_64-macos"
OSTYPE=darwin
CFGFLAGS="--disable-debugger" # ptrace.h is missing
;;
arm64-darwin|aarch64-darwin|arm64-macos|aarch64-macos)
TARGET="aarch64-macos"
OSTYPE=darwin
CFGFLAGS="--disable-debugger"
;;
wasm32|wasm|wasm32-wasi|wasi)
TARGET="wasm32-wasi-musl"
;;
arm-linux|arm32-linux)
TARGET="arm-linux"
;;
arm64-linux|aarch64-linux)
TARGET="aarch64-linux-musl"
;;
ppc-linux|powerpc-linux)
TARGET="powerpc-linux"
;;
ppc64-linux|powerpc64-linux)
TARGET="powerpc64-linux"
;;
amd64-linux|x86_64-linux|x64-linux)
TARGET="x86_64-linux"
;;
riscv-linux|riscv64-linux)
TARGET="riscv64-linux"
;;
amd64-freebsd|x86_64-freebsd|x64-freebsd)
TARGET="x86_64-freebsd"
;;
mips-linux|mips64-linux)
TARGET="mips-linux"
;;
ios)
TARGET="aarch64-ios-none" #aarch64-linux-android"
OSTYPE=darwin
CFGFLAGS="--disable-debugger"
;;
w32|wXP|wxp|i386-windows)
TARGET="i386-windows-gnu"
OSTYPE=windows
;;
w64|windows)
TARGET="x86_64-windows-gnu"
OSTYPE=windows
;;
arm64-windows|aarch64-windows)
TARGET="aarch64-windows-gnu"
OSTYPE=windows
;;
amd64-netbsd)
## missing libc
TARGET="x86_64-netbsd.9"
;;
wip)
TARGET="aarch64-netbsd.9-musl"
;;
native)
TARGET=""
;;
*)
echo "Unknown target $TARGET"
;;
esac
# seems to be problematic, better leave cflags to the user
#export CFLAGS="-Oz"
#export LDFLAGS="-flto"
if [ -z "${TARGET}" ]; then
export CC="zig cc"
export LD="zig cc"
else
export CC="zig cc -target ${TARGET}"
export LD="zig cc -target ${TARGET}"
fi
# nollvm doesnt work with all targets
#export CC="$CC -fstage1 -fno-LLVM"
#export LD="$LD -fstage1 -fno-LLVM"
case "$OSTYPE" in
macos|ios|darwin)
export EXT_SO=dylib
;;
windows)
export EXT_AR=lib
export EXT_SO=dll
;;
*)
export EXT_SO=so
;;
esac
export AR="zig ar"
export RANLIB="zig ranlib"
./configure
time make -j
if [ "$STATIC" = 1 ]; then
CFGFLAGS="--with-libr"
export PARTIALLD="${CC} -r -Wl,--whole-archive -c"
fi
RUN_CONFIGURE=1
if [ "$RUN_CONFIGURE" = 1 ]; then
rm -f libr/include/r_version.h
# ./configure --host=aarch64-gnu-linux --with-ostype=linux
./configure --with-ostype=$OSTYPE ${CFGFLAGS} || exit 1
fi
if [ "${STATIC}" = 1 ]; then
time make -j PARTIALLD="${PARTIALLD}"
else
time make -j
fi