~ubuntu-branches/debian/experimental/ncbi-tools6/experimental

« back to all changes in this revision

Viewing changes to make/msvc_prj/one2all.sh

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2005-03-27 12:00:15 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050327120015-embhesp32nj73p9r
Tags: 6.1.20041020-3
* Fix FTBFS under GCC 4.0 caused by inconsistent use of "static" on
  functions.  (Closes: #295110.)
* Add a watch file, now that we can.  (Upstream's layout needs version=3.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
2
#
 
3
# $Id: one2all.sh,v 1.40 2003/10/23 16:02:07 ucko Exp $
 
4
# ===========================================================================
 
5
 
6
#                            PUBLIC DOMAIN NOTICE
 
7
#               National Center for Biotechnology Information
 
8
 
9
#  This software/database is a "United States Government Work" under the
 
10
#  terms of the United States Copyright Act.  It was written as part of
 
11
#  the author's official duties as a United States Government employee and
 
12
#  thus cannot be copyrighted.  This software/database is freely available
 
13
#  to the public for use. The National Library of Medicine and the U.S.
 
14
#  Government have not placed any restriction on its use or reproduction.
 
15
 
16
#  Although all reasonable efforts have been taken to ensure the accuracy
 
17
#  and reliability of the software and data, the NLM and the U.S.
 
18
#  Government do not and cannot warrant the performance or results that
 
19
#  may be obtained by using this software or data. The NLM and the U.S.
 
20
#  Government disclaim all warranties, express or implied, including
 
21
#  warranties of performance, merchantability or fitness for any particular
 
22
#  purpose.
 
23
 
24
#  Please cite the author in any work or product based on this material.
 
25
 
26
# ===========================================================================
 
27
 
28
# Author:  Anton Lavrentiev
 
29
 
30
# MSVC project file converter. Expand a signle configuration project file
 
31
# to multi-configuration project file.
 
32
#
 
33
# ===========================================================================
 
34
 
 
35
readfirstln() {
 
36
  cat $1 | while read p; do
 
37
    test -z "$p"  &&  continue
 
38
    echo "$p"
 
39
    break
 
40
  done
 
41
}
 
42
 
 
43
config() {
 
44
  # Argument checking first.
 
45
  #
 
46
  if [ _$1 = _--without-dizzy ]; then
 
47
    dizzy='no'
 
48
    shift
 
49
  else
 
50
    dizzy='yes'
 
51
  fi
 
52
  if [ _$1 = _ -o \! -f $1 ]; then
 
53
    echo "ERROR: File \"$1\" inexistent. Stop."
 
54
    return 3
 
55
  fi
 
56
  if [ _$2 != _Debug -a _$2 != _Release ]; then
 
57
    echo "ERROR: Unknown release parameter \"$2\". Stop."
 
58
    return 3
 
59
  fi
 
60
  DEBUG=$2
 
61
  if [ _$3 = _ ]; then
 
62
    CFG="/ML"
 
63
  elif [ $3 = MT ]; then
 
64
    CFG="/MT"
 
65
  elif [ $3 = DLL ]; then
 
66
    CFG="/MD"
 
67
  else
 
68
    echo "ERROR: Unknown configuration \"$3\". Stop."
 
69
    return 3
 
70
  fi
 
71
  SFX="$3"
 
72
 
 
73
  # Our config is ${DEBUG}${SFX}. Compiler switch is ${CFG}.
 
74
  #
 
75
  if [ $DEBUG = Debug ]; then
 
76
    CFG="${CFG}d"
 
77
  fi
 
78
 
 
79
  # Init the sed script, which will make conversion.
 
80
  #
 
81
  cat /dev/null >/tmp/$$_cmd.sed
 
82
 
 
83
  # First replace config name wherever appropriate.
 
84
  #
 
85
  for p in Release Debug ; do
 
86
    for q in DLL MT ; do
 
87
      cat <<-EOF >>/tmp/$$_cmd.sed
 
88
        /^# PROP / !s|$p$q|$p|g
 
89
        /^# PROP .*"[^ ]*$p$q[^ ]*"/ s|$p$q|$p|g
 
90
        EOF
 
91
    done
 
92
    if [ $p != $DEBUG$SFX ]; then
 
93
      cat <<-EOF >>/tmp/$$_cmd.sed
 
94
        /^# PROP / !s|$p|$DEBUG$SFX|g
 
95
        /^# PROP .*"[^ ]*$p[^ ]*"/ s|$p|$DEBUG$SFX|g
 
96
        EOF
 
97
    fi
 
98
  done
 
99
 
 
100
  # Replace debugging macro.
 
101
  #
 
102
  if [ $DEBUG = Debug ]; then
 
103
    echo 's|NDEBUG|_DEBUG|g' >>/tmp/$$_cmd.sed
 
104
  else
 
105
    echo 's|_DEBUG|NDEBUG|g' >>/tmp/$$_cmd.sed
 
106
  fi
 
107
 
 
108
  # Does the project use wxWindows (or is a part of wxWindows)?
 
109
  #
 
110
  if [ `grep -c '^# ADD .*CPP .*__WXDEBUG__' $1` != 0 -o \
 
111
       `grep -c '^# ADD .*CPP .*__WXMSW__' $1`   != 0 -o \
 
112
       `grep -c '^# ADD .*CPP .*WX.\\{2,3\\}INGDLL' $1` != 0 ]; then
 
113
    GUI="wxwin"
 
114
 
 
115
    # Flag proper macros for DLL mode.
 
116
    #
 
117
    if [ _$SFX = _DLL ]; then
 
118
      if [ `grep -c '^# ADD .*CPP .*/D *["]\\{0,1\\}WXMAKINGDLL=*[0-9]*["]\\{0,1\\}' $1` != 0 ]; then
 
119
        WXDLL='/D "WXMAKINGDLL=1"'
 
120
      else
 
121
        WXDLL='/D "WXUSINGDLL=1"'
 
122
      fi
 
123
    else
 
124
      WXDLL=""
 
125
    fi
 
126
 
 
127
  # Is this an FLTK-dependent project?
 
128
  #
 
129
  elif [ `grep -c '^# ADD .*LINK32 .*fltk[a-z]*[.]lib' $1` != 0 ]; then
 
130
     GUI="fltk"
 
131
  else
 
132
     GUI=""
 
133
  fi
 
134
 
 
135
  # Either replace with hooks, or just remove the compiler switches,
 
136
  # which may be configuration-dependent or inconsistent.
 
137
  #
 
138
  cat <<-EOF >>/tmp/$$_cmd.sed
 
139
        /^# ADD .*CPP / {
 
140
          s|  */O[0-9A-Za-z]*| @O|
 
141
          s|  */O[0-9A-Za-z]*||g
 
142
          s|  */Gm||g
 
143
          s|  */GZ||g
 
144
          s|  */FR||g
 
145
          s|  */Fr||g
 
146
          s|  */c| @c|
 
147
          s|  */c||g
 
148
          s|  */ZI| @Z|
 
149
          s|  */ZI||g
 
150
          s|  */Zi| @Z|
 
151
          s|  */Zi||g
 
152
          s|  */Z7| @Z|
 
153
          s|  */Z7||g
 
154
          s|  */D  *"\{0,1\}DEBUG=*[0-9]*"\{0,1\}| @D|g
 
155
        EOF
 
156
 
 
157
  # Remove some wxWindows macros, which are surely configuration-dependent.
 
158
  #
 
159
  if [ "$GUI" = "wxwin" ]; then
 
160
    cat <<-EOF >>/tmp/$$_cmd.sed
 
161
          s|  */D  *["]\\{0,1\\}__WXDEBUG__=*[0-9]*["]\\{0,1\\}||g
 
162
          s|  */D  *["]\\{0,1\\}WXUSINGDLL=*[0-9]*["]\\{0,1\\}||g
 
163
          s|  */D  *["]\\{0,1\\}WXMAKINGDLL=*[0-9]*["]\\{0,1\\}||g
 
164
        EOF
 
165
  fi
 
166
 
 
167
  # Clear the linker debug option.
 
168
  #
 
169
  cat <<-EOF >>/tmp/$$_cmd.sed
 
170
        }
 
171
        /^# ADD .*LINK32 / s|  */debug||g
 
172
        EOF
 
173
 
 
174
  # When requested, remove include/library paths, which refer to DIZZY.
 
175
  #
 
176
  if [ "$dizzy" = "no" ]; then
 
177
    cat <<-EOF >>/tmp/$$_cmd.sed
 
178
        /^# ADD .*CPP / s|  */I  *["]\\{0,1\\}\\\\\\\\[Dd][Ii][Zz][Zz][Yy]\\\\[^ ]*||g
 
179
        /^# ADD .*RSC / s|  */i  *["]\\{0,1\\}\\\\\\\\[Dd][Ii][Zz][Zz][Yy]\\\\[^ ]*||g
 
180
        /^# ADD .*LINK32 / s|  */libpath:["]\\{0,1\\}\\\\\\\\[Dd][Ii][Zz][Zz][Yy]\\\\[^ ]*||g
 
181
        EOF
 
182
  fi
 
183
 
 
184
  # Configuration-dependent changes: replace hooks and
 
185
  # add more compiler options where appropriate.
 
186
  #
 
187
  if [ $DEBUG = Debug ]; then
 
188
    cat <<-EOF >>/tmp/$$_cmd.sed
 
189
        /^# PROP / s|  *Use_Debug_Libraries  *0| Use_Debug_Libraries 1|
 
190
        /^# ADD .*LINK32 / {
 
191
          s|  */pdb:[^ ]*||g
 
192
          s|/mach|/pdb:none /debug &|
 
193
        }
 
194
        /^# ADD .*CPP / {
 
195
          s|@O|/Od|
 
196
          s|@Z|/Z7|
 
197
          s| @Z||g
 
198
          s|/W[^ ]*|& /Gm|
 
199
          s|@c|/GZ /c|
 
200
          s|@D|/D "DEBUG=1"|
 
201
          s| @D||g
 
202
        EOF
 
203
  else
 
204
    cat <<-EOF >>/tmp/$$_cmd.sed
 
205
        /^# PROP / s|  *Use_Debug_Libraries  *1| Use_Debug_Libraries 0|
 
206
        /^# ADD .*LINK32 / s|  */pdbtype[^ ]*||g
 
207
        /^# ADD .*CPP / {
 
208
          s|@O|/O2|
 
209
          s| @Z||g
 
210
          s|@c|/c|
 
211
          s| @D||g
 
212
        EOF
 
213
  fi
 
214
 
 
215
  # Now replace the code generation switch.
 
216
  #
 
217
  for p in "/MD" "/ML" "/MT" ; do
 
218
    cat <<-EOF >>/tmp/$$_cmd.sed
 
219
          s|  *${p}d| $p|g
 
220
          s| $p| @C|g
 
221
        EOF
 
222
  done
 
223
 
 
224
  # Finish with code generation switch, and then make sure
 
225
  # that incremental linking is on except for wxWindows DLLs (slow).
 
226
  #
 
227
  cat <<-EOF >>/tmp/$$_cmd.sed
 
228
          t cfgrst
 
229
          :cfgrst
 
230
          s|@C|$CFG|
 
231
          t cfgokay
 
232
          s|/nologo|& $CFG|
 
233
          t cfgokay
 
234
          s| CPP|& $CFG|
 
235
          :cfgokay
 
236
          s| @C||g
 
237
        }
 
