aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHongjun Ni <hongjun.ni@intel.com>2019-02-12 07:53:43 +0000
committerGerrit Code Review <gerrit@fd.io>2019-02-12 07:53:43 +0000
commitbfb867bb8a8cf77d98a4301252f2d8b93ad7b146 (patch)
tree1f7757368b919f89c7b6deafb25c3004ea6c8eb8
parent15b50e99b52df68c92a92fc54aa994fc1a2753ff (diff)
parentf3e9a1884abc48c583788148b5880813e971563e (diff)
Merge "add build-package for sweetcomb"
-rw-r--r--Makefile15
-rw-r--r--src/CMakeLists.txt7
-rw-r--r--src/cmake/Packager.cmake149
3 files changed, 165 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index 6f4fa0b..f7549cf 100644
--- a/Makefile
+++ b/Makefile
@@ -50,7 +50,7 @@ endif
TARGETS = sweetcomb
-.PHONY: help install-dep install-dep-extra install-vpp checkstyle fixstyle build build-scvpp
+.PHONY: help install-dep install-dep-extra install-vpp checkstyle fixstyle build-plugins build-scvpp build-package
define banner
@echo "========================================================================"
@@ -67,9 +67,10 @@ help:
@echo " checkstyle - check coding style"
@echo " fixstyle - fix coding style"
@echo " build-scvpp - build scvpp"
- @echo " build - build plugin"
- @echo " clean - clean all build"
- @echo " distclean - remove all build directory"
+ @echo " build-plugins - build plugins"
+ @echo " build-package - build rpm or deb package"
+ @echo " clean - clean all build"
+ @echo " distclean - remove all build directory"
$(BR)/.deps.ok:
ifeq ($(findstring y,$(UNATTENDED)),y)
make install-dep
@@ -190,9 +191,12 @@ fixstyle:
build-scvpp:
@mkdir -p $(BR)/build-scvpp/;cd $(BR)/build-scvpp;cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr $(WS_ROOT)/src/scvpp/;make install;
-build:
+
+build-plugins:
@mkdir -p $(BR)/build-plugins/;cd $(BR)/build-plugins/;cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr $(WS_ROOT)/src/plugins/;make install;
+build-package:
+ @mkdir -p $(BR)/build-package/;cd $(BR)/build-package/;cmake $(WS_ROOT)/src/;make package;
clean:
@cd $(BR)/build-scvpp && make clean;
@cd $(BR)/build-plugins && make clean;
@@ -200,3 +204,4 @@ clean:
distclean:
@rm -rf $(BR)/build-scvpp
@rm -rf $(BR)/build-plugins
+ @rm -rf $(BR)/build-package
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 59b93d8..4888114 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -14,7 +14,9 @@
#
cmake_minimum_required(VERSION 2.8)
-project(sysrepo-vpp)
+project(sweetcomb)
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
+
include(GNUInstallDirs)
@@ -33,3 +35,6 @@ set(CMAKE_C_FLAGS_DEBUG "-g -O0")
# add subdirectories
add_subdirectory(scvpp)
add_subdirectory(plugins)
+
+include(Packager)
+make_packages()
diff --git a/src/cmake/Packager.cmake b/src/cmake/Packager.cmake
new file mode 100644
index 0000000..4305652
--- /dev/null
+++ b/src/cmake/Packager.cmake
@@ -0,0 +1,149 @@
+# Copyright (c) 2017-2019 Cisco and/or its affiliates.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#############
+# RPM/DEB/TGZ Packaging utils
+#
+
+set(CONTACT "sweetcomb-dev@lists.fd.io" CACHE STRING "Contact")
+set(PACKAGE_MAINTAINER "Sweetcomb Team" CACHE STRING "Maintainer")
+set(PACKAGE_VENDOR "fd.io" CACHE STRING "Vendor")
+
+# macro(set)
+
+macro(make_packages)
+ if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
+ # parse /etc/os-release
+ file(READ "/etc/os-release" os_version)
+ string(REPLACE "\n" ";" os_version ${os_version})
+ foreach(_ver ${os_version})
+ string(REPLACE "=" ";" _ver ${_ver})
+ list(GET _ver 0 _name)
+ list(GET _ver 1 _value)
+ set(OS_${_name} ${_value})
+ endforeach()
+
+ # extract version from git
+ execute_process(
+ COMMAND git describe --long --match v*
+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+ OUTPUT_VARIABLE VER
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+
+ if (NOT VER)
+ set(VER "v1.0")
+ endif()
+
+ string(REGEX REPLACE "v(.*)-([0-9]+)-(g[0-9a-f]+)" "\\1;\\2;\\3" VER ${VER})
+ list(GET VER 0 tag)
+ string(REPLACE "-" "~" tag ${tag})
+ list(GET VER 1 commit_num)
+ list(GET VER 2 commit_name)
+
+ if (NOT DEFINED ENV{BUILD_NUMBER})
+ set(bld "b1")
+ else()
+ set(bld "b$ENV{BUILD_NUMBER}")
+ endif()
+
+ message("Build number is: ${bld}")
+
+ #define DEB and RPM version numbers
+ if(${commit_num} EQUAL 0)
+ set(deb_ver "${tag}")
+ set(rpm_ver "${tag}")
+ else()
+ set(deb_ver "${tag}-${commit_num}-release")
+ set(rpm_ver "${tag}-${commit_num}-release")
+ endif()
+
+ get_cmake_property(components COMPONENTS)
+
+ if(OS_ID_LIKE MATCHES "debian")
+ set(CPACK_GENERATOR "DEB")
+ set(type "DEBIAN")
+
+ execute_process(
+ COMMAND dpkg --print-architecture
+ OUTPUT_VARIABLE arch
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+
+ set(CPACK_PACKAGE_VERSION "${deb_ver}")
+ foreach(lc ${components})
+ if (${lc} MATCHES ".*Unspecified.*")
+ continue()
+ endif()
+
+ string(TOUPPER ${lc} uc)
+ set(CPACK_${type}_${uc}_FILE_NAME "${lc}_${deb_ver}_${arch}.deb")
+
+ set(DEB_DEPS)
+ if (NOT ${${lc}_DEB_DEPENDENCIES} STREQUAL "")
+ string(REPLACE "stable_version" ${tag} DEB_DEPS ${${lc}_DEB_DEPENDENCIES})
+ endif()
+
+ set(CPACK_${type}_${uc}_PACKAGE_DEPENDS "${DEB_DEPS}")
+ set(CPACK_${type}_${uc}_PACKAGE_NAME "${lc}")
+ set(CPACK_COMPONENT_${uc}_DESCRIPTION "${${lc}_DESCRIPTION}")
+ endforeach()
+ elseif(OS_ID_LIKE MATCHES "rhel")
+ set(CPACK_GENERATOR "RPM")
+ set(type "RPM")
+
+ execute_process(
+ COMMAND uname -m
+ OUTPUT_VARIABLE arch
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+
+ set(CPACK_PACKAGE_VERSION "${rpm_ver}")
+ foreach(lc ${components})
+ if (${lc} MATCHES ".*Unspecified.*")
+ continue()
+ endif()
+
+ string(TOUPPER ${lc} uc)
+ set(CPACK_${type}_${uc}_DESCRIPTION "${${lc}_DESCRIPTION}")
+
+ set(RPM_DEPS)
+ if (NOT ${${lc}_DEB_DEPENDENCIES} STREQUAL "")
+ string(REPLACE "stable_version" ${tag} RPM_DEPS ${${lc}_RPM_DEPENDENCIES})
+ endif()
+
+ set(CPACK_${type}_${uc}_PACKAGE_REQUIRES "${RPM_DEPS}")
+
+ if(${lc} MATCHES ".*-dev")
+ set(package_name ${lc}el)
+ else()
+ set(package_name ${lc})
+ endif()
+
+ set(CPACK_RPM_${uc}_PACKAGE_NAME "${package_name}")
+ set(CPACK_${type}_${uc}_FILE_NAME "${package_name}-${rpm_ver}.${arch}.rpm")
+ endforeach()
+ endif()
+
+ if(CPACK_GENERATOR)
+ set(CPACK_PACKAGE_NAME ${ARG_NAME})
+ set(CPACK_STRIP_FILES OFF)
+ set(CPACK_PACKAGE_VENDOR "${PACKAGE_VENDOR}")
+ set(CPACK_COMPONENTS_IGNORE_GROUPS 1)
+ set(CPACK_${CPACK_GENERATOR}_COMPONENT_INSTALL ON)
+ set(CPACK_${type}_PACKAGE_MAINTAINER "Sweetcomb Team")
+ set(CPACK_${type}_PACKAGE_RELEASE 1)
+ include(CPack)
+ endif()
+ endif()
+endmacro()