Skip to content

Commit

Permalink
[gcc] Enable gcc-go frontend and libraries. Contributes to JB#62642
Browse files Browse the repository at this point in the history
Since we don't use update-alternatives, make gcc-go always provide
symlinks to go and gofmt. Checks that such binaries don't yet exist.
This makes it possible to have gcc-go and go installed at the same time.
This assumes that Go packages them as regular files, not symlinks.
  • Loading branch information
direc85 committed Oct 18, 2024
1 parent 553c9d0 commit 9f576fb
Show file tree
Hide file tree
Showing 6 changed files with 921 additions and 25 deletions.
181 changes: 176 additions & 5 deletions cross-aarch64-gcc.spec
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ ExclusiveArch: %ix86 x86_64
%global _performance_build 1
%global build_ada 0
%global build_objc 0
%global build_go 0
%global build_go 1
%global build_d 0
%global include_gappletviewer 0
%global build_libstdcxx_doc 0
Expand Down Expand Up @@ -190,6 +190,7 @@ Patch14: gcc10-pr96939-2.patch
Patch15: gcc10-pr96939-3.patch
Patch16: gcc10-reproducible-builds.patch
Patch17: gcc10-reproducible-builds-buildid-for-checksum.patch
Patch18: gcc10-compiler-correct-condition-for-calling-memclrHasPoin.patch

BuildRequires: binutils >= 2.31
BuildRequires: glibc-static
Expand Down Expand Up @@ -221,6 +222,10 @@ Requires: binutils >= 2.25
Requires: glibc64bit-helper
%endif

%if %{build_go}
BuildRequires: net-tools, procps
%endif

Obsoletes: gcc < %{version}-%{release}
AutoReq: true
# /!crossbuild
Expand All @@ -232,6 +237,29 @@ AutoReq: true
%endif
%global gcc_target_platform %{_target_platform}

%if !%{crossbuild}
%if %{build_go}
# Avoid stripping these libraries and binaries.
%global __os_install_post \
chmod 644 %{buildroot}%{_prefix}/%{_lib}/libgo.so.16.* \
chmod 644 %{buildroot}%{_prefix}/bin/go.gcc \
chmod 644 %{buildroot}%{_prefix}/bin/gofmt.gcc \
chmod 644 %{buildroot}%{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}/cgo \
chmod 644 %{buildroot}%{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}/buildid \
chmod 644 %{buildroot}%{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}/test2json \
chmod 644 %{buildroot}%{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}/vet \
%__os_install_post \
chmod 755 %{buildroot}%{_prefix}/%{_lib}/libgo.so.16.* \
chmod 755 %{buildroot}%{_prefix}/bin/go.gcc \
chmod 755 %{buildroot}%{_prefix}/bin/gofmt.gcc \
chmod 755 %{buildroot}%{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}/cgo \
chmod 755 %{buildroot}%{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}/buildid \
chmod 755 %{buildroot}%{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}/test2json \
chmod 755 %{buildroot}%{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}/vet \
%{nil}
%endif
%endif

%description
The gcc package contains the GNU Compiler Collection version 4.9.
You'll need this package in order to compile C code.
Expand Down Expand Up @@ -474,6 +502,43 @@ Autoreq: true
This is one set of libraries which support 64bit multilib on top of
32bit enviroment from compiler side.

%package go
Summary: Go support
Requires: gcc = %{version}-%{release}
Requires: libgo = %{version}-%{release}
Requires: libgo-devel = %{version}-%{release}
Provides: gccgo = %{version}-%{release}
Autoreq: true

%description go
The gcc-go package provides support for compiling Go programs
with the GNU Compiler Collection.

%package -n libgo
Summary: Go runtime
Autoreq: true

%description -n libgo
This package contains Go shared library which is needed to run
Go dynamically linked programs.

%package -n libgo-devel
Summary: Go development libraries
Requires: libgo = %{version}-%{release}
Autoreq: true

%description -n libgo-devel
This package includes libraries and support files for compiling
Go programs.

%package -n libgo-static
Summary: Static Go libraries
Requires: libgo = %{version}-%{release}
Requires: gcc = %{version}-%{release}

%description -n libgo-static
This package contains static Go libraries.

%package plugin-devel
Summary: Support for compiling GCC plugins
Requires: gcc = %{version}-%{release}
Expand Down Expand Up @@ -507,6 +572,7 @@ not stable, so plugins must be rebuilt any time GCC is updated.
%patch15 -p0 -b .pr96939-3~
%patch16 -p0 -b .reproducible-builds~
%patch17 -p1 -b .reproducible-builds-buildid-for-checksum~
%patch18 -p1 -b .correct-condition-for-calling-memclrHasPointers~


