1#
2#    "wcc386.exe" wrapper
3#    Copyright (C) 2004 Keishi Suenaga <s_kesihi@mutt.freemail.ne.jp>
4#
5#    This program is free software; you can redistribute it and/or modify
6#    it under the terms of the GNU General Public License as published by
7#    the Free Software Foundation; either version 2 of the License, or
8#    (at your option) any later version.
9#
10#    This program is distributed in the hope that it will be useful,
11#    but WITHOUT ANY WARRANTY; without even the implied warranty of
12#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13#    GNU General Public License for more details.
14#
15#    You should have received a copy of the GNU General Public License Version 2
16#    along with this program; if not, write to the Free Software
17#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18#
19#    wcc386_w.sh:
20#       wcc386 wrapper script.
21#       Make wcc386 to accespt GNU autotools like calls.
22#
23
24#!/bin/sh
25
26foo0=`echo $@|perl -pe 's/($s)(-O.)($s)/$1 $3/'|perl -pe 's/($s)(-D)($S)/$1-d$3/g' -|perl -pe 's/($s)(-I)($S)/$1-i=$3/g' -|perl -pe 's/\\//\\\\/g' -`
27
28###############################################################################
29#                                                                             #
30# compilelink()  parameters     foo0  the list of command line                #
31#                               fname filename of exe file                    #
32#                               compileonly  do not invoke wlink              #
33#                                                                             #
34###############################################################################
35
36compilelink(){
37     complist=" "
38     clist=" "
39     liblist=" "
40     objlist=" "
41     rmobjlist=" "
42     for foo in $foo0 ;do
43       case $foo in
44       *.c)
45         if test "x$fname" = "x " ;then
46           fname=`echo $foo|perl -pe 's/(.*)\.c/$1/' -`
47         fi
48         clist="$clist $foo"
49         ;;
50       *.cc)
51         if test "x$fname" = "x " ;then
52           fname=`echo $foo|perl -pe 's/(.*)\.cc/$1/' -`
53         fi
54         clist="$clist $foo"
55         ;;
56       *.cpp)
57         if test "x$fname" = "x " ;then
58           fname=`echo $foo|perl -pe 's/(.*)\.cpp/$1/' -`
59         fi
60         clist="$clist $foo"
61         ;;
62       *.obj)
63         objlist="$objlist file $foo"
64         rmobjlist="$rmobjlist $foo"
65         ;;
66       *.lib)
67         liblist="$liblist Library $foo"
68         ;;
69       -l*)
70         echo "Ignoreing $foo"
71         ;;
72       *)
73       complist="$complist $foo"
74       esac
75    done
76    if test "x$clist" != "x "; then
77      for foo in $clist ; do
78        if ! wcc386 -zq $foo $complist; then exit -1; fi
79        bar=`echo $foo|perl -pe 's/(.*)\.c.*/$1/' -`.obj
80        objlist="$objlist file $bar"
81        rmobjlist="$rmobjlist $bar"
82      done
83    fi
84    if test "x$compileonly" != xyes; then
85      if ! wlink  op q $objlist $liblist  Name "$fname".exe; then exit -1; fi
86      rm $rmobjlist
87    fi
88}
89
90case $foo0 in
91"")
92  wcc386
93  ;;
94*"-p "*|*" -p"*)
95  if ! wcc386 -zq $foo0; then exit -1; fi
96  ;;
97*"-c "*|*" -c"*)
98  foo=`echo $foo0|perl -pe 's/-c / /' -|perl -pe 's/ -c$/ /' -`
99  case $foo0 in
100  *"-o "*)
101    bar=`echo $foo|perl -pe 's/-o /-fo=/' -`
102    if ! wcc386 -zq $bar; then exit -1; fi
103    ;;
104  *)
105    foo0=$foo
106    compileonly=yes
107    compilelink
108    ;;
109  esac
110  ;;
111*)
112  case $foo0 in
113  *"-o "*)
114    echo $foo0
115     bar=" "
116     found=" "
117     for foo in $foo0 ;do
118       case $foo in
119       -o)
120	     found=yes
121         ;;
122       *)
123         if test "x$found" = xyes; then
124           fname=`echo $foo|perl -pe 's/(.*)\.exe/$1/' -`
125	       found=no
126	     else
127	       bar="$bar $foo"
128         fi
129         ;;
130       esac
131    done
132    foo0=$bar
133    if test "x$fname" = x; then
134      echo "wcc386_w Error"
135      exit -1;
136    fi
137    compilelink
138    ;;
139  *)
140     fname=" "
141     objfname=" "
142     for foo in $foo0 ;do
143       case $foo in
144       *.c)
145         if test "x$fname" = "x " ;then
146           fname=`echo $foo|perl -pe 's/(.*)\.c/$1/' -`
147         fi
148         ;;
149       *.cc)
150         if test "x$fname" = "x " ;then
151           fname=`echo $foo|perl -pe 's/(.*)\.cc/$1/' -`
152         fi
153         ;;
154       *.cpp)
155         if test "x$fname" = "x " ;then
156           fname=`echo $foo|perl -pe 's/(.*)\.cpp/$1/' -`
157         fi
158         ;;
159       *.obj)
160         if test "x$objfname" = "x " ;then
161           objfname=`echo $foo|perl -pe 's/(.*)\.obj/$1/' -`
162         fi
163         ;;
164
165       *)
166       esac
167    done
168    if test "x$fname" = "x " && test "x$objfname" = "x "; then
169      echo "wcc386_w Error"
170      exit -1;
171    fi
172    if test "x$fname" = "x "; then
173      fname=$objfname
174    fi
175    compilelink
176    ;;
177 esac
178 ;;
179esac
180
181exit 0;
182