summaryrefslogtreecommitdiffstats
path: root/mkmultiarch
blob: 8f25e48edc3251cf4d21ef828473be6946d78bac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
#---------------------------------------------------------------
# Project         : Mandrakelinux
# Module          : multiarch-utils
# File            : mkmultiarch
# Version         : $Id$
# Author          : Gwenole Beauchesne
# Created On      : Wed Jan 12 10:54:10 CET 2005
#---------------------------------------------------------------

usage="Usage: $0 <binaries|includes> <file1> [<file2> ...]"
mplat=`multiarch-platform`
type=$1
case $type in
    binaries|includes) shift;;
    *) echo $usage; exit 1;;
esac

function error() {
    echo ${1+"$@"} > /dev/stderr
    exit 1
}

function dispatch_binaries() {
    local file=$1
    local bindir=`dirname $file`
    local archbindir=$bindir/$mplat
    [[ -d $archbindir ]] || mkdir -p $archbindir
    mv $file $archbindir/
    ln -s /usr/bin/multiarch-dispatch $file
}

function dispatch_includes() {
    local file=$1
    local incdir=`dirname $file`
    local prefix=`echo $incdir | sed -n '/\(.*\/include\)\/.*/s//\1/p'`
    [[ -z "$prefix" ]] && error "Unsupported includedir $incdir"
    local suffix=`echo $incdir | sed -n '/.*\/include\/\(.*\)/s//\1/p'`
    [[ -n "$suffix" ]] && suffix="$suffix/"
    # dispatch nested includes expected in local directory
    sed -n '/^#[ \t]*include[ \t]*"\([^"][^"]*\)".*/s//\1/p' $file | \
    while read localfile; do
	[[ -f "$incdir/$localfile" ]] && dispatch_includes $incdir/$localfile
    done
    # dispatch selected include file
    local archincdir=$prefix/$mplat/$suffix
    [[ -d $archincdir ]] || mkdir -p $archincdir
    mv $file $archincdir/
    cat > $file << EOF
#define _MULTIARCH_HEADER $suffix${file##*/}
#include <multiarch-dispatch.h>
EOF
}

while [[ $# -gt 0 ]]; do
    dispatch_$type $1
    shift
done