pack.sh 8.69 KB
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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515
#!/bin/bash

PROJECTDIR=$(dirname $(dirname $(readlink -f ${0})))
WORKDIR=$(mktemp -d)

if [ -e /etc/os-release ]; then
	. /etc/os-release
fi

#
# Limpa diretório temporário
#
cleanup()
{
	rm -fr ${WORKDIR}
}

#
# Monta projeto no diretório corrente.
#
build()
{
	make clean

	make all
	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

	cp -rv .bin/Release/* ${WORKDIR}/build/bin
	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

	make DESTDIR=${WORKDIR}/build install
	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

}

build_plugin()
{

	echo -e "\e]2;${2}-${1}\a"

	cd ${WORKDIR}/sources/pw3270-plugin-${2}
	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

	export cache=${WORKDIR}/cache/pw3270-plugin-${2}.cache

	./configure \
		CFLAGS=${CFLAGS} \
		LDFLAGS=${LDFLAGS} \
		LIB3270_CFLAGS="${LIB3270_CFLAGS}" \
		LIB3270_LIBS="${LIB3270_LIBS}" \
		LIBV3270_CFLAGS="${LIBV3270_CFLAGS}" \
		LIBV3270_LIBS="${LIBV3270_LIBS}" \
		--host=${host} \
		--prefix=${prefix} \
		--libdir=${prefix}/lib

	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

	make all
	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

	cp -rv .bin/Release/* ${WORKDIR}/build/bin
	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

}

#
# Monta binários
#
# $1 = Arquitetura (x86_32/x86_64)
#
pack()
{

	echo -e "\e]2;pw3270-${1}\a"

	case ${1} in
	x86_32)
		host=i686-w64-mingw32
		host_cpu=i686
		prefix=/usr/i686-w64-mingw32/sys-root/mingw
		tools=i686-w64-mingw32
		pkg_config=/usr/bin/i686-w64-mingw32-pkg-config
		mingw_name=mingw32
		;;

	x86_64)
		host=x86_64-w64-mingw32
		host_cpu=x86_64
		prefix=/usr/x86_64-w64-mingw32/sys-root/mingw
		tools=x86_64-w64-mingw32
		pkg_config=/usr/bin/x86_64-w64-mingw32-pkg-config
		mingw_name=mingw64
		;;

	*)
		failed "Arquitetura desconhecida: ${1}"

	esac

#	sudo zypper \
#		--non-interactive \
#		in \
#		${mingw_name}-libcurl-devel \
#		${mingw_name}-curl \
#		${mingw_name}-libopenssl-devel \
#		${mingw_name}-libintl-devel \
#		${mingw_name}-atk-devel \
#		${mingw_name}-pango-devel \
#		${mingw_name}-win_iconv-devel \
#		${mingw_name}-pixman-devel \
#		${mingw_name}-glib2-devel \
#		${mingw_name}-cairo-devel \
#		${mingw_name}-freetype-devel \
#		${mingw_name}-winpthreads-devel \
#		${mingw_name}-gtk3-devel \
#		${mingw_name}-cross-gcc-c++ \
#		${mingw_name}-cross-pkg-config \
#		${mingw_name}-cross-cpp \
#		${mingw_name}-cross-binutils \
#		${mingw_name}-cross-nsis

	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

	export HOST_CC=/usr/bin/gcc

	rm -fr ${WORKDIR}/cache
	mkdir -p ${WORKDIR}/cache

	rm -fr ${WORKDIR}/build
	mkdir -p ${WORKDIR}/build/src/include
	mkdir -p ${WORKDIR}/build/.bin/Release

	#
	# Setup Target dir
	#
	mkdir -p ${WORKDIR}/build/bin

	export CFLAGS=-I${WORKDIR}/build/${prefix}/include -DWIN32 -D_WIN32
	export LDFLAGS=-L${WORKDIR}/build/bin
	export PKG_CONFIG_PATH=${WORKDIR}/build/${prefix}/lib/pkgconfig

	#
	# Build lib3270
	#
	echo -e "\e]2;lib3270-${1}\a"

	cd ${WORKDIR}/sources/lib3270
	export cache=${WORKDIR}/cache/lib3270.cache

	./configure \
		--host=${host} \
		--prefix=${prefix} \
		--libdir=${prefix}/lib \
		--enable-self-signed-cert-check \
		--enable-ssl-crl-check \
		--enable-crl-expiration-check \
		--disable-ldap \
		--enable-curl \
	 	--with-default-crl-url="ldap://pkildap.bb.com.br:389/CN=CRL1,CN=AC%20Banco%20do%20Brasil%20-%20EI%20v1,OU=ICP-BB,O=Banco%20do%20Brasil%20S.A.,C=BR?certificaterevocationlist" \
		--with-default-host="tn3270s://3270.df.bb:9023"

	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

	build

	export LIB3270_CFLAGS="-DLIB3270_NAME=3270"
	export LIB3270_LIBS="-l3270"

	#
	# Build libv3270
	#
	echo -e "\e]2;libv3270-${1}\a"

	cd ${WORKDIR}/sources/libv3270
	export cache=${WORKDIR}/cache/libv3270.cache

	./configure \
		CFLAGS=${CFLAGS} \
		LDFLAGS=${LDFLAGS} \
		LIB3270_CFLAGS="${LIB3270_CFLAGS}" \
		LIB3270_LIBS="${LIB3270_LIBS}" \
		--host=${host} \
		--prefix=${prefix} \
		--libdir=${prefix}/lib

	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

	build

	export LIBV3270_CFLAGS="-DLIBV3270_MODE=3270"
	export LIBV3270_LIBS="-lv3270"

	#
	# Build main application
	#
	echo -e "\e]2;pw3270-${1}\a"

	cd ${WORKDIR}/sources/pw3270
	export cache=${WORKDIR}/cache/application.cache

	./configure \
		CFLAGS=${CFLAGS} \
		LDFLAGS=${LDFLAGS} \
		LIB3270_CFLAGS="${LIB3270_CFLAGS}" \
		LIB3270_LIBS="${LIB3270_LIBS}" \
		LIBV3270_CFLAGS="${LIBV3270_CFLAGS}" \
		LIBV3270_LIBS="${LIBV3270_LIBS}" \
		--host=${host} \
		--prefix=${prefix} \
		--libdir=${prefix}/lib \
		--with-source-locales=${WORKDIR}/locale

	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

	mkdir -p ${WORKDIR}/locale

	cp ${WORKDIR}/sources/lib3270/.pot/*.pot ${WORKDIR}/locale
	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

	cp ${WORKDIR}/sources/libv3270/.pot/*.pot ${WORKDIR}/locale
	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

	build

	#
	# Build plugins
	#
	build_plugin ${1} hllapi

	#
	# Install data & icons
	#
	echo -e "\e]2;pw3270-icons-${1}\a"

	cd ${WORKDIR}/sources/pw3270

	make -C ${WORKDIR}/sources/pw3270 locale
	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

	cp -rv .bin/locale ${WORKDIR}/build
	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

	mkdir -p ${WORKDIR}/build/win

	mkdir -p ${WORKDIR}/sources/pw3270/.bin/Release
	cp -rv ${WORKDIR}/build/bin/* ${WORKDIR}/sources/pw3270/.bin/Release

	chmod +x ${WORKDIR}/sources/pw3270/win/makeruntime.sh
	${WORKDIR}/sources/pw3270/win/makeruntime.sh
	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

	mkdir -p ${WORKDIR}/build/bin
	cp -rv ${WORKDIR}/sources/pw3270/.bin/runtime ${WORKDIR}/build/bin
	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

	#
	# Copy branding
	#
	cp ${WORKDIR}/branding/*.ico ${WORKDIR}/build
	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

	cp ${WORKDIR}/branding/*.png ${WORKDIR}/build
	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

	cp ${WORKDIR}/branding/AUTHORS ${WORKDIR}/build
	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

	cp ${WORKDIR}/branding/LICENSE ${WORKDIR}/build
	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

	cp -rv ${WORKDIR}/branding/ui ${WORKDIR}/build
	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

	cp -rv ${WORKDIR}/branding/*.conf ${WORKDIR}/build
	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

	cp -rv ${WORKDIR}/sources/pw3270/charsets/*.xml ${WORKDIR}/build
	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

	#
	# Create installation package
	#
	echo -e "\e]2;pw3270-package-${1}\a"

	cd ${WORKDIR}/build

	cp ${WORKDIR}/sources/pw3270/win/pw3270.nsi ./pw3270.nsi
	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

	makensis -DWITHGTK pw3270.nsi
	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

	cp -v *.exe ${PROJECTDIR}
	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

	if [ -d ~/public_html/win/pw3270 ]; then
		mkdir -p ~/public_html/win/pw3270/${1}
		cp -v *.exe ~/public_html/win/pw3270/${1}
		if [ "$?" != "0" ]; then
			cleanup
			exit -1
		fi
	fi

#	if [ ! -z ${WIN_PACKAGE_SERVER} ]; then
#		scp *.exe ${WIN_PACKAGE_SERVER}/pw3270
#		if [ "$?" != "0" ]; then
#			cleanup
#			exit -1
#		fi
#	fi

}

#
# Get sources from GIT
#
mkdir -p ${WORKDIR}/sources

for src in lib3270 libv3270 pw3270 pw3270-plugin-hllapi; do

	echo "Baixando ${src}..."
	echo -e "\e]2;Downloading ${src}\a"

	git clone https://github.com/PerryWerneck/${src}.git ${WORKDIR}/sources/${src}
	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi

	cd ${WORKDIR}/sources/${src}

	NOCONFIGURE=1 ./autogen.sh
	if [ "$?" != "0" ]; then
		cleanup
		exit -1
	fi


done

#
# Setup branding
#
echo -e "\e]2;Branding\a"

mkdir -p ${WORKDIR}/branding

BRANDING_SOURCES=${WORKDIR}/sources/pw3270/branding

cp -rv ${BRANDING_SOURCES}/* ${WORKDIR}/branding
if [ "$?" != "0" ]; then
	cleanup
	exit -1
fi

convert -density 384 -background transparent ${BRANDING_SOURCES}/pw3270.svg -define icon:auto-resize -colors 256 ${WORKDIR}/branding/pw3270.ico
if [ "$?" != "0" ]; then
	cleanup
	exit -1
fi

convert -background transparent ${BRANDING_SOURCES}/pw3270.svg ${WORKDIR}/branding/pw3270.png
if [ "$?" != "0" ]; then
	cleanup
	exit -1
fi

optipng -o7 ${WORKDIR}/branding/pw3270.png
if [ "$?" != "0" ]; then
	cleanup
	exit -1
fi

convert -background transparent ${BRANDING_SOURCES}/pw3270-logo.svg ${WORKDIR}/branding/pw3270-logo.png
if [ "$?" != "0" ]; then
	cleanup
	exit -1
fi

optipng -o7 ${WORKDIR}/branding/pw3270-logo.png
if [ "$?" != "0" ]; then
	cleanup
	exit -1
fi

cp ${WORKDIR}/sources/pw3270/AUTHORS ${WORKDIR}/branding
if [ "$?" != "0" ]; then
	cleanup
	exit -1
fi

cp ${WORKDIR}/sources/pw3270/LICENSE ${WORKDIR}/branding
if [ "$?" != "0" ]; then
	cleanup
	exit -1
fi

cp ${WORKDIR}/sources/pw3270/conf/colors.conf ${WORKDIR}/branding
if [ "$?" != "0" ]; then
	cleanup
	exit -1
fi

cp -rv ${WORKDIR}/sources/pw3270/ui ${WORKDIR}/branding
if [ "$?" != "0" ]; then
	cleanup
	exit -1
fi

#
# Create installers 
#
pack x86_32
pack x86_64

cleanup