From eb1c56744ae788320a3a510f042671e765bcfcf0 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Sat, 13 Mar 2021 04:02:23 +0100 Subject: [PATCH] Add scripts to create packages, working splits. Needs grooming. --- bin/create-manifest | 13 +++++++++++ bin/create-meta | 20 +++++++++++++++++ bin/create-package | 10 +++++++++ bin/create-split-dev | 11 ++++++++++ bin/create-split-doc | 10 +++++++++ bin/create-split-libs | 9 ++++++++ bin/create-split-man | 10 +++++++++ bin/create-split-src | 10 +++++++++ bin/create-split.subr | 31 +++++++++++++++++++++++++++ package.mk | 50 +++++++++++++++++++++++++++---------------- 10 files changed, 156 insertions(+), 18 deletions(-) create mode 100755 bin/create-manifest create mode 100755 bin/create-meta create mode 100755 bin/create-package create mode 100755 bin/create-split-dev create mode 100755 bin/create-split-doc create mode 100755 bin/create-split-libs create mode 100755 bin/create-split-man create mode 100755 bin/create-split-src create mode 100644 bin/create-split.subr diff --git a/bin/create-manifest b/bin/create-manifest new file mode 100755 index 0000000..bd30b04 --- /dev/null +++ b/bin/create-manifest @@ -0,0 +1,13 @@ +#!/bin/sh + +find . | while read F ; do + if [ -f $F ]; then + sum=$(sha256sum $F | cut -d ' ' -f 1) + echo "f:$F:$sum" + elif [ -d $F ]; then + echo "d:$F" + else + # Don't know the type, could be a problem + exit 1 + fi +done diff --git a/bin/create-meta b/bin/create-meta new file mode 100755 index 0000000..a31e262 --- /dev/null +++ b/bin/create-meta @@ -0,0 +1,20 @@ +#!/bin/sh + +du_sk=`du -sk . | sed "s/[ \t].*//g"` +size=$(echo "$du_sk * 1024" | bc) + +cat < package-manifest +create-meta > package-info +tar cvf $package package-manifest package-info data.tar.zst diff --git a/bin/create-split-dev b/bin/create-split-dev new file mode 100755 index 0000000..4cbf9a8 --- /dev/null +++ b/bin/create-split-dev @@ -0,0 +1,11 @@ +#!/bin/sh + +. $(dirname $(which create-split-dev))/create-split.subr + +# Usage: create-split-dev + +# dev split package targets developers content, which means +# - /include/ and /pkgconfig/ directories +# - .h and .hpp files + +create_split ${pkg_fake_root_dev_dir} "(/pkgconfig|/include|\.h|\.hpp)$" diff --git a/bin/create-split-doc b/bin/create-split-doc new file mode 100755 index 0000000..153f194 --- /dev/null +++ b/bin/create-split-doc @@ -0,0 +1,10 @@ +#!/bin/sh + +. $(dirname $(which create-split-man))/create-split.subr + +# Usage: create-split-doc + +# For documentation, move any file or directory matching: +# - "/share/doc" + +create_split ${pkg_fake_root_doc_dir} "/share/doc/" diff --git a/bin/create-split-libs b/bin/create-split-libs new file mode 100755 index 0000000..c759775 --- /dev/null +++ b/bin/create-split-libs @@ -0,0 +1,9 @@ +#!/bin/sh + +. $(dirname $(which create-split-man))/create-split.subr + +# Usage: create-split-libs + +# For library split, move .a files (static libraries). + +create_split ${pkg_fake_root_libs_dir} "\.a$" diff --git a/bin/create-split-man b/bin/create-split-man new file mode 100755 index 0000000..b78a21a --- /dev/null +++ b/bin/create-split-man @@ -0,0 +1,10 @@ +#!/bin/sh + +. $(dirname $(which create-split-man))/create-split.subr + +# Usage: create-split-man + +# For manuals, move any file or directory matching +# "/share/man" + +create_split ${pkg_fake_root_man_dir} "/share/man" diff --git a/bin/create-split-src b/bin/create-split-src new file mode 100755 index 0000000..f25d4a6 --- /dev/null +++ b/bin/create-split-src @@ -0,0 +1,10 @@ +#!/bin/sh + +# Usage: create-split-src + +# Currently in ${pkg_fake_root_dir} +# Should send files in ${pkg_fake_root_src_dir} + +# First, list files +find . | while read F; do +done diff --git a/bin/create-split.subr b/bin/create-split.subr new file mode 100644 index 0000000..0ce6d6a --- /dev/null +++ b/bin/create-split.subr @@ -0,0 +1,31 @@ +#!/bin/sh + +move_content(){ + new_root=$1 + content=$2 + + # Recreate the whole path into the new directory. + new_dir="${new_root}/$(dirname $content)" + [ -d "${new_dir}" ] || ( + echo mkdir -p "${new_dir}" + mkdir -p "${new_dir}" + ) + mv -v "${content}" "${new_dir}" +} + +# usage: create_split new_root regex [regex...] +create_split(){ + new_root=$1 ; shift + + find . | while read F; do + if [ -e "${F}" ]; then + for regex in $* ; do + echo $F | grep -E "${regex}" >/dev/null 2>/dev/null + if [ $? -eq 0 ] ; then + move_content "${new_root}" "${F}" + fi + : # Do not end the function with a potential error. + done + fi + done +} diff --git a/package.mk b/package.mk index 4bde9af..d261b14 100644 --- a/package.mk +++ b/package.mk @@ -65,7 +65,7 @@ pkg_build_par_dir = $(pkg_working_dir)/build/ pkg_build_dir = $(pkg_build_par_dir)/$(name)-$(version) pkg_fake_root_dir = $(pkg_working_dir)/root -pkg_working_log = $(WORKING_DIR)/$(UUID).log +log_file = $(WORKING_DIR)/$(UUID).log # shortcut bdir ?= $(pkg_build_dir) @@ -84,7 +84,7 @@ download_tool ?= wget # pre_configure pre_build pre_fake_root_install post_fake_root_install: - @echo $@ => do nothing + @echo "$@ => do nothing" # # Misc @@ -96,8 +96,9 @@ create_source_dir: create_build_dir: mkdir -p $(pkg_build_par_dir) mkdir -p $(pkg_fake_root_dir) +create_repository_dir: + mkdir -p $(repository_directory)/$(ARCH) -# TODO: use these targets # Clean directories clean_build_dir: $(keep_build_env) || rm -rf $(pkg_build_par_dir) @@ -212,40 +213,50 @@ package_base = $(repository_directory)/$(ARCH)/$(name)-$(version)-r$(release).$( package_base: $(package_base) $(package_base): @echo "Packaging $@" + @# strip binaries + cd $(pkg_fake_root_dir) && find . -type f | while read F ; do strip $F 2>/dev/null ; done ; : cd $(pkg_fake_root_dir) && create-package $@ -pkg_fake_root_src_dir = $(pkg_fake_root_dir)-src -pkg_fake_root_man_dir = $(pkg_fake_root_dir)-man -pkg_fake_root_dev_dir = $(pkg_fake_root_dir)-dev -pkg_fake_root_doc_dir = $(pkg_fake_root_dir)-doc +export pkg_fake_root_src_dir = $(pkg_fake_root_dir)-src +export pkg_fake_root_doc_dir = $(pkg_fake_root_dir)-doc +export pkg_fake_root_man_dir = $(pkg_fake_root_dir)-man +export pkg_fake_root_dev_dir = $(pkg_fake_root_dir)-dev +export pkg_fake_root_libs_dir = $(pkg_fake_root_dir)-libs -# src split package_src = $(repository_directory)/$(ARCH)/$(name)-src-$(version)-r$(release).$(baguette_ext) package_src: $(package_src) $(package_src): - @echo "Packaging $@" - cd $(pkg_fake_root_src_dir) && dependencies="" conflicts="" provides="" create-package $@ + @echo "Packaging $@ (work in progress)" + @#cd $(pkg_fake_root_dir) && create-split-src + @#cd $(pkg_fake_root_src_dir) && dependencies="" conflicts="" provides="" create-package $@ -# doc split package_doc = $(repository_directory)/$(ARCH)/$(name)-doc-$(version)-r$(release).$(baguette_ext) package_doc: $(package_doc) $(package_doc): @echo "Packaging $@" - cd $(pkg_fake_root_src_dir) && dependencies="" conflicts="" provides="" create-package $@ + cd $(pkg_fake_root_dir) && create-split-doc + cd $(pkg_fake_root_doc_dir) && dependencies="" conflicts="" provides="" create-package $@ -# man split package_man = $(repository_directory)/$(ARCH)/$(name)-man-$(version)-r$(release).$(baguette_ext) package_man: $(package_man) $(package_man): @echo "Packaging $@" - cd $(pkg_fake_root_src_dir) && dependencies="" conflicts="" provides="" create-package $@ + cd $(pkg_fake_root_dir) && create-split-man + cd $(pkg_fake_root_man_dir) && dependencies="" conflicts="" provides="" create-package $@ -# dev split package_dev = $(repository_directory)/$(ARCH)/$(name)-dev-$(version)-r$(release).$(baguette_ext) package_dev: $(package_dev) $(package_dev): @echo "Packaging $@" - cd $(pkg_fake_root_src_dir) && dependencies="" conflicts="" provides="" create-package $@ + cd $(pkg_fake_root_dir) && create-split-dev + cd $(pkg_fake_root_dev_dir) && dependencies="" conflicts="" provides="" create-package $@ + +package_libs = $(repository_directory)/$(ARCH)/$(name)-libs-$(version)-r$(release).$(baguette_ext) +package_libs: $(package_libs) +$(package_libs): + @echo "Packaging $@" + cd $(pkg_fake_root_dir) && create-split-libs + cd $(pkg_fake_root_libs_dir) && dependencies="" conflicts="" provides="" create-package $@ check_binaries_wget_or_ftp: @@ -256,9 +267,12 @@ check_binaries_zip: @which unzip check_binaries: check_binaries_wget_or_ftp check_binaries_tar check_binaries_zip -splits: package_src package_doc package_man package_dev package_base +splits: package_src package_doc package_man package_dev package_libs +# The main package is the last to be created since it includes +# all content that wasn't matched by splits. +packages: create_repository_dir splits package_base getting-build-env: check_binaries download extract -create: getting-build-env configure build fake_root_install splits clean_working_dir +create: getting-build-env configure build fake_root_install packages clean_working_dir # Targets not representing a file on the FS.