#!/bin/bash
+SCRIPT_FILE=$(readlink -f $0)
+SCRIPT_DIR=$(dirname $SCRIPT_FILE)
+
CONFIGURATION=Release
-# Build tools
-dotnet build -c $CONFIGURATION src/Generator.Bind/Generator.Bind.NETCore.csproj
-dotnet build -c $CONFIGURATION src/Generator.Rewrite/Generator.Rewrite.NETCore.csproj
+PROJECT_BIND=$SCRIPT_DIR/src/Generator.Bind/Generator.Bind.NETCore.csproj
+PROJECT_REWRITE=$SCRIPT_DIR/src/Generator.Rewrite/Generator.Rewrite.NETCore.csproj
+PROJECT_OPENTK=$SCRIPT_DIR/src/OpenTK/OpenTK.Tizen.csproj
+
+BIND_EXE="dotnet $SCRIPT_DIR/src/Generator.Bind/bin/$CONFIGURATION/netcoreapp2.0/Bind.dll"
+
+ARTIFACTS_DIR=$SCRIPT_DIR/artifacts
+
+build() {
+ if [ -d /nuget ]; then
+ NUGET_SOURCE_OPT="-s /nuget -s $SCRIPT_DIR/packages"
+ fi
+
+ # Build tools
+ dotnet restore $NUGET_SOURCE_OPT $PROJECT_BIND
+ dotnet build --no-restore -c $CONFIGURATION $PROJECT_BIND
+
+ dotnet restore $NUGET_SOURCE_OPT $PROJECT_REWRITE
+ dotnet build --no-restore -c $CONFIGURATION $PROJECT_REWRITE
+
+ # Run Binding
+ $BIND_EXE -mode:es11
+ $BIND_EXE -mode:es20
+
+ # Build OpenTK
+ dotnet restore $NUGET_SOURCE_OPT $PROJECT_OPENTK
+ dotnet build --no-restore -c $CONFIGURATION $PROJECT_OPENTK
+
+ # Pack OpenTK.Tizen
+ dotnet pack --no-restore --no-build -c $CONFIGURATION $PROJECT_OPENTK
+
+ # Artifacts
+ mkdir -p $ARTIFACTS_DIR/bin/ref
+ cp -f $SCRIPT_DIR/src/OpenTK/bin/$CONFIGURATION/netstandard2.0/OpenTK.* $ARTIFACTS_DIR/bin/
+ cp -f $SCRIPT_DIR/src/OpenTK/bin/$CONFIGURATION/netstandard2.0/ref/* $ARTIFACTS_DIR/bin/ref/
+ cp -f $SCRIPT_DIR/src/OpenTK/bin/$CONFIGURATION/OpenTK.Tizen.*.nupkg $ARTIFACTS_DIR
+}
+
+clean() {
+ dotnet clean -c $CONFIGURATION $PROJECT_BIND
+ dotnet clean -c $CONFIGURATION $PROJECT_REWRITE
+ dotnet clean -c $CONFIGURATION $PROJECT_OPENTK
+
+ rm -fr $ARTIFACTS_DIR
+}
+
-# Run Binding
-dotnet src/Generator.Bind/bin/$CONFIGURATION/netcoreapp2.0/Bind.dll
+export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true
-# Build OpenTK
-dotnet build -c $CONFIGURATION src/OpenTK/OpenTK.Tizen.csproj
+cmd=$1; shift
-# Pack OpenTK.Tizen
-dotnet pack --no-build -c $CONFIGURATION src/OpenTK/OpenTK.Tizen.csproj
+if [ "x$cmd" == "xclean" ]; then
+ clean
+else
+ build
+fi
--- /dev/null
+Name: opentk
+Summary: C# binding for OpenGL, OpenGL ES
+Version: 3.0.1
+Release: 1
+Group: Development/Libraries
+License: MIT
+URL: https://github.com/opentk/opentk/
+Source0: %{name}-%{version}.tar.gz
+Source1: %{name}.manifest
+
+BuildArch: noarch
+ExcludeArch: aarch64
+AutoReqProv: no
+
+BuildRequires: dotnet-build-tools
+BuildRequires: csapi-tizenfx-nuget
+
+%description
+The Open Toolkit library is a fast, low-level C# binding for OpenGL, OpenGL ES and OpenAL.
+It runs on all major platforms and powers hundreds of apps, games and scientific research.
+
+%package nuget
+Summary: NuGet package for %{name}
+Group: Development/Libraries
+AutoReqProv: no
+
+%description nuget
+NuGet package for %{name}
+
+%package debug
+Summary: All .pdb files of Tizen .NET
+Group: Development/Libraries
+AutoReqProv: no
+
+%description debug
+All .pdb files of Tizen .NET
+
+
+%prep
+%setup -q
+cp %{SOURCE1} .
+
+
+%build
+%{?asan:export ASAN_OPTIONS=use_sigaltstack=false:allow_user_segv_handler=true:handle_sigfpe=false:`cat /ASAN_OPTIONS`}
+
+./build-tizen.sh
+
+
+%install
+
+%define DOTNET_ASSEMBLY_PATH /usr/share/dotnet.tizen/framework
+
+mkdir -p %{buildroot}%{DOTNET_ASSEMBLY_PATH}
+
+install -p -m 644 artifacts/bin/OpenTK.dll %{buildroot}%{DOTNET_ASSEMBLY_PATH}
+install -p -m 644 artifacts/bin/OpenTK.pdb %{buildroot}%{DOTNET_ASSEMBLY_PATH}
+
+mkdir -p %{buildroot}/nuget
+install -p -m 644 artifacts/OpenTK.*.nupkg %{buildroot}/nuget
+
+
+%files
+%license License.txt
+%manifest %{name}.manifest
+%attr(644,root,root) %{DOTNET_ASSEMBLY_PATH}/*.dll
+
+%files nuget
+%attr(644,root,root) /nuget/*.nupkg
+
+%files debug
+%attr(644,root,root) %{DOTNET_ASSEMBLY_PATH}/*.pdb