Detecting the platform in rpm .spec file - centos

I have a .spec file to build rpm for Fedora, CentOS and Oracle Linux. I need to install a post-uninstall trigger for the kernel package. To achieve that for Oracle Linux, I need to put something like this in my spec file:
%triggerpostun -- kernel-uek
%(cat %{SOURCE1001})
On CentOS, the package is called kernel, and on Fedora it is called kernel-core. My question is, how do I specify the trigger in my spec file in a portable way (so that it works on all of these target platforms), without any duplication?
EDIT: Some information about what I have tried - I tried putting the following in my spec file:
%if 0%{?fedora}
%triggerpostun -- kernel-core
%else
%if 0%{?ol7}
%triggerpostun -- kernel-uek
%else
%triggerpostun -- kernel
%endif
%endif
%(cat %{SOURCE1006})
But on CentOS, this gives me a trigger like this:
triggerpostun scriptlet (using /bin/sh) -- kernel-uek
for filename in /boot/*.ksplice-updates*; do
if [[ -h $filename && ! -e $filename ]]; then
rm $filename
fi
done
which is wrong because the correct package name on CentOS is kernel.
I am complete noob to packaging, so let me know if you need more context to provide suggestion.

I assume the multiple %else are causing problems. I would define the conditions this way:
%if 0%{?fedora}
%define kernelpkgname kernel-core
%endif
%if 0%{?ol7}
%define kernelpkgname kernel-uek
%endif
%if 0%{?rhel} >= 6
%define kernelpkgname kernel
%endif
Then use kernelpkgname variable in the triggerpostun.
%postun
....
%triggerpostun -- %{kernelpkgname}
cat %{SOURCE1006}

Related

How do I make Alien use an existing tarball instead of downloading?

My distro does not offer any gsl <2.6 any more.
Given:
Alien::GSL 1.01
/tmp/gsl-2.5.tar.gz
How do I force it to compile that gsl instead of downloading from GNU FTP version 2.6, which I already have on the system anyway but is not delectable to Math::GSL 0.40?
I unsuccessfully tried:
copying the tarball into the unpacked Alien::GSL base directory
messing with alien_repository
This is for a throw-away project. I'm okay with manual installation instructions and patching toolchain code.
ikegami found the decisive hint:
It looks like you can set protocol of local to use a local file
Tested step-by-step instructions, plus some additional work-arounds; to me it looks like the build systems of the two modules are buggy/insufficiently tested:
cpanm --look Alien::GSL
patch Build.PL
diff --git a/Build.PL b/Build.PL
index 32f3057..6537138 100644
--- a/Build.PL
+++ b/Build.PL
## -20,10 +20,9 ## my $builder = Alien::Base::ModuleBuild->new(
alien_name => 'gsl',
alien_repository => [
{
- protocol => 'ftp',
- host => 'ftp.gnu.org',
- location => '/gnu/gsl',
- pattern => qr/^gsl-([\d\.]+)\.tar\.gz$/,
+ protocol => 'local',
+ location => '/tmp',
+ pattern => 'gsl-2.5.tar.gz',
},
],
meta_merge => {
--
2.23.0
perl Build.PL
./Build
Pay attention to the generated configure/libtool commands here, they match the Perl configuration. A manual installation without those various options is not guaranteed to be compatible or usable. (This is not superstition: a similar problem historically shows up when installing mod_perl2 and libapreq2 from source on a system httpd; perl needs to be compiled first, then httpd to match, then the other packages, otherwise it won't work.) This shows the value of installing through Alien, since it delegates to M::B, the correct options will be figured out. It's above my level of knowledge to accurately create them from scratch.
./Build test
gsl-config in blib now erroneously contains build paths, not install paths, fix:
perl -MConfig -i -lpe'
s|/.*(/auto/share/dist/Alien-GSL)|$Config{installsitelib}$1|
' blib/lib/auto/share/dist/Alien-GSL/bin/gsl-config
./Build install
exit # cpanm
cpanm --look Math::GSL
# let it pick up gsl-config on PATH
export PATH=$PATH:$(perl -mAlien::GSL -e'print Alien::GSL->bin_dir')
perl Build.PL
./Build
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(gsl-config --libs | perl -lne'/-L(\S+) / && print $1')
./Build test
./Build install
exit # cpanm
Finally rëexport the variables whenever you want to use Math::GSL.

config.site for vendor libs on Fedora x86_64

I'm having trouble building a few Autotool-based libraries on Fedora 26, x86_64. The 64-bit Fedora puts third party and vendor libraries in /usr/local/lib64. Ubuntu 17 uses /usr/local/lib so the same projects build OK.
I've been using --libdir=/usr/local/lib64 but three libraries resist it. I lack a config.site for /usr/local so I am trying to add one. The Autoconf manual on Site Defaults is a tad bit confusing to me when it discusses usr/local's config.site. It says:
[discussion of /usr version of confg.site] ...
Likewise, on platforms where 64-bit libraries are built by default,
then installed in /usr/local/lib64 instead of /usr/local/lib, it is
appropriate to install /usr/local/share/config.site:
# /usr/local/share/config.site for platforms that prefer
# the directory /usr/local/lib64 over /usr/local/lib.
test "$libdir" = '${exec_prefix}/lib' && libdir='${exec_prefix}/lib64'
The problem I am having is, is the modification above appended to the /usr/local version of config.site? Or does it replace an existing block of code? Or can I just copy it where it belongs without modification?
Or maybe, what does a cat of /usr/local/share/config.site look like?
Here is the config.site for /usr. Its not clear to me if it needs modification or how to modify it.
$ cat /usr/share/config.site
# This is the config.site file to satisfy FHS defaults when installing below
# /usr.
#
# You may override this file by your config.site using the CONFIG_SITE env
# variable.
#
# Note: This file includes also RHEL/Fedora fix for installing libraries into
# "/lib/lib64" on 64bit systems.
if test -n "$host"; then
# skip when cross-compiling
return 0
fi
if test "$prefix" = /usr \
|| { test "$prefix" = NONE && test "$ac_default_prefix" = /usr ; }
then
test "$sysconfdir" = '${prefix}/etc' && sysconfdir=/etc
test "$sharedstatedir" = '${prefix}/com' && sharedstatedir=/var
test "$localstatedir" = '${prefix}/var' && localstatedir=/var
ARCH=`uname -m`
for i in x86_64 ppc64 s390x aarch64; do
if test $ARCH = $i; then
test "$libdir" = '${exec_prefix}/lib' && libdir='${exec_prefix}/lib64'
break
fi
done
fi
config.site for vendor libs on Fedora x86_64
This answers the question of what config.site looks like for /usr/local/share/config.site. It does not answer the question of why --libdir=/usr/local/lib64 fails to set the directory, as #John Bollinger pointed out in the comments.
The /usr/local/share/config.site is wrong. Though it was copied from Fedora's config.site and placed in /usr/local/share, the prefix directories are wrong. The prefix test should use /usr/local and not /usr.
Below is the corrected one.
$ cat /usr/local/share/config.site
...
if test -n "$host"; then
# skip when cross-compiling
return 0
fi
if test "$prefix" = /usr/local \
|| { test "$prefix" = NONE && test "$ac_default_prefix" = /usr/local ; }
then
test "$sysconfdir" = '${prefix}/etc' && sysconfdir=/etc
test "$sharedstatedir" = '${prefix}/com' && sharedstatedir=/var
test "$localstatedir" = '${prefix}/var' && localstatedir=/var
ARCH=`uname -m`
for i in x86_64 ppc64 s390x aarch64; do
if test $ARCH = $i; then
test "$libdir" = '${exec_prefix}/lib' && libdir='${exec_prefix}/lib64'
break
fi
done
fi
I'm not sure if these are correct, however. They were not modified.
test "$sysconfdir" = '${prefix}/etc' && sysconfdir=/etc
test "$sharedstatedir" = '${prefix}/com' && sharedstatedir=/var
test "$localstatedir" = '${prefix}/var' && localstatedir=/var
Now, the next question is, why Fedora's /usr/share/config.site is not handling prefix=/usr/local properly. That's an open question at Issue 1510073 : Autoconf does not honor libdir in config.site for "libdir=#libdir#" in *.pc file, which has been closed as NOT A BUG.

Buildroot Config Option for applying custom patch

I am new to buildroot and working to build Linaro with buildroot ..I have multiple fragment kernel config files and specified that in buildroot defconfig.
I have specified a custom kernel patches directory with BR2_LINUX_PATCH_DIR .
I dont have some of the config flags not set which are supposed to be there in the .config files..so i suspect that the Patches are applied successfully..so i tried giving a non existing location as Linux Patch dir and it does not give any error..
Is there anything other than giving value to BR2_LINUX_PATCH_DIR and what should be the format of the dir structure...in buildroot manual it says it should be
Package_name/patch name..For linux what should be the package name? It should be the same with which linux dir is created.for example for me it is linux-custom
Plz suggest and guide me in this.
Thanks in Advance
The option is named BR2_LINUX_KERNEL_PATCH, there is nothing named BR2_LINUX_PATCH_DIR. It applies all patches listed in this option (if those are files), or all files named *.patch if what's given in this option is a directory. See the code in linux/linux.mk:
define LINUX_APPLY_LOCAL_PATCHES
for p in $(filter-out ftp://% http://% https://%,$(LINUX_PATCHES)) ; do \
if test -d $$p ; then \
$(APPLY_PATCHES) $(#D) $$p \*.patch || exit 1 ; \
else \
$(APPLY_PATCHES) $(#D) `dirname $$p` `basename $$p` || exit 1; \
fi \
done
endef
Also, I would recommend that you watch the output of Buildroot: it shows everything it is doing, especially it lists the patches it applied. Look at the line >>> linux .... Patching, which is the marker for the beginning of the patching step of the linux package.

Tokenizer in moses-SMT system stuck even with 10 sentences

I was trying to make a baseline MT system. Just for checking How it works I made Source (S) and Target (T) language corpus of just 2000 sentences. The very first step is to prepare the data for Machine Translation (MT) system. In this step first we have to perform tokenization as mentioned here Baseline SMT. I've used this code:
~/mosesdecoder/scripts/tokenizer/tokenizer.perl -l en \
< ~/corpus/training/news-commentary-v8.fr-en.en \
> ~/corpus/news-commentary-v8.fr-en.tok.en
~/mosesdecoder/scripts/tokenizer/tokenizer.perl -l fr \
< ~/corpus/training/news-commentary-v8.fr-en.fr \
> ~/corpus/news-commentary-v8.fr-en.tok.fr
( say S = French & T = English)
I checked after 2 hours it was still running. I got curious since it was not expected. Then I tried with just ten sentences. To my surprise, it's been 30 minutes and it is still running.
Did I do anything wrong?
PS: OS = Ubuntu 14.04.5 LTS
Sony ultrabook
No dual boot.
Please Follow bellow steps ;
git clone https://github.com/moses-smt/mosesdecoder.git
cd mosesdecoder
git clone https://github.com/moses-smt/giza-pp.git
cd giza-pp
make
mkdir tools
cp giza-pp/GIZA++-v2/GIZA++ giza-pp/GIZA++-v2/snt2cooc.out giza-pp/mkcls-v2/mkcls tools
scripts/tokenizer/tokenizer.perl -l fr < ~/corpus/training/news-commentary-v8.fr-en.fr > ~/corpus/news-commentary-v8.fr-en.tok.fr

Is aubio cross-compilable for iPhone/Android/ARM? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Anyone know of:
A build of the Aubio library for iPhone/ARM processor?
An intro-to-cross-compiling resource so I can try it myself?
Try using the latest git:
$ git clone git://git.aubio.org/git/aubio
$ cd aubio/
$ ./waf configure build --with-target-platform ios
I've succeeded in cross-compiling it without errors. I haven't tested the library itself, but the example executables seem to work, so that's a good sign!
The script I've put together (largely thanks to the invaluable information in this link) should work for a lot of other projects using Autotools (like Aubio's dependencies).
Note that both libsndfile and libsamplerate need a patch to cross-compile successfully, which I'm sure is ugly, but it works.
To use it, modify the script according to your system (should be pretty straightforward, I hope), download all the dependencies (listed in the build xxxxx lines at the end, your versions may vary) in the same directory as the script and run the script without arguments. At the end, everything should be inside the $SYS_ROOT directory.
Okay, the main dish is below :
#!/bin/bash
# Taken and improved from :
# http://cmumobileapps.com/2011/08/31/compiling-open-source-libraries-with-android-ndk-part-2
# The designation for the host, usually "linux-x86" for standard linuxes, and
# "darwin-x86" for OSX.
HOST="linux-x86"
# The target architecture. Here we're compiling for ARM using GCC 4.7 and
# platform version 14.
TARGET_ARCH="arm"
TARGET_HOST="arm-eabi"
TARGET_TOOLCHAIN="arm-linux-androideabi"
TARGET_GCC_VERSION="4.7"
TARGET_NDK_VERSION="14"
# Add the toolchain to the path to be able to use the ARM compiler.
export PATH="$ANDROID_NDK/toolchains/$TARGET_TOOLCHAIN-$TARGET_GCC_VERSION/prebuilt/$HOST/bin:$PATH"
# Where to find the platform-specific files?
export PLATFORM="$ANDROID_NDK/platforms/android-$TARGET_NDK_VERSION/arch-$TARGET_ARCH/"
# Where to copy the platform-specific files?
# Will be used later as the target system root for cross-compilation.
export SYS_ROOT="`pwd`/sysroot/"
# Executable names for the compilation toolchain
export CC="$TARGET_TOOLCHAIN-gcc --sysroot=$SYS_ROOT"
export CXX="$TARGET_TOOLCHAIN-g++ --sysroot=$SYS_ROOT"
export CPP="$TARGET_TOOLCHAIN-cpp --sysroot=$SYS_ROOT"
export LD="$TARGET_TOOLCHAIN-ld"
export AR="$TARGET_TOOLCHAIN-ar"
export RANLIB="$TARGET_TOOLCHAIN-ranlib"
export STRIP="$TARGET_TOOLCHAIN-strip"
# Add the STLPort library to the search path (needed for C++ files)
export CXXFLAGS="-I$ANDROID_NDK/sources/cxx-stl/stlport/stlport/"
export LDFLAGS="-L$ANDROID_NDK/sources/cxx-stl/stlport/libs/armeabi/ -lstlport_static"
# Where to install the cross-compiled packages?
# When running `make install`, all the files (executables, libraries,
# documentation,...) will be in this directory.
export INSTALL_DIR="$SYS_ROOT/usr/"
# Where will pkg-config look for information about installed packages?
export PKG_CONFIG_LIBDIR="$SYS_ROOT/usr/lib/pkgconfig/"
#################
# Configuration #
#################
# If the sysroot doesn't exist, create it and copy all the files from the NDK
# distribution.
if [[ ! -e "$SYS_ROOT" ]]; then
echo "Creating sysroot [$SYS_ROOT]"
cp -Rf "$PLATFORM" "$SYS_ROOT" || exit 2
fi
# If it doesn't exist, create the installation directory.
if [[ ! -e "$INSTALL_DIR" ]]; then
echo "Creating installation directory [$INSTALL_DIR]"
mkdir -p $INSTALL_DIR || exit 3
fi
###############
# Compilation #
###############
build() {
# Change directory to the package directory (in argument)
echo "Building $1"
pushd $1
# Clean things up (optional)
make clean 1>/dev/null 2>&1
# Configure the package
./configure --host=$TARGET_HOST LIBS="-lc -lgcc" --prefix=$INSTALL_DIR || exit 1
# Compile
make || exit 1
# Install in $INSTALL_DIR
make install || exit 1
# Return to the original directory
popd
}
# Build all things
build libogg-1.3.0
build libvorbis-1.3.3
build flac-1.2.1
build libsndfile-1.0.25-patch
build libsamplerate-0.1.8-patch
build fftw-3.3.3
build aubio-0.3.2
libsndfile patch
--- libsndfile-1.0.25/programs/sndfile-play.c 2012-12-31 17:03:34.289908113 +0100
+++ libsndfile-1.0.25-patch/programs/sndfile-play.c 2012-12-31 17:04:05.326412364 +0100
## -55,7 +55,7 ##
#if defined (__linux__) || defined (__FreeBSD_kernel__) || defined (__FreeBSD__)
#include <fcntl.h>
#include <sys/ioctl.h>
- #include <sys/soundcard.h>
+ #include <linux/soundcard.h>
#elif (defined (__MACH__) && defined (__APPLE__))
#include <Carbon.h>
--- libsndfile-1.0.25/src/sndfile.c 2012-12-31 17:03:34.343241171 +0100
+++ libsndfile-1.0.25-patch/src/sndfile.c 2013-01-01 18:53:37.436544846 +0100
## -309,7 +309,7 ##
{ SF_PRIVATE *psf ;
/* Ultimate sanity check. */
- assert (sizeof (sf_count_t) == 8) ;
+ /* assert (sizeof (sf_count_t) == 8) ; */
if ((psf = calloc (1, sizeof (SF_PRIVATE))) == NULL)
{ sf_errno = SFE_MALLOC_FAILED ;
libsamplerate patch
--- libsamplerate-0.1.8/examples/audio_out.c 2011-07-13 01:57:31.000000000 +0200
+++ libsamplerate-0.1.8-patch/examples/audio_out.c 2013-01-01 17:24:58.257526888 +0100
## -44,7 +44,7 ##
#include <fcntl.h>
#include <sys/ioctl.h>
-#include <sys/soundcard.h>
+#include <linux/soundcard.h>
#define LINUX_MAGIC MAKE_MAGIC ('L', 'i', 'n', 'u', 'x', 'O', 'S', 'S')
Here is a build script that worked for me:
#! /bin/sh
"""
build the toold chain home with:
build/tools/make-standalone-toolchain.sh --platform=android-9 --install-dir=../android-9-toolchain
"""
NDK_HOME=~/dev/SDKs/android-9-toolchain
set -x
set -e
export CC=$NDK_HOME/bin/arm-linux-androideabi-gcc
export CFLAGS=-I$NDK_HOME/include
export LDFLAGS="-L$NDK_HOME/lib"
export AR=$NDK_HOME/bin/arm-linux-androideabi-ar
./waf distclean
./waf configure --with-target-platform android --disable-jack
./waf build --verbose
./waf install --destdir dist-android
it will default to toolchain / gcc version 4.6, I changed this to 4.9 as that is the latest I have.
it should pull down the libraries it needs to finish compiling
the main part of the script was kindly provided by Paul Brossier author of Aubio