aboutsummaryrefslogtreecommitdiffstats
path: root/rpm-local/build.sh
blob: 797dd609ebbeb78b725805bb433c68cc0b084f08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/bin/sh -e
DIR="$(cd "$(dirname "$0")" && pwd -P)"
# Sources (in libosmocore, osmo-bts, ... subdirs)
SRCDIR="$(realpath "$DIR/../../")"
# Non-Osmocom sources (ortp/ortp-0.24.2.tar.gz, ...), download with 'osc co home:mnhauke:osmocom:nightly'
OSCDIR="/home/user/code/obs/home:mnhauke:osmocom:nightly"
IMAGE="centos8"

require_path() {
	if ! [ -e "$1" ]; then
		echo "ERROR: path not found: $1" >&2
		exit 1
	fi
}

build_docker_image() {
	if [ -e ".build.docker.$IMAGE" ]; then
		return
	fi
	require_path "images/$IMAGE/Dockerfile"

	( cd "$DIR/images"
	  docker build --build-arg "UID=$(id -u)" -t "$IMAGE:latest" "$IMAGE" )

	touch ".build.docker.$IMAGE"
}

# $1: path to spec file
spec_version() {
	require_path "$1"
	grep '^Version:' "$1" | cut -d ':' -f 2 | xargs
}

mkdir_rpmbuild() {
	# Clean previous dirs
	for dir in SOURCES BUILD; do
		if [ -d "rpmbuild/$dir" ]; then
			rm -rf "rpmbuild/$dir"
		fi
	done

	mkdir -p \
		"rpmbuild/RPMS" \
		"rpmbuild/SOURCES" \
		"rpmbuild/SPECS" \
		"rpmbuild/SRPMS"
}

# $1: pkgname (e.g. libosmocore)
skip_pkg() {
	if [ -e ".build.package.$1" ]; then
		echo ":: $pkgname (already built)"
		return 0
	fi
	echo ":: $pkgname"
	return 1
}

# $1: osmocom git repo name
_build_pkg() {
	local pkgname="$1"
	local specfile="spec/$pkgname/$pkgname.spec"

	# Copy spec file
	require_path "$specfile"
	cp "$specfile" "rpmbuild/SPECS/$pkgname.spec"

	# Copy source files (patches etc.)
	for i in "spec/$pkgname/"*; do
		case "$i" in
		*.spec)
			;;
		*)
			echo "add source: $i"
			cp -r "$i" "rpmbuild/SOURCES/"
		esac
	done

	# Install depends and build
	mkdir -p "cache/$IMAGE/dnf" "cache/distfiles"
	docker run \
		-it \
		--rm \
		-v "$DIR/rpmbuild:/home/user/rpmbuild" \
		-v "$DIR/scripts:/scripts" \
		-v "$DIR/cache/$IMAGE/dnf:/var/cache/dnf" \
		-v "$DIR/cache/distfiles:/home/user/distfiles" \
		"$IMAGE:latest" \
		/scripts/build_pkg.sh "$pkgname"

	touch ".build.package.$pkgname"
}

# $1: pkgname (e.g. libosmocore)
# $2: osmocom git repo name (if different than $1)
# $3-$n: path to additional source in $OSCDIR (e.g. gapk/0606_421.zip)
build_pkg_osmo() {
	local pkgname="$1"
	local repo="$2"
	local specfile="spec/$pkgname/$pkgname.spec"
	local version

	skip_pkg "$pkgname" && return
	mkdir_rpmbuild

	if [ -z "$repo" ]; then
		repo="$pkgname"
	fi

	version="$(spec_version "$specfile")"
	tarball="rpmbuild/SOURCES/$pkgname-$version.tar.xz"
	echo "add source: git HEAD tarball: $tarball"

	require_path "$SRCDIR/$repo"
	git -C "$SRCDIR/$repo" archive \
		--format=tar \
		--prefix="$repo-$version/" \
		HEAD \
		> "$tarball"

	if [ -n "$2" ] && [ -n "$3" ]; then
		shift 2
		for i in "$@"; do
			local tarball="$OSCDIR/$i"

			require_path "$tarball"
			echo "add source: $tarball"
			cp "$tarball" "rpmbuild/SOURCES/"
		done
	fi

	_build_pkg "$pkgname"
}

