Blame win/build-win.sh

87fe10
#!/bin/bash
87fe10
87fe10
set -e
87fe10
87fe10
ROOT="$(cd `dirname "$0"`; pwd)"
87fe10
cd "$ROOT"
87fe10
87fe10
source function.sh
87fe10
source toolchain.sh
87fe10
87fe10
87fe10
#OPTIONS="-O3 -DNDEBUG"
87fe10
OPTIONS="-g -O0"
87fe10
87fe10
87fe10
packages="zlib png freetype ogg vorbis flac mpg123 sdl2 sdl2image sdl2mixer"
87fe10
newpackages="helianthus demo"
87fe10
87fe10
dir_zlib=zlib-1.2.11
87fe10
dir_png=libpng-1.6.37
87fe10
dir_freetype=freetype-2.8.1
87fe10
dir_ogg=libogg-1.3.4
87fe10
dir_vorbis=libvorbis-1.3.7
87fe10
dir_flac=flac-1.3.2
87fe10
dir_mpg123=mpg123-1.26.3
87fe10
dir_sdl2=SDL2-2.0.12
87fe10
dir_sdl2image=SDL2_image-2.0.5
87fe10
dir_sdl2mixer=SDL2_mixer-2.0.4
87fe10
87fe10
tar_zlib=$dir_zlib.tar.gz
87fe10
tar_png=$dir_png.tar.gz
87fe10
tar_freetype=$dir_freetype.tar.gz
87fe10
tar_ogg=$dir_ogg.tar.gz
87fe10
tar_vorbis=$dir_vorbis.tar.gz
87fe10
tar_flac=$dir_flac.tar.xz
87fe10
tar_mpg123=$dir_mpg123.tar.bz2
87fe10
tar_sdl2=$dir_sdl2.tar.gz
87fe10
tar_sdl2image=$dir_sdl2image.tar.gz
87fe10
tar_sdl2mixer=$dir_sdl2mixer.tar.gz
87fe10
87fe10
url_zlib="http://zlib.net/$tar_zlib"
87fe10
url_png="https://prdownloads.sourceforge.net/libpng/$tar_png"
87fe10
url_freetype="https://download.savannah.gnu.org/releases/freetype/$tar_freetype"
87fe10
url_ogg="https://downloads.xiph.org/releases/ogg/$tar_ogg"
87fe10
url_vorbis="https://downloads.xiph.org/releases/vorbis/$tar_vorbis"
87fe10
url_flac="https://downloads.xiph.org/releases/flac/$tar_flac"
87fe10
url_mpg123="https://sourceforge.net/projects/mpg123/files/mpg123/1.26.3/$tar_mpg123"
87fe10
url_sdl2="https://www.libsdl.org/release/$tar_sdl2"
87fe10
url_sdl2image="https://www.libsdl.org/projects/SDL_image/release/$tar_sdl2image"
87fe10
url_sdl2mixer="https://www.libsdl.org/projects/SDL_mixer/release/$tar_sdl2mixer"
87fe10
87fe10
sha_zlib=c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1
87fe10
sha_png=daeb2620d829575513e35fecc83f0d3791a620b9b93d800b763542ece9390fb4
87fe10
sha_freetype=876711d064a6a1bd74beb18dd37f219af26100f72daaebd2d86cb493d7cd7ec6
87fe10
sha_ogg=fe5670640bd49e828d64d2879c31cb4dde9758681bb664f9bdbf159a01b0c76e
87fe10
sha_vorbis=0e982409a9c3fc82ee06e08205b1355e5c6aa4c36bca58146ef399621b0ce5ab
87fe10
sha_flac=91cfc3ed61dc40f47f050a109b08610667d73477af6ef36dcad31c31a4a8d53f
87fe10
sha_mpg123=30c998785a898f2846deefc4d17d6e4683a5a550b7eacf6ea506e30a7a736c6e
87fe10
sha_sdl2=349268f695c02efbc9b9148a70b85e58cefbbf704abd3e91be654db7f1e2c863
87fe10
sha_sdl2image=bdd5f6e026682f7d7e1be0b6051b209da2f402a2dd8bd1c4bd9c25ad263108d0
87fe10
sha_sdl2mixer=b4cf5a382c061cd75081cf246c2aa2f9df8db04bdda8dcdc6b6cca55bede2419
87fe10
87fe10
87fe10
#######################################################################
87fe10
87fe10
87fe10
function build_zlib() {
87fe10
	"$srcdir"/configure \
87fe10
		--prefix="$prefix" \
87fe10
		--static
87fe10
	make -j4
87fe10
	make install
87fe10
}
87fe10
87fe10
87fe10
function build_png() {
87fe10
	"$srcdir"/configure \
87fe10
		--prefix="$prefix" \
87fe10
		--host="$host" \
87fe10
		--enable-static \
87fe10
		--enable-shared
87fe10
	make -j4
87fe10
	make install
87fe10
}
87fe10
87fe10
87fe10
function build_freetype() {
87fe10
	"$srcdir"/configure \
87fe10
		--prefix="$prefix" \
87fe10
		--host="$host" \
87fe10
		--enable-static \
1b8859
		--enable-shared \
1b8859
		--without-bzip2
87fe10
	make -j4
87fe10
	make install
87fe10
	mkdir -p build-shared
87fe10
	cd build-shared
87fe10
	"$srcdir"/configure \
87fe10
		--prefix="$prefix" \
87fe10
		--host="$host" \
87fe10
		--disable-static \
1b8859
		--enable-shared \
1b8859
		--without-bzip2
87fe10
	make -j4
87fe10
	make install
87fe10
	cd ..
87fe10
}
87fe10
87fe10
87fe10
function build_ogg() {
87fe10
	"$srcdir"/configure \
87fe10
		--prefix="$prefix" \
87fe10
		--host="$host" \
87fe10
		--enable-static \
87fe10
		--enable-shared
87fe10
	make -j4
87fe10
	make install
87fe10
}
87fe10
87fe10
87fe10
function build_vorbis() {
87fe10
	"$srcdir"/configure \
87fe10
		--prefix="$prefix" \
87fe10
		--host="$host" \
87fe10
		--enable-static \
87fe10
		--enable-shared
87fe10
	make -j4
87fe10
	make install
87fe10
}
87fe10
87fe10
87fe10
function build_flac() {
87fe10
	"$srcdir"/configure \
87fe10
		--prefix="$prefix" \
87fe10
		--host="$host" \
87fe10
		--enable-static \
1b8859
		--enable-shared \
1b8859
		--disable-cpplibs
87fe10
	make -j4
87fe10
	make install
87fe10
}
87fe10
87fe10
87fe10
function build_mpg123() {
87fe10
	"$srcdir"/configure \
87fe10
		--prefix="$prefix" \
87fe10
		--host="$host" \
87fe10
		--enable-static \
87fe10
		--enable-shared
87fe10
	make -j4
87fe10
	make install
87fe10
}
87fe10
87fe10
87fe10
function build_sdl2() {
87fe10
	"$srcdir"/configure \
87fe10
		--prefix="$prefix" \
87fe10
		--host="$host" \
87fe10
		--enable-static \
87fe10
		--enable-shared
87fe10
	make -j4
87fe10
	make install
87fe10
}
87fe10
87fe10
87fe10
function build_sdl2image() {
87fe10
	"$srcdir"/configure \
87fe10
		--prefix="$prefix" \
87fe10
		--host="$host" \
87fe10
		--enable-static \
87fe10
		--enable-shared \
87fe10
		--enable-png \
87fe10
		--disable-png-shared \
87fe10
		--disable-pnm \
87fe10
		--disable-webp \
87fe10
		--disable-webp-shared
87fe10
	make -j4
87fe10
	make install
87fe10
}
87fe10
87fe10
87fe10
function build_sdl2mixer() {
87fe10
	"$srcdir"/configure \
87fe10
		--prefix="$prefix" \
87fe10
		--host="$host" \
87fe10
		--enable-static \
87fe10
		--enable-shared \
87fe10
		--enable-music-wave \
87fe10
		--enable-music-ogg \
87fe10
		--disable-music-ogg-shared \
87fe10
		--enable-music-flac \
87fe10
		--disable-music-flac-shared \
87fe10
		--enable-music-mp3-mpg123 \
87fe10
		--disable-music-mp3-mpg123-shared
87fe10
	make -j4
87fe10
	make install
87fe10
}
87fe10
87fe10
87fe10
function build_helianthus() {
87fe10
	mkdir -p src
87fe10
	cp -r ../../../src/data src/
87fe10
1b8859
	local flags=
1b8859
	if [ ! -z "$LINUX" ]; then
1b8859
		flags="-fPIC"
1b8859
	fi
1b8859
87fe10
	local file=
1b8859
	local srcfiles=()
1b8859
	local compileflags=(-Wall $OPTIONS $flags -I"$prefix/include/SDL2" -I"$prefix/include/freetype2")
87fe10
	for file in ../../../src/*.c ../../../src/*.S; do
1b8859
		local filename=$(basename "$file")
1b8859
		srcfiles+=("$file")
1b8859
		echocall "$CC" "$file" ${compileflags[@]} -c -o "$filename.o"
87fe10
	done
87fe10
1b8859
	local libs="SDL2 SDL2_image SDL2_mixer FLAC mpg123 vorbisfile vorbis ogg freetype png16 z"
87fe10
	local lib=
87fe10
	local file=
1b8859
	local libfiles=()
87fe10
	rm -f libhelianthus.a
87fe10
	for lib in $libs; do
87fe10
		mkdir -p $lib
87fe10
		cd $lib
1b8859
		echocall "$AR" -x "$prefix/lib/lib$lib.a"
87fe10
		for file in *.o; do
87fe10
			cp $file ../thirdparty_${lib}_$file
87fe10
		done
1b8859
		libfiles+=("$prefix/lib/lib$lib.a")
87fe10
		cd ..
87fe10
	done
1b8859
	echocall "$AR" rcs libhelianthus.a *.o
1b8859
1b8859
	if [ -z "$LINUX" ]; then
1b8859
		echocall "$CC" -shared "${srcfiles[@]}" ${compileflags[@]} "${libfiles[@]}" \
1b8859
			-lmingw32 \
1b8859
			-lm -static-libgcc \
1b8859
			-lopengl32 -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lshlwapi \
1b8859
			-lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion -luuid \
1b8859
			-Wl,--out-implib,libhelianthus.dll.a \
1b8859
			-o libhelianthus.dll
1b8859
	else
1b8859
		echocall "$CC" -shared "${srcfiles[@]}" ${compileflags[@]} "${libfiles[@]}" \
1b8859
			-lm -static-libgcc -lGL -ldl -pthread \
1b8859
			-o libhelianthus.so
1b8859
	fi
87fe10
87fe10
	mkdir -p ../../release/include/helianthus/helianthus
1b8859
	mkdir -p ../../release/lib-$bits
1b8859
	cp libhelianthus.a ../../release/lib-$bits/
1b8859
	if [ -z "$LINUX" ]; then
1b8859
		cp libhelianthus.dll ../../release/lib-$bits/
1b8859
		cp libhelianthus.dll.a ../../release/lib-$bits/
1b8859
	else
1b8859
		cp libhelianthus.so ../../release/lib-$bits/
1b8859
	fi
87fe10
	cp -r ../../../src/*.h ../../release/include/helianthus/helianthus/
87fe10
	rm -f ../../release/include/helianthus/helianthus/private.h
87fe10
	mv ../../release/include/helianthus/helianthus/helianthus.h ../../release/include/helianthus/
87fe10
}
87fe10
87fe10
87fe10
function build_demo() {
1b8859
	if [ -z "$LINUX" ]; then
1b8859
		echocall $CC \
1b8859
			../../../demo/src/*.c \
1b8859
			-Wall $OPTIONS \
1b8859
			-I"$ROOT/release/include/helianthus" \
1b8859
			"$ROOT/release/lib-$bits/libhelianthus.a" \
1b8859
			-lmingw32 -mconsole \
1b8859
			-lm -static-libgcc \
1b8859
			-lopengl32 -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lshlwapi \
1b8859
			-lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion -luuid \
1b8859
			-o demo.exe
1b8859
	else
1b8859
		echocall $CC \
1b8859
			../../../demo/src/*.c \
1b8859
			-Wall $OPTIONS \
1b8859
			-I"$ROOT/release/include/helianthus" \
1b8859
			"$ROOT/release/lib-$bits/libhelianthus.a" \
1b8859
			-lm -static-libgcc -lGL -ldl -pthread \
1b8859
			-o demo
1b8859
	fi
87fe10
	mkdir -p ../../release/demo
1b8859
	if [ -z "$LINUX" ]; then
1b8859
		cp demo.exe ../../release/demo/demo-$bits.exe
1b8859
	else
1b8859
		cp demo ../../release/demo/demo-$bits
1b8859
	fi
87fe10
	cp -r ../../../demo/data ../../release/demo/
502515
	mkdir -p ../../release/doc/
502515
	cp -r ../../../doc/ru ../../release/doc/
87fe10
}
87fe10
87fe10
87fe10
#######################################################################
87fe10
87fe10
87fe10
download
87fe10
unpack
1b8859
build win32 i686-w64-mingw32
1b8859
build win64 x86_64-w64-mingw32
1b8859
#LINUX=1 ADDCFLAGS="-m32 -fPIC" build linux32 ""
1b8859
LINUX=1 ADDCFLAGS=-fPIC build linux64 ""
87fe10
87fe10
print_section done
87fe10