Skip to content

Commit

Permalink
v2.21
Browse files Browse the repository at this point in the history
  • Loading branch information
VHSgunzo committed Oct 10, 2022
1 parent b1864c2 commit d404eee
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 1 deletion.
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI

on:
push:
branches:
- action
tags:
- '*'

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Build
uses: countstarlight/arch-makepkg-action@master
with:
#repos: >
# archlinuxcn=https://geo-mirror.chaotic.cx/$repo/$arch
#before: "sudo pacman -S --noconfirm archlinux-keyring chaotic-keyring chaotic-mirrorlist"
packages: >
musl
# base-devel
# coreutils
# curl
# upx
scripts: "./build.sh"
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: which-static-v*.tar.xz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# which-static
Statically compiled which with musl
* Statically compiled which with musl
## To get started:
* **Download the latest revision**
```
git clone https://github.com/VHSgunzo/which-static.git
```
* **Build**
```
cd which-static && ./build.sh
```
114 changes: 114 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/bin/bash

export MAKEFLAGS="-j$(nproc)"

# WITH_UPX=1
# NO_SYS_MUSL=1

which_version="latest"
musl_version="latest"

platform="$(uname -s)"
platform_arch="$(uname -m)"

[ "$which_version" == "latest" ] && \
which_version="$(curl -s https://ftp.gnu.org/gnu/which/|tac|\
grep -om1 'which-.*\.tar\.gz'|cut -d'>' -f2|sed 's|which-||g;s|.tar.gz||g')"

[ "$musl_version" == "latest" ] && \
musl_version="$(curl -s https://www.musl-libc.org/releases/|tac|grep -v 'latest'|\
grep -om1 'musl-.*\.tar\.gz'|cut -d'>' -f2|sed 's|musl-||g;s|.tar.gz||g')"

if [ -d build ]
then
echo "= removing previous build directory"
rm -rf build
fi

if [ -d release ]
then
echo "= removing previous release directory"
rm -rf release
fi

# create build and release directory
mkdir build
mkdir release
pushd build

# download tarballs
echo "= downloading which v${which_version}"
curl -LO https://ftp.gnu.org/gnu/which/which-${which_version}.tar.gz

echo "= extracting which"
tar -xf which-${which_version}.tar.gz

if [ "$platform" == "Linux" ]
then
echo "= setting CC to musl-gcc"
if [[ ! -x "$(which musl-gcc 2>/dev/null)" || "$NO_SYS_MUSL" == 1 ]]
then
echo "= downloading musl v${musl_version}"
curl -LO https://www.musl-libc.org/releases/musl-${musl_version}.tar.gz

echo "= extracting musl"
tar -xf musl-${musl_version}.tar.gz

echo "= building musl"
working_dir="$(pwd)"

install_dir="${working_dir}/musl-install"

pushd musl-${musl_version}
env CFLAGS="$CFLAGS -Os -ffunction-sections -fdata-sections" LDFLAGS='-Wl,--gc-sections' ./configure --prefix="${install_dir}"
make install
popd # musl-${musl-version}
export CC="${working_dir}/musl-install/bin/musl-gcc"
else
export CC="$(which musl-gcc 2>/dev/null)"
fi
export CFLAGS="-static -static-libgcc -static-libstdc++"
export LDFLAGS='--static'
else
echo "= WARNING: your platform does not support static binaries."
echo "= (This is mainly due to non-static libc availability.)"
fi

echo "= building which"
pushd which-${which_version}
env CFLAGS="$CFLAGS -g -O2 -Os -ffunction-sections -fdata-sections" LDFLAGS="$LDFLAGS -Wl,--gc-sections" ./configure
make
popd # which-${which_version}

popd # build

shopt -s extglob

echo "= extracting which binary"
cp build/which-${which_version}/which release 2>/dev/null

echo "= striptease"
for file in release/*
do
strip -s -R .comment -R .gnu.version --strip-unneeded "$file" 2>/dev/null
done

if [[ "$WITH_UPX" == 1 && -x "$(which upx 2>/dev/null)" ]]
then
echo "= upx compressing"
for file in release/*
do
upx -9 --best "$file" 2>/dev/null
done
fi

echo "= create release tar.xz"
tar --xz -acf which-static-v${which_version}-${platform_arch}.tar.xz release

if [ "$NO_CLEANUP" != 1 ]
then
echo "= cleanup"
rm -rf release build
fi

echo "= which v${which_version} done"

0 comments on commit d404eee

Please sign in to comment.