#!/bin/sh
# 
# LICENSE: <george@galis.org> wrote this file. 
# You can do anything with it -- George Georgalis

# https://wiki.gnome.org/Apps/Dia/Download

# custom build for larger resize handles

set -e

#version=0.97.3
version=$(date +%Y%m%d)
#major=${version%.*}
dir=dia-${version}
#file=dia-${version}.tar.xz
#uri=http://ftp.gnome.org/pub/gnome/sources/dia/${major}/${file}
#dist=/usr/local/dist
src=/usr/local/src
#mkdir -p $dist
#cd $dist
#ftp "$uri"
#[ "$(uname)" = "Linux" ] && [ ! -e "${file}" ] && wget "$uri"

chkerr () { [ -z "$*" ] && return || { echo "$*" >&2 ; exit 1 ;} ;}

mkdir -p $src
cd $src
#xzcat ${dist}/${file} | tar x
[ -d "dia.git" ] && { cd dia.git \
	&& git clean -f -d \
	&& git fetch -v --all \
	&& git reset --hard origin/master \
	|| chkerr 'ERROR: git reset' ;} \
	|| { git clone git://git.gnome.org/dia dia.git ; cd dia.git ;}

[ -e './configure' ] || sh autogen.sh

#cat<<EOF
patch ./app/handle_ops.c<<'EOF'
25c25
< #define HANDLE_SIZE 7
---
> #define HANDLE_SIZE 9
EOF

#cat<<EOF
patch ./lib/connectionpoint.h<<'EOF'
30c30
< #define CONNECTIONPOINT_SIZE 5
---
> #define CONNECTIONPOINT_SIZE 9
EOF

#cat<<EOF
patch ./app/connectionpoint_ops.c<<'EOF'
30c30
< #define CP_SZ (CONNECTIONPOINT_SIZE/2)
---
> /* #define CP_SZ (CONNECTIONPOINT_SIZE/2) */
44,46c44,47
<   irenderer->draw_pixel_line (renderer,
< 			x-CP_SZ,y-CP_SZ,
< 			x+CP_SZ,y+CP_SZ,
---
>   irenderer->fill_pixel_rect(renderer,
> 			x - CONNECTIONPOINT_SIZE/2 + 1,
> 			y - CONNECTIONPOINT_SIZE/2 + 1,
> 			CONNECTIONPOINT_SIZE-2, CONNECTIONPOINT_SIZE-2,
49,52c50,54
<   irenderer->draw_pixel_line (renderer,
< 			x+CP_SZ,y-CP_SZ,
< 			x-CP_SZ,y+CP_SZ,
< 			color);
---
>   irenderer->draw_pixel_rect(renderer,
> 			x - CONNECTIONPOINT_SIZE/2,
> 			y - CONNECTIONPOINT_SIZE/2,
> 			CONNECTIONPOINT_SIZE-1, CONNECTIONPOINT_SIZE-1,
> 			&color_white);
EOF

sleep 3

# typical dependencies "sudo apt-get build-dep dia"
./configure --prefix=/usr/local/${dir} && make && [ -w /usr/local ] && make install
make && [ -w /usr/local ] && make install
ls -l /usr/local/${dir}/bin/dia
echo true
exit

