venus: Remove dedebug
[openafs.git] / src / config / lwptool
1 #!/bin/sh
2
3 # This is a little helper script to build LWP static, and pthread shared and static
4 # objects from a single source file. We use libtool to do the heavy lifting for
5 # the pthreaded builds, but build the LWP objects here ourselves.
6
7 lwpcc=
8 mtcc=
9 linker=
10 ranlib=
11 mode=
12 object=
13 done=
14 quiet=
15
16 while [ -z "$done" ] && [ $# -gt 0 ] ; do
17     case "$1" in
18     --lwpcc)
19         shift
20         lwpcc="$1"
21         shift
22         ;;
23     --mtcc)
24         shift
25         mtcc="$1"
26         shift
27         ;;
28     --linker)
29         shift
30         linker="$1"
31         shift
32         ;;
33     --mode)
34         shift
35         mode="$1"
36         shift
37         ;;
38     --ranlib)
39         shift
40         ranlib="$1"
41         shift
42         ;;
43     --quiet)
44         shift
45         quiet="1"
46         ;;
47     -o)
48         shift
49         object="$1"
50         shift
51         ;;
52     --)
53         shift;
54         done=yes
55         ;;
56     *)
57         echo "Usage: lwptool --mode compile|link -o <object> --lwpcc <lwp compiler> --mtcc <pthread compiler> -- ..." >&2;
58         exit 1;
59         ;;
60     esac
61 done
62
63 _run_cmd() {
64     if [ x"$quiet" != x1 ] ; then
65         echo "$@"
66     fi
67     if "$@" ; then
68         :
69     else
70         echo "FAILED LWPTOOL COMMAND: $@" >&2
71         exit 1
72     fi
73 }
74
75 case "$mode" in
76 compile)
77     if [ -z "$object" ] || [ -z "$lwpcc" ] || \
78        [ -z "$mtcc" ] || [ -z "$mode" ] ; then
79         echo "Usage: lwptool --mode compile -o <object>" >&2;
80         echo "               --lwpcc <lwp compiler>" >&2;
81         echo "               --mtcc <pthread compiler> blah -- ..." >&2;
82         exit 1
83     fi
84
85     lwpobj=`echo $object | sed -e 's/.lo$/.o/'`
86     lwpobj=".lwp/$lwpobj"
87
88     mkdir .lwp 2>/dev/null
89     _run_cmd $lwpcc -o $lwpobj "$@"
90     _run_cmd $mtcc -o $object "$@"
91     ;;
92 link)
93     if [ -z "$object" ] || [ -z "$linker" ] || \
94        [ -z "$ranlib" ] ; then
95         echo "Usage: l§wptool --mode linker -o <object>" >&2;
96         echo "               --linker <linker and options>" >&2;
97         echo "               --ranlib <ranlib>" >&2;
98         exit 1
99     fi
100
101     # This will go horribly wrong if we ever have objects with shell
102     # special characters in their names
103
104     objects=
105     while [ $# -gt 0 ] ; do
106        arg=$1;
107        realobject=`echo $arg | sed -e 's/\(.*\).lo/.lwp\/\1.o/'`
108        objects="$objects $realobject"
109        shift
110     done
111
112     rm -f $object 2>/dev/null
113     _run_cmd $linker $object $objects
114     _run_cmd $ranlib $object
115     ;;
116 esac