cosmopolitan/tool/cosmocc/package.sh
Justine Tunney ca4cf67eb8
Include more programs in cosmocc
The Cosmopolitan Compiler Collection now includes the following programs

- `ar.ape` is a faster alternative to `ar rcsD` for creating determistic
  static archives. It's ~10x faster than GNU because it isn't quadratic.
  It'll even outperform LLVM ar by 2x, thanks to writev/copy_file_range.

- `sha256sum.ape` is a faster alternative to the `sha256sum` command. It
  goes 2x faster since it leverages vectorized assembly implementations.

- `resymbol` is a brand new program we invented, like objcopy, that lets
  you rename all the global symbols in a .o file to have a new suffix or
  prefix. In the future, this will be used by cosmocc automatically when
  building -O3 math kernels, that need to be vectorized for all hardware

- `gzip.ape` is a faster version of the `gzip` command, that is included
  by most Linux distros. It gains better performance using Chromium Zlib
  which, once again, includes highly optimized assembly, that Mark Adler
  won't merge into the official MS-DOS compatible zlib codebase.

- `cocmd` is the cosmopolitan shell. It can function as a faster `sh -c`
  alternative than bash and dash as the `SHELL = /opt/cosmocc/bin/cocmd`
  at the top of your Makefile. Please note you should be using the cosmo
  fork of GNU make (already included), since normal make won't recognize
  this as a bourne-compatible shell and remove the execve() optimization
  which makes things slower. In some ways that's true. This doesn't have
  a complete POSIX shell implementation. However it's enough for cosmo's
  mono repo. It also implements faster behaviors in some respects.

The following programs are also introduced, which aren't as interesting.
The main reason why they're here is so Cosmopolitan's mono repo shall be
able to remove build/bootstrap/ in future editions. That way we can keep
build utilities better up to date, without bloating the git history much

- `chmod.ape` for hermeticity
- `cp.ape` for hermeticity
- `echo.ape` for hermeticity
- `objbincopy` is an objcopy-like tool that's used to build ape loader
- `package.ape` is used for strict dependency checking of object graph
- `rm.ape` for hermeticity
- `touch.ape` for hermeticity
2024-07-01 02:05:25 -07:00

199 lines
6.6 KiB
Bash
Executable file

