leleliu008 / ppkg

A portable package builder/manager for Unix-like system.
Apache License 2.0
26 stars 3 forks source link
cli package-manager shell

ppkg

A portable package builder/manager for Unix-like system.

Caveats

Two implementations

This software provides two implementations:

implemented in language branch
implemented in POSIX Shell master
implemented in C c

In theroy, these two implementations should have the same behaver except for have bugs.

Using ppkg via GitHub Actions

In this way, you will be liberated from the rut of setting up the build environmemt.

In this way, all you need to do is just clicking the buttons and waiting for finishing. After finishing, a url refers to a zip archive will be provided to download.

For more details please refer to https://github.com/leleliu008/ppkg-package-manually-build

Install POSIX-Shell-based ppkg via curl

curl -LO https://raw.githubusercontent.com/leleliu008/ppkg/master/ppkg
chmod a+x ppkg
./ppkg setup

Install POSIX-Shell-based ppkg via wget

wget https://cdn.jsdelivr.net/gh/leleliu008/ppkg/ppkg
chmod a+x ppkg
./ppkg setup

Build from C source locally dependencies

dependency required? purpose
GCC or LLVM+clang required for compiling C source code
cmake required for generating build.ninja
ninja required for doing jobs that read from build.ninja
pkg-config>=0.18 required for finding libraries
jansson required for parsing and creating JSON.
libyaml required for parsing formula files whose format is YAML.
libgit2 required for updating formula repositories.
libcurl required for http requesting support.
openssl required for https requesting support and SHA-256 sum checking support.
libarchive required for uncompressing .zip and .tar.* files.
zlib required for compress and uncompress data.
pcre2 for Regular Expressions support. only required on OpenBSD.

Build from C source locally via ppkg

ppkg install ppkg

Build from C source locally via xcpkg

xcpkg install ppkg

Build from C source locally using vcpkg

# install g++ curl zip unzip tar git

git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
export VCPKG_ROOT="$PWD/vcpkg"
export PATH="$VCPKG_ROOT:$PATH"

vcpkg install curl openssl libgit2 libarchive libyaml jansson

git clone --depth=1 --branch=c https://github.com/leleliu008/ppkg
cd ppkg

cmake -S . -B   build.d -G Ninja -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake
cmake --build   build.d
cmake --install build.d

Build from C source locally via HomeBrew

brew install --HEAD leleliu008/fpliu/ppkg

Build from C source locally using your system's default package manager

Ubuntu

apt -y update
apt -y install git cmake ninja-build pkg-config gcc libcurl4 libcurl4-openssl-dev libgit2-dev libarchive-dev libyaml-dev libjansson-dev zlib1g-dev

git clone --depth=1 --branch=c https://github.com/leleliu008/ppkg
cd ppkg

cmake -S . -B   build.d -G Ninja -DCMAKE_INSTALL_PREFIX=/usr/local
cmake --build   build.d
cmake --install build.d

Fedora

dnf -y update
dnf -y install git cmake ninja-build pkg-config gcc libcurl-devel libgit2-devel libarchive-devel libyaml-devel jansson-devel zlib-devel

git clone --depth=1 --branch=c https://github.com/leleliu008/ppkg
cd ppkg

cmake -S . -B   build.d -G Ninja -DCMAKE_INSTALL_PREFIX=/usr/local
cmake --build   build.d
cmake --install build.d

ArchLinux

pacman -Syyuu --noconfirm
pacman -S     --noconfirm git cmake ninja pkg-config gcc curl openssl libgit2 libarchive libyaml jansson zlib

git clone --depth=1 --branch=c https://github.com/leleliu008/ppkg
cd ppkg

cmake -S . -B   build.d -G Ninja -DCMAKE_INSTALL_PREFIX=/usr/local
cmake --build   build.d
cmake --install build.d

AlpineLinux

apk add git cmake ninja pkgconf gcc libc-dev curl-dev openssl-dev libgit2-dev libarchive-dev yaml-dev jansson-dev zlib-dev

git clone --depth=1 --branch=c https://github.com/leleliu008/ppkg
cd ppkg

cmake -S . -B   build.d -G Ninja -DCMAKE_INSTALL_PREFIX=/usr/local
cmake --build   build.d
cmake --install build.d

VoidLinux

xbps-install -Suy xbps
xbps-install -Suy cmake ninja gcc pkg-config libcurl-devel libgit2-devel libarchive-devel libyaml-devel jansson-devel zlib-devel

git clone --depth=1 --branch=c https://github.com/leleliu008/ppkg
cd ppkg

cmake -S . -B   build.d -G Ninja -DCMAKE_INSTALL_PREFIX=/usr/local
cmake --build   build.d
cmake --install build.d

Gentoo Linux

