Toolchain spec templates

From Tizen Wiki
Jump to: navigation, search

Back to Porting Tizen


 %define gcc_version         483
 %define gcc_suffix          4.8.3
 %define CROSS_COMPILER_PATH /opt/toolchains/gcc-%{gcc_suffix}
 %define tizen_arch          your_new_arch
 %define libc                your_libc
 # spec file for package qemu-accel-%{tizen_arch}
 # Copyright (c) 2012 SUSE LINUX Products GmbH, Nuernberg, Germany.
 # 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
 # Choose which gcc hijack method (if any) to use.
 # Only select one of the two at a time!
 %define hijack_gcc         1
 %if 0%{?_with_perl_and_python_emul}
 Name:             qemu-accel-%{tizen_arch}-cross
 Name:             qemu-accel-%{tizen_arch}
 Version:          0.4
 Release:          0
 AutoReqProv:      off
 BuildRequires:    gcc-%{libc}
 BuildRequires:    fdupes
 BuildRequires:    glibc-locale
 BuildRequires:    gcc-c++
 BuildRequires:    gettext-runtime
 BuildRequires:    gettext-tools
 BuildRequires:    m4
 BuildRequires:    gawk
 BuildRequires:    flex
 BuildRequires:    cmake
 %if 0%{?_with_perl_and_python_emul}
 BuildRequires:    perl
 BuildRequires:    python
 # required for xxd
 BuildRequires:    vim
 BuildRequires:    patchelf
 #BuildRequires:    rpmlint-mini
 BuildRequires:    qemu-linux-user
 Requires:         coreutils
 Summary:          Native binaries for speeding up cross compile
 License:          GPL-2.0
 Group:            Development/Libraries/Cross
 ExclusiveArch:    %ix86
 # default path in qemu
 %define HOST_ARCH %(echo %{_host_cpu} | sed -e "s/i.86/i586/;s/ppc/powerpc/;s/sparc64.*/sparc64/;s/sparcv.*/sparc/;")
 %define our_path /emul/%{HOST_ARCH}-for-%{tizen_arch}
 %define %{tizen_arch}_cross_env gcc-%{gcc_suffix}
 This package is used in %{tizen_arch} architecture builds using qemu to speed up builds
 with native binaries.
 This should not be installed on systems, it is just intended for qemu environments.
 %setup -q -D -T -n .
 binaries="/%_lib/ /%_lib/ %{_libdir}/rpm-plugins/" # loaded via dlopen by glibc
 %ifarch %ix86
     echo "ERROR unhandled arch"
     exit 1
 for executable in $LD \
     /usr/bin/{bash,rpm,rpmdb} \
     /usr/bin/{gzip,grep,egrep,sed,tar} \
     /usr/lib/ /usr/lib/ /lib/ \
     /usr/bin/{bzip2,cat,expr,make,m4,mkdir,msgexec,msgfmt,msgcat,msgmerge,mv,patch,rm,rmdir,rpmbuild,xz,xzdec} \
     /usr/bin/{awk,gawk} \
     /usr/bin/flex \
 %if 0%{?_with_perl_and_python_emul}
     /usr/bin/{a2p,perl,perl5.16.3} \
     /usr/bin/python \
     # add lib dependencies
     binaries="$binaries $executable `ldd $executable | sed -n 's,.*=> \(/[^ ]*\) .*,\1,p'`"
 %if %hijack_gcc
 for executable in %{CROSS_COMPILER_PATH}/bin/* \
 %{CROSS_COMPILER_PATH}/%{tizen_arch}-linux/bin/* \
 %{CROSS_COMPILER_PATH}/lib/gcc/%{tizen_arch}-linux/%{gcc_suffix}/* \
     [ -d $executable ] && continue
     binaries="$binaries $executable"
 for binary in $binaries
     outfile=%buildroot%{our_path}$(echo $binary | sed 's:/opt/toolchains/gcc-%{gcc_suffix}:/usr:;s:%{%{tizen_arch}_cross_env}:/usr:;s:%{tizen_arch}-linux-::')
     [ -f $outfile ] && continue
     mkdir -p ${outfile%/*}
     cp -aL $binary $outfile 
     objdump -s -j .rodata -j .data $outfile | sed 's/^ *\([a-z0-9]*\)/\1:/' | \
         grep ': ' | grep -v 'file format' | grep -v 'Contents of section' | \
         xxd -g4 -r - $
     if grep -q "%{HOST_ARCH}"$; then
         echo "ERROR file $binary leaks host information into the guest"
         exit 1
     rm -f $
     [ "$binary" == "$LD" ] && continue
     if | "$outfile" == *".a" || "$outfile" == *".la"  ; then
     patchelf --debug --set-rpath "%our_path/%_lib:%our_path%_libdir" $outfile
     # not all binaries have an .interp section
     if patchelf --print-interpreter $outfile; then
         patchelf --debug --set-interpreter %{our_path}$LD $outfile
 pushd %{buildroot}%{our_path} &&    ln -s usr/bin && popd
 %if %hijack_gcc
     # create symlinks for lib64 / lib mappings (gcc!)
     mkdir -p "%{buildroot}%{our_path}/usr/lib/"
     mkdir -p "%{buildroot}%{our_path}/usr/lib/gcc/%{tizen_arch}-linux/%{gcc_suffix}"
     mkdir -p "%{buildroot}%{our_path}/usr/libexec/gcc"
     mkdir -p "%{buildroot}%{our_path}/usr/%{tizen_arch}-linux"
     cp "%{buildroot}%{our_path}/usr/bin/gcc" "%{buildroot}%{our_path}/usr/bin/cc"
     ln -s ../bin/cpp %{buildroot}%{our_path}/usr/lib
     rm -rf %{buildroot}%{our_path}/usr/bin/%{tizen_arch}-linux-*
     ln -sf ../bin %{buildroot}%{our_path}/usr/%{tizen_arch}-linux/bin
     ln -sf bash %{buildroot}%{our_path}/bin/sh
     # allow abuild to do the mv
     chmod 777 %{buildroot}/emul
 # Make QEMU available through /qemu
 mkdir %buildroot/qemu
 cp -L /usr/bin/qemu-%{tizen_arch}{,-binfmt} %buildroot/qemu/
 %fdupes -s %{buildroot}
 export NO_BRP_CHECK_RPATH="true"


 %define gcc_version         483
 %define gcc_suffix          4.8.3
 %define CROSS_COMPILER_PATH /opt/toolchains/gcc-%{gcc_suffix}
 %define tizen_arch          your_new_arch
 %define libc                your_libc
 Name:           %{libc}
 Summary:        Standard Shared Libraries (from the GNU C Library)
 License:        LGPL-2.1+ and LGPL-2.1+-with-GCC-exception and GPL-2.0+
 Group:          Base/Libraries
 AutoReq:        0
 BuildRequires:  fdupes
 BuildRequires:  xz
 BuildRequires:  gcc-%{libc}
 Version:        2.18
 Release:        0
 Source5:        nsswitch.conf
 Source7:        bindresvport.blacklist
 # For systemd 
 Source20:       nscd.conf
 Source21:       nscd.service
 Requires(pre):  filesystem
 Requires:       /usr/bin/sed
 Provides:       rtld(GNU_HASH)
 Provides:       ldconfig
 # The dynamic linker supports DT_GNU_HASH
 Provides:       rtld(GNU_HASH)
 Provides:       glibc
 Provides:       kernel-headers
 Provides:       linux-kernel-headers = 3.1.0
 ExclusiveArch:  %ix86 %{tizen_arch}
 The GNU C Library provides the most important standard libraries used
 by nearly all programs: the standard C library, the standard math
 library, and the POSIX thread library. A system is not functional
 without these libraries.
 %package         locale
 Summary:         Locale Data for Localized Programs
 License:         GPL-2.0+ and MIT and LGPL-2.1+
 Requires(post):  /usr/bin/cat
 Requires:        %{libc} = %{version}
 Provides:        glibc-locale
 %description locale
 Locale data for the internationalisation features of the GNU C library.
 %package         devel
 Summary:         Include Files and Libraries Mandatory for Development
 License:         BSD-3-Clause and LGPL-2.1+ and LGPL-2.1+-with-GCC-exception and GPL-2.0+
 Requires:        %{libc} = %{version}
 Provides:        glibc-devel
 Provides:        glibc-devel-32bit
 %description devel
 These libraries are needed to develop programs which use the standard C
 %package         devel-static
 Summary:         C library static libraries for -static linking
 License:         BSD-3-Clause and LGPL-2.1+ and LGPL-2.1+-with-GCC-exception and GPL-2.0+
 Requires:        %{name}-devel = %{version}
 Provides:        %{name}-static = %version
 Provides:        glibc-devel-static
 %description     devel-static
 The glibc-devel-static package contains the C library static libraries
 for -static linking.  You don't need these, unless you link statically,
 which is highly discouraged.
 %setup -q -D -T -n .
 # We don't want to strip the .symtab from our libraries in,
 # certainly not from* because it is used by libthread_db to find
 # some non-exported symbols in order to detect if threading support
 # should be enabled.  These symbols are _not_ exported, and we can't easily
 # export them retroactively without changing the ABI.  So we have to
 # continue to "export" them via .symtab, instead of .dynsym :-(
 # But we also want to keep .symtab and .strtab of other libraries since some
 # debugging tools currently require these sections directly inside the main
 # files - specifically valgrind and PurifyPlus.
 export STRIP_KEEP_SYMTAB=*.so*
 # Make sure we will create the gconv-modules.cache
 mkdir -p %{buildroot}%{_libdir}/gconv
 touch    %{buildroot}%{_libdir}/gconv/gconv-modules.cache
 # Install base glibc
 mkdir -p %buildroot%{_libdir}
 cp -rf   %{CROSS_COMPILER_PATH}/%{tizen_arch}-linux/sys-root/lib/*     %buildroot%{_libdir}
 cp -rf   %{CROSS_COMPILER_PATH}/%{tizen_arch}-linux/lib/lib*         %buildroot%{_libdir}
 rm -rf   %buildroot/%{_libdir}/*.a
 rm -rf   %buildroot/%{_libdir}/*.la
 # Miscelanna:
 mkdir -p %{buildroot}/etc
 install -m 644 %{SOURCE7} %{buildroot}/etc
 install -m 644 %{SOURCE5} %{buildroot}/etc
 # Create
 cat > %{buildroot}/etc/ <<EOF
 include /etc/*.conf
 # Add ldconfig cache directory for directory ownership
 mkdir -p %{buildroot}/var/cache/ldconfig
 # Empty the
 rm -f %{buildroot}/etc/
 touch %{buildroot}/etc/
 # Remove timezone data, now coming in standalone package:
 for i in sbin/sln usr/bin/tzselect usr/sbin/zic usr/sbin/zdump etc/localtime; do
     rm -f  %{buildroot}/$i
 rm -rf     %{buildroot}%{_datadir}/zoneinfo
 mkdir   -p %{buildroot}/usr/lib/tmpfiles.d/
 install -m 644 %{SOURCE20}  %{buildroot}/usr/lib/tmpfiles.d/
 mkdir   -p %{buildroot}/usr/lib/systemd/system
 install -m 644 %{SOURCE21}  %{buildroot}/usr/lib/systemd/system
 mkdir   -p %{buildroot}/usr/bin
 mkdir   -p %{buildroot}/sbin
 install -m 655 %{CROSS_COMPILER_PATH}/%{tizen_arch}-linux/sys-root/sbin/ldconfig     %{buildroot}/sbin
 install -m 655 %{CROSS_COMPILER_PATH}/%{tizen_arch}-linux/sys-root/usr/bin/ldd       %{buildroot}/usr/bin
 install -m 655 %{CROSS_COMPILER_PATH}/%{tizen_arch}-linux/sys-root/usr/bin/getconf   %{buildroot}/usr/bin
 install -m 655 %{CROSS_COMPILER_PATH}/%{tizen_arch}-linux/sys-root/usr/bin/iconv     %{buildroot}/usr/bin
 install -m 655 %{CROSS_COMPILER_PATH}/%{tizen_arch}-linux/sys-root/usr/bin/getent    %{buildroot}/usr/bin
 # glibc
 %config(noreplace)  /etc/bindresvport.blacklist
 %config             /etc/
 %config             /etc/nsswitch.conf
 %attr(0644,root,root) %verify(not md5 size mtime) %ghost %config(missingok,noreplace) /etc/
 %files locale
 %files devel


 %define gcc_version         483
 %define gcc_suffix          4.8.3
 %define CROSS_COMPILER_PATH /opt/toolchains/gcc-%{gcc_suffix}
 %define tizen_arch          your_new_arch
 %define libc                your_libc
 Name:           gcc%{gcc_version}
 Version:        %{gcc_suffix}
 Release:        1
 ExclusiveArch:  %ix86 %{tizen_arch}
 Group:          Development/Toolchain
 AutoReq:        0
 BuildRequires:  gcc-%{libc}
 Summary:        The GNU C Compiler and Support Files
 License:        GPL-3.0+
 Provides:       gcc%{gcc_version}
 Core package for the GNU Compiler Collection, including the C language
 Language frontends other than C are split to different sub-packages,
 namely gcc-ada, gcc-c++, gcc-fortran, gcc-java, gcc-objc and
 %package -n     gcc%{gcc_version}-cross
 Summary:        The GNU C Compiler and Support Files
 License:        GPL-3.0+
 %description -n gcc%{gcc_version}-cross
 Fake rpm that emulate crosscomipler, needed for refsw compilation.
 %package -n     cpp%{gcc_version}
 Summary:        The system GNU Preprocessor
 License:        GPL-3.0+
 %description -n cpp%{gcc_version}
 The system GNU Preprocessor.
 %package -n     gcc%{gcc_version}-locale
 Summary:        The system GNU Compiler locale files
 License:        GPL-3.0+
 %description -n gcc%{gcc_version}-locale
 The system GNU Compiler locale files.
 %package -n     gcc%{gcc_version}-info
 Summary:        The system GNU Compiler documentation
 License:        GFDL-1.2
 %description -n gcc%{gcc_version}-info
 The system GNU Compiler documentation.
 %package -n     gcc%{gcc_version}-c++
 Summary:        The system GNU C++ Compiler
 License:        GPL-3.0+
 Provides:       c++_compiler
 %description -n gcc%{gcc_version}-c++
 The system GNU C++ Compiler.
 %package -n     libstdc++%{gcc_version}-devel
 Summary:        The system GNU C++ development files
 License:        GPL-3.0-with-GCC-exception
 %description -n libstdc++%{gcc_version}-devel
 The system GNU C++ development files.
 %setup -q -D -T -n .
 mkdir -p %buildroot/usr/bin
 rm -rf   %buildroot/usr/%{tizen_arch}-linux/bin
 mkdir -p %buildroot/usr/%{tizen_arch}-linux/bin
 # create fake binaries
 for executable in %buildroot/usr/bin/{c++,c++filt,cc,cpp,g++,gcc,gcc-%{gcc_suffix},gcj,gcov,gprof,jcf-dump,ld,run,size,strip,sstrip,strings}
     ln -sf fake_binary $executable
 # prepare folders without fake executables
 cp -rf %{CROSS_COMPILER_PATH}/include   %buildroot/usr
 cp -rf %{CROSS_COMPILER_PATH}/share     %buildroot/usr
 cp -rf %{CROSS_COMPILER_PATH}/lib       %buildroot/usr
 ln -sf /usr/bin/cpp                     %buildroot/usr/lib/cpp
 #prepare folders with fake executables
 mkdir -p %buildroot/usr/libexec/gcc/%{tizen_arch}-linux/%{gcc_suffix}
 cp     %{CROSS_COMPILER_PATH}/libexec/gcc/%{tizen_arch}-linux/%{gcc_suffix}/* %buildroot/usr/libexec/gcc/%{tizen_arch}-linux/%{gcc_suffix}/
 for executable in %buildroot/usr/libexec/gcc/%{tizen_arch}-linux/%{gcc_suffix}/{cc1,cc1obj,cc1plus,collect2,f951,jc1,jvgenmain,lto1,lto-wrapper}
    ln -sf /usr/bin/fake_binary $executable
 mkdir -p %buildroot/usr/%{tizen_arch}-linux/bin
 cp -rf   %{CROSS_COMPILER_PATH}/%{tizen_arch}-linux/include                    %buildroot/usr/%{tizen_arch}-linux
 cp -rf   %{CROSS_COMPILER_PATH}/%{tizen_arch}-linux/lib                        %buildroot/usr/%{tizen_arch}-linux
 cp -r    %{CROSS_COMPILER_PATH}/%{tizen_arch}-linux/sys-root/usr/include/*     %buildroot/usr/include
 cp -r    %{CROSS_COMPILER_PATH}/%{tizen_arch}-linux/sys-root/usr/lib/*         %buildroot/usr/lib
 ln -sf /usr/bin/fake_binary %buildroot/usr/%{tizen_arch}-linux/bin/fake_binary
 ln -sf ../../               %buildroot/usr/%{tizen_arch}-linux/sys-root
 for executable in %buildroot/usr/%{tizen_arch}-linux/bin/{ar,as,c++,g++,gcc,gfortran,ld,nm,objcopy,objdump,ranlib,strip}
    ln -sf /usr/bin/fake_binary $executable
 # create wrappers on standard tools
 for i in ld gcc c++ cpp ar nm strip objcopy objdump ranlib readelf; do
     echo '#!/bin/bash
     exec '$i' "$@"
     ' > %{buildroot}/usr/bin/%{tizen_arch}-linux-$i
     chmod +x %{buildroot}/usr/bin/%{tizen_arch}-linux-$i
 #clean unnecessary files
 rm -rf %buildroot/usr/share/info
 rm -rf %buildroot/usr/share/man
 rm -rf %buildroot/usr/share/gdb
 rm -rf `find %buildroot/usr| grep "\.la$"`
 %files -n gcc%{gcc_version}-cross
 %files -n cpp%{gcc_version}
 %files -n gcc%{gcc_version}-c++
 %files -n gcc%{gcc_version}-locale
 %files -n gcc%{gcc_version}-info
 %files -n libstdc++%{gcc_version}-devel


 %define gcc_version          483
 %define gcc_suffix           4.8.3
 %define CROSS_COMPILER_PATH  /opt/toolchains/gcc-%{gcc_suffix}
 %define tizen_arch           your_new_arch
 %define libc                 your_libc
 Name:           fake_binutils
 Version:        2.19.92
 Release:        0
 Summary:        GNU Binutils
 License:        GFDL-1.3 and GPL-3.0+
 Group:          Development/Tools/Building
 AutoReq:        0
 BuildRequires:  gcc-%{libc}
 Provides:       binutils
 ExclusiveArch:  %ix86 %{tizen_arch}
 C compiler utilities: ar, as, gprof, ld, nm, objcopy, objdump, ranlib,
 size, strings, and strip. These utilities are needed whenever you want
 to compile a program or kernel.
 %package        devel
 Summary:        The GNU Binutils devel
 License:        GPL-3.0+
 Provides:       binutils-devel
 %description    devel
 Fake package to resolve dependencies
 %setup -q -D -T -n .
 echo 'int printf(char *, ...);int main(int argc, char **argv){printf("\nThis is fake \"%s\". If you see this message that smth is wrong with qemu\n", argv[0]);return 0;}' > fake_binary.c
 %ifarch %{tizen_arch}
     gcc -o fake_binary fake_binary.c
 %ifarch %ix86
     %{CROSS_COMPILER_PATH}/bin/%{tizen_arch}-linux-gcc -o fake_binary fake_binary.c
 cp fake_binary %_sourcedir/
 mkdir -p  %buildroot/usr/bin
 cp -rf    %_sourcedir/fake_binary     %buildroot/usr/bin
 chmod a+x %buildroot/usr/bin/fake_binary
 rm    -rf %buildroot/usr/%{tizen_arch}-linux/bin
 mkdir -p  %buildroot/usr/%{tizen_arch}-linux/bin
 for executable in %buildroot/usr/bin/{ar,as,ld,,ld.bfd,nm,ranlib,strip,addr2line,objcopy,objdump,readelf}
     ln -sf fake_binary $executable
 # add linker scripts
 mkdir -p %buildroot/%{_libdir}
 cp -rf   %{CROSS_COMPILER_PATH}/%{tizen_arch}-linux/lib/ldscripts %buildroot/%{_libdir}
 mkdir -p %buildroot/usr/%{tizen_arch}-linux/lib/
 %files devel