From 3dd4903f880784341fabf638eaf52c38f4c6c1eb Mon Sep 17 00:00:00 2001 From: Renato Botelho do Couto Date: Tue, 5 Dec 2017 04:02:27 -0600 Subject: [PATCH 1/3] Ignore generated files --- .gitignore | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..b0920a2a --- /dev/null +++ b/.gitignore @@ -0,0 +1,45 @@ +*.o +*.so.* +*_parse.tab.c +*_parse.tab.h +lex.*_parse.c + +Makefile +apps/Makefile +apps/*/Makefile +docker/Makefile +docker/*/Makefile +etc/Makefile +example/Makefile +lib/Makefile +lib/*/Makefile +autom4te.cache/ + +clixon.conf.cpp +clixon.mk +config.log +config.status + +apps/backend/clixon_backend +apps/backend/test +apps/backend/test.c +apps/cli/clixon_cli +apps/cli/test +apps/cli/test.c +apps/dbctrl/clixon_dbctrl +apps/netconf/clixon_netconf +apps/restconf/clixon_restconf +apps/xmldb/clixon_xmldb + +docker/backend/Dockerfile +docker/cli/Dockerfile +docker/netconf/Dockerfile + +etc/clixonrc + +example/*.conf + +include/clixon_config.h + +lib/src/build.c +lib/clixon/clixon.h From e7b1c0c38ca73c1f510ff44bac3f588d08c5fab8 Mon Sep 17 00:00:00 2001 From: Renato Botelho do Couto Date: Tue, 5 Dec 2017 04:00:54 -0600 Subject: [PATCH 2/3] Implement `make dist` target Add dist target to create project tarball. It uses a script called version, that was obtained from vpp source code to produce a version string using `git describe` that is incremental based on last annotated tag available. --- .gitignore | 2 ++ Makefile.in | 34 ++++++++++++++++++++++++ build-root/scripts/version | 1 + extras/scripts/version | 53 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+) create mode 120000 build-root/scripts/version create mode 100755 extras/scripts/version diff --git a/.gitignore b/.gitignore index b0920a2a..940d7d51 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,5 @@ include/clixon_config.h lib/src/build.c lib/clixon/clixon.h + +build-root/*.tar.xz diff --git a/Makefile.in b/Makefile.in index 97e1f57b..4ad5ff70 100644 --- a/Makefile.in +++ b/Makefile.in @@ -108,9 +108,43 @@ distclean: rm -f Makefile TAGS config.status config.log *~ .depend rm -rf Makefile autom4te.cache rm -rf clixon.conf.cpp clixon.mk + rm -f build-root/*.tar.xz for i in $(SUBDIRS) doc example docker; \ do (cd $$i && $(MAKE) $(MFLAGS) $@); done +export BR=$(CURDIR)/build-root + +$(BR)/scripts/.version: +ifneq ("$(wildcard /etc/redhat-release)","") + $(shell $(BR)/scripts/version rpm-string > $(BR)/scripts/.version) +else + $(shell $(BR)/scripts/version > $(BR)/scripts/.version) +endif + +DIST_FILE = $(BR)/clixon-$(shell extras/scripts/version).tar +DIST_SUBDIR = clixon-$(shell extras/scripts/version | cut -f1 -d-) + +dist: + @if git rev-parse 2> /dev/null ; then \ + git archive \ + --prefix=$(DIST_SUBDIR)/ \ + --format=tar \ + -o $(DIST_FILE) \ + HEAD ; \ + git describe > $(BR)/.version ; \ + else \ + (cd .. ; tar -cf $(DIST_FILE) $(DIST_SUBDIR) --exclude=*.tar) ; \ + extras/scripts/version > $(BR)/.version ; \ + fi + @tar --append \ + --file $(DIST_FILE) \ + --transform='s,.*/.version,$(DIST_SUBDIR)/extras/scripts/.version,' \ + $(BR)/.version + @$(RM) $(BR)/.version $(DIST_FILE).xz + @xz -v --threads=0 $(DIST_FILE) + @$(RM) $(BR)/clixon-latest.tar.xz + @ln -rs $(DIST_FILE).xz $(BR)/clixon-latest.tar.xz + docker: for i in docker; \ do (cd $$i && $(MAKE) $(MFLAGS) $@); done diff --git a/build-root/scripts/version b/build-root/scripts/version new file mode 120000 index 00000000..0144b7ee --- /dev/null +++ b/build-root/scripts/version @@ -0,0 +1 @@ +../../extras/scripts/version \ No newline at end of file diff --git a/extras/scripts/version b/extras/scripts/version new file mode 100755 index 00000000..d52ca207 --- /dev/null +++ b/extras/scripts/version @@ -0,0 +1,53 @@ +#!/bin/bash +# +# Obtained from VPP - https://wiki.fd.io/view/VPP +# + +path=$( cd "$(dirname "${BASH_SOURCE}")" ; pwd -P ) + +cd "$path" + +if [ -f .version ]; then + vstring=$(cat .version) +else + vstring=$(git describe) + if [ $? != 0 ]; then + exit 1 + fi +fi + +TAG=$(echo ${vstring} | cut -d- -f1 | sed -e 's/^[vR]//') +ADD=$(echo ${vstring} | cut -s -d- -f2) + +git rev-parse 2> /dev/null +if [ $? == 0 ]; then + CMT=$(git describe --dirty | cut -s -d- -f3,4) +else + CMT=$(echo ${vstring} | cut -s -d- -f3,4) +fi +CMTR=$(echo $CMT | sed 's/-/_/') + +if [ -n "${BUILD_NUMBER}" ]; then + BLD="~b${BUILD_NUMBER}" +fi + +if [ "$1" = "rpm-version" ]; then + echo ${TAG} + exit +fi + +if [ "$1" = "rpm-release" ]; then + [ -z "${ADD}" ] && echo release && exit + echo ${ADD}${CMTR:+~${CMTR}}${BLD} + exit +fi + + if [ -n "${ADD}" ]; then + if [ "$1" = "rpm-string" ]; then + echo ${TAG}-${ADD}${CMTR:+~${CMTR}}${BLD} + else + echo ${TAG}-${ADD}${CMT:+~${CMT}}${BLD} + fi + else + echo ${TAG}-release +fi From 1c187c57296c435347d595d0ac399cec202149e7 Mon Sep 17 00:00:00 2001 From: Renato Botelho do Couto Date: Tue, 5 Dec 2017 07:27:59 -0600 Subject: [PATCH 3/3] Prepare build system to produce RPMs Add .spec file under extras/rpms and create targets to produce source and binary rpms --- .gitignore | 2 ++ Makefile.in | 12 +++++-- configure | 13 +++++--- configure.ac | 8 +++++ extras/rpm/Makefile.in | 35 ++++++++++++++++++++ extras/rpm/clixon.spec | 72 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 135 insertions(+), 7 deletions(-) create mode 100644 extras/rpm/Makefile.in create mode 100644 extras/rpm/clixon.spec diff --git a/.gitignore b/.gitignore index 940d7d51..1b2cb35f 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,5 @@ lib/src/build.c lib/clixon/clixon.h build-root/*.tar.xz +build-root/*.rpm +build-root/rpmbuild diff --git a/Makefile.in b/Makefile.in index 4ad5ff70..6b75f631 100644 --- a/Makefile.in +++ b/Makefile.in @@ -106,9 +106,9 @@ clean: distclean: rm -f Makefile TAGS config.status config.log *~ .depend - rm -rf Makefile autom4te.cache - rm -rf clixon.conf.cpp clixon.mk - rm -f build-root/*.tar.xz + rm -rf autom4te.cache + rm -rf clixon.conf.cpp clixon.mk build-root/rpmbuild + rm -f build-root/*.tar.xz build-root/*.rpm extras/rpm/Makefile for i in $(SUBDIRS) doc example docker; \ do (cd $$i && $(MAKE) $(MFLAGS) $@); done @@ -145,6 +145,12 @@ dist: @$(RM) $(BR)/clixon-latest.tar.xz @ln -rs $(DIST_FILE).xz $(BR)/clixon-latest.tar.xz +pkg-rpm: dist + make -C extras/rpm + +pkg-srpm: dist + make -C extras/rpm srpm + docker: for i in docker; \ do (cd $$i && $(MAKE) $(MFLAGS) $@); done diff --git a/configure b/configure index 910cde6d..dde106ab 100755 --- a/configure +++ b/configure @@ -659,6 +659,7 @@ build_os build_vendor build_cpu build +CLIGEN_PREFIX CLIGEN_VERSION CLIXON_VERSION_MINOR CLIXON_VERSION_MAJOR @@ -2158,6 +2159,11 @@ CLIXON_VERSION_PATCH="0" CLIXON_VERSION="\"${CLIXON_VERSION_MAJOR}.${CLIXON_VERSION_MINOR}.${CLIXON_VERSION_PATCH}.PRE\"" # Fix to specific version (eg 3.5) or head (3) CLIGEN_VERSION="3" +if test "$prefix" = "NONE"; then + CLIGEN_PREFIX="$ac_default_prefix" +else + CLIGEN_PREFIX="$prefix" +fi ac_config_headers="$ac_config_headers include/clixon_config.h lib/clixon/clixon.h" @@ -3560,6 +3566,7 @@ if test "${with_cligen}"; then echo "Using CLIGEN here: ${with_cligen}" CPPFLAGS="-I${with_cligen}/include ${CPPFLAGS}" LDFLAGS="-L${with_cligen}/lib ${LDFLAGS}" + test -d "$with_cligen" && CLIGEN_PREFIX="$with_cligen" fi @@ -4328,11 +4335,8 @@ _ACEOF - - - # See also datastore/keyvalue/Makefile in with_keyvalue clause above -ac_config_files="$ac_config_files Makefile lib/Makefile lib/src/Makefile lib/clixon/Makefile apps/Makefile apps/cli/Makefile apps/backend/Makefile apps/netconf/Makefile apps/restconf/Makefile include/Makefile etc/Makefile etc/clixonrc example/Makefile example/docker/Makefile docker/Makefile docker/cli/Makefile docker/cli/Dockerfile docker/backend/Makefile docker/backend/Dockerfile docker/netconf/Makefile docker/netconf/Dockerfile datastore/Makefile datastore/text/Makefile yang/Makefile doc/Makefile" +ac_config_files="$ac_config_files Makefile lib/Makefile lib/src/Makefile lib/clixon/Makefile apps/Makefile apps/cli/Makefile apps/backend/Makefile apps/netconf/Makefile apps/restconf/Makefile include/Makefile etc/Makefile etc/clixonrc example/Makefile example/docker/Makefile extras/rpm/Makefile docker/Makefile docker/cli/Makefile docker/cli/Dockerfile docker/backend/Makefile docker/backend/Dockerfile docker/netconf/Makefile docker/netconf/Dockerfile datastore/Makefile datastore/text/Makefile yang/Makefile doc/Makefile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -5040,6 +5044,7 @@ do "etc/clixonrc") CONFIG_FILES="$CONFIG_FILES etc/clixonrc" ;; "example/Makefile") CONFIG_FILES="$CONFIG_FILES example/Makefile" ;; "example/docker/Makefile") CONFIG_FILES="$CONFIG_FILES example/docker/Makefile" ;; + "extras/rpm/Makefile") CONFIG_FILES="$CONFIG_FILES extras/rpm/Makefile" ;; "docker/Makefile") CONFIG_FILES="$CONFIG_FILES docker/Makefile" ;; "docker/cli/Makefile") CONFIG_FILES="$CONFIG_FILES docker/cli/Makefile" ;; "docker/cli/Dockerfile") CONFIG_FILES="$CONFIG_FILES docker/cli/Dockerfile" ;; diff --git a/configure.ac b/configure.ac index a8c4054c..5085b476 100644 --- a/configure.ac +++ b/configure.ac @@ -47,6 +47,11 @@ CLIXON_VERSION_PATCH="0" CLIXON_VERSION="\"${CLIXON_VERSION_MAJOR}.${CLIXON_VERSION_MINOR}.${CLIXON_VERSION_PATCH}.PRE\"" # Fix to specific version (eg 3.5) or head (3) CLIGEN_VERSION="3" +if test "$prefix" = "NONE"; then + CLIGEN_PREFIX="$ac_default_prefix" +else + CLIGEN_PREFIX="$prefix" +fi AC_CONFIG_HEADERS([include/clixon_config.h lib/clixon/clixon.h]) @@ -62,6 +67,7 @@ AC_SUBST(CLIXON_VERSION_STRING) AC_SUBST(CLIXON_VERSION_MAJOR) AC_SUBST(CLIXON_VERSION_MINOR) AC_SUBST(CLIGEN_VERSION) # Bind to specific CLIgen version +AC_SUBST(CLIGEN_PREFIX) AC_MSG_RESULT(CLIXON version is ${CLIXON_VERSION}) @@ -122,6 +128,7 @@ if test "${with_cligen}"; then echo "Using CLIGEN here: ${with_cligen}" CPPFLAGS="-I${with_cligen}/include ${CPPFLAGS}" LDFLAGS="-L${with_cligen}/lib ${LDFLAGS}" + test -d "$with_cligen" && CLIGEN_PREFIX="$with_cligen" fi AC_CHECK_HEADERS(cligen/cligen.h,, AC_MSG_ERROR(cligen missing. Try: git clone https://github.com/olofhagsand/cligen.git)) @@ -213,6 +220,7 @@ AC_OUTPUT(Makefile etc/clixonrc example/Makefile example/docker/Makefile + extras/rpm/Makefile docker/Makefile docker/cli/Makefile docker/cli/Dockerfile diff --git a/extras/rpm/Makefile.in b/extras/rpm/Makefile.in new file mode 100644 index 00000000..2a4018f8 --- /dev/null +++ b/extras/rpm/Makefile.in @@ -0,0 +1,35 @@ +TARBALL=$(shell realpath ../../build-root/clixon-latest.tar.xz) +BASENAME=$(shell basename $(TARBALL) | sed -e s/.tar.\*//) +VERSION=$(shell echo $(BASENAME) | cut -f2 -d-) +RELEASE=$(shell echo $(BASENAME) | cut -f3- -d- | sed -e s/-/_/g) +BR=$(shell realpath $(CURDIR)/../../build-root) +RPMBUILD=$(BR)/rpmbuild + +all: RPM + +spec: + @echo $(TARBALL) + mkdir -p $(RPMBUILD)/{RPMS,SRPMS,BUILD,SOURCES,SPECS} + cp $(TARBALL) $(RPMBUILD)/SOURCES/clixon-$(VERSION)-$(RELEASE).tar.xz + cp clixon.spec $(RPMBUILD)/SPECS + +srpm: spec + rpmbuild -bs \ + --define "cligen_prefix @CLIGEN_PREFIX@" \ + --define "_topdir $(RPMBUILD)" \ + --define "_version $(VERSION)" \ + --define "_release $(RELEASE)" \ + $(RPMBUILD)/SPECS/clixon.spec + mv $$(find $(RPMBUILD)/SRPMS -name \*.src.rpm -type f) $(BR) + +# Define DEVELOPER environmrnt variable to prevent .spec to add cligent to the +# list of build requirements +RPM: spec + rpmbuild -bb \ + --define "cligen_prefix @CLIGEN_PREFIX@" \ + $${DEVELOPER:+--define "developer yes"} \ + --define "_topdir $(RPMBUILD)" \ + --define "_version $(VERSION)" \ + --define "_release $(RELEASE)" \ + $(RPMBUILD)/SPECS/clixon.spec + mv $$(find $(RPMBUILD)/RPMS -name \*.rpm -type f) $(BR) diff --git a/extras/rpm/clixon.spec b/extras/rpm/clixon.spec new file mode 100644 index 00000000..c6ee5f70 --- /dev/null +++ b/extras/rpm/clixon.spec @@ -0,0 +1,72 @@ +%{!?_topdir: %define _topdir %(pwd)} +%{!?cligen_prefix: %define cligen_prefix %{_prefix}} + +Name: clixon +Version: %{_version} +Release: %{_release} +Summary: The XML-based command line processing tool CLIXON +Group: System Environment/Libraries +License: ASL 2.0 or GPLv2 +URL: http://www.clicon.org +AutoReq: no +BuildRequires: flex, bison +Requires: cligen, fcgi + +# Sometimes developers want to build it without installing cligen but passing +# path using --with-cligen and pointing it to cligen buildroot. Use %{developer} +# macro for these cases +%if 0%{!?developer:1} +BuildRequires: cligen +%endif + +Source: %{name}-%{version}-%{release}.tar.xz + +%description +The XML-based command line processing tool CLIXON. + +%package devel +Summary: CLIXON header files +Group: Development/Libraries +Requires: clixon + +%description devel +This package contains header files for CLIXON. + +%prep +%setup + +%build +%configure --with-cligen=%{cligen_prefix} --without-keyvalue +make + +%install +make DESTDIR=${RPM_BUILD_ROOT} install install-include + +%files +%{_libdir}/* +%{_bindir}/* +%{_sbindir}/* +#%{_sysconfdir}/* +%{_datadir}/%{name}/* +/www-data/clixon_restconf + +%files devel +%{_includedir}/%{name}/* + +%clean + +%post +/sbin/ldconfig + +caps="cap_setuid,cap_fowner,cap_chown,cap_dac_override" +caps="${caps},cap_kill,cap_net_admin,cap_net_bind_service" +caps="${caps},cap_net_broadcast,cap_net_raw" + +if [ -x /usr/sbin/setcap ]; then + /usr/sbin/setcap ${caps}=ep %{_bindir}/clixon_cli + /usr/sbin/setcap ${caps}=ep %{_bindir}/clixon_netconf + /usr/sbin/setcap ${caps}=ep %{_sbindir}/clixon_backend +fi + +%postun +/sbin/ldconfig