SUMMARY="Design Schematics and PCBs"
DESCRIPTION="LibrePCB is a free EDA software to develop printed circuit boards.

Key Features:
* Cross-platform (Unix/Linux, Mac OS X, Windows)
* All-in-one (project management, library/schematic/board editors)
* Intuitive, modern and easy-to-use graphical user interface
* Very powerful library design with some innovative concepts
* Human-readable file formats
* Open Source (GNU GPLv3)"
HOMEPAGE="https://librepcb.org/"
COPYRIGHT="Urban Bruhin"
LICENSE="GNU GPL v3"
REVISION="1"
SOURCE_URI="https://download.librepcb.org/releases/$portVersion/librepcb-$portVersion-source.zip"
CHECKSUM_SHA256="8c7bf475ed59eb5b5e4b13073b96b9468ee01fb6980ef2b3471b1fbb39c46721"
SOURCE_DIR="librepcb-$portVersion"
PATCHES="librepcb-$portVersion.patchset"
ADDITIONAL_FILES="
	librepcb.rdef.in
	icons.zip
	"

ARCHITECTURES="all !x86_gcc2"
SECONDARY_ARCHITECTURES="x86"

PROVIDES="
	librepcb$secondaryArchSuffix = $portVersion
	app:LibrePCB$secondaryArchSuffix = $portVersion
	cmd:eagle_import = $portVersion
	cmd:librepcb_cli = $portVersion
	cmd:uuid_generator = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libGL$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:g++$secondaryArchSuffix
	cmd:lrelease$secondaryArchSuffix >= 5
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:unzip
	"

PATCH()
{
	unzip -o $sourceDir/../../additional-files/icons.zip -d $sourceDir/img
}

BUILD()
{
	mkdir -p build
	cd build

	cmake .. \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_PREFIX=$appsDir/LibrePCB

	make $jobArgs
}

INSTALL()
{
	mkdir -p $prefix/bin $appsDir/LibrePCB/{bin,share}

	cp build/apps/librepcb/librepcb $appsDir/LibrePCB/bin/LibrePCB
	cp build/apps/librepcb-cli/librepcb-cli $appsDir/LibrePCB/bin
	cp build/apps/EagleImport/eagle-import $appsDir/LibrePCB/bin
	cp build/apps/UuidGenerator/uuid-generator $appsDir/LibrePCB/bin
	cp -R share/librepcb $appsDir/LibrePCB/share

	ln -s $appsDir/LibrePCB/bin/LibrePCB $appsDir/LibrePCB/LibrePCB
	ln -s $appsDir/LibrePCB/bin/librepcb-cli $prefix/bin/librepcb-cli
	ln -s $appsDir/LibrePCB/bin/eagle-import $prefix/bin/eagle-import
	ln -s $appsDir/LibrePCB/bin/uuid-generator $prefix/bin/uuid-generator

	local APP_SIGNATURE="application/x-vnd.librepcb"
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3`"
	local LONG_INFO="$SUMMARY"
	sed \
		-e "s|@APP_SIGNATURE@|$APP_SIGNATURE|" \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		-e "s|@LONG_INFO@|$LONG_INFO|" \
		$portDir/additional-files/librepcb.rdef.in > $sourceDir/librepcb.rdef

	addResourcesToBinaries $sourceDir/librepcb.rdef $appsDir/LibrePCB/bin/LibrePCB
	mimeset -f $appsDir/LibrePCB/bin/LibrePCB

	addAppDeskbarSymlink $appsDir/LibrePCB/bin/LibrePCB LibrePCB
}
