File: mkdll.sh

package info (click to toggle)
octave2.1-forge 2006.03.17%2Bdfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 16,672 kB
  • ctags: 6,047
  • sloc: cpp: 49,610; ansic: 14,035; perl: 2,789; sh: 2,087; makefile: 1,560; lex: 1,219; tcl: 799; fortran: 422; objc: 202
file content (71 lines) | stat: -rwxr-xr-x 1,646 bytes parent folder | download | duplicates (4)
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
64
65
66
67
68
69
70
71
#! /bin/sh

test $# -eq 0 && cat <<EOF && exit 1
mkdll.sh libarchive.a [outname.dll [outlib.lib]]

Converts a static library to a DLL plus a LIB for linking
to that DLL.  By default the output name is archive.

This routine goes to considerable trouble to protect
against object files of the same name in different
subdirectories.
EOF

# Get full path to archive name
archive="$1"
test "${archive#/}" = "$archive" && archive="`pwd`/$archive"
test ! -f "$archive" && echo "$archive does not exist" && exit -1 

# Get base name from /path/libbase.a
base="${archive##*/}"; base="${base#lib}"; base="${base%.a}"

# Determine dll and lib names, or default them from base
if test $# -gt 1 ; then
  dll="$2"
  if test $# -gt 2 ; then
    lib="$3"
  else
    lib="${dll%.dll}.lib"
  fi
else
  dll="$base.dll"
  lib="$base.lib"
fi

# Create a temporary directory for building the archive
test -e "/tmp/$base-dll" && echo "/tmp/$base-dll exists...remove it" && exit 1
mkdir "/tmp/$base-dll"

# extract the archive to a working directory
dir="`pwd`"
work="/tmp/$base-dll"
(cd "$work" && ar x "$archive")

# duplicate filenames in the archive need to be extracted individually 
dups=`ar t "$archive" | sort | uniq -c | grep -v '^ *1[^0-9]'`
even=0
cd "$work"
mkdir dups
for x in 0 junk $dups; do
    if test $even -eq 0; then 
	n=$x
	even=1
    else
	while test $n -gt 1; do
	    n=`expr $n - 1`
	    echo "extracting $x-$n"
	    (cd dups && ar xN $n "$archive" $x)
	    mv dups/$x $x-$n
	done
	even=0
    fi
done
rmdir dups

# Build the dll
cd "$dir"
gcc -shared "-o$dll" "-Wl,--out-implib,$lib" $work/*

# A little bit of cleanup
rm -f $work/*
rmdir $work