File Arduino.spec of Package Arduino

#
# spec file for package Arduino
#
# Copyright (c) 2016-2018 SUSE LINUX GmbH, Nuernberg, Germany.
# Copyright (c) 2016-2018 kkaempf
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#

# prevent "Empty %files file .../debugsources.list"
%global debug_package %{nil}

# Installed but not listed: /usr/lib/debug/usr/share/java/Arduino-1.6.10/arduino-builder.debug
%define _unpackaged_files_terminate_build 0

# Which version of the Arduino ctags package we reference
%define ctags_version 5.8-arduino11

#%{!?gcc_version: %define gcc_version 8}
%define gcc_version 11

Name:           Arduino
Version:        1.8.19
Release:        0
Summary:        Open-source electronics prototyping platform
License:        GPL-2.0
Group:          Development/Libraries/Java
Url:            https://github.com/arduino/Arduino
Source0:        %{name}-%{version}.tar.gz
Source1:        http://downloads.arduino.cc/packages/package_index.json.gz
Source2:        http://downloads.arduino.cc/packages/package_index.json.sig
Source3:        http://downloads.arduino.cc/libraries/library_index.json.gz
Source4:        http://downloads.arduino.cc/libraries/library_index.json.sig
Source5:        %{name}.rpmlintrc
# https://raw.githubusercontent.com/arduino/arduino-builder/master/hardware/platform.keys.rewrite.txt
Source6:        platform.keys.rewrite.txt
# ctags pattern
Source7:        platform.local.txt

# PATCH-FIX-OPENSUSE use-installed-libastylej.patch use the installed libastylej, don't download
Patch1:         0001-use-installed-libastylej.patch
# PATCH-FIX-OPENSUSE use-installed-avr-gcc.patch  use the installed avr-gcc and avrdude
Patch2:         0002-use-installed-avr-gcc.patch
# PATCH-FIX-OPENSUSE prevent downloading of avr-gcc toolchain
Patch3:         0003-drop-avr-toolchain-bundle.patch
Patch4:         0004-cross-arch-build-xml.patch
Patch5:         0005-Use-installed-arduino-builder.patch
Patch6:         0006-Use-installed-liblistSerialsj.patch
Patch7:         0007-Fix-arch-bits-as-lib-suffix-for-x86.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
%if 0%{?suse_version} > 1010
BuildRequires:  fdupes
%endif
BuildRequires:  ant
BuildRequires:  Arduino-kit = %{version}
BuildRequires:  arduino-ctags
BuildRequires:  arduino-core
BuildRequires:  grep
BuildRequires:  gzip
BuildRequires:  java-devel >= 1.8.0
BuildRequires:  jpackage-utils
BuildRequires:  jna > 4.2.1
BuildRequires:  jna-contrib > 4.2.1
BuildRequires:  jssc
BuildRequires:  libastylej3
BuildRequires:  liblistSerialsj
BuildRequires:  sed
BuildRequires:  unzip
BuildRequires:  update-desktop-files
Requires:       arduino-builder
Requires:       arduino-core
Requires:       arduino-ctags 
Requires:       avrdude
Requires:       cross-avr-binutils
#Requires:       cross-avr-gcc%%{gcc_version}
Requires:       /usr/bin/avr-gcc
Requires:       java = 1.8.0
Requires:       jna > 4.2.1
Requires:       jna-contrib > 4.2.1
Requires:       jssc
Requires:       libastylej3
Requires:       liblistSerialsj

ExclusiveArch:  %ix86 x86_64

# This packages replaces arduino-1.0.x
Provides:       arduino
Obsoletes:      arduino < 1.6

# This is a hack. Leap 15.{4,5} provides cross-avr-gcc1{1,2}-bootstrap
# packages but not cross-avr-gcc1{1,2} m(, which also provide
# /usr/bin/avr-gcc m( Anyway, the bootstrap versions are always wrong
# -- seife
Conflicts:      cross-avr-gcc11-bootstrap
Conflicts:      cross-avr-gcc12-bootstrap

%description
The open-source Arduino Software (IDE) makes it easy to write code and
upload it to the board. It runs on Windows, Mac OS X, and Linux. The
environment is written in Java and based on Processing and other
open-source software.
This software can be used with any Arduino board.

%prep
%setup -q -c -n src
rm -rf ../kit
cp -Rf %{_datadir}/tetra ../kit
cd %{name}-%{version}
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%patch7 -p1

# limit to openSUSE 13.2 and Leap 42.2
%if 0%{?suse_version} == 1320 || ( 0%{?suse_version} == 1315 && 0%{?sle_version} == 120200 )
#%%patch8 -p1
%endif
mkdir libraries

%build

set -xe
if [ \! -x $JAVA_HOME/bin/javac ] && echo $JAVA_HOME | grep jre ; then
  echo WTF IS SETTING \$JAVA_HOME TO JRE \!?
  JAVA_HOME=$(echo $JAVA_HOME | sed -e s/jre/java/g)
fi

