File strace.spec of Package strace-microblaze

Summary: Tracks and displays system calls associated with a running process
Name: strace
Version: 4.13
Release: 1%{?dist}
%define srcname %name-%version
%define arch microblaze
%define libc gnu
%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		linux.bin
%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}
%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; 
gcc_version=`%{toolchain_path}/usr/bin/%{cross}-gcc --version | head -n1 | tr ' ' '\n' | tail -n1`
libc_version=`find %{toolchain_path} -name "libc.so.*" -o -name "uClibc.*"  | \
                   xargs ls -al | tr ' ' '\n' | tail -n1`
kernel_version=`strings %{images_path}/%{kernel} | grep 'Linux version' | cut -f3 -d' '`

echo "========================================================";
echo "Cross compiling %{arch} using %{cross}-gcc"
echo "libc: %{libc} --> $libc_version"
echo "gcc: %{cross}-gcc --> $gcc_version"
echo "running on Linux $kernel_version"
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 -9 > "$TARGET"

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

cp %{images_path}/* %{images_pwd}

QEMU=qemu-system-%{arch}
QEMU_ARGS="-M petalogix-s3adsp1800 -m 3G -kernel %{images_pwd}/%{kernel} -monitor null -serial stdio -nographic"
LOGIN="buildroot login: "
OK=__OK__
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"

echo "Starting QEMU...."
/usr/bin/expect -c " \
    set timeout -1; \
    eval spawn ${QEMU} ${QEMU_ARGS}; \
    expect \"${LOGIN}\"; \
    send \"root\\r\"; \
    expect -re \"# $\"; \
    send \"${CMD}\\r\"; \
    expect -re \"# $\" " \
    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