238
        /^# ADD .*LINK32 / s|  */incremental[:yesno]*||g
 
239
        EOF
 
240
  if [ `grep -c '^# ADD .*LINK32 .*/dll' $1` = 0 ]; then
 
241
    INCRLNK='yes'
 
242
  elif [ -n "$GUI" -a `echo "$WXDLL" | grep -c '^# ADD .*CPP .*WXMAKINGDLL'` != 0 ]; then
 
243
    INCRLNK='no'
 
244
  else
 
245
    INCRLNK=""
 
246
  fi
 
247
  test "$INCRLNK" = "yes" -a $DEBUG != Debug  &&  INCRLNK='no'
 
248
  if [ -n "$INCRLNK" ]; then
 
249
    echo "/^# ADD .*LINK32 / s|/nologo|& /incremental:$INCRLNK|" >>/tmp/$$_cmd.sed
 
250
  fi
 
251
 
 
252
  # wxWindows-specific changes from now on.
 
253
  #
 
254
  if [ "$GUI" = "wxwin" ]; then
 
255
    # Define __WXDEBUG__ for debug configs.
 
256
    #
 
257
    if [ $DEBUG = Debug ]; then
 
258
      WXDEBUG='/D "__WXDEBUG__=1"'
 
259
    else
 
260
      WXDEBUG=""
 