cd ..
PROJECT_PREFIX=`readlink -e .`
cp -aL kit/build/* src/%{name}-%{version}/build
cp -aL kit/build/shared/* src/%{name}-%{version}/build/shared
mkdir -p src/%{name}-%{version}/build/linux/work/lib
cp -aL kit/jars/*.jar src/%{name}-%{version}/build/linux/work/lib
cp -aL kit/jars/lib src/%{name}-%{version}/arduino-core

cd src/%{name}-%{version}
rm -rf build/linux/linux/dist/tools
find . -type f -iname \*.tgz -or -iname \*.so \
-or -iname .cvsignore \
-or -iname \*.exe -or -iname \*.dll \
-or -iname \*.elf -or -iname \*.a | xargs -n1 rm -rvf
jna=$(find .. -name jna\*.jar)
jssc=$(find .. -name jssc\*.jar)

rm -f $jna $jssc
ln -s %{_javadir}/jna*.jar %{_jnidir}/jssc.jar arduino-core/lib
ln -s %{_javadir}/jna*.jar %{_jnidir}/jssc.jar build/linux/work/lib
ln -s %{_jnidir}/jssc.jar app/lib

cp %{S:1} .
cp %{S:2} .
cp %{S:3} .
cp %{S:4} .

( cd arduino-core ; ant ; )
( cd build ; ant -Dversion=%{version} -Dlight_bundle=true -Dlocal_sources=true; )

%install

export NO_BRP_CHECK_BYTECODE_VERSION=true
%define arduinodir %{_libdir}/arduino
mkdir -p %{buildroot}%{arduinodir}
cd %{name}-%{version}
# drop own libastylej.so
rm -f build/linux/work/lib/libastylej.so
cp -a build/linux/work/* %{buildroot}%{arduinodir}
mkdir -p %{buildroot}/%{_bindir}
ln -s %{arduinodir}/arduino %{buildroot}/%{_bindir}
# use external libastylej.so
# ugly hack: factory now has libastylej.so.3, 15.4 still has libastylej.so
# -- seife
if [ -e %{_libdir}/libastyle.so ]; then
	ln -s %{_libdir}/libastylej.so %{buildroot}%{arduinodir}/lib/libastylej.so
else
	ln -s %{_libdir}/libastylej.so.3 %{buildroot}%{arduinodir}/lib/libastylej.so
fi
ln -s %{_libdir}/liblistSerialsj.so %{buildroot}%{arduinodir}/lib

rm -f %{buildroot}%{arduinodir}/hardware/tools/avr/lib/pkgconfig/*.pc

#mkdir -p %{buildroot}%{_datadir}/arduino
#echo %{buildroot}%{arduinodir}/* | sed -e s,%{buildroot},,g | xargs \
#  ln -s -t %{buildroot}%{_datadir}/arduino 

%if 0%{?suse_version} > 1010
# fdupes does not work with different file modes
find %{buildroot}%{arduinodir} -name LICENSE.txt | xargs -r chmod 0644
%fdupes %{buildroot}%{arduinodir}
%endif

# avr platform moved to arduino-core package
# hardware

# drop the symlink
#rm -f %{buildroot}%{_datadir}/arduino/hardware
# move the hardware stuff to %{_datadir}/arduino for arduino-hardware
#mv %{buildroot}%{arduinodir}/hardware %{buildroot}%{_datadir}/arduino/hardware
# symlink back to where the Java stack expects it
#ln -s %{_datadir}/arduino/hardware %{buildroot}%{arduinodir}
# platform.keys.rewrite
#cp %{S:6} %{buildroot}%{arduinodir}/hardware
# platform.local.txt - for ctags
#cp %{S:7} %{buildroot}%{arduinodir}/hardware/suse-arduino/avr
## -tools for arduino-builder (bsc#1072010)
mkdir -p %{buildroot}%{arduinodir}/hardware/tools/avr
# .desktop

grep -v ICON_NAME build/linux/dist/desktop.template \
 | sed 's/<BINARY_LOCATION>/\/usr\/bin\/arduino/' > Arduino.desktop
echo "Icon=%{arduinodir}/lib/arduino.png" >> Arduino.desktop
%suse_update_desktop_file -i %{name} Development IDE Electronics

%clean
rm -rf %{buildroot}

%post
# arduino-builder buildrequires arduino-hardware, which we build in this spec
# so we can't package this symlink since it would buildrequire arduino-builder, resulting in a buildrequire-loop
ln -sf %{_bindir}/arduino-builder %{arduinodir}
# transaction to arduino folder
rm -rf %{_libdir}/%{name}-%{version}

# remove arduino-builder symlink on uninstall, keep it on update
%postun
if [ $1 -eq 0 ]; then
  rm -rf %{arduinodir}/arduino-builder
fi

%files
%defattr(-,root,root)
%{_bindir}/arduino
%{arduinodir}/
%{_datadir}/applications/%{name}.desktop

%changelog
openSUSE Build Service is sponsored by