File strace.spec of Package strace-sparc

Summary: Tracks and displays system calls associated with a running process
Name: strace
Version: 4.12
Release: 1%{?dist}
%define srcname %name-%version
%define arch sparc
%define libc uclibc
%define cross %{arch}-buildroot-linux-%{libc}
License: BSD
Group: Development/Debuggers
URL: http://sourceforge.net/projects/strace/
Source0: %{name}-%{version}.tar.gz
BuildRequires: buildroot-toolchain-%{arch}, buildroot-images-%{arch}
BuildRequires: autoconf, automake, git, expect, python, xz
%define pkg_path	/opt/buildroot-%{arch}
%define toolchain_path	%{pkg_path}/toolchain
%define images_path	%{pkg_path}/images
%define images_pwd	%{_tmppath}
%define kernel		zImage
%define rootfs		rootfs.ext2
%define strace64_arches ppc64 sparc64

%if 0%{?suse_version} >= 1300
BuildRequires: qemu-extra
%endif

%if 0%{?fedora_version} >= 20 || 0%{?centos_version} >= 800 || 0%{?rhel_version} >= 800 
BuildRequires: qemu-system-%{arch}, qemu-system-x86
%endif

BuildRoot:  %{_tmppath}/strace-%{version}-build

%description
The strace program intercepts and records the system calls called and
received by a running process.  Strace can print a record of each
system call, its arguments and its return value.  Strace is useful for
diagnosing problems and debugging, as well as for instructional
purposes.

Install strace if you need a tool to track the system calls made and
received by a process.

%ifarch %{strace64_arches}
%package -n strace64
Summary: Tracks and displays system calls associated with a running process.
Group: Development/Debuggers

%description -n strace64
The strace program intercepts and records the system calls called and
received by a running process.  Strace can print a record of each
system call, its arguments and its return value.  Strace is useful for
diagnosing problems and debugging, as well as for instructional
purposes.

Install strace if you need a tool to track the system calls made and
received by a process.

This package provides the `strace64' program to trace 64-bit processes.
The `strace' program in the `strace' package is for 32-bit processes.
%endif

%prep
%setup -q -n %{srcname}

%build
export TARGET=%{_tmppath}/strace.tar.xz
export PATH="$PATH:%{toolchain_path}/usr/bin"
export AM_COLOR_TESTS=no
export AWK=/usr/bin/awk

set +x; 
echo "========================================================";
echo "Cross compiling %{arch} using %{cross}-gcc"
echo "libc: %{libc}"
echo "gcc: %{cross}-gcc"
echo "========================================================"; 
set -x;

./bootstrap
./configure --prefix=/usr --enable-maintainer-mode --target=%{cross} --host=%{cross} --build=x86_64-unknown-linux-gnu

make ChangeLog
make CREDITS
make %{?_smp_mflags}

# build tests
echo "Building tests"
TESTS_TARGET=`cd tests;TMP=$(mktemp); echo 'print-%: ; @echo $($*)' > $TMP; make -f $TMP -f Makefile print-check_PROGRAMS; rm $TMP`
make -C tests %{?_smp_mflags} ${TESTS_TARGET}

echo "Bundling binaries"
tar --exclude='*.tar*' --exclude='*.o' --exclude='.git' --exclude='debian' -c . | xz > "$TARGET"

echo "Start serving bundled strace..."
fuser 8888/tcp &> /dev/null || ( cd $(dirname "$TARGET") && python -m SimpleHTTPServer 8888 & )

cp %{images_path}/* %{images_pwd}

set +x

QEMU=qemu-system-%{arch}
QEMU_ARGS="-M SS-10 -m 2G -kernel %{images_pwd}/%{kernel} -drive file=%{images_pwd}/%{rootfs},format=raw "
QEMU_ARGS+="-monitor null -serial stdio -nographic -append \\\"root=/dev/sda console=ttyS0,115200\\\" "
QEMU_ARGS+="-net nic,model=lance -net user"
LOGIN="buildroot login: "
OK=__OK__
PROMPT=__PROMPT__
CMD="mount -t ramfs ramfs /mnt; cd /mnt; \
    wget -qO- 10.0.2.2:8888/$(basename $TARGET) | xz -d - | tar  xf - ;\
    date -s $(date -I --date 'tomorrow') > /dev/null; \
    echo 0 > /proc/sys/kernel/printk; \
    cd tests; AM_COLOR_TESTS=no VERBOSE=1 make check-TESTS && echo $OK; \
    cat test-suite.log"
set -x

echo "Starting QEMU...."
/usr/bin/expect -c " \
    set timeout -1; \
    eval spawn $QEMU $QEMU_ARGS; \
    expect \"${LOGIN}\"; \
    send \"root\\r\"; \
    expect -re \"# $\"; \
    send \"export PS1=${PROMPT}\\r\"; \
    expect -re \"${PROMPT}\$\"; \
    expect -re \"${PROMPT}\$\"; \
    send \"${CMD}\\r\"; \
    expect -re \"${PROMPT}\$\" " \
    2>&1 | tee _testlog

#set +x
test `grep $OK _testlog | wc -l` = 2 || exit 1
#set -x

%install
export PATH="$PATH:$(pwd)/buildroot-%{arch}/output/host/usr/bin"
make DESTDIR=%{buildroot} install
rm -f %{buildroot}%{_bindir}/strace-graph

%define copy64 ln
%if 0%{?rhel}
%if 0%{?rhel} < 6
%endif
%define copy64 cp -p
%endif

%ifarch %{strace64_arches}
%{copy64} %{buildroot}%{_bindir}/strace %{buildroot}%{_bindir}/strace64
%endif


%files
%doc CREDITS ChangeLog ChangeLog-CVS COPYING NEWS README
%{_bindir}/strace
%{_bindir}/strace-log-merge
%{_mandir}/man1/*

%ifarch %{strace64_arches}
%files -n strace64
%{_bindir}/strace64
%endif