-
-
Notifications
You must be signed in to change notification settings - Fork 636
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make cosmocc capable of cross compilation
- Loading branch information
Showing
21 changed files
with
435 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/sh | ||
|
||
MODE=${MODE:-${m:-aarch64}} | ||
COSMO=${COSMO:-/opt/cosmo} | ||
COSMOS=${COSMOS:-/opt/cosmos/aarch64} | ||
TOOL="$COSMO/o/third_party/gcc/bin/aarch64-linux-musl-addr2line" | ||
|
||
if [ ! -x "$TOOL" ]; then | ||
echo "$0: you need to run: aarch64-unknown-cosmo-cc --update" >&2 | ||
exit 1 | ||
fi | ||
|
||
exec "$TOOL" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
apecopy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/sh | ||
|
||
PROG=${0##*/} | ||
MODE=${MODE:-${m:-aarch64}} | ||
COSMO=${COSMO:-/opt/cosmo} | ||
|
||
fatal_error() { | ||
echo "$PROG: $1" >&2 | ||
exit 1 | ||
} | ||
|
||
if [ ! -x "$COSMO/o//tool/build/ar.com" ]; then | ||
fatal_error "you need to run: aarch64-unknown-cosmo-cc --update" | ||
fi | ||
|
||
if [ x"$1" = x"rc" ] || | ||
[ x"$1" = x"rcD" ] || | ||
[ x"$1" = x"rcu" ] | | ||
[ x"$1" = x"rcuD" ] || | ||
[ x"$1" = x"rcs" ] || | ||
[ x"$1" = x"rcsD" ] || | ||
[ x"$1" = x"--help" ] || | ||
[ x"$1" = x"--version" ]; then | ||
AR="$COSMO/o//tool/build/ar.com" | ||
else | ||
AR="$COSMO/o/third_party/gcc/bin/aarch64-linux-musl-ar" | ||
fi | ||
|
||
exec "$AR" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/sh | ||
|
||
MODE=${MODE:-${m:-aarch64}} | ||
COSMO=${COSMO:-/opt/cosmo} | ||
COSMOS=${COSMOS:-/opt/cosmos/aarch64} | ||
TOOL="$COSMO/o/third_party/gcc/bin/aarch64-linux-musl-as" | ||
|
||
if [ ! -x "$TOOL" ]; then | ||
echo "$0: you need to run: aarch64-unknown-cosmo-cc --update" >&2 | ||
exit 1 | ||
fi | ||
|
||
exec "$TOOL" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cosmocc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cosmocc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cosmocc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cosmocc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/sh | ||
|
||
MODE=${MODE:-${m:-aarch64}} | ||
COSMO=${COSMO:-/opt/cosmo} | ||
COSMOS=${COSMOS:-/opt/cosmos/aarch64} | ||
TOOL="$COSMO/o/third_party/gcc/bin/aarch64-linux-musl-ld" | ||
|
||
if [ ! -x "$TOOL" ]; then | ||
echo "$0: you need to run: aarch64-unknown-cosmo-cc --update" >&2 | ||
exit 1 | ||
fi | ||
|
||
exec "$TOOL" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/sh | ||
|
||
MODE=${MODE:-${m:-aarch64}} | ||
COSMO=${COSMO:-/opt/cosmo} | ||
COSMOS=${COSMOS:-/opt/cosmos/aarch64} | ||
TOOL="$COSMO/o/third_party/gcc/bin/aarch64-linux-musl-objcopy" | ||
|
||
if [ ! -x "$TOOL" ]; then | ||
echo "$0: you need to run: aarch64-unknown-cosmo-cc --update" >&2 | ||
exit 1 | ||
fi | ||
|
||
exec "$TOOL" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/sh | ||
|
||
MODE=${MODE:-${m:-aarch64}} | ||
COSMO=${COSMO:-/opt/cosmo} | ||
COSMOS=${COSMOS:-/opt/cosmos/aarch64} | ||
TOOL="$COSMO/o/third_party/gcc/bin/aarch64-linux-musl-objdump" | ||
|
||
if [ ! -x "$TOOL" ]; then | ||
echo "$0: you need to run: aarch64-unknown-cosmo-cc --update" >&2 | ||
exit 1 | ||
fi | ||
|
||
exec "$TOOL" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/sh | ||
|
||
MODE=${MODE:-${m:-aarch64}} | ||
COSMO=${COSMO:-/opt/cosmo} | ||
COSMOS=${COSMOS:-/opt/cosmos/aarch64} | ||
TOOL="$COSMO/o/third_party/gcc/bin/aarch64-linux-musl-strip" | ||
|
||
if [ ! -x "$TOOL" ]; then | ||
echo "$0: you need to run: aarch64-unknown-cosmo-cc --update" >&2 | ||
exit 1 | ||
fi | ||
|
||
exec "$TOOL" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.