261
    fi
 
262
 
 
263
    # ${WX} is to be added to compiler options.
 
264
    #
 
265
    WX=`echo $WXDEBUG $WXDLL`
 
266
 
 
267
    if [ -n "$WX" ]; then
 
268
      cat <<-EOF >>/tmp/$$_cmd.sed
 
269
        /^# ADD .*CPP / {
 
270
          t reset
 
271
          :reset
 
272
          s|/Y|$WX &|
 
273
          t success
 
274
          s|/D|$WX &|
 
275
          t success
 
276
          s|/c|$WX &|
 
277
          t success
 
278
          s| *\$| $WX|
 
279
          :success
 
280
        }
 
281
        EOF
 
282
    fi
 
283
 
 
284
    # Enforce /subsystem:windows.
 
285
    #
 
286
    cat <<-EOF >>/tmp/$$_cmd.sed
 
287
        /^# ADD .*LINK32 / s|/subsystem:[A-Za-z]*|@s|g
 
288
        /^# ADD LINK32 / {
 
289
          t wxlrst
 
290
          :wxlrst
 
291
          s|@s|/subsystem:windows|
 
292
          t wxlcnt
 
293
          s|/nologo|& /subsystem:windows|
 
294
          t wxlcnt
 
295
          s|\$| /subsystem:windows|
 