#!/bin/sh
# cosmopolitan toolchain packager
#
# tool/cosmocc/package.sh
# cd cosmocc
# zip -ry9 ../cosmocc.zip .
#
set -ex
mode() {
case $(uname -m) in
arm64|aarch64) echo aarch64 ;;
*) echo ;;
esac
}
OUTDIR=${1:-cosmocc}
APELINK=o/$(mode)/tool/build/apelink
AMD64=${2:-x86_64}
ARM64=${3:-aarch64}
GCCVER=12.3.0
make -j64 m= \
$APELINK
make -j64 m=$AMD64 \
o/cosmocc.h.txt \
o/$AMD64/ape/ape.lds \
o/$AMD64/libc/crt/crt.o \
o/$AMD64/ape/ape.elf \
o/$AMD64/ape/ape.macho \
o/$AMD64/ape/ape.o \
o/$AMD64/ape/ape-copy-self.o \
o/$AMD64/ape/ape-no-modify-self.o \
o/$AMD64/cosmopolitan.a \
o/$AMD64/third_party/libcxx/libcxx.a \
o/$AMD64/tool/build/assimilate.dbg \
o/$AMD64/tool/build/march-native.dbg \
o/$AMD64/tool/build/mktemper.dbg \
o/$AMD64/tool/build/fixupobj.dbg \
o/$AMD64/tool/build/zipcopy.dbg \
o/$AMD64/tool/build/mkdeps.dbg \
o/$AMD64/tool/build/zipobj.dbg \
o/$AMD64/tool/build/apelink.dbg \
o/$AMD64/tool/build/pecheck.dbg \
o/$AMD64/tool/build/ar.dbg \
o/$AMD64/tool/build/chmod.dbg \
o/$AMD64/tool/build/cocmd.dbg \
o/$AMD64/tool/build/compile.dbg \
o/$AMD64/tool/build/cp.dbg \
o/$AMD64/tool/build/echo.dbg \
o/$AMD64/tool/build/gzip.dbg \
o/$AMD64/tool/build/objbincopy.dbg \
o/$AMD64/tool/build/package.dbg \
o/$AMD64/tool/build/rm.dbg \
o/$AMD64/tool/build/touch.dbg \
o/$AMD64/tool/build/sha256sum.dbg \
o/$AMD64/tool/build/resymbol.dbg \
o/$AMD64/third_party/make/make.dbg \
o/$AMD64/third_party/ctags/ctags.dbg
make -j64 m=$ARM64 \
o/$ARM64/ape/ape.elf \
o/$ARM64/ape/aarch64.lds \
o/$ARM64/libc/crt/crt.o \
o/$ARM64/ape/ape-copy-self.o \
o/$ARM64/ape/ape-no-modify-self.o \
o/$ARM64/cosmopolitan.a \
o/$ARM64/third_party/libcxx/libcxx.a \
o/$ARM64/tool/build/assimilate.dbg \
o/$ARM64/tool/build/march-native.dbg \
o/$ARM64/tool/build/mktemper.dbg \
o/$ARM64/tool/build/fixupobj.dbg \
o/$ARM64/tool/build/zipcopy.dbg \
o/$ARM64/tool/build/mkdeps.dbg \
o/$ARM64/tool/build/zipobj.dbg \
o/$ARM64/tool/build/apelink.dbg \
o/$ARM64/tool/build/pecheck.dbg \
o/$ARM64/tool/build/ar.dbg \
o/$ARM64/tool/build/chmod.dbg \
o/$ARM64/tool/build/cocmd.dbg \
o/$ARM64/tool/build/compile.dbg \
o/$ARM64/tool/build/cp.dbg \
o/$ARM64/tool/build/echo.dbg \
o/$ARM64/tool/build/gzip.dbg \
o/$ARM64/tool/build/objbincopy.dbg \
o/$ARM64/tool/build/package.dbg \
o/$ARM64/tool/build/rm.dbg \
o/$ARM64/tool/build/touch.dbg \
o/$ARM64/tool/build/sha256sum.dbg \
o/$ARM64/tool/build/resymbol.dbg \
o/$ARM64/third_party/make/make.dbg \
o/$ARM64/third_party/ctags/ctags.dbg
mkdir -p "$OUTDIR/bin/"
cp tool/cosmocc/README.md "$OUTDIR/"
cp tool/cosmocc/LICENSE.* "$OUTDIR/"
mkdir -p "$OUTDIR/include/"
cp -R libc/isystem/* "$OUTDIR/include/"
cp -R libc/integral "$OUTDIR/include/libc/"
for x in $(cat o/cosmocc.h.txt); do
mkdir -p "$OUTDIR/include/${x%/*}/"
cp -f $x "$OUTDIR/include/${x%/*}/"
done
fetch() {
if command -v wget >/dev/null; then
wget $1
else
curl -LO $1
fi
}
OLD=$PWD
cd "$OUTDIR/"
if [ ! -x bin/x86_64-linux-cosmo-gcc ]; then
fetch https://github.com/ahgamut/superconfigure/releases/download/z0.0.45/aarch64-gcc.zip
unzip aarch64-gcc.zip
rm -f aarch64-gcc.zip
fetch https://github.com/ahgamut/superconfigure/releases/download/z0.0.45/x86_64-gcc.zip
unzip x86_64-gcc.zip
rm -f x86_64-gcc.zip
fi
rm -f bin/*-cpp
rm -f bin/*-gcc-*
rm -f bin/*-gprof
rm -f bin/*-strings
for arch in aarch64 x86_64; do
ln -sf $arch-linux-cosmo-addr2line bin/$arch-unknown-cosmo-addr2line
ln -sf $arch-linux-cosmo-ar bin/$arch-unknown-cosmo-ar
ln -sf $arch-linux-cosmo-as bin/$arch-unknown-cosmo-as
ln -sf $arch-linux-cosmo-c++filt bin/$arch-unknown-cosmo-c++filt
ln -sf $arch-linux-cosmo-g++ bin/$arch-linux-cosmo-c++
ln -sf $arch-linux-cosmo-gcc bin/$arch-linux-cosmo-cc
ln -sf $arch-linux-cosmo-gcc bin/$arch-linux-cosmo-cpp
ln -sf $arch-linux-cosmo-nm bin/$arch-unknown-cosmo-nm
ln -sf $arch-linux-cosmo-objcopy bin/$arch-unknown-cosmo-objcopy
ln -sf $arch-linux-cosmo-objdump bin/$arch-unknown-cosmo-objdump
ln -sf $arch-linux-cosmo-readelf bin/$arch-unknown-cosmo-readelf
ln -sf $arch-linux-cosmo-strip bin/$arch-unknown-cosmo-strip
# cmp -s libexec/gcc/$arch-linux-cosmo/$GCCVER/ld.bfd libexec/gcc/$arch-linux-cosmo/$GCCVER/ld
# ln -sf ld.bfd libexec/gcc/$arch-linux-cosmo/$GCCVER/ld
# cmp -s libexec/gcc/$arch-linux-cosmo/$GCCVER/ld.bfd bin/$arch-linux-cosmo-ld
# ln -sf ../libexec/gcc/$arch-linux-cosmo/$GCCVER/ld.bfd bin/$arch-linux-cosmo-ld
cmp -s libexec/gcc/$arch-linux-cosmo/$GCCVER/as bin/$arch-linux-cosmo-as
ln -sf ../libexec/gcc/$arch-linux-cosmo/$GCCVER/as bin/$arch-linux-cosmo-as
cmp -s libexec/gcc/$arch-linux-cosmo/$GCCVER/ld.bfd bin/$arch-linux-cosmo-ld.bfd
ln -sf ../libexec/gcc/$arch-linux-cosmo/$GCCVER/ld.bfd bin/$arch-linux-cosmo-ld.bfd
done
cd "$OLD"
for arch in $AMD64 $ARM64; do
mkdir -p "$OUTDIR/$arch-linux-cosmo/lib/"
cp -f o/$arch/libc/crt/crt.o "$OUTDIR/$arch-linux-cosmo/lib/"
cp -f o/$arch/cosmopolitan.a "$OUTDIR/$arch-linux-cosmo/lib/libcosmo.a"
cp -f o/$arch/third_party/libcxx/libcxx.a "$OUTDIR/$arch-linux-cosmo/lib/"
for lib in c dl gcc_s m crypt pthread resolv rt dl unwind gomp stdc++; do
printf '\041\074\141\162\143\150\076\012' >"$OUTDIR/$arch-linux-cosmo/lib/lib$lib.a"
done
mkdir -p "$OUTDIR/lib/gcc/"
touch "$OUTDIR/lib/gcc/libgomp.spec" # needed if user passes -fopenmp but not -lgomp
done
cp -f o/$AMD64/ape/ape.o "$OUTDIR/x86_64-linux-cosmo/lib/"
cp -f o/$AMD64/ape/ape.lds "$OUTDIR/x86_64-linux-cosmo/lib/"
cp -f o/$ARM64/ape/aarch64.lds "$OUTDIR/aarch64-linux-cosmo/lib/"
cp -f o/$AMD64/ape/ape-no-modify-self.o "$OUTDIR/x86_64-linux-cosmo/lib/"
cp -f ape/ape-m1.c "$OUTDIR/bin/"
cp -af tool/cosmocc/bin/* "$OUTDIR/bin/"
cp -f o/$AMD64/ape/ape.elf "$OUTDIR/bin/ape-x86_64.elf"
cp -f o/$AMD64/ape/ape.macho "$OUTDIR/bin/ape-x86_64.macho"
cp -f o/$ARM64/ape/ape.elf "$OUTDIR/bin/ape-aarch64.elf"
for x in assimilate march-native mktemper fixupobj zipcopy apelink pecheck mkdeps zipobj \
ar chmod cocmd cp echo gzip objbincopy package rm touch sha256sum resymbol; do
ape $APELINK \
-l o/$AMD64/ape/ape.elf \
-l o/$ARM64/ape/ape.elf \
-M ape/ape-m1.c \
-o "$OUTDIR/bin/$x" \
o/$AMD64/tool/build/$x.dbg \
o/$ARM64/tool/build/$x.dbg
done
for x in ar chmod cp echo gzip package rm touch sha256sum; do
mv "$OUTDIR/bin/$x" "$OUTDIR/bin/$x.ape"
done
for x in make ctags; do
ape $APELINK \
-l o/$AMD64/ape/ape.elf \
-l o/$ARM64/ape/ape.elf \
-M ape/ape-m1.c \
-o "$OUTDIR/bin/$x" \
o/$AMD64/third_party/$x/$x.dbg \
o/$ARM64/third_party/$x/$x.dbg
done