o2lo.in 2.09 KB
Newer Older
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
59
60
61
62
63
#!/bin/sh

## ---------------------------------------------------------- ##
## $1: .lo file                                               ##
## $2: .cu.o file object file with dynamic symbol relocation  ##
## $3: .o file object file with static symbol relocation      ##
## ---------------------------------------------------------- ##

AWK=@AWK@
GREP=@GREP@
LIBTOOL=@abs_top_builddir@/libtool

if test $# -lt 3; then
    echo "Create a libtool .lo file provided the target.o file"
    echo ""
    echo "\t$0 <file.lo> <file.cu.o> <file.o>"
fi

LO_FILE=$1
PIC_FILE=$(echo $2 | awk -F '/' '{print $NF}')
O_FILE=$(echo $3 | awk -F '/' '{print $NF}')
LIB_PIC_FILE=.libs/$O_FILE
BASENAME=$(echo $2 | awk -F '/' '{for(i=1; i<NF; i++) {print $i "/"}}')

PROGRAM=$($GREP -m 1 PROGRAM= $LIBTOOL | cut -d = -f 2)
PACKAGE=$($GREP -m 1 PACKAGE= $LIBTOOL | cut -d = -f 2)
VERSION=$($GREP -m 1 VERSION= $LIBTOOL | cut -d = -f 2)

must_libtool_define() {
    eval "var=\$$1"
    if [ -z "$var" ]; then
	echo "libtool script did not contain $1 variable used to build .lo file."
	exit
    fi
}

must_libtool_define "PROGRAM"
must_libtool_define "PACKAGE"
must_libtool_define "VERSION"

must_exist() {
    if [ ! -f $1 ]; then
	echo "File $1 is missing."
	exit
    fi
}

must_exist $PWD/$BASENAME$O_FILE
must_exist $PWD/$BASENAME$PIC_FILE

mv $PWD/$BASENAME$PIC_FILE $PWD/$BASENAME$LIB_PIC_FILE

echo "# Generated by $PROGRAM (GNU $PACKAGE) $VERSION" > ${LO_FILE}
echo "# Generated by $PROGRAM (GNU $PACKAGE) $VERSION" >> ${LO_FILE}
echo "# $LO_FILE - a libtool object file"              >> ${LO_FILE}
echo "# Please DO NOT delete this file!"               >> ${LO_FILE}
echo "# It is necessary for linking the library."      >> ${LO_FILE}
echo ""                                                >> ${LO_FILE}
echo "# Name of the PIC object."                       >> ${LO_FILE}
echo "pic_object=$LIB_PIC_FILE"                        >> ${LO_FILE}
echo ""                                                >> ${LO_FILE}
echo "# Name of the non-PIC object"                    >> ${LO_FILE}
echo "non_pic_object=$O_FILE"                          >> ${LO_FILE}