File: build.sh

package info (click to toggle)
libcaptury 0.3.0~svn158-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,548 kB
  • ctags: 175
  • sloc: sh: 9,002; cpp: 846; makefile: 45
file content (167 lines) | stat: -rwxr-xr-x 3,138 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
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
#! /bin/bash

function die() {
	echo "${*}" 1>&2
	exit 1
}

PREFIX=${PREFIX:-/opt/sandbox}
INSTALL=no
VERBOSE=0

function print_help() {
	echo "syntax: ./build.sh [arguments]"
	echo
	echo " --help               prints this help."
	echo " --prefix PATH        specifies where to install, when ./configure is executed."
	echo " --install            performs install action on successfull built."
	echo " --clean              cleans tree"
	echo " -v, --verbose        increases verbosity."
	echo
}

function clean_tree() {
	echo "Cleaning tree"
	for ABI in $(get_install_abis); do
		rm -rf abi-${ABI}
	done
	./autogen.sh clean
}

function get_install_abis() {
	local ABIS
	case $(uname -m) in
		x86_64)
			if [[ -d /lib32 ]]; then
				ABIS=(x86 amd64)
			else
				ABIS=(amd64) # no multilib-arch
			fi
			;;
		i?86)
			ABIS=(x86)
			;;
		*)
			die "Unsupported ABI"
			;;
	esac
	echo "${ABIS[@]}"
}

function get_libdir() {
	if [[ -n $ABI ]]; then
		case $ABI in
			amd64) 	echo "lib64" ;;
			x86)	echo "lib32" ;;
			*)		echo "lib" ;;
		esac
	else
		echo "lib"
	fi
}

while test -n "$*"; do
	case $1 in
		--help)
			print_help
			exit 0
			;;
		--prefix)
			PREFIX="$2"
			shift 2
			;;
		-v)
			VERBOSE=$[VERBOSE + 1]
			;;
		--install|install)
			INSTALL=yes
			shift
			;;
		--clean|clean)
			clean_tree
			exit 0
			;;
		*)
			die "Unknown parameter."
			;;
	esac
done

# some envvar backups
O_PKG_CONFIG_PATH="${PKG_CONFIG_PATH}"
O_LD_LIBRARY_PATH="${LD_LIBRARY_PATH}"
O_CFLAGS="${CFLAGS:--O0 -ggdb3 -pipe}"
O_CXXFLAGS="${CXXFLAGS:--O0 -ggdb3 -pipe}"
O_LDFLAGS="${LDFLAGS}"

function setup_env() {
	export CFLAGS="${O_CFLAGS} ${ABI_CFLAGS}"
	export CXXFLAGS="${O_CXXFLAGS} ${ABI_CXXFLAGS}"

	case ${ABI} in
		amd64)
			export CFLAGS="${O_CFLAGS}"
			export CXXFLAGS="${O_CXXFLAGS}"
			export LD_LIBRARY_PATH="${O_LD_LIBRARY_PATH}"
			export LDFLAGS="${O_LDFLAGS}"
			;;
		x86)
			export CFLAGS="${O_CFLAGS} -m32"
			export CXXFLAGS="${O_CXXFLAGS} -m32"

			# solves link error when linking src/example program
			export LDFLAGS="-L/usr/lib32" 
			export LD_LIBRARY_PATH="/usr/lib32"
			;;
	esac

	export PKG_CONFIG_PATH="${PREFIX}/$(get_libdir)/pkgconfig:${O_PKG_CONFIG_PATH}"
}

print_env() {
	echo " * ENVIRONMENT FOR ABI: ${ABI}"
	echo " * "
	echo " * CFLAGS=\"$CFLAGS\""
	echo " * CXXFLAGS=\"$CXXFLAGS\""
	echo " * LDFLAGS=\"$LDFLAGS\""
	echo " * LD_LIBRARY_PATH=\"$LD_LIBRARY_PATH\""
	echo
}

if [[ ! -f configure ]]; then
	./autogen.sh || die "./autogen failed."
fi

for ABI in $(get_install_abis); do
	export ABI

	echo "Building for ${ABI} ABI"

	setup_env
	print_env

	confopts=""
	confopts="${confopts} --prefix=${PREFIX}"
	confopts="${confopts} --libdir=${PREFIX}/$(get_libdir)"

	mkdir -p "abi-${ABI}"
	pushd "abi-${ABI}"
		if [[ ! -f libcaptury.pc ]]; then
			../configure ${confopts} \
				|| die "configure failed for ${ABI} ABI"
		fi

		make || die "make failed for ${ABI} ABI"

		if [[ ${INSTALL} = "yes" ]]; then
			make install || "make install failed for ${ABI} ABI"
		fi
	popd
done

echo
if [[ ${INSTALL} != "yes" ]]; then
	echo "Now run \`$0 --install\` to actually install the software."
else
	echo "SUCCESS!"
fi