This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Building crossgcc rpms (as non-root)


Charlie Brady wrote:

I'm struggling with a set of issues that don't seem to have documented solutions, which somewhat surprises me. You'll see I've parenthesised "as non-root" above, as I believe it should be an assumption (of course, one always builds rpms as non-root!) although I daily find evidence that it isn't.

The standard practice for building RPMs as non-root is to use a BuildRoot - a sandbox into which one installs files before packaging. It's essentially a chroot area. There's two reasons for doing this - one is security (as non-root, you don't have permission to write to the final file location), and the other is because you don't want to pollute your build system's file system.

The process for building a gcc cross-compiler is (IIUC):

1. Configure, build and install binutils
2. Build a bootstrap-compiler
3. Build and install header files and glibc
4. Build and install gcc

Step 1 is OK, because we can make an RPM (installing into a BuildRoot in the process), then install the RPM as root. The cross-binutils RPM can be a BuildPrereq of the cross-gcc RPM.

Step 2 is OK, we can build the bootstrap compiler into a local directory.

Step 3 is maybe OK, except we need to install the header files and libraries into a BuildRoot location. Setting install_root seems to do that OK.

Step 4 is where things always go wrong for me. The build of gcc proper always fails because it can't find the include files built in Step 3, because they have not yet been installed in their final location.

Hmmm. I'm using newlib rather than glibc, but here's what I'm doing [ see attached spec file ]. This is essentially the crosstool script that should be familiar to anyone on this list, reformatted into an rpm spec. Use --target to specify the platform. I'm mainly using --target m68k-coff and --target arm-coff. The spec also references some patches, but for test purposes you can probably just comment out those parts.

- Toralf
# Usage: rpbuild --target <cross target> ....
# Note : Package's architecture/OS are taken from _target_cpu/_target_os, also
#        set according to --target spec. We want *host* (not cross target)
#        platform in package fields, so we need to override these macros.

%define cross_target %{_target}
%define _target_cpu %{_arch}
%define _target_os %{_os}

%define debug_package %{nil}

Summary: Cross Compiler for %{cross_target}
Name: cross-gcc-%{cross_target}
Version: 2.95.3
Release: 1pcap4
Group: Development/Languages
Vendor: PCAP
License: GPL
Url: http://www.procaptura.com/
BuildRoot: /var/tmp/%{name}-root
Source0: ftp://ftp.gnu.org/pub/gnu/gcc/gcc-%{version}.tar.gz
Source1: http://www.kernel.org/pub/linux/devel/binutils/binutils-2.14.90.0.5.tar.bz2
Source2: ftp://sources.redhat.com/pub/newlib/newlib-1.11.0.tar.gz
Source10: http://crossgcc.billgatliff.com/build-crossgcc.sh
Patch0: cross-gcc-small68k.patch
Patch1: cross-gcc-nomonARM.patch
Patch2: cross-gcc-stackARM.patch

%define _gcc %(basename %{SOURCE0} '.tar.gz')
%define _binutils %(basename %{SOURCE1} '.tar.bz2')
%define _newlib %(basename %{SOURCE2} '.tar.gz')

%description


%prep
%setup -c -a 1 -a 2
%patch0 -p0 -b .small68k
%patch1 -p0 -b .nomonARM
%patch2 -p0 -b .stackARM

%build
%__rm -rf %{buildroot}

export PATH=${PATH}:%{buildroot}%{_prefix}/bin


# Build binutils

mkdir build-binutils; cd build-binutils
../%{_binutils}/configure --target=%{cross_target} --prefix=%{_prefix} \
  2>&1 | tee configure.log
make all install 2>&1 | tee make.log
make prefix=%{buildroot}%{_prefix} install 2>&1 | tee -a make.log
cd ..
# test to see if this step passed
if [ ! -f %{buildroot}%{_prefix}/bin/%{cross_target}-ld ]; then
    echo Build failed during binutils && exit 1
fi

# Now, build minimal gcc (gcc-core), which is necessary to build system
# libs also required by "real" gcc
# Note: Configure for build root to make sure we don't get any surprises
#       when building from there.

mkdir build-gcc-core; cd build-gcc-core
../%{_gcc}/configure --target=%{cross_target} --prefix=%{buildroot}%{_prefix} \
   --enable-languages=c --with-local-prefix=%{buildroot}%{_prefix}/%{cross_target} \
   --without-headers --with-newlib 2>&1 | tee configure.log
make all-gcc install-gcc 2>&1 | tee make.log
cd ..
# test to see if this step passed
if [ ! -f %{buildroot}/%{_prefix}/bin/%{cross_target}-gcc ]; then
    echo Build failed during gcc-core && exit 1
fi

# The C library, "newlib" variant

mkdir build-newlib; cd build-newlib

perl -pi -e 's/(-DCOMPACT_CTYPE)/$1 -DPREFER_SIZE_OVER_SPEED -DINTEGER_ONLY/' ./%{_newlib}/newlib/configure.host


../%{_newlib}/configure --target=%{cross_target} --prefix=%{_prefix} \
   --enable-target-optspace 2>&1 | tee configure.log
make all info 2>&1 | tee make.log
make prefix=%{buildroot}%{_prefix} install install-info 2>&1 | tee -a make.log
cd ..
# test to see if this step passed
if [ ! -f %{buildroot}%{_prefix}/%{cross_target}/lib/libc.a ]; then
    echo Building libc failed && exit 1
fi

# Finally, full gcc
mkdir build-gcc; cd build-gcc
# - Pass "--no-split" to makeinfo as we want to rename info files (see 
#   "install"); when info is split, the documents will reference each other
#   via hard-coded filenames, so we can't just move the files.
#   ('--no-split' used only for gcc as the info contents are probably so small
#    that they are written to one file in any case for the other projects)
MAKEINFOFLAGS="--no-split" \
../%{_gcc}/configure --target=%{cross_target} --prefix=%{_prefix} \
   --enable-languages=c,c++ --with-local-prefix=%{_prefix}/%{cross_target} \
   2>&1 | tee configure.log
make all 2>&1 | tee make.log
cd ..

# Some additional documentation
cd build-binutils/gas
make dvi
cd ../..

%install
export PATH=${PATH}:%{buildroot}%{_prefix}/bin

for tool in build-binutils build-newlib build-gcc
do
  cd $tool
  %makeinstall
  cd ..
done

# Update names of info files so that we may include those, too
( cd %{buildroot}%{_infodir}
  ls | egrep -v '^%{cross_target}' | while read info
  do
    %__mv $info %{cross_target}-$info
  done
)

%clean
%__rm -rf %{buildroot}

%post


%files
%defattr(-,root,root)
%doc build-binutils/gas/doc/*.dvi
%{_bindir}/%{cross_target}*
%{_prefix}/%{cross_target}
%{_libdir}/gcc-lib/%{cross_target}
%{_mandir}/*/%{cross_target}*
%{_infodir}/%{cross_target}*


------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]