echo 'Sailfish OS gcc %{version}-%{gcc_release}' > gcc/DEV-PHASE
Expand Down Expand Up @@ -594,6 +660,12 @@ esac
#export OPT_FLAGS=`echo "$OPT_FLAGS" | sed -e "s/-O2/-O2 -fkeep-inline-functions/g"`
export OPT_FLAGS=`echo "$OPT_FLAGS" | sed -e "s/-fstack-protector//g"`

%if %{build_go}
enablelgo=,go
%else
enablelgo=
%endif

%if %{crossbuild}
# cross build
export PATH=/opt/cross/bin:$PATH
Expand Down Expand Up @@ -668,7 +740,7 @@ CC="$CC" CFLAGS="$OPT_FLAGS" CXXFLAGS="`echo $OPT_FLAGS | sed 's/ -Wall / /g'`"
--enable-linker-build-id \
--disable-libmpx \
%if %{bootstrap} == 0
--enable-languages=c,c++,lto \
--enable-languages=c,c++${enablelgo},lto \
--enable-threads=posix \
--enable-shared \
%endif
Expand Down Expand Up @@ -807,6 +879,11 @@ ln -sf gcc %{buildroot}%{_prefix}/bin/cc
mkdir -p %{buildroot}/%{_lib}
ln -sf ..%{_prefix}/bin/cpp %{buildroot}/%{_lib}/cpp

%if %{build_go}
mv %{buildroot}%{_prefix}/bin/go{,.gcc}
mv %{buildroot}%{_prefix}/bin/gofmt{,.gcc}
%endif

cxxconfig="`find %{gcc_target_platform}/libstdc++-v3/include -name c++config.h`"
for i in `find %{gcc_target_platform}/[36]*/libstdc++-v3/include -name c++config.h 2>/dev/null`; do
if ! diff -up $cxxconfig $i; then
Expand Down Expand Up @@ -982,7 +1059,7 @@ ln -sf ../../../../%{_lib}/libobjc.so.4 libobjc.so
ln -sf ../../../../%{_lib}/libstdc++.so.6.*[0-9] libstdc++.so
ln -sf ../../../../%{_lib}/libgomp.so.1.* libgomp.so
%if %{build_go}
ln -sf ../../../../%{_lib}/libgo.so.16.* libgo.so
ln -sf ../../../libgo.so.16.* libgo.so
%endif
%if %{build_libquadmath}
ln -sf ../../../../%{_lib}/libquadmath.so.0.* libquadmath.so
Expand All @@ -1004,6 +1081,9 @@ mv ../../../../%{_lib}/libasan_preinit.o libasan_preinit.o
%if %{build_libubsan}
ln -sf ../../../../%{_lib}/libubsan.so.1.* libubsan.so
%endif
%if %{build_go}
ln -sf ../../../../%{_lib}/libgo.so.16.* libgo.so
%endif
%if %{build_libtsan}
rm -f libtsan.so
echo 'INPUT ( %{_prefix}/%{_lib}/'`echo ../../../../%{_lib}/libtsan.so.0.* | sed 's,^.*libt,libt,'`' )' > libtsan.so
Expand Down Expand Up @@ -1073,6 +1153,11 @@ ln -sf ../../../%{multilib_32_arch}-%{_vendor}-%{_target_os}/%{gcc_version}/libs
%if %{build_libquadmath}
ln -sf ../../../%{multilib_32_arch}-%{_vendor}-%{_target_os}/%{gcc_version}/libquadmath.a 32/libquadmath.a
%endif
%if %{build_go}
ln -sf ../../../%{multilib_32_arch}-%{_vendor}-%{_target_os}/%{gcc_version}/libgo.a 32/libgo.a
ln -sf ../../../%{multilib_32_arch}-%{_vendor}-%{_target_os}/%{gcc_version}/libgobegin.a 32/libgobegin.a
ln -sf ../../../%{multilib_32_arch}-%{_vendor}-%{_target_os}/%{gcc_version}/libgolibbegin.a 32/libgolibbegin.a
%endif
%endif

# If we are building a debug package then copy all of the static archives
Expand All @@ -1097,9 +1182,9 @@ for d in . $FULLLSUBDIR; do
done
%endif