296
          :wxlcnt
 
297
        }
 
298
        /^# ADD .*LINK32 / s| *@s||g
 
299
        EOF
 
300
 
 
301
    # Take care of libraries: remove all wxWindows ones
 
302
    #
 
303
    cat <<-EOF >>/tmp/$$_cmd.sed
 
304
        /^# ADD .*LINK32 .*wx[dl]\\{0,1\\}[.]lib/ {
 
305
          s/  *jpegd\\{0,1\\}[.]lib//g
 
306
          s/  *pngd\\{0,1\\}[.]lib//g
 
307
          s/  *tiffd\\{0,1\\}[.]lib//g
 
308
          s/  *xpmd\\{0,1\\}[.]lib//g
 
309
          s/  *zlibd\\{0,1\\}[.]lib//g
 
310
          s/  *wx[dl]\\{0,1\\}[.]lib/ @wx/g
 
311
        EOF
 
312
 
 
313
    # Insert them back but with correct names (which we use).
 
314
    # Note that in DLL mode only one (import) library has to be included.
 
315
    # The note above was true formely; now images libs are all static.
 
316
    #
 
317
    #if [ _$SFX != _DLL ]; then
 
318
      cat <<-EOF >>/tmp/$$_cmd.sed
 
319
          s/@wx/jpeg.lib png.lib tiff.lib zlib.lib wx.lib/
 
320
        EOF
 
321
    #else
 
322
    #  cat <<-EOF >>/tmp/$$_cmd.sed
 
323
    #     s/@wx/wx.lib/
 
324
    #   EOF
 
325
    #fi
 
326
    cat <<-EOF >>/tmp/$$_cmd.sed
 
327
          s/ @wx//g
 
328
        }
 
329
        EOF
 
330
  fi
 
331
 
 
332
  # FLTK specific changes from now on
 
333
  #
 
334
  if [ "$GUI" = "fltk" ]; then
 
335
    # Enforce /subsystem:windows.
 
336
    #
 
337
    cat <<-EOF >>/tmp/$$_cmd.sed
 
338
        /^# ADD .*LINK32 / s|/subsystem:[A-Za-z]*|@s|g
 
339
        /^# ADD LINK32 / {
 
340
          t fllrst
 
341
          :fllrst
 
342
          s|@s|/subsystem:windows|
 
343
          t fllcnt
 
344
          s|/nologo|& /subsystem:windows|
 
345
          t fllcnt
 
346
          s|\$| /subsystem:windows|
 
347
          :fllcnt
 
348
        }
 
349
        /^# ADD .*LINK32 / s| *@s||g
 
350
        EOF
 
351
 
 
352
    # Take care of libraries: remove all FLTK ones
 
353
    #
 
354
    cat <<-EOF >>/tmp/$$_cmd.sed
 
355
        /^# ADD .*LINK32 * fltk[a-z]*[.]lib/ {
 
356
          s/  *fltk[a-z]*[.]lib/ @fltk/g
 
357
        EOF
 
358
 
 
359
    # Insert them back but with correct names (which we use).
 
360
    # Note that in DLL mode only one (import) library has to be included.
 
361
    #
 
362
    #if [ _$SFX != _DLL ]; then
 
363
    #  cat <<-EOF >>/tmp/$$_cmd.sed
 
364
    #     s/@fltk/fltkforms.lib fltkimages.lib fltkgl.lib fltk.lib/
 
365
    #   EOF
 
366
    #else
 
367
      cat <<-EOF >>/tmp/$$_cmd.sed
 
368
          s/@fltk/fltkdll.lib/
 
369
        EOF
 
370
    #fi
 
371
    cat <<-EOF >>/tmp/$$_cmd.sed
 
372
          s/ @fltk//g
 
373
        }
 
374
        EOF
 
375
  fi
 
