Debian Codegraph @

make-srpm.sh

raw
1 #!/bin/bash
2
3 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 #
5 # The contents of this file are subject to the Mozilla Public License Version
6 # 1.1 (the "License"); you may not use this file except in compliance with
7 # the License. You may obtain a copy of the License at
8 # http://www.mozilla.org/MPL/
9 #
10 # Software distributed under the License is distributed on an "AS IS" basis,
11 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 # for the specific language governing rights and limitations under the
13 # License.
14 #
15 # Alternatively, the contents of this file may be used under the terms of
16 # either the GNU General Public License Version 2 or later (the "GPL"), or
17 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
18 # in which case the provisions of the GPL or the LGPL are applicable instead
19 # of those above. If you wish to allow use of your version of this file only
20 # under the terms of either the GPL or the LGPL, and not to allow others to
21 # use your version of this file under the terms of the MPL, indicate your
22 # decision by deleting the provisions above and replace them with the notice
23 # and other provisions required by the GPL or the LGPL. If you do not delete
24 # the provisions above, a recipient may use your version of this file under
25 # the terms of any one of the MPL, the GPL or the LGPL.
26
27 SELF="$0"
28
29 PKG="nss-pem"
30
31 die() {
32 echo "$SELF: error: $1" >&2
33 exit 1
34 }
35
36 match() {
37 grep "$@" > /dev/null
38 }
39
40 DST="`readlink -f "$PWD"`"
41
42 REPO="`git rev-parse --show-toplevel`"
43 test -d "$REPO" || die "not in a git repo"
44
45 NV="`git describe --tags`"
46 echo "$NV" | match "^$PKG-" || die "release tag not found"
47
48 VER="`echo "$NV" | sed "s/^$PKG-//"`"
49
50 TIMESTAMP="`git log --pretty="%cd" --date=iso -1 \
51 | tr -d ':-' | tr ' ' . | cut -d. -f 1,2`"
52
53 VER="`echo "$VER" | sed "s/-.*-/.$TIMESTAMP./"`"
54
55 BRANCH="`git rev-parse --abbrev-ref HEAD`"
56 test -n "$BRANCH" || die "failed to get current branch name"
57 test master = "${BRANCH}" || VER="${VER}.${BRANCH//[\/-]/_}"
58 test -z "`git diff HEAD`" || VER="${VER}.dirty"
59
60 NV="${PKG}-${VER}"
61 printf "\n%s: preparing a release of \033[1;32m%s\033[0m\n\n" "$SELF" "$NV"
62
63 if [[ "$1" != "--generate-spec" ]]; then
64 TMP="`mktemp -d`"
65 trap "rm -rf '$TMP'" EXIT
66 cd "$TMP" >/dev/null || die "mktemp failed"
67
68 # clone the repository
69 git clone "$REPO" "$PKG" || die "git clone failed"
70 cd "$PKG" || die "git clone failed"
71
72 # run tests
73 ( mkdir build && cd build && cmake ../src && make -j && make -j test) \
74 || die "'make test' has failed"
75
76 SRC_TAR="${NV}.tar"
77 SRC="${SRC_TAR}.xz"
78 git archive --prefix="$NV/" --format="tar" HEAD -- . > "$SRC_TAR" \
79 || die "failed to export sources"
80
81 xz -c "$SRC_TAR" > "$SRC" || die "failed to compress sources"
82 fi
83
84 SPEC="./$PKG.spec"
85 cat > "$SPEC" << EOF
86 %undefine __cmake_in_source_build
87 %undefine __cmake3_in_source_build
88
89 Name: $PKG
90 Version: $VER
91 Release: 1%{?dist}
92 Summary: PEM file reader for Network Security Services (NSS)
93
94 # See README for details
95 # list.h - GPL-2.0-only
96 # * - MPL-1.1 OR GPL-2.0-or-later OR LGPL-2.1-or-later
97 License: GPL-2.0-only AND (MPL-1.1 OR GPL-2.0-or-later OR LGPL-2.1-or-later)
98 URL: https://github.com/kdudka/nss-pem
99 Source0: https://github.com/kdudka/nss-pem/releases/download/$NV/$SRC
100
101 BuildRequires: cmake3
102 BuildRequires: gcc
103 BuildRequires: make
104 BuildRequires: nss-pkcs11-devel
105
106 # require at least the version of nss that nss-pem was built against (#1428965)
107 Requires: nss%{?_isa} >= %(nss-config --version 2>/dev/null || echo 0)
108
109 %description
110 PEM file reader for Network Security Services (NSS), implemented as a PKCS#11
111 module.
112
113 %prep
114 %setup -q
115
116 %build
117 %cmake3 -S src
118 %cmake3_build
119
120 %install
121 %cmake3_install
122
123 %check
124 %ctest3
125
126 %files
127 %{_libdir}/libnsspem.so
128 %license COPYING.{GPL,MPL}
129 EOF
130
131 rpmbuild -bs "$SPEC" \
132 --define "_sourcedir ." \
133 --define "_specdir ." \
134 --define "_srcrpmdir $DST"