1 | #!/bin/bash |
---|
2 | #------------------------------------------------------------------------------- |
---|
3 | # Copyright (C) 2006-2021 British Crown (Met Office) & Contributors. |
---|
4 | # |
---|
5 | # This file is part of FCM, tools for managing and building source code. |
---|
6 | # |
---|
7 | # FCM is free software: you can redistribute it and/or modify |
---|
8 | # it under the terms of the GNU General Public License as published by |
---|
9 | # the Free Software Foundation, either version 3 of the License, or |
---|
10 | # (at your option) any later version. |
---|
11 | # |
---|
12 | # FCM is distributed in the hope that it will be useful, |
---|
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | # GNU General Public License for more details. |
---|
16 | # |
---|
17 | # You should have received a copy of the GNU General Public License |
---|
18 | # along with FCM. If not, see <http://www.gnu.org/licenses/>. |
---|
19 | #------------------------------------------------------------------------------- |
---|
20 | # NAME |
---|
21 | # fcm-rpmbuild |
---|
22 | # |
---|
23 | # SYNOPSIS |
---|
24 | # fcm-rpmbuild [--gui] [REV] |
---|
25 | # E.g.: |
---|
26 | # fcm rpmbuild 2014-03 |
---|
27 | # |
---|
28 | # DESCRIPTION |
---|
29 | # Build an RPM for distributing FCM. |
---|
30 | # Assume that the current working directory is a local Git clone containing |
---|
31 | # the FCM project. |
---|
32 | # |
---|
33 | # OPTIONS |
---|
34 | # --gui - add GUI packages such as "perl-Tk" and "xxdiff". |
---|
35 | # |
---|
36 | # ARGUMENTS |
---|
37 | # REV - Revision to build. Default to HEAD. |
---|
38 | #------------------------------------------------------------------------------- |
---|
39 | |
---|
40 | set -eu |
---|
41 | THIS=$(basename $0) |
---|
42 | NAME='fcm' |
---|
43 | |
---|
44 | rpmdev-setuptree |
---|
45 | |
---|
46 | # Build RPM without no dependency on subversion or xxdiff? |
---|
47 | REQUIRES_GUI= |
---|
48 | if (($# > 0)) && [[ $1 == '--gui' ]]; then |
---|
49 | REQUIRES_GUI='perl-Tk xxdiff' |
---|
50 | shift 1 |
---|
51 | fi |
---|
52 | |
---|
53 | # Create the source tree |
---|
54 | REV=${1:-HEAD} |
---|
55 | REV_NAME=$(git describe $REV) |
---|
56 | REV_BASE=$(git describe --abbrev=0 $REV) |
---|
57 | RELEASE=1 |
---|
58 | if [[ $REV_NAME != $REV_BASE ]]; then |
---|
59 | COMMIT_DATE=$(date -u +%Y%m%dT%H%M "--date=$(git show -s --format=%ci $REV)") |
---|
60 | RELEASE=${COMMIT_DATE}git${REV_NAME#$REV_BASE-*-g} |
---|
61 | fi |
---|
62 | REV_BASE_DOT=$(sed 's/-/./g' <<<$REV_BASE) |
---|
63 | git archive --format=tar --prefix=$NAME-$REV_BASE_DOT/ $REV \ |
---|
64 | | (cd ~/rpmbuild/SOURCES/ && tar -xf -) |
---|
65 | SOURCE=~/rpmbuild/SOURCES/$NAME-$REV_BASE_DOT |
---|
66 | echo "FCM.VERSION=\"$REV_NAME\";" >$SOURCE/doc/etc/$NAME-version.js |
---|
67 | rm -r $SOURCE/{test,t} |
---|
68 | if [[ -z $REQUIRES_GUI ]]; then |
---|
69 | rm $SOURCE/{bin/fcm_gui,lib/FCM1/Interactive/InputGetter/GUI.pm} |
---|
70 | fi |
---|
71 | |
---|
72 | # Create the rpmbuild spec file |
---|
73 | { |
---|
74 | cat <<__SPEC__ |
---|
75 | Name: $NAME |
---|
76 | Version: $REV_BASE_DOT |
---|
77 | Release: $RELEASE |
---|
78 | Summary: A modern Fortran build system + wrappers to SVN |
---|
79 | Group: Development/Tools |
---|
80 | License: GPLv3 |
---|
81 | URL: https://github.com/metomi/$NAME/ |
---|
82 | Source0: https://github.com/metomi/$NAME/releases/ |
---|
83 | BuildArch: noarch |
---|
84 | Requires: diffutils filesystem gzip make perl-core perl-Config-IniFiles perl-MailTools perl-XML-Parser subversion subversion-perl $REQUIRES_GUI |
---|
85 | |
---|
86 | %description |
---|
87 | FCM: A modern Fortran build system + wrappers to Subversion for scientific |
---|
88 | software development |
---|
89 | |
---|
90 | %prep |
---|
91 | |
---|
92 | %build |
---|
93 | |
---|
94 | %install |
---|
95 | rm -fr %{buildroot} |
---|
96 | mkdir -p %{buildroot}/opt/ %{buildroot}/usr/bin |
---|
97 | cp -pr %_sourcedir/$NAME-$REV_BASE_DOT %{buildroot}/opt/$NAME |
---|
98 | cp -p %_sourcedir/$NAME-$REV_BASE_DOT/usr/bin/fcm %{buildroot}/usr/bin |
---|
99 | |
---|
100 | %clean |
---|
101 | rm -fr %{buildroot} |
---|
102 | |
---|
103 | %files |
---|
104 | /opt/$NAME |
---|
105 | /usr/bin/fcm |
---|
106 | __SPEC__ |
---|
107 | } >~/rpmbuild/SPECS/$NAME.spec |
---|
108 | |
---|
109 | cd ~/rpmbuild/SPECS |
---|
110 | rpmbuild -ba $NAME.spec |
---|
111 | rm -fr ~/rpmbuild/SOURCES/$NAME-$REV_BASE_DOT |
---|
112 | exit |
---|