376
 
 
377
  # Print name of configuration, which was created, and run the script.
 
378
  #
 
379
  echo "${DEBUG}${SFX}" ${GUI:+"("$GUI")"}
 
380
 
 
381
  sed -f /tmp/$$_cmd.sed $1 >/tmp/$$_new
 
382
  cp -f /tmp/$$_new $1
 
383
  rm -f /tmp/$$_cmd.sed /tmp/$$_new
 
384
 
 
385
  return 0
 
386
}
 
387
 
 
388
configcb()
 
389
{
 
390
  cat /dev/null >/tmp/$$_cmd.sed
 
391
 
 
392
  # First replace config name wherever appropriate.
 
393
  #
 
394
  for p in Release Debug ; do
 
395
    for q in DLL MT ; do
 
396
      cat <<-EOF >>/tmp/$$_cmd.sed
 
397
        s|$p *$q|$p|g
 
398
        EOF
 
399
    done
 
400
    if [ $p != $2$3 ]; then
 
401
      cat <<-EOF >>/tmp/$$_cmd.sed
 
402
        s|$p|$2$3|g
 
403
        EOF
 
404
    fi
 
405
  done
 
406
  sed -f /tmp/$$_cmd.sed $1
 
407
  rm -f /tmp/$$_cmd.sed
 
408
}
 
409
 
 
410
usage() {
 
411
  echo 'Automatic multi config for Microsoft Visual C++ Project File V 6.0'
 
412
  echo 'Usage:'
 
413
  echo `basename $0` '[--without-dizzy] filename'
 
414
  exit 1
 
415
}
 
416
 
 
417
if [ _$1 = _--without-dizzy ]; then
 
418
  without_dizzy="$1"
 
419
  shift
 
420
else
 
421
  without_dizzy=""
 
422
fi
 
423
 
 
424
if [ _$1 = _ ]; then
 
425
  usage
 
426
elif [ \! -f $1 ]; then
 
427
  echo "ERROR: File \"$1\" must exist. Stop."
 
428
  exit 3
 
429
fi
 
430
 
 
431
if [ _$2 != _ ]; then
 
432
  if [ $2 != 4 -a $2 != 3 -a $2 != 2 ]; then
 
433
    echo "ERROR: Unknown special parameter \"$2\". Stop."
 
434
    exit 3
 
435
  fi
 
436
  if [ $2 = 2 ]; then
 
437
    CFGSET='DLL'
 
438
  elif [ $2 = 3 ]; then
 
439
    CFGSET='MT'
 
440
  else
 
441
    CFGSET='DLL ""'
 
442
  fi
 
443
else
 
444
  CFGSET='DLL MT ""'
 
445
fi
 
446
file=/tmp/$$_file
 
447
 
 
448
# DOS-2-UNIX conversion (shouldn't be here, but just in case for sanity).
 
449
#
 
450
sed -e 's/
 
 
b"*$//' $1 >$file"
 
451
 
 
452
# Check signature.
 
453
#
 
454
cat <<-"EOF" >/tmp/$$_genusign
 
455
        # Microsoft Developer Studio Project File
 
456
        # Microsoft Developer Studio Generated Build File, Format Version 6.00
 
457
        # ** DO NOT EDIT **
 
458
 
 
459
        # TARGTYPE
 
460
        EOF
 
461
cat /dev/null >/tmp/$$_filesign
 
462
head -1 $file | sed -e 's/ -.*//' >>/tmp/$$_filesign
 
463
head -3 $file | tail +2 >>/tmp/$$_filesign
 
464
head -5 $file | tail +4 | sed -e 's/ *".*$//' >>/tmp/$$_filesign
 
465
diff /tmp/$$_filesign /tmp/$$_genusign >/dev/null 2>&1
 
466
exit=$?
 
467
rm -f /tmp/$$_filesign /tmp/$$_genusign
 
468
if [ $exit != 0 ]; then
 
469
  echo "ERROR: $1 doesn't look like MSVC++ Project File. Stop."
 
470
  rm -f $file
 
471
  exit 2
 
472
fi
 
473
 
 
474
# Extract configuration part of the project file and count configurations.
 
475
#
 
476
cat <<-EOF >/tmp/$$_.sed
 
477
        /^!IF /,/^!ENDIF/ {
 
478
          /^!ENDIF/ q
 
479
          p
 
480
        }
 
481
        d
 
482
        EOF
 
483
NCFG=`sed -n -f /tmp/$$_.sed $file | egrep -c '^[!ELS]+IF '`
 