# Strip debug info from Fortran/ObjC/Java static libraries
# Strip debug info from Fortran/ObjC/Java/Go static libraries
strip -g `find . \( -name libobjc.a -o -name libgomp.a \
-o -name libgcc.a -o -name libgcov.a -o -name libquadmath.a \) -a -type f`
-o -name libgcc.a -o -name libgcov.a -o -name libquadmath.a -o -name libgo.a \) -a -type f`
popd
chmod 755 %{buildroot}%{_prefix}/%{_lib}/libgomp.so.1.*
chmod 755 %{buildroot}%{_prefix}/%{_lib}/libcc1.so.0.*
Expand Down Expand Up @@ -1328,6 +1413,26 @@ if posix.access ("/sbin/ldconfig", "x") then
end
end

%post go
pushd %{_bindir}
if [ ! -f go ] ; then
ln -s go.gcc go
fi
if [ ! -f gofmt ] ; then
ln -s gofmt.gcc gofmt
fi
popd

%preun go
pushd %{_bindir}
if [ -L go ]; then
rm go
fi
if [ -L gofmt ]; then
rm gofmt
fi
popd

%post -n libstdc++ -p /sbin/ldconfig

%postun -n libstdc++ -p /sbin/ldconfig
Expand Down Expand Up @@ -1904,6 +2009,72 @@ end
%license libsanitizer/LICENSE.TXT
%endif

%if %{build_go}
%files go
%ghost %{_prefix}/bin/go
%attr(755,root,root) %{_prefix}/bin/go.gcc
%{_prefix}/bin/gccgo
%ghost %{_prefix}/bin/gofmt
%attr(755,root,root) %{_prefix}/bin/gofmt.gcc
%{_mandir}/man1/gccgo.1*
%{_mandir}/man1/go.1*
%{_mandir}/man1/gofmt.1*
%dir %{_prefix}/%{_lib}/gcc
%dir %{_prefix}/%{_lib}/gcc/%{gcc_target_platform}
%dir %{_prefix}/%{_lib}/gcc/%{gcc_target_platform}/%{gcc_version}
%dir %{_prefix}/libexec/gcc
%dir %{_prefix}/libexec/gcc/%{gcc_target_platform}
%dir %{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}
%{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}/go1
%attr(755,root,root) %{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}/cgo
%attr(755,root,root) %{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}/buildid
%attr(755,root,root) %{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}/test2json
%attr(755,root,root) %{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}/vet
%ifarch %{multilib_64_archs}
%dir %{_prefix}/%{_lib}/gcc/%{gcc_target_platform}/%{gcc_version}/32
%{_prefix}/%{_lib}/gcc/%{gcc_target_platform}/%{gcc_version}/32/libgo.so
%{_prefix}/%{_lib}/gcc/%{gcc_target_platform}/%{gcc_version}/32/libgo.a
%{_prefix}/%{_lib}/gcc/%{gcc_target_platform}/%{gcc_version}/32/libgobegin.a
%{_prefix}/%{_lib}/gcc/%{gcc_target_platform}/%{gcc_version}/32/libgolibbegin.a
%endif
%ifarch sparcv9 ppc %{multilib_64_archs}
%{_prefix}/%{_lib}/gcc/%{gcc_target_platform}/%{gcc_version}/libgo.so
%endif
%doc rpm.doc/go/*

%files -n libgo
%attr(755,root,root) %{_prefix}/%{_lib}/libgo.so.16*
%doc rpm.doc/libgo/*

%files -n libgo-devel
%dir %{_prefix}/%{_lib}/gcc
%dir %{_prefix}/%{_lib}/gcc/%{gcc_target_platform}
%dir %{_prefix}/%{_lib}/gcc/%{gcc_target_platform}/%{gcc_version}
%dir %{_prefix}/%{_lib}/go
%dir %{_prefix}/%{_lib}/go/%{gcc_version}
%{_prefix}/%{_lib}/go/%{gcc_version}/%{gcc_target_platform}
%ifarch %{multilib_64_archs}
%ifnarch sparc64 ppc64 ppc64p7
%dir %{_prefix}/%{_lib}/go
%dir %{_prefix}/%{_lib}/go/%{gcc_version}
%{_prefix}/%{_lib}/go/%{gcc_version}/%{gcc_target_platform}
%endif
%endif
%ifnarch sparcv9 sparc64 ppc ppc64 ppc64p7
%{_prefix}/%{_lib}/gcc/%{gcc_target_platform}/%{gcc_version}/libgobegin.a
%{_prefix}/%{_lib}/gcc/%{gcc_target_platform}/%{gcc_version}/libgolibbegin.a
%{_prefix}/%{_lib}/gcc/%{gcc_target_platform}/%{gcc_version}/libgo.so
%endif

%files -n libgo-static
%dir %{_prefix}/%{_lib}/gcc
%dir %{_prefix}/%{_lib}/gcc/%{gcc_target_platform}
%dir %{_prefix}/%{_lib}/gcc/%{gcc_target_platform}/%{gcc_version}
%ifnarch sparcv9 sparc64 ppc ppc64 ppc64p7
%{_prefix}/%{_lib}/gcc/%{gcc_target_platform}/%{gcc_version}/libgo.a
%endif
%endif

%files plugin-devel
%defattr(-,root,root,-)
%dir %{_prefix}/%{_lib}/gcc
Expand Down
Loading

0 comments on commit 9f576fb

Please sign in to comment.