# $1: pkgname (e.g. ortp)
# $2-$n: path to source in $OSCDIR (e.g. ortp/ortp-0.24.2.tar.gz, leave empty if no source needed)
build_pkg_other() {
	local pkgname="$1"

	skip_pkg "$pkgname" && return
	mkdir_rpmbuild

	shift
	if [ -n "$1" ]; then
		for i in "$@"; do
			local tarball="$OSCDIR/$i"

			require_path "$tarball"
			echo "add source: $tarball"
			cp "$tarball" "rpmbuild/SOURCES/"
		done
	fi

	_build_pkg "$pkgname"
}

require_path "$SRCDIR"
require_path "$OSCDIR"
build_docker_image "$IMAGE"

#
# Build packages
#

# Compatibility with build dependency available in openSUSE
build_pkg_other "systemd-rpm-macros"

# ortp (dependency of libosmo-abis)
build_pkg_other "ortp" "ortp/ortp-0.24.2.tar.gz"

# uhd (dependency of osmo-bts)
build_pkg_other "python-cheetah"
build_pkg_other "uhd"

# libdbi-drivers-dbd-sqlite3 (dependency of osmo-msc)
build_pkg_other "libdbi"
build_pkg_other "libdbi-drivers"

# limesuite (dependency of osmo-bts)
# needs wxwidgets
# build_pkg_other "limesuite" "limesuite/limesuite-20.01.0.tar.xz"

# libgtpnl (dependency of osmo-ggsn)
build_pkg_other libgtpnl "libgtpnl/libgtpnl-1.2.1.0.tar.xz"

# sofia-sip-ua-glib (dependency of osmo-sip-connector)
build_pkg_other "sofia-sip"

# liboping (dependency of osmo-sysmon)
build_pkg_other "liboping"

# libgsm-devel (dependency of gapk)
build_pkg_other "libgsm"

# libopencore-amr-devel (dependency of gapk)
build_pkg_other "opencore-amr"

# Osmocom libraries
build_pkg_osmo "libosmocore"
build_pkg_osmo "libosmo-abis"
build_pkg_osmo "libosmo-netif"
build_pkg_osmo "libsmpp34"
build_pkg_osmo "libasn1c"
build_pkg_osmo "libosmo-sccp"

# Osmocom RAN
build_pkg_osmo "osmo-bts"
build_pkg_osmo "osmo-trx"
build_pkg_osmo "osmo-pcu"

# Osmocom CN
build_pkg_osmo "osmo-ggsn"
build_pkg_osmo "osmo-iuh"
build_pkg_osmo "osmo-hlr"
build_pkg_osmo "osmo-mgw"
build_pkg_osmo "osmo-msc"
build_pkg_osmo "osmo-bsc"
build_pkg_osmo "osmo-sgsn"
build_pkg_osmo "osmo-sip-connector"

# Other
build_pkg_osmo "gapk" "gapk" "gapk/0606_421.zip"
build_pkg_osmo "osmocom-bb"
# needs: libulfius
# build_pkg_osmo "osmo-cbc"
build_pkg_osmo "osmo-e1d"
build_pkg_osmo "osmo-e1-recorder"
build_pkg_osmo "osmo-el2tpd"
# needs: libzmq
# build_pkg_osmo "osmo-pcap"
# can't parse
# build_pkg_osmo "osmo-python-tests"
# needs: qmi-glib
# build_pkg_osmo "osmo-qcdiag"

# needs: libosmo-simtrace2, libulfius
# build_pkg_osmo "osmo-remsim"
build_pkg_osmo "osmo-sim-auth"
build_pkg_osmo "osmo-sysmon"
build_pkg_osmo "osmo-uecups"

# needs: docbook_5, graphviz-gnome, libxslt-tools, mscgen, python3-nwdiag, texlive-scheme-medium
# build_pkg_osmo "osmo-gsm-manuals-devel" "osmo-gsm-manuals"