File: build-release.sh

package info (click to toggle)
kchmviewer 7.7-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, buster, sid
  • size: 1,784 kB
  • sloc: cpp: 7,973; sh: 145; makefile: 4
file content (127 lines) | stat: -rwxr-xr-x 3,023 bytes parent folder | download
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
#!/bin/sh

# Export the source code
BUILD_RPM64=1
BUILD_RPM32=1
BUILD_WINDOWS=1

PACKAGE=kchmviewer
BINARYFILE="bin/kchmviewer"

FILE_VERSION="src/version.h"
RPM_OUTDIR="/home/tim/rpmbuild/RPMS"

# Get current version
VERSION_MAJOR=`sed -n 's/^\#define\s\+APP_VERSION_MAJOR\s\+\([0-9a-z]\+\)/\1/p' $FILE_VERSION`
VERSION_MINOR=`sed -n 's/^\#define\s\+APP_VERSION_MINOR\s\+\"\?\([0-9a-z]\+\)\"\?/\1/p' $FILE_VERSION`
CURRENTVER="$VERSION_MAJOR.$VERSION_MINOR"

BUILDDIR="$PACKAGE-$CURRENTVER"
RELEASEDIR="release-$CURRENTVER"

if [ -d "$BUILDDIR" ]; then
	rm -rf "$BUILDDIR"
fi

if [ -d "$RELEASEDIR" ]; then
	rm -rf "$RELEASEDIR"
fi

mkdir "$RELEASEDIR" || exit 1


# Source package
svn export . "$BUILDDIR/" || exit 1
tar zcf "$RELEASEDIR/$PACKAGE-$CURRENTVER.tar.gz" $BUILDDIR || exit 1


# Linux RPMs
for target in qt5-32 qt5-64 qt4-64; do

	echo "Building for $target"
	rm -rf "$BUILDDIR"
	svn export . "$BUILDDIR/" || exit 1

	# Get the Qt version
	case $target in
		qt4-*)
			QMAKE=qmake
			QTLIBS="QtDBus QtXml QtGui QtCore QtNetwork QtWebKit"
			RPMSUFFIX="qt4"
			;;

		qt5-*)
			QMAKE=qmake-qt5
			QTLIBS="Qt5WebKitWidgets Qt5PrintSupport Qt5WebKit Qt5Widgets Qt5Xml Qt5DBus Qt5Network Qt5Gui Qt5Core GL"
			RPMSUFFIX="qt5"
			;;

		*)
			echo "Invalid target"
			exit 1
	esac

	# Get the arch
	case $target in
		*-32)
			QMAKESPEC="linux-g++-32"
			RPMARCH="i586"
			LINKLIBS="pthread chm zip $QTLIBS"

			;;

		*-64)
			QMAKESPEC="linux-g++-64"
			RPMARCH="x86_64"
			;;

		*)
			echo "Invalid arch"
			exit 1
	esac

	# Hack the libs
	if [ -n "$LINKLIBS" ]; then
		pushd $BUILDDIR

		# Link the libraries so the linker finds the 32-bit libs instead of 64-bit ones
		for lib in $LINKLIBS; do

			libpath=`find /lib /usr/lib/ -maxdepth 1 -name lib$lib.so | sort -r | head -n1`
			if [ -z "$libpath" ]; then
				libpath=`find /lib /usr/lib/ -maxdepth 1 -name lib$lib.so\.[0-9] | sort -r | head -n1`

				if [ -z "$libpath" ]; then
					echo "No library $lib found"
					exit
				fi
			fi
	
			ln -s $libpath "src/lib$lib.so"
		done
		popd
	fi

	# Build it	
	(cd "$BUILDDIR" && $QMAKE -r -spec $QMAKESPEC "CONGIF+=release" && make -j4) || exit 1

	# Making the RPM root
	rm -rf "$BUILDDIR/buildroot"
	mkdir -p "$BUILDDIR/buildroot/usr/bin"
	mkdir -p "$BUILDDIR/buildroot/usr/share/applications"
	mkdir -p "$BUILDDIR/buildroot/usr/share/pixmaps"
	cp packages/*.desktop "$BUILDDIR/buildroot/usr/share/applications"
	cp packages/*.png "$BUILDDIR/buildroot/usr/share/pixmaps"
	strip --strip-all "$BUILDDIR/bin/kchmviewer" -o "$BUILDDIR/buildroot/usr/bin/kchmviewer" || exit 1

	# Prepare a spec file
	sed "s/^Version: [0-9.]\\+/Version: $CURRENTVER/" packages/rpm.spec > $BUILDDIR/rpm.spec

	# Build an RPM
	rpmbuild -bb --target=$RPMARCH --buildroot `pwd`"/$BUILDDIR/buildroot/" $BUILDDIR/rpm.spec || exit 1
	mv $RPM_OUTDIR/$RPMARCH/kchmviewer-$CURRENTVER-1.$RPMARCH.rpm "$RELEASEDIR/kchmviewer-$CURRENTVER-1.${RPMARCH}-${RPMSUFFIX}.rpm" || exit 1
	rm -rf "$BUILDDIR"
done

echo "Done! Version $CURRENTVER released!"