emerge dev-vcs/git cmake dev-util/ninja gcc pkg-config net-misc/curl dev-libs/libgit2 libarchive dev-libs/libyaml dev-libs/jansson dev-libs/zlib

git clone --depth=1 --branch=c https://github.com/leleliu008/ppkg
cd ppkg

cmake -S . -B   build.d -G Ninja -DCMAKE_INSTALL_PREFIX=/usr/local
cmake --build   build.d
cmake --install build.d

openSUSE

zypper update  -y
zypper install -y git cmake ninja gcc pkg-config libcurl-devel libgit2-devel libarchive-devel libyaml-devel libjansson-devel zlib-devel

git clone --depth=1 --branch=c https://github.com/leleliu008/ppkg
cd ppkg

cmake -S . -B   build.d -G Ninja -DCMAKE_INSTALL_PREFIX=/usr/local
cmake --build   build.d
cmake --install build.d

FreeBSD and DragonFlyBSD

pkg install -y git cmake ninja pkgconf gcc curl openssl libgit2 libarchive libyaml jansson zlib

git clone --depth=1 --branch=c https://github.com/leleliu008/ppkg
cd ppkg

cmake -S . -B   build.d -G Ninja -DCMAKE_INSTALL_PREFIX=/usr/local
cmake --build   build.d
cmake --install build.d

OpenBSD

pkg_add git cmake ninja pkgconf llvm curl libgit2 libarchive libyaml jansson zlib

git clone --depth=1 --branch=c https://github.com/leleliu008/ppkg
cd ppkg

cmake -S . -B   build.d -G Ninja -DCMAKE_INSTALL_PREFIX=/usr/local
cmake --build   build.d
cmake --install build.d

NetBSD

pkgin -y install git mozilla-rootcerts cmake ninja-build pkg-config clang curl openssl libgit2 libarchive libyaml jansson zlib

mozilla-rootcerts install

git clone --depth=1 --branch=c https://github.com/leleliu008/ppkg
cd ppkg

cmake -S . -B   build.d -G Ninja -DCMAKE_INSTALL_PREFIX=/usr/local
cmake --build   build.d
cmake --install build.d

~/.ppkg

all relevant directories and files are located under ~/.ppkg directory.

ppkg command usage

environment variables

Note: some commonly used environment variables are override by this software, these are CC, CXX, CPP, AS, AR, LD, CFLAGS, CPPFLAGS, LDFLAGS, PKG_CONFIG_LIBDIR, PKG_CONFIG_PATH, ACLOCAL_PATH

ppkg formula scheme

a ppkg formula is a YAML format file which is used to config a ppkg package's meta-information including one sentence description, package version, installation instructions, etc.

a ppkg formula's filename suffix must be .yml

a ppkg formula'a filename prefix would be treated as the package name.

a ppkg formula'a filename prefix must match the regular expression partten ^[A-Za-z0-9+-._@]{1,50}$

a ppkg formula's file content only has one level mapping and shall has following KEY:

