SUMMARY="The Open Source CAD System For Everyone"
DESCRIPTION="QCAD is a free, open source application for computer aided drafting \
(CAD) in two dimensions (2D). With QCAD you can create technical drawings such as \
plans for buildings, interiors, mechanical parts or schematics and diagrams. QCAD \
works on Windows, macOS and Linux. The source code of QCAD is released under the \
GPL version 3 (GPLv3), a popular Open Source license.

QCAD was designed with modularity, extensibility and portability in mind. But what \
people notice most often about QCAD is its intuitive user interface. QCAD is an easy \
to use but powerful 2D CAD system for everyone. You don't need any CAD experience to \
get started with QCAD immediately."
HOMEPAGE="https://www.qcad.org/"
COPYRIGHT="RibbonSoft GmbH"
LICENSE="GNU GPL v3"
REVISION="1"
SOURCE_URI="https://github.com/qcad/qcad/archive/refs/tags/v$portVersion.tar.gz"
CHECKSUM_SHA256="a6736d38cc14a36fee390a1bbf97ddeb8ad9c2bd5a572ff4992c2028fc3a4612"
PATCHES="qcad-$portVersion.patchset"
ADDITIONAL_FILES="qcad.rdef.in"

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

PROVIDES="
	qcad$secondaryArchSuffix = $portVersion
	app:QCAD$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libexecinfo$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5PrintSupport$secondaryArchSuffix
	lib:libQt5Svg$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libexecinfo$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libGL$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5PrintSupport$secondaryArchSuffix
	devel:libQt5Svg$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:find
	cmd:g++$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:qmake$secondaryArchSuffix >= 5
	cmd:which
	"

BUILD()
{
	qmake -r
	make $jobArgs
}

INSTALL()
{
	mkdir -p $appsDir/QCAD/lib \
		$appsDir/QCAD/plugins

	cp -f release/*.so $appsDir/QCAD/lib
	cp -f release/qcad-bin $appsDir/QCAD/QCAD
	cp -Rf plugins $appsDir/QCAD
	cp -dpR {examples,fonts,libraries,linetypes,patterns,scripts,themes,ts} $appsDir/QCAD
	rm -rf $appsDir/QCAD/plugins/{codecs,imageformats,printsupport,sqldrivers}

	find $appsDir/QCAD \( -name '*.pri' -or -name '*.pro' -or -name '*.ts' \) -delete
	find $appsDir/QCAD \( -name 'Makefile' -or -name '.gitignore' \) -delete

	local APP_SIGNATURE="application/x-vnd.qcad"
	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/qcad.rdef.in > qcad.rdef

	addResourcesToBinaries qcad.rdef $appsDir/QCAD/QCAD
	mimeset -f $appsDir/QCAD/QCAD
	addAppDeskbarSymlink $appsDir/QCAD/QCAD
}
