From f8cc093e17b28c6abc8e6f3535b1a17e12487275 Mon Sep 17 00:00:00 2001 From: apio Date: Thu, 4 Jan 2024 21:04:58 +0100 Subject: [PATCH] tools: Add useful script to develop ports --- .gitignore | 1 + tools/make-package.sh | 167 ++++++++++++++++++++++------------------ tools/package-helper.sh | 95 +++++++++++++++++++++++ 3 files changed, 187 insertions(+), 76 deletions(-) create mode 100755 tools/package-helper.sh diff --git a/.gitignore b/.gitignore index ef246df0..e1b23b33 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ base/etc/skel/LICENSE kernel/config.cmake ports/out/ ports/temp/ +ports/dev/ diff --git a/tools/make-package.sh b/tools/make-package.sh index 96a8c1c0..90823eaa 100755 --- a/tools/make-package.sh +++ b/tools/make-package.sh @@ -13,7 +13,7 @@ then exit 1 fi -export WORKDIR=$LUNA_ROOT/ports/temp/ +export WORKDIR=${WORKDIR:-$LUNA_ROOT/ports/temp} show_error() { @@ -28,11 +28,13 @@ source ports/$PORT_NAME/PACKAGE [ -z ${format+x} ] && show_error "error: The port's PACKAGE file does not have a 'format' key." [ -z ${url+x} ] && show_error "error: The port's PACKAGE file does not have a 'url' key." -if ! [ -z ${dependencies+x} ]; then - echo "Installing dependencies of $name: (${dependencies[@]})" - for dep in ${dependencies[@]}; do - tools/install-package.sh $dep - done +if [ -x ${skip_dependencies+x} ]; then + if ! [ -z ${dependencies+x} ]; then + echo "Installing dependencies of $name: (${dependencies[@]})" + for dep in ${dependencies[@]}; do + tools/install-package.sh $dep + done + fi fi export portdir=$LUNA_ROOT/ports/$name/ @@ -43,37 +45,39 @@ export installdir=$WORKDIR/pkgroot-$name mkdir -p $WORKDIR cd $WORKDIR -# Download package sources -case $format in - tar) - [ -z ${output+x} ] && show_error "error: The 'tar' download format needs an 'output' key." - [ -z ${sha256sum+x} ] && show_error "error: The 'tar' download format needs a 'sha256sum' key." - if ! [ -f $output ]; then - echo "Downloading tarball for $name..." - wget $url --quiet - else - echo "Using cached tarball for $name." - fi - echo "$sha256sum $output" | sha256sum -c - tar xf $output - ;; - git) - if ! [ -d $srcdir ]; then - echo "Cloning repository for $name..." - git clone $url $srcdir - else - echo "Using local repository for $name." - fi - if ! [ -z ${tag+x} ]; then - cd $srcdir - git checkout $tag - cd - - fi - ;; - *) - show_error "error: Unrecognized 'format' key in PACKAGE file: '$format'" - ;; -esac +if [ -z ${skip_download_sources+x} ]; then + # Download package sources + case $format in + tar) + [ -z ${output+x} ] && show_error "error: The 'tar' download format needs an 'output' key." + [ -z ${sha256sum+x} ] && show_error "error: The 'tar' download format needs a 'sha256sum' key." + if ! [ -f $output ]; then + echo "Downloading tarball for $name..." + wget $url --quiet + else + echo "Using cached tarball for $name." + fi + echo "$sha256sum $output" | sha256sum -c + tar xf $output + ;; + git) + if ! [ -d $srcdir ]; then + echo "Cloning repository for $name..." + git clone $url $srcdir + else + echo "Using local repository for $name." + fi + if ! [ -z ${tag+x} ]; then + cd $srcdir + git checkout $tag + cd - + fi + ;; + *) + show_error "error: Unrecognized 'format' key in PACKAGE file: '$format'" + ;; + esac +fi if ! [ "$set_cc_variables" = "no" ]; then export CC=x86_64-luna-gcc @@ -89,54 +93,65 @@ fi mkdir -p $builddir cd $builddir -declare -F do_patch &>/dev/null && do_patch - -echo "Configuring $name..." - -if [ "$use_default_configure" = "true" ]; then - $srcdir/configure --host=$LUNA_ARCH-luna --prefix=/usr -elif [ "$use_cmake_configure" = "true" ]; then - cmake -S $srcdir -B . -DCMAKE_C_COMPILER=$LUNA_ARCH-luna-gcc -DCMAKE_CXX_COMPILER=$LUNA_ARCH-luna-g++ -G "Unix Makefiles" -else - declare -F do_configure &>/dev/null || show_error "error: If not using a default configure line, the PACKAGE file must provide a 'do_configure' function." - do_configure +if [ -z ${skip_patch+x} ]; then + declare -F do_patch &>/dev/null && do_patch fi -echo "Building $name..." +if [ -z ${skip_configure+x} ]; then + echo "Configuring $name..." -export MAKEJOBS=$(nproc) - -if [ "$default_build_make" = "true" ]; then - make -j$MAKEJOBS -elif [ "$default_build_cmake" = "true" ]; then - cmake --build . -else - declare -F do_build &>/dev/null || show_error "error: If not using a default build preset, the PACKAGE file must provide a 'do_build' function." - do_build + if [ "$use_default_configure" = "true" ]; then + $srcdir/configure --host=$LUNA_ARCH-luna --prefix=/usr + elif [ "$use_cmake_configure" = "true" ]; then + cmake -S $srcdir -B . -DCMAKE_C_COMPILER=$LUNA_ARCH-luna-gcc -DCMAKE_CXX_COMPILER=$LUNA_ARCH-luna-g++ -G "Unix Makefiles" + else + declare -F do_configure &>/dev/null || show_error "error: If not using a default configure line, the PACKAGE file must provide a 'do_configure' function." + do_configure + fi fi -echo "Installing $name..." +if [ -z ${skip_build+x} ]; then + echo "Building $name..." -mkdir -p $installdir -export DESTDIR=$installdir + export MAKEJOBS=$(nproc) -if [ "$default_install_make" = "true" ]; then - make install -elif [ "$default_install_cmake" = "true" ]; then - cmake --install $builddir --prefix /usr -else - declare -F do_install &>/dev/null || show_error "error: If not using a default install preset, the PACKAGE file must provide a 'do_install' function." - do_install + if [ "$default_build_make" = "true" ]; then + make -j$MAKEJOBS + elif [ "$default_build_cmake" = "true" ]; then + cmake --build . + else + declare -F do_build &>/dev/null || show_error "error: If not using a default build preset, the PACKAGE file must provide a 'do_build' function." + do_build + fi fi -rm -f $installdir/usr/lib/*.la # remove all libtool .la files, as they use host stuff which we don't want at all -set +e -$LUNA_ARCH-luna-strip $installdir/usr/bin/* # strip all binaries -set -e +if [ -z ${skip_install+x} ]; then + echo "Installing $name..." -cd $installdir + rm -rf $installdir # clean it if it already existed + mkdir -p $installdir + export DESTDIR=$installdir -tar czf $LUNA_ROOT/ports/out/$name-$version.tar.gz * + if [ "$default_install_make" = "true" ]; then + make install + elif [ "$default_install_cmake" = "true" ]; then + cmake --install $builddir --prefix /usr + else + declare -F do_install &>/dev/null || show_error "error: If not using a default install preset, the PACKAGE file must provide a 'do_install' function." + do_install + fi -cd $LUNA_ROOT -rm -rf $WORKDIR + rm -f $installdir/usr/lib/*.la # remove all libtool .la files, as they use host stuff which we don't want at all + set +e + $LUNA_ARCH-luna-strip $installdir/usr/bin/* # strip all binaries + set -e + + cd $installdir + + tar czf $LUNA_ROOT/ports/out/$name-$version.tar.gz * +fi + +if [ -z ${preserve_workdir+x} ]; then + cd $LUNA_ROOT + rm -rf $WORKDIR +fi diff --git a/tools/package-helper.sh b/tools/package-helper.sh new file mode 100755 index 00000000..8107e2ab --- /dev/null +++ b/tools/package-helper.sh @@ -0,0 +1,95 @@ +#!/usr/bin/env bash +set -e + +source $(dirname $0)/env.sh + +cd $LUNA_ROOT + +SUBCOMMAND=$1 +PORT_NAME=$2 + +if [ "$SUBCOMMAND" = "help" ]; then + echo "TODO: add help" + exit 1 +fi + +if ! [ -f ports/$PORT_NAME/PACKAGE ] +then + echo "Package $PORT_NAME does not exist. Make sure there is a valid PACKAGE file in the appropriate directory!" + exit 1 +fi + +source ports/$PORT_NAME/PACKAGE + +export preserve_workdir=1 +export WORKDIR=$LUNA_ROOT/ports/dev + +case $SUBCOMMAND in + download) + export skip_configure=1 + export skip_build=1 + export skip_install=1 + export skip_dependencies=1 + export skip_patch=1 + + tools/make-package.sh $PORT_NAME + + if [ "$format" = "tar" ]; then + cd ${srcdir:-$WORKDIR/$name-$version} + git init + git add . + git commit -m "Temporary development git repository for diffs." + cd $LUNA_ROOT + fi + + echo "Created dev source tree in ${srcdir:-$WORKDIR/$name-$version}." + ;; + setup-dependencies) + export skip_download_sources=1 + export skip_build=1 + export skip_install=1 + export skip_configure=1 + export skip_patch=1 + + tools/make-package.sh $PORT_NAME + ;; + patch) + export skip_download_sources=1 + export skip_build=1 + export skip_install=1 + export skip_configure=1 + export skip_dependencies=1 + + tools/make-package.sh $PORT_NAME + ;; + configure) + export skip_download_sources=1 + export skip_build=1 + export skip_install=1 + export skip_dependencies=1 + export skip_patch=1 + + tools/make-package.sh $PORT_NAME + ;; + compile) + export skip_download_sources=1 + export skip_configure=1 + export skip_dependencies=1 + export skip_patch=1 + + tools/make-package.sh $PORT_NAME + + echo "Packaged dev build as $LUNA_ROOT/ports/out/$name-$version.tar.gz. Install it using tools/install-package.sh." + ;; + generate-diff) + cd ${srcdir:-$WORKDIR/$name-$version} + git diff > $LUNA_ROOT/ports/$name/$name.patch + echo "Created $LUNA_ROOT/ports/$name/$name.patch. Remember to add patching code to the PACKAGE file!" + ;; + cleanup) + rm -rfv $WORKDIR/*$name* + ;; + *) + echo "No such subcommand. Run 'tools/package-helper.sh help $name' for help." + ;; +esac