484
rm -f /tmp/$$_.sed
 
485
if [ $NCFG -gt 1 ]; then
 
486
  echo "ERROR: $1 contains more than one configuration ($NCFG). Stop."
 
487
  rm -f $file
 
488
  exit 2
 
489
fi
 
490
 
 
491
# Check for per-config dependencies, and warn if any.
 
492
#
 
493
DEP=`grep -c '^# PROP  *AllowPerConfigDependencies  *1' $file`
 
494
cat <<-EOF >/tmp/$$_prop.sed
 
495
        /^# Begin Target/,\$ p
 
496
        d
 
497
        EOF
 
498
sed -n -f /tmp/$$_prop.sed $file | grep '^!IF ' >/dev/null 2>&1
 
499
if [ $DEP != 0 -a $? = 0 ]; then
 
500
  echo "WARNING: $1 contains per-configuration dependencies,"
 
501
  echo 'which may or may not be handled correctly by this script.'
 
502
fi
 
503
rm -f /tmp/$$_prop.sed
 
504
 
 
505
# Extract beginning of the file.
 
506
#
 
507
cat <<-EOF >/tmp/$$_head.sed
 
508
        /^!MESSAGE "/ {
 
509
          w /tmp/$$_cmp
 
510
          q
 
511
        }
 
512
        p
 
513
        d
 
514
        EOF
 
515
sed -n -f /tmp/$$_head.sed $file >/tmp/$$_head
 
516
rm -f /tmp/$$_head.sed
 
517
config /tmp/$$_head Release `echo $CFGSET | sed -e 's| .*||'` >/dev/null 2>&1
 
518
sed -e 's/ "/ %/' -e 's/" /% /' /tmp/$$_cmp >/tmp/$$_comp
 
519
mv /tmp/$$_comp /tmp/$$_cmp
 
520
 
 
521
# Extract the middle part.
 
522
#
 
523
cat <<-EOF >/tmp/$$_mid.sed
 
524
        /^# Begin Project/,/^!IF / {
 
525
          /^# PROP  *AllowPerConfigDependencies / s/  *1/ 0/
 
526
          /^!IF / q
 
527
          /^# PROP BASE / {
 
528
            i\\
 
529
 
 
530
            q
 
531
          }
 
532
          p
 
533
        }
 
534
        d
 
535
        EOF
 
536
sed -n -f /tmp/$$_mid.sed $file >/tmp/$$_mid
 
537
rm -f /tmp/$$_mid.sed
 
538
 
 
539
# Now extract configuration-dependent part, and make required configs.
 
540
#
 
541
cat <<-EOF >/tmp/$$_cut.sed
 
542
        /^!IF /,/^!E/ {
 
543
          s/^!ELSEIF .*\$/!ENDIF /
 
544
          H
 
545
        }
 
546
        /^!ENDIF/ {
 
547
          x
 
548
          q
 
549
        }
 
550
        d
 
551
        EOF
 
552
sed -n -f /tmp/$$_cut.sed $file >/tmp/$$_cfgtmpl
 
553
if [ \! -s /tmp/$$_cfgtmpl ]; then
 
554
  cat <<-EOF >/tmp/$$_cut.sed
 
555
        /^# PROP BASE /,/^# Begin Target/ {
 
556
          /# Begin Target/ q
 
557
          p
 
558
        }
 
559
        d
 
560
        EOF
 
561
  echo "!IF  \"\$(CFG)\" == \"`sed -e 's/^.* %//' -e 's/% .*\$//' /tmp/$$_cmp`\"" >/tmp/$$_cfgtmpl
 
562
  echo >>/tmp/$$_cfgtmpl
 
563
  sed -n -f /tmp/$$_cut.sed $file >>/tmp/$$_cfgtmpl
 
564
  echo >>/tmp/$$_cfgtmpl
 
565
  echo '!ENDIF ' >>/tmp/$$_cfgtmpl
 
566
fi
 
567
rm -f /tmp/$$_cut.sed
 
568
cat /dev/null >/tmp/$$_title
 
569
cat /dev/null >/tmp/$$_cfg
 
570
cat /dev/null >/tmp/$$_message
 
571
for i in Release Debug ; do
 
572
  for j in $CFGSET ; do
 
573
    if [ $j = '""' ]; then
 
574
      j=""
 
575
    fi
 
576
    cp /tmp/$$_cfgtmpl /tmp/$$_cfg_$i$j
 
577
    config $without_dizzy /tmp/$$_cfg_$i$j $i $j >>/tmp/$$_message
 