KEY required? overview
pkgtype optional indicates what type of this package. value shall be any one of exe, pie, lib, exe+lib.
To exe type package, ppkg would add --static -static options to LDFLAGS if --static install option is given.
To pie type package, it means that it doesn't support fully statically linking, it is supposed to be dynamically linked.
If this mapping is not present, ppkg will determine the package type by package name, if a package name starts/ends with lib, it would be recognized as type lib, otherwise, it would be recognized as type exe
summary required describe this package in one sentence.
license optional a space-separated list of SPDX license short identifiers
version optional the version of this package.
If this mapping is not present, it will be calculated from src-url, if src-url is also not present, it will be calculated from running time as format date +%Y.%m.%d
web-url optional the home webpage of this package.
If this mapping is not present, git-url must be present.
git-url optional the source code git repository.
If src-url is not present, this mapping must be present.
git-ref optional reference: https://git-scm.com/book/en/v2/Git-Internals-Git-References
example values: HEAD refs/heads/master refs/heads/main refs/tags/v1, default value is HEAD
git-sha optional the full git commit id, 40-byte hexadecimal string, if git-ref and git-sha both are present, git-sha takes precedence over git-ref
git-nth optional tell ppkg that how many depth commits would you like to be fetched. default is 1, this would save your time and storage. If you want to fetch all commits, set this to 0
src-url optional the source code download url of this package.
If value of this mapping ends with one of .zip .tar.xz .tar.gz .tar.lz .tar.bz2 .tgz .txz .tlz .tbz2 .crate, it will be uncompressed to $PACKAGE_WORKING_DIR/src when this package is installing, otherwise, it will be copied to $PACKAGE_WORKING_DIR/src
also support format like dir://DIR
src-uri optional the mirror of src-url.
src-sha optional the sha256sum of source code.
src-sha and src-url must appear together.
fix-url optional the patch file download url of this package.
If value of this mapping ends with one of .zip .tar.xz .tar.gz .tar.lz .tar.bz2 .tgz .txz .tlz .tbz2 .crate, it will be uncompressed to $PACKAGE_WORKING_DIR/fix when this package is installing, otherwise, it will be copied to $PACKAGE_WORKING_DIR/fix.
fix-uri optional the mirror of fix-url.
fix-sha optional the sha256sum of patch file.
fix-sha and fix-url must appear together.
fix-opt optional options to be passed to patch command. default value is -p1.
patches optional multiple lines of <fix-sha>\|<fix-url>[\|fix-uri][\|fix-opt].
res-url optional other resource download url of this package.
If value of this mapping ends with one of .zip .tar.xz .tar.gz .tar.lz .tar.bz2 .tgz .txz .tlz .tbz2 .crate, it will be uncompressed to $PACKAGE_WORKING_DIR/res when this package is installing, otherwise, it will be copied to $PACKAGE_WORKING_DIR/res.
res-uri optional the mirror of res-url.
res-sha optional the sha256sum of resource file.
res-sha and res-url must appear together.
reslist optional multiple lines of <res-sha>\|<res-url>[\|res-uri][\|unpack-dir][\|N]. unpack-dir is relative to $PACKAGE_WORKING_DIR/res, default value is empty. N is --strip-components=N
dep-pkg optional a space-separated list of ppkg packages that are depended by this package when installing and/or runtime, which will be installed via ppkg.
dep-lib optional a space-separated list of libraries that will be linked. library name starts with -l will be directly passed to the linker. otherwise, it will be recognized as a pkg-config package name and it will be calculated via pkg-config --libs-only-l then passed to the linker.
dep-upp optional a space-separated list of uppm packages that are depended by this package when installing and/or runtime, which will be installed via uppm.
dep-pym optional a space-separated list of python packages that are depended by this package when installing and/or runtime, which will be installed via pip3.
dep-plm optional a space-separated list of perl modules that are depended by this package when installing and/or runtime, which will be installed via cpan.
ccflags optional append to CFLAGS
xxflags optional append to CXXFLAGS
ppflags optional append to CPPFLAGS
ldflags optional append to LDFLAGS
bsystem optional build system name.
values can be one or a combination of autogen autotools configure cmake cmake+gmake cmake+ninja meson xmake gmake ninja cargo go rake
bscript optional the directory where the build script is located in, relative to PACKAGE_WORKING_DIR. build script such as configure, Makefile, CMakeLists.txt, meson.build, Cargo.toml, etc.
binbstd optional whether to build in the directory where the build script is located in, otherwise build in other directory.
value shall be 0 or 1. default value is 0.
movable optional whether can be moved/copied to other locations.
value shall be 0 or 1. default value is 1.
parallel optional whether to allow build system running jobs in parallel.
value shall be 0 or 1. default value is 1.
onstart optional POSIX shell code to be run when this package's formula is loaded.
PWD is $PACKAGE_WORKING_DIR
onready optional POSIX shell code to be run when this package's needed resources all are ready.
PWD is $PACKAGE_BSCRIPT_DIR
onfinal optional POSIX shell code to be run when this package is successfully installed.
PWD is $PACKAGE_INSTALL_DIR
do12345 optional POSIX shell code to be run for native build.
It is only meaningful when requesting for cross building.
It is running in a separated process.
dopatch optional POSIX shell code to be run to apply patches manually.
PWD is $PACKAGE_BSCRIPT_DIR
prepare optional POSIX shell code to be run to do some additional preparation.
PWD is $PACKAGE_BSCRIPT_DIR
install optional POSIX shell code to be run when user run ppkg install <PKG>. If this mapping is not present, ppkg will run default install code according to bsystem.
PWD is $PACKAGE_BSCRIPT_DIR if binbstd is 0, otherwise it is $PACKAGE_BCACHED_DIR
dotweak optional POSIX shell code to be run to do some tweaks immediately after installing.
PWD is $PACKAGE_INSTALL_DIR
caveats optional multiple lines of plain text to be displayed after installation.
phases
phases
build system name build script file name
meson meson.build
cmake CMakeLists.txt
gmake GNUMakefile or Makefile
ninja build.ninja
xmake xmake.lua
cargo Cargo.toml
go go.mod
rake Rakefile
autogen autogen.sh
autotools configure.ac
configure configure

commands that can be used out of the box:

