From 122f81c5bc23ee3636cf123857826c4d14ec31e1 Mon Sep 17 00:00:00 2001 From: Michał Łyszczek Date: Thu, 15 Nov 2018 10:18:04 +0100 Subject: pkg: add scipts to create packages for various systems --- pkg/deb/changelog.template | 5 ++ pkg/deb/compat | 1 + pkg/deb/control.template | 28 ++++++++ pkg/deb/copyright | 34 ++++++++++ pkg/deb/create-pkg.sh | 138 ++++++++++++++++++++++++++++++++++++++++ pkg/deb/libembedlog-dev.install | 4 ++ pkg/deb/libembedlog0.install | 1 + pkg/deb/rules | 8 +++ pkg/deb/source/format | 1 + pkg/rpm/create-pkg.sh | 114 +++++++++++++++++++++++++++++++++ pkg/rpm/embedlog.spec.template | 68 ++++++++++++++++++++ pkg/test.c | 20 ++++++ pkg/tgz/create-pkg.sh | 81 +++++++++++++++++++++++ 13 files changed, 503 insertions(+) create mode 100644 pkg/deb/changelog.template create mode 100644 pkg/deb/compat create mode 100644 pkg/deb/control.template create mode 100644 pkg/deb/copyright create mode 100755 pkg/deb/create-pkg.sh create mode 100644 pkg/deb/libembedlog-dev.install create mode 100644 pkg/deb/libembedlog0.install create mode 100755 pkg/deb/rules create mode 100644 pkg/deb/source/format create mode 100644 pkg/rpm/create-pkg.sh create mode 100644 pkg/rpm/embedlog.spec.template create mode 100644 pkg/test.c create mode 100755 pkg/tgz/create-pkg.sh diff --git a/pkg/deb/changelog.template b/pkg/deb/changelog.template new file mode 100644 index 0000000..b45f90c --- /dev/null +++ b/pkg/deb/changelog.template @@ -0,0 +1,5 @@ +libembedlog (@{VERSION}) @{CODENAME}; urgency=low + + * embedlog package + + -- Michał Łyszczek @{DATE} diff --git a/pkg/deb/compat b/pkg/deb/compat new file mode 100644 index 0000000..f599e28 --- /dev/null +++ b/pkg/deb/compat @@ -0,0 +1 @@ +10 diff --git a/pkg/deb/control.template b/pkg/deb/control.template new file mode 100644 index 0000000..9bf9bb2 --- /dev/null +++ b/pkg/deb/control.template @@ -0,0 +1,28 @@ +Source: libembedlog +Section: devel +Priority: optional +Maintainer: Michał Łyszczek +Build-Depends: debhelper (>=10), autotools-dev, dh-autoreconf +Standards-Version: 3.9.8 +Vcs-Git: https://git.kurwinet.pl/embedlog +Vcs-browser: https://git.kurwinet.pl/embedlog +Homepage: https://embedlog.kurwinet.pl + +Package: libembedlog@{ABI_VERSION} +Section: libs +Pre-Depends: ${misc:Pre-Depends} +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: embedlog is a highly portable c89 complaint logger (with + additional features for users with c99 compilers and/or POSIX systems). + This library is designed mainly for embedded devices, but can also be + used in high level OSes like Linux. + +Package: libembedlog-dev +Section: libdevel +Depends: libembedlog@{ABI_VERSION} (= ${binary:Version}), ${misc:Depends} +Architecture: any +Description: embedlog is a highly portable c89 complaint logger (with + additional features for users with c99 compilers and/or POSIX systems). + This library is designed mainly for embedded devices, but can also be + used in high level OSes like Linux. diff --git a/pkg/deb/copyright b/pkg/deb/copyright new file mode 100644 index 0000000..41332aa --- /dev/null +++ b/pkg/deb/copyright @@ -0,0 +1,34 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: embedlog +Source: https://git.kurwinet.pl/embedlog + +Files: * +Copyright: 2017, 2018 Michał Łyszczek +License: BSD-2-Clause + +Files: debian/* +Copyright: 2018 Michał Łyszczek +License: BSD-2-Clause + +License: BSD-2-Clause + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + . + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + . + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + . + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. diff --git a/pkg/deb/create-pkg.sh b/pkg/deb/create-pkg.sh new file mode 100755 index 0000000..bebf5d9 --- /dev/null +++ b/pkg/deb/create-pkg.sh @@ -0,0 +1,138 @@ +#!/bin/sh + +scp_server="pkgs@kurwik" +project="embedlog" + +if [ ${#} -ne 3 ] +then + echo "usage: ${0} " + echo "" + echo "where:" + echo " git tag version to build (without prefix v)" + echo " target architecture" + echo " target os (debian9, debian8 etc)" + echo "" + echo "example" + echo " ${0} 1.0.0 i386 debian9" + exit 1 +fi + +version="${1}" +arch="${2}" +host_os="${3}" + +### +# preparing +# + +rm -rf "/tmp/${project}-${version}" +mkdir "/tmp/${project}-${version}" + +cd "/tmp/${project}-${version}" +git clone "https://git.kurwinet.pl/${project}" +cd "${project}" + +git checkout "${version}" || exit 1 + +if [ ! -d "pkg/deb" ] +then + echo "pkg/deb does not exist, cannot create debian pkg" + exit 1 +fi + +version="$(grep "AC_INIT(" "configure.ac" | cut -f3 -d\[ | cut -f1 -d\])" +abi_version="$(echo ${version} | cut -f1 -d.)" + +echo "version ${version}" +echo "abi version ${abi_version}" + +### +# building package +# + +codename="$(lsb_release -c | awk '{print $2}')" + +cp -r "pkg/deb/" "debian" +sed -i "s/@{DATE}/$(date -R)/" "debian/changelog.template" +sed -i "s/@{VERSION}/${version}/" "debian/changelog.template" +sed -i "s/@{CODENAME}/${codename}/" "debian/changelog.template" +sed -i "s/@{ABI_VERSION}/${abi_version}/" "debian/control.template" + +mv "debian/changelog.template" "debian/changelog" +mv "debian/control.template" "debian/control" + +export CFLAGS="-I/usr/bofc/include" +export LDFLAGS="-L/usr/bofc/lib" +debuild -us -uc || exit 1 + +# unsed, so it these don't pollute gcc, when we built test program +unset CFLAGS +unset LDFLAGS + +### +# verifying +# + +cd .. + +# debuild doesn't fail when lintial finds an error, so we need +# to check it manually, it doesn't take much time, so whatever + +for d in *.deb +do + echo "Running lintian on ${d}" + lintian ${d} || exit 1 +done + +dpkg -i "lib${project}${abi_version}_${version}_${arch}.deb" || exit 1 +dpkg -i "lib${project}-dev_${version}_${arch}.deb" || exit 1 + +failed=0 +gcc ${project}/pkg/test.c -o testprog -lembedlog || failed=1 + +if ldd ./testprog | grep "\/usr\/bofc" +then + # sanity check to make sure test program uses system libraries + # and not locally installed ones (which are used as build + # dependencies for other programs + + echo "test prog uses libs from manually installed /usr/bofc \ + instead of system path!" + failed=1 +fi + +./testprog || failed=1 + +dpkg -r "lib${project}${abi_version}" "lib${project}-dev" || exit 1 + +# run test prog again, but now fail if there is no error, testprog +# should fail as there is no library in te system any more +./testprog && failed=1 + +if [ ${failed} -eq 1 ] +then + exit 1 +fi + +if [ -n "${scp_server}" ] +then + dbgsym_pkg="lib${project}${abi_version}-dbgsym_${version}_${arch}.deb" + + if [ ! -f "${dbgsym_pkg}" ] + then + # on some systems packages with debug symbols are created with + # ddeb extension and not deb + dbgsym_pkg="lib${project}${abi_version}-dbgsym_${version}_${arch}.ddeb" + fi + + echo "copying data to ${scp_server}:${project}/${host_os}/${arch}" + scp "lib${project}-dev_${version}_${arch}.deb" \ + "${dbgsym_pkg}" \ + "lib${project}${abi_version}_${version}_${arch}.deb" \ + "lib${project}_${version}.dsc" \ + "lib${project}_${version}.tar.xz" \ + "lib${project}_${version}_${arch}.build" \ + "lib${project}_${version}_${arch}.buildinfo" \ + "lib${project}_${version}_${arch}.changes" \ + "${scp_server}:${project}/${host_os}/${arch}" || exit 1 +fi diff --git a/pkg/deb/libembedlog-dev.install b/pkg/deb/libembedlog-dev.install new file mode 100644 index 0000000..55cf121 --- /dev/null +++ b/pkg/deb/libembedlog-dev.install @@ -0,0 +1,4 @@ +usr/lib/*/*.so +usr/include/embedlog.h +usr/share/man/man3/* +usr/share/man/man7/* diff --git a/pkg/deb/libembedlog0.install b/pkg/deb/libembedlog0.install new file mode 100644 index 0000000..3de3b10 --- /dev/null +++ b/pkg/deb/libembedlog0.install @@ -0,0 +1 @@ +usr/lib/*/*.so.* diff --git a/pkg/deb/rules b/pkg/deb/rules new file mode 100755 index 0000000..222d161 --- /dev/null +++ b/pkg/deb/rules @@ -0,0 +1,8 @@ +#!/usr/bin/make -f +export DH_VERBOSE = 1 + +%: + dh $@ --list-missing --with autoreconf + +override_dh_auto_test: + $(MAKE) check diff --git a/pkg/deb/source/format b/pkg/deb/source/format new file mode 100644 index 0000000..89ae9db --- /dev/null +++ b/pkg/deb/source/format @@ -0,0 +1 @@ +3.0 (native) diff --git a/pkg/rpm/create-pkg.sh b/pkg/rpm/create-pkg.sh new file mode 100644 index 0000000..8f74cf6 --- /dev/null +++ b/pkg/rpm/create-pkg.sh @@ -0,0 +1,114 @@ +#!/bin/sh + +project="embedlog" +scp_server="pkgs@kurwik" + +if [ ${#} -ne 3 ] +then + echo "usage: ${0} " + echo "" + echo "where" + echo " git tag version" + echo " target architecture" + echo " target os (rhel-7, centos-7 etc)" + exit 1 +fi + +git_version="${1}" +arch="${2}" +host_os="${3}" + +cd "${HOME}/rpmbuild" +pkg_version="$(curl "https://git.kurwinet.pl/${project}/plain/configure.ac?h=${git_version}" | \ + grep "AC_INIT(" | cut -f3 -d\[ | cut -f1 -d\])" +wget "https://git.kurwinet.pl/${project}/snapshot/${project}-${git_version}.tar.gz" \ + -O "SOURCES/${project}-${pkg_version}.tar.gz" +wget "https://git.kurwinet.pl/${project}/plain/pkg/rpm/${project}.spec.template?h=${git_version}" \ + -O "SPECS/${project}-${pkg_version}.spec" +lt_version="$(curl "https://git.kurwinet.pl/${project}/plain/src/Makefile.am?h=${git_version}" | \ + grep "${project}_la_LDFLAGS = -version-info" | cut -f4 -d\ )" + +current="$(echo ${lt_version} | cut -f1 -d:)" +revision="$(echo ${lt_version} | cut -f2 -d:)" +age="$(echo ${lt_version} | cut -f3 -d:)" + +lib_version="$(( current - age )).${age}.${revision}" +abi_version="$(( current - age ))" +rel_version="$(cat SPECS/${project}-${pkg_version}.spec | \ + grep "Release:" | awk '{print $2}')" + +sed -i "s/@{VERSION}/${pkg_version}/" SPECS/${project}-${pkg_version}.spec +sed -i "s/@{GIT_VERSION}/${git_version}/" SPECS/${project}-${pkg_version}.spec +sed -i "s/@{LIB_VERSION}/${lib_version}/" SPECS/${project}-${pkg_version}.spec +sed -i "s/@{ABI_VERSION}/${abi_version}/" SPECS/${project}-${pkg_version}.spec + + +if cat /etc/os-release | grep "openSUSE Leap" +then + # opensuse doesn't generate debug symbols by defaul, check spec file + # for comment + sed -i 's/# __DEBUG_PACKAGE__/%debug_package/' \ + SPECS/${project}-${pkg_version}.spec +fi + +rpmbuild -ba SPECS/${project}-${pkg_version}.spec || exit 1 + +### +# verify +# + +if type zypper >/dev/null +then + # looks like we are dealing with opensuse + + zypper install -y --allow-unsigned-rpm \ + "RPMS/${arch}/${project}-${pkg_version}-${rel_version}.${arch}.rpm" \ + "RPMS/${arch}/${project}-devel-${pkg_version}-${rel_version}.${arch}.rpm" +else + # else, assume rhel or centos or fedora or whatever that uses yum + + yum -y install \ + "RPMS/${arch}/${project}-${pkg_version}-${rel_version}.${arch}.rpm" \ + "RPMS/${arch}/${project}-devel-${pkg_version}-${rel_version}.${arch}.rpm" +fi + +failure=0 +gcc "BUILD/${project}-${git_version}/pkg/test.c" -lembedlog -o /tmp/${project}-test || failure=1 + +if ldd /tmp/${project}-test | grep "\/usr\/bofc" +then + # sanity check to make sure test program uses system libraries + # and not locally installed ones (which are used as build + # dependencies for other programs + + echo "test prog uses libs from manually installed /usr/bofc \ + instead of system path!" + failed=1 +fi + +/tmp/${project}-test || failure=1 + +if type zypper >/dev/null +then + zypper remove -y "${project}" "${project}-devel" +else + yum -y remove "${project}" "${project}-devel" +fi + +# run test prog again, but now fail if there is no error, testprog +# should fail as there is no library in te system any more +/tmp/${project}-test && failed=1 + +if [ ${failure} -eq 1 ] +then + exit 1 +fi + +if [ -n "${scp_server}" ] +then + echo "copying data to ${scp_server}:${project}/${host_os}/${arch}" + scp "RPMS/${arch}/${project}-${pkg_version}-${rel_version}.${arch}.rpm" \ + "RPMS/${arch}/${project}-devel-${pkg_version}-${rel_version}.${arch}.rpm" \ + "RPMS/${arch}/${project}-debuginfo-${pkg_version}-${rel_version}.${arch}.rpm" \ + "${scp_server}:${project}/${host_os}/${arch}" || exit 1 +fi diff --git a/pkg/rpm/embedlog.spec.template b/pkg/rpm/embedlog.spec.template new file mode 100644 index 0000000..15da905 --- /dev/null +++ b/pkg/rpm/embedlog.spec.template @@ -0,0 +1,68 @@ +Name: embedlog +Version: @{VERSION} +Release: 1 +Summary: highly portable c89 complaint logger + +Group: System Environment/Libraries +License: BSD +URL: https://embedlog.kurwinet.pl +Source0: https://git.kurwinet.pl/embedlog/snapshot/embedlog-%{version}.tar.gz +Vendor: Bits of Code +Packager: Michał Łyszczek + +BuildRequires: automake autoconf libtool + +%description +embedlog is a highly portable c89 complaint logger (with +additional features for users with c99 compilers and/or POSIX systems). +This library is designed mainly for embedded devices, but can also be +used in high level OSes like Linux. + +%package devel +Summary: embedlog development package +Group: Development/Libraries +Requires: %{name} = %{version}-%{release} + +%description devel +embedlog development package containing headers and manuals + +%prep +%setup -q -n embedlog-@{GIT_VERSION} + +# debug packge macro, it is commented by default as rhel and centos +# automatically build debug package, but open suse does not. Change it to +# "@debug_package" (just change that @ to percent %% character) +# when debug symbols are not automatically installed + +# __DEBUG_PACKAGE__ + +%build +./autogen.sh +%configure +make %{?_smp_mflags} + +%install +[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT +make DESTDIR=$RPM_BUILD_ROOT install + +%clean +[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT + +%post -p /sbin/ldconfig +%postun -p /sbin/ldconfig + +%files +%defattr(-,root,root,-) +%doc AUTHORS LICENSE readme.md +%{_libdir}/libembedlog.so.@{ABI_VERSION} +%{_libdir}/libembedlog.so.@{LIB_VERSION} + +%files devel +%defattr(-,root,root,-) +%{_includedir}/embedlog.h +%{_libdir}/libembedlog.so +%{_libdir}/libembedlog.a +%{_libdir}/libembedlog.la +%{_mandir}/*/* + +%changelog diff --git a/pkg/test.c b/pkg/test.c new file mode 100644 index 0000000..059ef0c --- /dev/null +++ b/pkg/test.c @@ -0,0 +1,20 @@ +/* ========================================================================== + Licensed under BSD 2clause license See LICENSE file for more information + Author: Michał Łyszczek + ========================================================================== */ + +/* this is very minimum program, just to check if embedlog is installed + * on the system or not + */ + +#include +#include + +int main(void) +{ + el_init(); + el_option(EL_OUT, EL_OUT_STDERR); + el_print(ELN, "embedlog works!"); + el_cleanup(); + return 0; +} diff --git a/pkg/tgz/create-pkg.sh b/pkg/tgz/create-pkg.sh new file mode 100755 index 0000000..952ba6f --- /dev/null +++ b/pkg/tgz/create-pkg.sh @@ -0,0 +1,81 @@ +#!/bin/sh + +project="embedlog" +scp_server="pkgs@kurwik" +revision="1" + +if [ ${#} -ne 3 ] +then + echo "usage: ${0} " + echo "" + echo "where" + echo " git tag version" + echo " target architecture" + echo " target os (slackware-14.2 etc)" + exit 1 +fi + +git_version="${1}" +arch="${2}" +host_os="${3}" +workdir="/tmp/${project}-${arch}-${git_version}" + +set -e + +rm -rf "${workdir}" +mkdir "${workdir}" +cd "${workdir}" + +wget "https://git.kurwinet.pl/${project}/snapshot/${project}-${git_version}.tar.gz" +tar xf "${project}-${git_version}.tar.gz" +cd "${project}-${git_version}" + +version="$(grep "AC_INIT(" "configure.ac" | cut -f3 -d\[ | cut -f1 -d\])" +./autogen.sh +CFLAGS="-I/usr/bofc/include" LDFLAGS="-L/usr/bofc/lib" ./configure --prefix=/usr +make check + +mkdir "${workdir}/root" +mkdir "${workdir}/root/install" +DESTDIR="${workdir}/root" make install + +[ -f "pkg/tgz/doinst.sh" ] && cp "pkg/tgz/doinst.sh" "${workdir}/root/install" +cd "${workdir}/root" +find . \( -name *.3 -or -name *.7 \) | xargs gzip +makepkg -l y -c n "${workdir}/${project}-${version}-${arch}-${revision}.tgz" +installpkg "${workdir}/${project}-${version}-${arch}-${revision}.tgz" + +failed=0 +gcc "${workdir}/${project}-${git_version}/pkg/test.c" -o "${workdir}/testprog" \ + -lembedlog || failed=1 + +if ldd "${workdir}/testprog" | grep "\/usr\/bofc" +then + # sanity check to make sure test program uses system libraries + # and not locally installed ones (which are used as build + # dependencies for other programs + + echo "test prog uses libs from manually installed /usr/bofc \ + instead of system path!" + failed=1 +fi + +"${workdir}/testprog" || failed=1 + +removepkg "${project}" + +# run test prog again, but now fail if there is no error, testprog +# should fail as there is no library in te system any more +"${workdir}/testprog" && failed=1 + +if [ ${failed} -eq 1 ] +then + exit 1 +fi + +if [ -n "${scp_server}" ] +then + echo "copying data to ${scp_server}:${project}/${host_os}/${arch}" + scp "${workdir}/${project}-${version}-${arch}-${revision}.tgz" \ + "${scp_server}:${project}/${host_os}/${arch}" || exit 1 +fi -- cgit v1.2.3-8-gadcc