mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-07 03:38:31 +00:00
Make cosmocc capable of cross compilation
This commit is contained in:
parent
504a4bbf84
commit
d1b937bf1d
21 changed files with 439 additions and 132 deletions
95
bin/apecopy
Executable file
95
bin/apecopy
Executable file
|
@ -0,0 +1,95 @@
|
|||
#!/bin/sh
|
||||
|
||||
PROG=${0##*/}
|
||||
COSMO=${COSMO:-/opt/cosmo}
|
||||
|
||||
if [ x"$1" = x"--version" ]; then
|
||||
cat <<EOF
|
||||
$PROG 0.1
|
||||
Copyright (c) 2023 Justine Alexandra Roberts Tunney
|
||||
Cosmopolitan Libc and LLVM libcxx/compiler-rt are subject to non-GPL
|
||||
notice licenses, e.g. ISC, MIT, etc. Your compiled programs must embed
|
||||
our copyright notices. This toolchain is configured to do so default.
|
||||
Cosmopolitan comes with absolutely NO WARRANTY of any kind.
|
||||
For more information, see the Cosmopolitan LICENSE files.
|
||||
Copyright (C) 2019 Free Software Foundation, Inc.
|
||||
This launches GNU GCC/Binutils subprocesses, which is free software; see
|
||||
Cosmopolitan's third_party/gcc/ for source code and copying conditions.
|
||||
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
|
||||
PARTICULAR PURPOSE.
|
||||
EOF
|
||||
fi
|
||||
|
||||
if [ x"$1" = x"--help" ]; then
|
||||
cat <<EOF
|
||||
Usage: $PROG INPUT OUTPUT
|
||||
Converts an executable linked by cosmocc to the Actually Portable
|
||||
Executable file format. See $PROG --version for other details.
|
||||
EOF
|
||||
fi
|
||||
|
||||
fatal_error() {
|
||||
echo "$PROG: fatal error: $1" >&2
|
||||
echo "operation terminated." >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
CROSS=1
|
||||
ARCH=${PROG%%-*} # split(prog, '-')[0]
|
||||
if [ x"$ARCH" = x"$PROG" ]; then
|
||||
ARCH=x86_64
|
||||
CROSS=0
|
||||
fi
|
||||
|
||||
if [ x"$ARCH" = x"x86_64" ]; then
|
||||
MODE=${MODE:-$m}
|
||||
else
|
||||
MODE=${MODE:-${m:-$ARCH}}
|
||||
fi
|
||||
|
||||
if [ $CROSS -eq 0 ]; then
|
||||
COSMOS=${COSMOS:-/opt/cosmos}
|
||||
else
|
||||
COSMOS=${COSMOS:-/opt/cosmos/$ARCH}
|
||||
fi
|
||||
|
||||
if [ x"$ARCH" = x"x86_64" ]; then
|
||||
OBJCOPYFLAGS="-S -O binary"
|
||||
elif [ x"$ARCH" = x"aarch64" ]; then
|
||||
OBJCOPYFLAGS="-S"
|
||||
else
|
||||
fatal_error "$ARCH: unsupported architecture"
|
||||
fi
|
||||
|
||||
if [ ! -d "$COSMO" ]; then
|
||||
fatal_error "you need to clone cosmopolitan to your $COSMO directory"
|
||||
fi
|
||||
|
||||
if [ ! -f "$COSMO/o//tool/build/zipcopy.com" ] ||
|
||||
[ ! -f "$COSMO/o/third_party/gcc/bin/$ARCH-linux-musl-objcopy" ]; then
|
||||
if [ $CROSS -eq 0 ]; then
|
||||
fatal_error "you need to run: cosmocc --update"
|
||||
else
|
||||
fatal_error "you need to run: $ARCH-unknown-cosmo-cosmocc --update"
|
||||
fi
|
||||
fi
|
||||
|
||||
INPUT=$1
|
||||
OUTPUT=$2
|
||||
if [ ! -f "$INPUT" ]; then
|
||||
fatal_error "$INPUT: missing input and output arguments"
|
||||
elif [ ! -f "$INPUT" ]; then
|
||||
fatal_error "$INPUT: no such file"
|
||||
elif [ ! -f "$INPUT" ]; then
|
||||
fatal_error "$INPUT: missing output argument"
|
||||
elif [ x"$INPUT" = x"$OUTPUT" ]; then
|
||||
fatal_error "$INPUT: input and output file can't be the same"
|
||||
fi
|
||||
|
||||
"$COSMO/o/third_party/gcc/bin/$ARCH-linux-musl-objcopy" \
|
||||
$OBJCOPYFLAGS \
|
||||
"$INPUT" \
|
||||
"$OUTPUT" || exit
|
||||
"$COSMO/o//tool/build/zipcopy.com" \
|
||||
"$INPUT" \
|
||||
"$OUTPUT" || exit
|
Loading…
Add table
Add a link
Reference in a new issue