command usage-example
bash Reference
CoreUtils Reference
xargs Reference
find Reference
gawk Reference
gsed Reference
grep Reference
tree Reference
jq Reference
yq Reference
d2 Reference
bat Reference
xxd Reference
git Reference
curl Reference
bsdtar Reference
pkg-config Reference
patchelf Reference
sysinfo Reference
echo echo 'your message.'
info info 'your information.'
warn warn "no package manager found."
error error 'error message.'
abort abort 1 "please specify a package name."
success success "build success."
isInteger isInteger $x \|\| abort 1 "should be an integer."
isCrossBuild isCrossBuild && abort 1 "This package is not supposed to be cross built."
wfetch wfetch <URL> [--uri=<URL-MIRROR>] [--sha256=<SHA256>] [-o <PATH> [-q]
configure configure --enable-pic
mesonw mesonw -Dneon=disabled -Darm-simd=disabled
cmakew cmakew -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON
gmakew gmakew
xmakew xmakew
cargow cargow
gow gow

shell variables can be used directly:

variable overview
PPKG_ARG0 the 1st arguments of ppkg that you've supplied.
PPKG_ARG1 the 2nd arguments of ppkg that you've supplied.
PPKG_ARGV the all arguments of ppkg that you've supplied.
PPKG_PATH the full path of ppkg that you're running.
PPKG_HOME the home directory of ppkg that you're running.
PPKG_VERSION the version of ppkg that you're running.
UPPM the executable filepath of uppm
TIMESTAMP_UNIX the unix timestamp of this action.
NATIVE_OS_KIND current running os kind. value shall be any one of linux darwin freebsd netbsd openbsd dragonflybsd
NATIVE_OS_TYPE current running os type. value shall be any one of linux macos freebsd netbsd openbsd dragonflybsd
NATIVE_OS_NAME current running os name. value might be any one of Debian GNU/Linux Ubuntu CentOS Fedora FreeBSD NetBSD OpenBSD, DragonFlyBSD, etc
NATIVE_OS_VERS current running os version.
NATIVE_OS_ARCH current running os arch. value might be any one of x86_64 amd64 arm64 aarch64, ppc64le, riscv64, s390x, etc
NATIVE_OS_NCPU current running os's cpu core count.
NATIVE_OS_LIBC current running os's libc name. value shall be any one of glibc and musl.
NATIVE_OS_EUID current running os's effective user ID.
NATIVE_OS_EGID current running os's effective group ID.
TARGET_PLATFORM_NAME target platform name that is built for. value shall be any one of linux macos freebsd netbsd openbsd dragonflybsd
TARGET_PLATFORM_VERS target platform version that is built with.
TARGET_PLATFORM_ARCH target platform arch that is built for. value might be any one of x86_64 amd64 arm64 aarch64, ppc64le, riscv64, s390x, etc
CROSS_COMPILING value shall be 0 or 1. indicates whether is cross-compiling.
CC the C Compiler.
CFLAGS the flags of CC.
CXX the C++ Compiler.
CXXFLAGS the flags of CXX.
CPP the C/C++ PreProcessor.
CPPFLAGS the flags of CPP.
AS the assembler.
AR the archiver.
RANLIB the archiver extra tool.
LD the linker.
LDFLAGS the flags of LD.
NM a command line tool to list symbols from object files.
STRIP a command line tool to discard symbols and other data from object files.
PACKAGE_WORKING_DIR the working directory when installing.
PACKAGE_BSCRIPT_DIR the directory where the build script (e.g. Makefile, configure, CMakeLists.txt, meson.build, Cargo.toml, etc) is located in.
PACKAGE_BCACHED_DIR the directory where the temporary files are stored in when building.
PACKAGE_INSTALL_DIR the directory where the final files will be installed to.
x_INSTALL_DIR the installation directory of x package.
x_INCLUDE_DIR $x_INSTALL_DIR/include
x_LIBRARY_DIR $x_INSTALL_DIR/lib

ppkg formula repository

a typical hierarchical structure of a ppkg formula repository looks like below:

PPKGFormulaRepoName
├── formula
│   ├── packageA.yml
│   └── packageB.yml
├── LICENSE
└── README.md

ppkg formula repository local location

${PPKG_HOME}/repos.d/${PPKGFormulaRepoName}

ppkg formula repository local config

a ppkg formula repository's config file is located at ${PPKG_HOME}/repos.d/${PPKGFormulaRepoName}/.ppkg-formula-repo.yml

a typical ppkg formula repository's config file content looks like below:

url: https://github.com/leleliu008/ppkg-formula-repository-official-core
branch: master
pinned: 0
enabled: 1
created: 1673684639
updated: 1673684767

If a ppkg formula repository is pinned, which means it would not be updated.

If a ppkg formula repository is disabled, which means ppkg would not search formulas in this formula repository.

ppkg formula repository management

run ppkg formula-repo-add command to create a new formula repository locally from an exsting remote git repository.

run ppkg formula-repo-init command to create a new formula repository locally without taking any further action.

ppkg official formula repository

ppkg official formula repository is hosted at https://github.com/leleliu008/ppkg-formula-repository-official-core

It would be automatically fetched to your local repository as name official-core when you run ppkg update command.

Note: If you find that a package is not in ppkg official formula repository yet, PR is welcomed.

prebuild packages built by this software