From e48460055b2673733ac12bdb15dde2c6e2e4eb26 Mon Sep 17 00:00:00 2001 From: Ronan Le Martret Date: Fri, 9 Jun 2017 18:00:41 +0200 Subject: Update packaging creation * update rpm creation * add deb packaging Change-Id: Idc1623b7b0ca72d4842e59f9495fc26c487ef008 Signed-off-by: Ronan Le Martret --- cmake/common.cmake | 142 +++++++++++++++++++++++++++++++++++++++------- deb/deb-config.dsc.in | 14 +++++ deb/deb-config.install.in | 2 + deb/debian.changelog.in | 5 ++ deb/debian.compat.in | 1 + deb/debian.control.in | 15 +++++ deb/debian.rules.in | 87 ++++++++++++++++++++++++++++ rpm/rpm-config.spec.in | 27 ++++++--- 8 files changed, 262 insertions(+), 31 deletions(-) create mode 100644 deb/deb-config.dsc.in create mode 100644 deb/deb-config.install.in create mode 100644 deb/debian.changelog.in create mode 100644 deb/debian.compat.in create mode 100644 deb/debian.control.in create mode 100644 deb/debian.rules.in diff --git a/cmake/common.cmake b/cmake/common.cmake index 8e4cb6b..c41ec21 100644 --- a/cmake/common.cmake +++ b/cmake/common.cmake @@ -76,6 +76,9 @@ macro(defstr name value) add_definitions(-D${name}=${value}) endmacro(defstr) +# Native packaging name +set(NPKG_PROJECT_NAME agl-${PROJECT_NAME}) + # Pre-packaging macro(project_targets_populate) @@ -237,27 +240,14 @@ macro(wgt_package_build) endmacro(wgt_package_build) macro(rpm_package_build) - if(NOT EXISTS ${RPM_TEMPLATE_DIR}/rpm-config.spec.in) - MESSAGE(FATAL_ERROR "${Red}Missing mandatory files: you need rpm-config.spec.in in ${RPM_TEMPLATE_DIR} folder.${ColourReset}") - endif() - - # extract PROJECT_PKG_DEPS and replace ; by , for RPM spec file - get_property(PROJECT_PKG_DEPS GLOBAL PROPERTY PROJECT_PKG_DEPS) - foreach (PKFCONF ${PROJECT_PKG_DEPS}) - set(RPM_PKG_DEPS "${RPM_PKG_DEPS}, pkgconfig(${PKFCONF})") - endforeach() - - # build rpm spec file from template - configure_file(${RPM_TEMPLATE_DIR}/rpm-config.spec.in ${PROJECT_NAME}.spec) - configure_file(${RPM_TEMPLATE_DIR}/rpm-config.spec.in ${PROJECT_PKG_ENTRY_POINT}/${PROJECT_NAME}.spec) - - add_custom_command(OUTPUT ${PROJECT_NAME}.spec + add_custom_command(OUTPUT ${NPKG_PROJECT_NAME}.spec DEPENDS ${PROJECT_TARGETS} - COMMAND git --git-dir=${CMAKE_CURRENT_SOURCE_DIR}/.git archive --format=tar.gz --prefix=${PROJECT_NAME}-${PROJECT_VERSION}/ HEAD -o ${PROJECT_PKG_BUILD_DIR}/${PROJECT_NAME}_${PROJECT_VERSION}.orig.tar.gz - COMMAND rpmbuild --define=\"%_sourcedir ${PROJECT_PKG_BUILD_DIR}\" -ba ${PROJECT_PKG_BUILD_DIR}/${PROJECT_NAME}.spec + archive + packaging + COMMAND rpmbuild --define=\"%_sourcedir ${PROJECT_PKG_ENTRY_POINT}\" -ba ${PROJECT_PKG_ENTRY_POINT}/${NPKG_PROJECT_NAME}.spec ) - add_custom_target(rpm DEPENDS ${PROJECT_NAME}.spec) + add_custom_target(rpm DEPENDS ${NPKG_PROJECT_NAME}.spec) add_dependencies(rpm populate) set(ADDITIONAL_MAKE_CLEAN_FILES, "${PROJECT_NAME}.spec") @@ -268,6 +258,10 @@ macro(rpm_package_build) endif() endmacro(rpm_package_build) +macro(deb_package_build) +#TODO +endmacro(deb_package_build) + macro(project_package_build) if(EXISTS ${RPM_TEMPLATE_DIR}) rpm_package_build() @@ -432,9 +426,113 @@ endmacro() # Add RSYNCTARGET remote_targets_populate() -add_custom_command(OUTPUT ${PROJECT_PKG_ENTRY_POINT}/${PROJECT_NAME}_${PROJECT_VERSION}.orig.tar.gz -DEPENDS ${PROJECT_TARGETS} - COMMAND git --git-dir=${CMAKE_CURRENT_SOURCE_DIR}/.git archive --format=tar.gz --prefix=${PROJECT_NAME}-${PROJECT_VERSION}/ HEAD -o ${PROJECT_PKG_ENTRY_POINT}/${PROJECT_NAME}_${PROJECT_VERSION}.orig.tar.gz +#Archive project +set(ARCHIVE_OUTPUT_ARCHIVE ${PROJECT_PKG_ENTRY_POINT}/${NPKG_PROJECT_NAME}_${PROJECT_VERSION}.orig.tar) +set(ARCHIVE_OUTPUT ${ARCHIVE_OUTPUT_ARCHIVE}.gz) +set(TMP_ARCHIVE_SUBMODULE ${PROJECT_PKG_ENTRY_POINT}/${NPKG_PROJECT_NAME}-sub) +set(CMD_ARCHIVE_SUBMODULE \'git archive --verbose --prefix=${NPKG_PROJECT_NAME}-${PROJECT_VERSION}/$$path/ --format tar HEAD --output ${TMP_ARCHIVE_SUBMODULE}-$$sha1.tar\' ) +add_custom_command(OUTPUT ${ARCHIVE_OUTPUT} + DEPENDS ${PROJECT_TARGETS} + #Create git archive of the main project + COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR}\; git --git-dir=${CMAKE_CURRENT_SOURCE_DIR}/.git archive --format=tar --prefix=${NPKG_PROJECT_NAME}-${PROJECT_VERSION}/ HEAD -o ${ARCHIVE_OUTPUT_ARCHIVE} + #Create tmp git archive for each submodule + COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR}\; git --git-dir=${CMAKE_CURRENT_SOURCE_DIR}/.git submodule foreach --recursive ${CMD_ARCHIVE_SUBMODULE} + #Concatenate main archive and tmp submodule archive + COMMAND for SUBTAR in ${TMP_ARCHIVE_SUBMODULE}-*.tar\; do tar --concatenate --file=${ARCHIVE_OUTPUT_ARCHIVE} $$SUBTAR\;done + #Remove tmp submodule archive + COMMAND rm -rf ${TMP_ARCHIVE_SUBMODULE}-*.tar + #Compress main archive + COMMAND gzip --force --verbose ${ARCHIVE_OUTPUT_ARCHIVE} ) +add_custom_target(archive DEPENDS ${ARCHIVE_OUTPUT}) + +#Get the os type +if(EXISTS "/etc/os-release") + execute_process(COMMAND grep ID_LIKE /etc/os-release + OUTPUT_VARIABLE TMP_OSRELEASE + ) + if (NOT TMP_OSRELEASE STREQUAL "") + string(REGEX REPLACE ".*=" "" OSRELEASE ${TMP_OSRELEASE}) + else() + set(OSRELEASE "NOT DEBIAN OS") + endif() + message(STATUS "OSRELEASE = ${OSRELEASE}") +else() + set(OSRELEASE "NOT DEBIAN OS") +endif() + +#Format Build require package +foreach (PKG_CONFIG ${PKG_REQUIRED_LIST}) + #Unset TMP variable + unset(XPREFIX) + unset(XRULE) + unset(RPM_EXTRA_DEP) + unset(DEB_EXTRA_DEP) + #For deb package,add EOL format only for a new line + if(DEB_PKG_DEPS) + set(DEB_PKG_DEPS "${DEB_PKG_DEPS},\n") + endif() + #Get pkg-config rule on version + string(REGEX REPLACE "[<>]?=.*$" "" XPREFIX ${PKG_CONFIG}) + string(REGEX MATCH "[<>]?=" XRULE ${PKG_CONFIG}) + #Only if pkg-config has rule on version + if(XRULE) + string(REGEX REPLACE ".*[<>]?=" "" XVERS ${PKG_CONFIG}) + set(RPM_EXTRA_DEP " ${XRULE} ${XVERS}") + set(DEB_EXTRA_DEP " (${XRULE} ${XVERS})") + endif() + #Format for rpm package + set(RPM_PKG_DEPS "${RPM_PKG_DEPS}BuildRequires: pkgconfig(${XPREFIX})${RPM_EXTRA_DEP}\n") + #Format for deb package + #Because the tool "dpkg" is used on the packages db to find the + #package providing the pkg-cong file ${XPREFIX}.pc, we need + #to test the OS release package type + if( OSRELEASE MATCHES "debian" ) + execute_process( + COMMAND dpkg -S *${XPREFIX}.pc + OUTPUT_VARIABLE TMP_PKG_BIN + ) + #Need to be harden check + string(REGEX REPLACE ":.*$" "" PKG_BIN ${TMP_PKG_BIN}) + set(DEB_PKG_DEPS "${DEB_PKG_DEPS} ${PKG_BIN} ${DEB_EXTRA_DEP}") + endif() +endforeach() + +if(NOT EXISTS ${RPM_TEMPLATE_DIR}/rpm-config.spec.in) + MESSAGE(FATAL_ERROR "${Red}Missing mandatory files: you need rpm-config.spec.in in ${RPM_TEMPLATE_DIR} folder.${ColourReset}") +endif() +set(PACKAGING_SPEC_OUTPUT ${PROJECT_PKG_ENTRY_POINT}/${NPKG_PROJECT_NAME}.spec) +# build rpm spec file from template +configure_file(${RPM_TEMPLATE_DIR}/rpm-config.spec.in ${PACKAGING_SPEC_OUTPUT}) + +#Because the tool "dpkg" is used on the packages db to find the +#package providing the pkg-cong file ${XPREFIX}.pc, we need +#to test the OS release package type +if( OSRELEASE MATCHES "debian" ) + # build deb spec file from template + set(PACKAGING_DEB_OUTPUT_DSC ${PROJECT_PKG_ENTRY_POINT}/${NPKG_PROJECT_NAME}.dsc) + configure_file(${DEB_TEMPLATE_DIR}/deb-config.dsc.in ${PACKAGING_DEB_OUTPUT_DSC}) + set(PACKAGING_DEB_OUTPUT_INSTALL ${PROJECT_PKG_ENTRY_POINT}/debian.${NPKG_PROJECT_NAME}.install) + configure_file(${DEB_TEMPLATE_DIR}/deb-config.install.in ${PACKAGING_DEB_OUTPUT_INSTALL}) + set(PACKAGING_DEB_OUTPUT_CHANGELOG ${PROJECT_PKG_ENTRY_POINT}/debian.changelog) + configure_file(${DEB_TEMPLATE_DIR}/debian.changelog.in ${PACKAGING_DEB_OUTPUT_CHANGELOG}) + set(PACKAGING_DEB_OUTPUT_COMPAT ${PROJECT_PKG_ENTRY_POINT}/debian.compat) + configure_file(${DEB_TEMPLATE_DIR}/debian.compat.in ${PACKAGING_DEB_OUTPUT_COMPAT}) + set(PACKAGING_DEB_OUTPUT_CONTROL ${PROJECT_PKG_ENTRY_POINT}/debian.control) + configure_file(${DEB_TEMPLATE_DIR}/debian.control.in ${PACKAGING_DEB_OUTPUT_CONTROL}) + set(PACKAGING_DEB_OUTPUT_RULES ${PROJECT_PKG_ENTRY_POINT}/debian.rules) + configure_file(${DEB_TEMPLATE_DIR}/debian.rules.in ${PACKAGING_DEB_OUTPUT_RULES}) +endif() + +add_custom_target( packaging DEPENDS ${PACKAGING_SPEC_OUTPUT} + ${PACKAGING_DEB_OUTPUT_DSC} + ${PACKAGING_DEB_OUTPUT_INSTALL} + ${PACKAGING_DEB_OUTPUT_CHANGELOG} + ${PACKAGING_DEB_OUTPUT_COMPAT} + ${PACKAGING_DEB_OUTPUT_CONTROL} + ${PACKAGING_DEB_OUTPUT_CONTROL} + ${PACKAGING_DEB_OUTPUT_RULES}) -add_custom_target(archive DEPENDS ${PROJECT_PKG_ENTRY_POINT}/${PROJECT_NAME}_${PROJECT_VERSION}.orig.tar.gz) +add_custom_command(TARGET packaging + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --cyan "++ Packaging") diff --git a/deb/deb-config.dsc.in b/deb/deb-config.dsc.in new file mode 100644 index 0000000..be9c0f2 --- /dev/null +++ b/deb/deb-config.dsc.in @@ -0,0 +1,14 @@ +Format: @PROJECT_VERSION@ +Source: @NPKG_PROJECT_NAME@ +Binary: @NPKG_PROJECT_NAME@-bin +Architecture: any +Version: 2.0-0 +Maintainer: @PROJECT_AUTHOR@ <@PROJECT_AUTHOR_MAIL@> +Standards-Version: 3.8.2 +Homepage: @PROJECT_URL@ +Build-Depends: debhelper (>= 5), + cmake, + gcc, + g++, +@DEB_PKG_DEPS@ +Debtransform-Tar: @NPKG_PROJECT_NAME@_@PROJECT_VERSION@.orig.tar.gz diff --git a/deb/deb-config.install.in b/deb/deb-config.install.in new file mode 100644 index 0000000..5858efd --- /dev/null +++ b/deb/deb-config.install.in @@ -0,0 +1,2 @@ +/opt/AGL/* +/etc/profile.d/* diff --git a/deb/debian.changelog.in b/deb/debian.changelog.in new file mode 100644 index 0000000..f72c717 --- /dev/null +++ b/deb/debian.changelog.in @@ -0,0 +1,5 @@ +@NPKG_PROJECT_NAME@ (@PROJECT_VERSION@-0) UNRELEASED; urgency=low + + * init build + + -- @PROJECT_AUTHOR@ <@PROJECT_AUTHOR_MAIL@> Mon, 25 Dec 2007 10:50:38 +0100 diff --git a/deb/debian.compat.in b/deb/debian.compat.in new file mode 100644 index 0000000..45a4fb7 --- /dev/null +++ b/deb/debian.compat.in @@ -0,0 +1 @@ +8 diff --git a/deb/debian.control.in b/deb/debian.control.in new file mode 100644 index 0000000..6956a24 --- /dev/null +++ b/deb/debian.control.in @@ -0,0 +1,15 @@ +Priority: optional +Maintainer: @PROJECT_AUTHOR@ <@PROJECT_AUTHOR_MAIL@> +Source: @NPKG_PROJECT_NAME@ +Build-Depends: debhelper (>= 5), + cmake, + gcc, + g++, +@DEB_PKG_DEPS@ +Standards-Version: 3.8.2 +Homepage: @PROJECT_URL@ + +Package: @NPKG_PROJECT_NAME@ +Section: libs +Architecture: any +Description: @PROJECT_DESCRIPTION@ diff --git a/deb/debian.rules.in b/deb/debian.rules.in new file mode 100644 index 0000000..693bba4 --- /dev/null +++ b/deb/debian.rules.in @@ -0,0 +1,87 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Uncomment this to turn on verbose mode. +export DH_VERBOSE=1 + +# These are used for cross-compiling and for saving the configure script +# from having to guess our platform (since we know it already) +DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE) +DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE) + + +CFLAGS = -Wall -g + +ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) + CFLAGS += -O0 +else + CFLAGS += -O2 +endif +ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS))) + INSTALL_PROGRAM += -s +endif + +configure: configure-stamp +configure-stamp: + dh_testdir + # + touch configure-stamp + +build: build-stamp +build-stamp: configure-stamp + dh_testdir + mkdir -p build + cd build;cmake ../ -DCMAKE_INSTALL_PREFIX:PATH=/opt/AGL/@PROJECT_NAME@ -DCMAKE_INSTALL_LIBDIR:PATH=lib/$(DEB_HOST_MULTIARCH);$(MAKE) + # + touch build-stamp + +clean: + #dh_testdir + dh_testroot + rm -f configure-stamp build-stamp + [ ! -f Makefile ] || $(MAKE) distclean + #dh_clean + +install: build + dh_testdir + dh_testroot + dh_prep + dh_installdirs + # Add here commands to install the package into debian/tmp + mkdir -p debian/tmp/opt/AGL/@PROJECT_NAME@;cd build;make populate;cp -r package/* ../debian/tmp/opt/AGL/@PROJECT_NAME@/ + mkdir -p debian/tmp/etc/profile.d + echo '#---------- AGL @PROJECT_NAME@ options Start ---------" ' > debian/tmp/etc/profile.d/AGL_@PROJECT_NAME@.sh + echo '# Object: AGL cmake option for binder/bindings' >> debian/tmp/etc/profile.d/AGL_@PROJECT_NAME@.sh + echo 'export LD_LIBRARY_PATH=/opt/AGL/@PROJECT_NAME@/lib/$(DEB_HOST_MULTIARCH):${LD_LIBRARY_PATH}' >> debian/tmp/etc/profile.d/AGL_@PROJECT_NAME@.sh + echo 'export LIBRARY_PATH=/opt/AGL/@PROJECT_NAME@/lib/$(DEB_HOST_MULTIARCH):${LIBRARY_PATH}' >> debian/tmp/etc/profile.d/AGL_@PROJECT_NAME@.sh + echo 'export PATH=/opt/AGL/@PROJECT_NAME@/AGL/bin:\$PATH' >> debian/tmp/etc/profile.d/AGL_@PROJECT_NAME@.sh + echo '#---------- AGL options End ---------' >> debian/tmp/etc/profile.d/AGL_@PROJECT_NAME@.sh + # Move all files in their corresponding package + dh_install --list-missing -s --sourcedir=debian/tmp + # empty dependency_libs in .la files + #sed -i "/dependency_libs/ s/'.*'/''/" `find debian/ -name '*.la'` + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir + dh_testroot + dh_installchangelogs + dh_installdocs + dh_installexamples + dh_installman + dh_link + dh_strip + dh_compress + dh_fixperms + dh_makeshlibs -V + dh_installdeb + dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install diff --git a/rpm/rpm-config.spec.in b/rpm/rpm-config.spec.in index 0383102..ecfa795 100644 --- a/rpm/rpm-config.spec.in +++ b/rpm/rpm-config.spec.in @@ -1,7 +1,7 @@ ########################################################################### # Copyright 2015, 2016, 2017 IoT.bzh # -# author: Fulup Ar Foll +# author: @PROJECT_AUTHOR@ <@PROJECT_AUTHOR_MAIL@> # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ ########################################################################### -Name: @PROJECT_NAME@ +Name: @NPKG_PROJECT_NAME@ Version: @PROJECT_VERSION@ Release: 1 License: @PROJECT_LICENSE@ @@ -25,12 +25,14 @@ Summary: @PROJECT_DESCRIPTION@ Url: @PROJECT_URL@ Source0: %{name}_%{version}.orig.tar.gz -Prefix: /opt/@PROJECT_NAME@ BuildRequires: cmake BuildRequires: gcc gcc-c++ -BuildRequires: @RPM_PKG_DEPS@ +@RPM_PKG_DEPS@ -BuildRoot:%{_tmppath}/%{name}-%{version}-build +BuildRoot: %{_tmppath}/%{name}-%{version}-build + +%define _prefix /opt/AGL/@PROJECT_NAME@ +%define __cmake cmake %description @PROJECT_DESCRIPTION@ @@ -43,10 +45,17 @@ BuildRoot:%{_tmppath}/%{name}-%{version}-build %__make %{?_smp_mflags} %install +CURDIR=$(pwd) [ -d build ] && cd build -%make_install +make populate +mkdir -p %{?buildroot}%{_prefix} +cp -r package/* %{?buildroot}%{_prefix} + +cd $CURDIR +find %{?buildroot}%{_prefix} -type d -exec echo "%dir {}" \;>> pkg_file +find %{?buildroot}%{_prefix} -type f -exec echo "{}" \;>> pkg_file +sed -i 's@%{?buildroot}@@g' pkg_file + -%files +%files -f pkg_file %defattr(-,root,root) -%dir %{_prefix}/* -%{_prefix}/*/* -- cgit 1.2.3-korg