-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
160 additions
and
1 deletion.
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,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 }} |
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 |
---|---|---|
@@ -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 | ||
``` |
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,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" |