578
    if [ $? != 0 ]; then
 
579
      tail -1 /tmp/$$_message
 
580
      rm -f /tmp/$$_*
 
581
      exit 3
 
582
    fi
 
583
    grep '^!IF ' /tmp/$$_cfg_$i$j >>/tmp/$$_title
 
584
    cat /tmp/$$_cfg_$i$j >>/tmp/$$_cfg
 
585
    rm -f /tmp/$$_cfg_$i$j
 
586
  done
 
587
done
 
588
echo "${1}:" `cat /tmp/$$_message`
 
589
rm -f /tmp/$$_cfgtmpl /tmp/$$_message
 
590
 
 
591
# Summarize configurations in the header and tail parts of the project.
 
592
#
 
593
sed -e 's/^!IF.*CFG)" == //' -e 'y/ "/~%/' /tmp/$$_title >/tmp/$$_tlt
 
594
mv /tmp/$$_tlt /tmp/$$_title
 
595
cat /dev/null >/tmp/$$_msg
 
596
cat /dev/null >/tmp/$$_name
 
597
for i in `cat /tmp/$$_title` ; do
 
598
  sed -e "s/ %.*% / $i /" -e 'y/~%/ "/' /tmp/$$_cmp >>/tmp/$$_msg
 
599
  echo "# Name $i" | tr '~%' ' "' >>/tmp/$$_name
 
600
done
 
601
sed -e 's/ .*$/ /' /tmp/$$_cmp >>/tmp/$$_msg
 
602
echo >>/tmp/$$_msg
 
603
rm -f /tmp/$$_title
 
604
 
 
605
# Extract the tail part and modify name list on-the-fly.
 
606
#
 
607
cat <<-EOF >/tmp/$$_tail.sed
 
608
        /^# Begin Target/,/^# End Project/ {
 
609
          /^# Name /  {
 
610
            r /tmp/$$_name
 
611
            d
 
612
          }
 
613
          /^!IF /,/^!ENDIF/ d
 
614
          p
 
615
        }
 
616
        d
 
617
        EOF
 
618
sed -n -f /tmp/$$_tail.sed $file >/tmp/$$_tail
 
619
rm -f /tmp/$$_tail.sed /tmp/$$_name $file
 
620
 
 
621
# Glue all parts but the tail.
 
622
#
 
623
cat /tmp/$$_head /tmp/$$_msg /tmp/$$_mid /tmp/$$_cfg >/tmp/$$_newhead
 
624
mv /tmp/$$_newhead /tmp/$$_head
 
625
rm -f /tmp/$$_msg /tmp/$$_mid /tmp/$$_cfg
 
626
 
 
627
# Replace ENDIF..IF with ELSEIF.
 
628
#
 
629
cat <<-EOF >/tmp/$$_elseif.sed
 
630
        /^!ENDIF/,/^!IF / {
 
631
          s/^!IF /!ELSEIF /
 
632
          /^!ELSEIF / !d
 
633
        }
 
634
        EOF
 
635
sed -f /tmp/$$_elseif.sed /tmp/$$_head >/tmp/$$_newhead
 
636
rm -f /tmp/$$_elseif.sed
 
637
mv /tmp/$$_newhead /tmp/$$_head
 
638
cat <<-EOF >>/tmp/$$_head
 
639
        !ENDIF 
 
640
 
 
641
        EOF
 
642
 
 
643
grep '^SOURCE=' $1 | sed 's/^SOURCE=//;s/[\\]/\\\\/g;s/[.]/[.]/g' >/tmp/$$_flist
 
644
 
 
645
for i in `cat /tmp/$$_flist | sed 's/[[]//g;s/]//g'`; do
 
646
  file="/tmp/$$_`echo $i | sed 's/[./\\]/_/g'`"
 
647
  cat <<-EOF >/tmp/$$_cbext.sed
 
