# # RTEMS Tools Project (http://www.rtems.org/) # Copyright 2010-2012 Chris Johns (chrisj@rtems.org) # All rights reserved. # # This file is part of the RTEMS Tools package in 'rtems-tools'. # # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # # Determine the defaults and load the specific file. # import glob import pprint import re import os import error import execute basepath = 'tb' defaults = { # Nothing 'nil': '', # Set to invalid values. '_host': '', '_build': '%{_host}', '_target': '', # Paths '_host_platform': '%{_host_cpu}-%{_host_vendor}-%{_host_os}%{?_gnu}', '_build': '%{_host}', '_arch': '%{_host_arch}', '_tbdir': '', '_topdir': os.getcwd(), '_configdir': '%{_topdir}/config:%{_tbdir}/config', '_tardir': '%{_topdir}/tar', '_sourcedir': '%{_topdir}/sources', '_builddir': '%{_topdir}/build/%{name}-%{version}-%{release}', '_docdir': '%{_defaultdocdir}', '_tmppath': '%{_topdir}/build/tmp', 'buildroot:': '%{_tmppath}/%{name}-root-%(%{__id_u} -n)', # Defaults, override in platform specific modules. '___setup_shell': '/bin/sh', '__aclocal': 'aclocal', '__ar': 'ar', '__arch_install_post': '%{nil}', '__as': 'as', '__autoconf': 'autoconf', '__autoheader': 'autoheader', '__automake': 'automake', '__awk': 'awk', '__bash': '/bin/bash', '__bzip2': '/usr/bin/bzip2', '__cat': '/bin/cat', '__cc': '/usr/bin/gcc', '__chgrp': '/usr/bin/chgrp', '__chmod': '/bin/chmod', '__chown': '/usr/sbin/chown', '__cp': '/bin/cp', '__cpio': '/usr/bin/cpio', '__cpp': '/usr/bin/gcc -E', '__cxx': '/usr/bin/g++', '__grep': '/usr/bin/grep', '__gzip': '/usr/bin/gzip', '__id': '/usr/bin/id', '__id_u': '%{__id} -u', '__install': '/usr/bin/install', '__install_info': '/usr/bin/install-info', '__ld': '/usr/bin/ld', '__ldconfig': '/sbin/ldconfig', '__ln_s': 'ln -s', '__make': 'make', '__mkdir': '/bin/mkdir', '__mkdir_p': '/bin/mkdir -p', '__mv': '/bin/mv', '__nm': '/usr/bin/nm', '__objcopy': '%{_bindir}/objcopy', '__objdump': '%{_bindir}/objdump', '__patch': '/usr/bin/patch', '__perl': 'perl', '__perl_provides': '%{_usrlibrpm}/perl.prov', '__perl_requires': '%{_usrlibrpm}/perl.req', '__ranlib': 'ranlib', '__remsh': '%{__rsh}', '__rm': '/bin/rm', '__rsh': '/usr/bin/rsh', '__sed': '/usr/bin/sed', '__setup_post': '%{__chmod} -R a+rX,g-w,o-w .', '__sh': '/bin/sh', '__tar': '/usr/bin/tar', '__tar_extract': '%{__tar} -xvvf', '__unzip': '/usr/bin/unzip', '__xz': '/usr/bin/xz', '_datadir': '%{_prefix}/share', '_defaultdocdir': '%{_prefix}/share/doc', '_exeext': '', '_exec_prefix': '%{_prefix}', '_lib': 'lib', '_libdir': '%{_exec_prefix}/%{_lib}', '_libexecdir': '%{_exec_prefix}/libexec', '_localedir': '%{_datadir}/locale', '_localstatedir': '%{_prefix}/var', '_prefix': '%{_usr}', '_usr': '/usr/local', '_usrsrc': '%{_usr}/src', '_var': '/usr/local/var', '_varrun': '%{_var}/run', # Shell Build Settings. '___build_args': '-e', '___build_cmd': '%{?_sudo:%{_sudo} }%{?_remsh:%{_remsh} %{_remhost} }%{?_remsudo:%{_remsudo} }%{?_remchroot:%{_remchroot} %{_remroot} }%{___build_shell} %{___build_args}', '___build_post': 'exit 0', # Prebuild set up script. '___build_pre': '''# ___build_pre in as set up in defaults.py # Directories TB_SOURCE_DIR="%{_sourcedir}" TB_BUILD_DIR="%{_builddir}" TB_OPT_FLAGS="%{optflags}" TB_ARCH="%{_arch}" TB_OS="%{_os}" export TB_SOURCE_DIR TB_BUILD_DIR TB_OPT_FLAGS TB_ARCH TB_OS # Documentation TB_DOC_DIR="%{_docdir}" export TB_DOC_DIR # Packages TB_PACKAGE_NAME="%{name}" TB_PACKAGE_VERSION="%{version}" TB_PACKAGE_RELEASE="%{release}" export TBPACKAGE_NAME TB_PACKAGE_VERSION TB_PACKAGE_RELEASE # Build root directory %{?buildroot:TB_BUILD_ROOT="%{buildroot}"} export TB_BUILD_ROOT # The compiler flags %{?_targetcflags:CFLAGS_FOR_TARGET="%{_targetcflags}"} %{?_targetcxxflags:CXXFLAGS_FOR_TARGET="%{_targetcxxflags}"} export CFLAGS_FOR_TARGET # Default environment set up. LANG=C export LANG unset DISPLAY || : umask 022 cd "%{_builddir}"''', '___build_shell': '%{?_buildshell:%{_buildshell}}%{!?_buildshell:/bin/sh}', '___build_template': '''#!%{___build_shell} %{___build_pre} %{nil}''', # Configure command 'configure': ''' CFLAGS="${CFLAGS:-%optflags}" ; export CFLAGS ; CXXFLAGS="${CXXFLAGS:-%optflags}" ; export CXXFLAGS ; FFLAGS="${FFLAGS:-%optflags}" ; export FFLAGS ; ./configure --build=%{_build} --host=%{_host} \ --target=%{_target_platform} \ --program-prefix=%{?_program_prefix} \ --prefix=%{_prefix} \ --exec-prefix=%{_exec_prefix} \ --bindir=%{_bindir} \ --sbindir=%{_sbindir} \ --sysconfdir=%{_sysconfdir} \ --datadir=%{_datadir} \ --includedir=%{_includedir} \ --libdir=%{_libdir} \ --libexecdir=%{_libexecdir} \ --localstatedir=%{_localstatedir} \ --sharedstatedir=%{_sharedstatedir} \ --mandir=%{_mandir} \ --infodir=%{_infodir}''' } class command_line: """Process the command line in a common way for all Tool Builder commands.""" _defaults = { 'params' : [], 'warn-all' : '0', 'quiet' : '0', 'trace' : '0', 'dry-run' : '0', 'no-clean' : '0', 'no-smp' : '0', 'rebuild' : '0' } _long_opts = { '--prefix' : '_prefix', '--prefixbase' : '_prefixbase', '--topdir' : '_topdir', '--configdir' : '_configdir', '--builddir' : '_builddir', '--sourcedir' : '_sourcedir', '--usrlibrpm' : '_usrlibrpm', # XXX remove ? '--tmppath' : '_tmppath', '--log' : '_logfile', '--url' : '_url_base', '--targetcflags' : '_targetcflags', '--targetcxxflags' : '_targetcxxflags', '--libstdcxxflags' : '_libstdcxxflags' } _long_true_opts = { '--trace' : '_trace', '--dry-run' : '_dry_run', '--warn-all' : '_warn_all', '--no-clean' : '_no_clean', '--no-smp' : '_no_smp', '--rebuild' : '_rebuild' } _target_triplets = { '--host' : '_host', '--build' : '_build', '--target' : '_target' } def _help(self): print '%s: [options] [args]' % (self.command_name) print 'Options and arguments:' print '--trace : Trace the execution (not current used)' print '--dry-run : Do everything but actually run the build' print '--warn-all : Generate warnings' print '--no-clean : Do not clean up the build tree' print '--no-smp : Run with 1 job and not as many as CPUs' print '--rebuild : Rebuild (not used)' print '--host : Set the host triplet' print '--build : Set the build triplet' print '--target : Set the target triplet' print '--prefix path : Tools build prefix, ie where they are installed' print '--prefixbase path : ' print '--topdir path : Top of the build tree, default is $PWD' print '--configdir path : Path to the configuration directory, default: ./config' print '--builddir path : Path to the build directory, default: ./build' print '--sourcedir path : Path to the source directory, default: ./source' print '--tmppath path : Path to the temp directory, default: ./tmp' print '--log file : Log file where all build out is written too' print '--url url : URL to look for source' print '--targetcflags flags : List of C flags for the target code' print '--targetcxxflags flags : List of C++ flags for the target code' print '--libstdcxxflags flags : List of C++ flags to build the target libstdc++ code' print '--with-