#!/bin/sh PROG=${0##*/} COSMO=${COSMO:-/opt/cosmo} if [ x"$1" = x"--version" ]; then cat <&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