648
        /^SOURCE=$i\$/,/^SOURCE=/ {
 
649
          /^SOURCE=$i\$/ d
 
650
          /^[#] End Source File/ !H
 
651
          /^!ENDIF/ {
 
652
            x
 
653
            q
 
654
          }
 
655
          /^[#] End Custom Build/ {
 
656
            x
 
657
            q
 
658
          }
 
659
          d
 
660
        }
 
661
        d
 
662
        EOF
 
663
  sed -f /tmp/$$_cbext.sed $1 >$file
 
664
done
 
665
rm -f /tmp/$$_cbext.sed
 
666
 
 
667
cat /dev/null >/tmp/$$_cb.sed
 
668
for k in `cat /tmp/$$_flist | sed 's/[[]//g;s/]//g'`; do
 
669
  file="/tmp/$$_`echo $k | sed 's/[./\\]/_/g'`"
 
670
  test -s $file  ||  continue
 
671
  if [ `readfirstln $file | grep -c '^[!]'` = 0 ]; then
 
672
    echo "!IF  \"\$(CFG)\" == \"`sed -e 's/^.* %//' -e 's/% .*\$//' /tmp/$$_cmp`\"" >$file.1
 
673
    echo           >>$file.1
 
674
    cat $file      >>$file.1
 
675
    echo           >>$file.1
 
676
    echo '!ENDIF ' >>$file.1
 
677
    mv $file.1 $file
 
678
  fi
 
679
  cat /dev/null >$file.new
 
680
  for i in Release Debug ; do
 
681
    for j in $CFGSET ; do
 
682
      if [ $j = '""' ]; then
 
683
        j=""
 
684
      fi
 
685
      configcb $file $i $j >>$file.new
 
686
    done
 
687
  done
 
688
  echo >$file
 
689
 
 
690
  # Replace ENDIF..IF with ELSEIF.
 
691
  #
 
692
  cat <<-EOF >/tmp/$$_elseif.sed
 
693
        /^!ENDIF/,/^!IF / {
 
694
          s/^!IF /!ELSEIF /
 
695
          /^!ELSEIF / !d
 
696
        }
 
697
        EOF
 
698
  sed -f /tmp/$$_elseif.sed $file.new >>$file
 
699
  rm -f /tmp/$$_elseif.sed $file.new
 
700
  cat <<-EOF >>$file
 
701
        !ENDIF
 
702
 
 
703
        EOF
 
704
  cat <<-EOF >>/tmp/$$_cb.sed
 
705
        /^SOURCE=$k\$/,/^[#] End Source File/ {
 
706
          /^SOURCE=$k\$/ {
 
707
            p
 
708
            r $file
 
709
            d
 
710
          }
 
711
          /^[#] End Source File/ p
 
712
          d
 
713
        }
 
714
        EOF
 
715
done
 
716
 
 
717
sed -f /tmp/$$_cb.sed /tmp/$$_tail >/tmp/$$_tail.1
 
718
 
 
719
# Final catenation of results to a single project file.
 
720
#
 
721
cat /tmp/$$_head /tmp/$$_tail.1 >/tmp/$$_proj
 
722
rm -f /tmp/$$_cmp /tmp/$$_head /tmp/$$_tail /tmp/$$_tail.1 /tmp/$$_cb.sed
 
723
for i in `cat /tmp/$$_flist | sed 's/[[]//g;s/]//g'`; do
 
724
  file="/tmp/$$_`echo $i | sed 's/[./\\]/_/g'`"
 
725
  rm -f $file
 
726
done
 
727
rm -f /tmp/$$_flist
 
728
 
 
729
# Remove consequent empty lines (could occur earlier in substitutions)
 
730
# and replace original project file (backup kept in .bak).
 
731
# Make the output file to be a DOS (CR/LF) text file.
 
732
#
 
733
cat <<-EOF >/tmp/$$_pretty.sed
 
734
        /./ {
 
735
          p
 
736
          d
 
737
        }
 
738
        /^\$/ p
 
739
        :Empty
 
740
        /^\$/ {
 
741
          N
 
742
          s/.//
 
743
          b Empty
 
744
        }
 
745
        p
 
746
        EOF
 
747
mv $1 $1.bak
 
748
 
 
749
PATH=$PATH:/usr/sbin:/sbin
 
750
doser='sed -e s/$/
 
 
b"/'"
 
751
if [ `echo $OSTYPE   2>&1 | grep -c -i cygwin` -ge 1 -o  \
 
752
     `echo $MACHTYPE 2>&1 | grep -c -i cygwin` -ge 1 -o  \
 
753
     `mount          2>&1 | grep -c -i cygwin` -ge 1 ]; then
 
754
  echo >$1
 
755
  test "`ls -l $1 | tr '\t' ' ' | sed 's/  */ /g' | cut -f5 -d' '`" != "1"  && \
 
756
    doser='sed -n p'
 
757
fi
 
758
sed -n -f /tmp/$$_pretty.sed /tmp/$$_proj | $doser >$1
 
759
rm -f /tmp/$$_pretty.sed /tmp/$$_proj
 
760
touch -r $1.bak $1
 
761
 
 
762
exit 0