#6 Manage /usr/bin/cc with update-alternatives
Opened 4 years ago by tstellar. Modified 2 years ago
rpms/ tstellar/gcc cc-alternatives  into  rawhide

file modified
+33 -3
@@ -4,7 +4,7 @@ 

  %global gcc_major 10

  # Note, gcc_release must be integer, if you want to add suffixes to

  # %%{release}, append them after %%{gcc_release} on Release: line.

- %global gcc_release 0.8

+ %global gcc_release 0.9

  %global nvptx_tools_gitrev 5f6f343a302d620b0868edab376c00b15741e39e

  %global newlib_cygwin_gitrev 50e2a63b04bdd018484605fbb954fd1bd5147fa0

  %global _unpackaged_files_terminate_build 0
@@ -244,6 +244,8 @@ 

  %endif

  Requires: libgcc >= %{version}-%{release}

  Requires: libgomp = %{version}-%{release}

+ Requires(post): %{_sbindir}/alternatives

+ Requires(preun): %{_sbindir}/alternatives

  %if !%{build_ada}

  Obsoletes: gcc-gnat < %{version}-%{release}

  %endif
@@ -338,6 +340,8 @@ 

  Provides: gcc-g++ = %{version}-%{release}

  Provides: g++ = %{version}-%{release}

  Autoreq: true

+ Requires(post): %{_sbindir}/alternatives

+ Requires(preun): %{_sbindir}/alternatives

  

  %description c++

  This package adds C++ support to the GNU Compiler Collection.
@@ -1906,6 +1910,12 @@ 

  # Help plugins find out nvra.

  echo gcc-%{version}-%{release}.%{_arch} > $FULLPATH/rpmver

  

+ for f in cc c++; do

+   rm %{buildroot}%{_bindir}/$f

+   touch %{buildroot}%{_bindir}/$f

+ done

+ 

+ 

  %check

  cd obj-%{gcc_target_platform}

  
@@ -1927,6 +1937,12 @@ 

    | uuencode testlogs-%{_target_platform}.tar.xz || :

  rm -rf testlogs-%{_target_platform}-%{version}-%{release}

  

+ %post

+ %{_sbindir}/update-alternatives --install %{_bindir}/cc cc %{_bindir}/gcc 50

+ 

+ %post c++

+ %{_sbindir}/update-alternatives --install %{_bindir}/c++ c++ %{_bindir}/g++ 50

+ 

  %post go

  %{_sbindir}/update-alternatives --install \

    %{_prefix}/bin/go go %{_prefix}/bin/go.gcc 92 \
@@ -1950,6 +1966,16 @@ 

    end

  end

  

+ %postun

+ if [ $1 -eq 0 ] ; then

+   %{_sbindir}/update-alternatives --remove cc %{_bindir}/gcc

+ fi

+ 

+ %postun c++

+ if [ $1 -eq 0 ] ; then

+   %{_sbindir}/update-alternatives --remove c++ %{_bindir}/g++

+ fi

+ 

  %postun -n libgcc -p <lua>

  if posix.access ("/sbin/ldconfig", "x") then

    local pid = posix.fork ()
@@ -1993,7 +2019,7 @@ 

  %ldconfig_scriptlets -n libgo

  

  %files -f %{name}.lang

- %{_prefix}/bin/cc

+ %ghost %{_prefix}/bin/cc

  %{_prefix}/bin/c89

  %{_prefix}/bin/c99

  %{_prefix}/bin/gcc
@@ -2331,7 +2357,7 @@ 

  %files c++

  %{_prefix}/bin/%{gcc_target_platform}-*++

  %{_prefix}/bin/g++

- %{_prefix}/bin/c++

+ %ghost %{_prefix}/bin/c++

  %{_mandir}/man1/g++.1*

  %dir %{_prefix}/lib/gcc

  %dir %{_prefix}/lib/gcc/%{gcc_target_platform}
@@ -3003,6 +3029,10 @@ 

  %endif

  

  %changelog

+ * Mon Feb 24 2020 Tom Stellard <tstellar@redhat.com> 10.0.1-0.9

+ - Manage /usr/bin/cc with update-alternatives

+ - https://fedoraproject.org/wiki/Changes/Use-Update-Alternatives-For-usr-bin-cc

+ 

  * Sun Feb 16 2020 Jakub Jelinek <jakub@redhat.com> 10.0.1-0.8

  - update from trunk

    - PRs analyzer/93212, analyzer/93288, analyzer/93350, analyzer/93356,

@@ -0,0 +1,5 @@ 

+ #include <stdio.h>

+ 

+ int main() {

+   printf("Hello world\n");

+ }

@@ -0,0 +1,5 @@ 

+ #include <iostream>

+ 

+ int main() {

+   std::cout << "Hello world\n";

+ }

@@ -0,0 +1,36 @@ 

+ #!/bin/bash

+ 

+ # This test assumes gcc and gcc-c++ are already installed.

+ 

+ set -exo pipefail

+ 

+ # Verify that /usr/bin/cc points to gcc.

+ ls -l /etc/alternatives/cc | grep gcc

+ 

+ # Verify that /usr/bin/c++ points to g++

+ ls -l /etc/alternatives/c++ | grep g++

+ 

+ # Run cc and verify it invokes gcc

+ /usr/bin/cc --version | grep 'cc (GCC)'

+ 

+ # Run c++ and verify it invokes g++

+ /usr/bin/c++ --version | grep 'c++ (GCC)'

+ 

+ # Compile a C program

+ /usr/bin/cc -o hello-c hello.c

+ ./hello-c | grep 'Hello world'

+ 

+ # Compile a C++ program

+ /usr/bin/c++ -o hello-cpp hello.cpp

+ ./hello-cpp | grep 'Hello world'

+ 

+ # Uninstall gcc and verify that cc and c++ are gone.

+ dnf remove -y gcc gcc-c++

+ 

+ test ! -h /etc/alternatives/cc

+ 

+ test ! -h /etc/alternatives/c++

+ 

+ test ! -e /usr/bin/cc

+ 

+ test ! -e /usr/bin/c++

@@ -0,0 +1,14 @@ 

+ # The cc-alternative test uninstalls gcc, so it needs to be run by

+ # itself in a separate .yml file so it doesn't modify the test

+ # environment for other tests.

+ 

+ - hosts: localhost

+   roles:

+   - role: standard-test-basic

+     tags:

+       - classic

+     required_packages:

+       - gcc

+       - gcc-c++

+     tests:

+       - cc-alternative

rebased onto 6d16d466f041d3512352bc2c63192957f7dbae72

4 years ago

rebased onto 95ce5038f2795d720ba9e5f22303641f91cdf88a

4 years ago

rebased onto 7bbb787

4 years ago

is this change abandoned or planned for another release? it would be super useful to have it as currently usr/bin/c++ cannot be changed contrary to usr/bin/cc and it can be a chore maintaining multiple compiler and compiler versions (unless messing with environment variables or make it a part of your of build script. both are not as clean as changing the alternative)