Source

Coin / cfg / gendsp.sh.in

Full commit
  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
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
#! /bin/sh
# **************************************************************************
# This is a hack for generating a Microsoft Developer Studio project and
# workspace files (.dsp/.dsw) for building Coin from the MSVC++ IDE.  It
# hooks into the Automake process as a fake compiler, building the project
# file instead of the sources.
#
# It now also creates an installation script for the header files.
# It also supports automatically moc'ing of source files, if certain
# conventions are followed.
#
# TODO:
#  - Indicate that the dsp file is *not* generated by Microsoft Developer
#    Studio?  Will the MSVC++ IDE eat "foreign" dsp files?
#
# 20050105 larsa

me=$0

enable_static=true

# **************************************************************************
# useful sed commands

sed_d2u='s,\\,/,g' # dos2unix path delimiter switching
sed_u2d='s,/,\\,g' # unix2dos path delimiter switching

# **************************************************************************
# useful autoconf variables - added for optimization/simplification reasons

prefix="@prefix@"
build_dir="@abs_top_builddir@"
src_dir="@abs_top_srcdir@"
ac_unique_file="@ac_unique_file@"
sim_ac_relative_src_dir="@sim_ac_relative_src_dir@"
sim_ac_relative_src_dir_p="@sim_ac_relative_src_dir_p@"

me_u=`echo $me | sed $sed_d2u`
medir_u=`echo $me_u | sed 's,[^/]*$,,g'`
srcdir_u=`cd $medir_u/..; pwd | sed $sed_d2u`
thisdir_u=`pwd | sed $sed_d2u`

if $sim_ac_relative_src_dir_p; then
  if test -f $srcdir_u/$sim_ac_relative_src_dir/$ac_unique_file; then
    :
    # things are in place
  else
    echo >&2 "$me: error: directories have been moved relative to each other"
    echo >&2 "   since the last configure run."
    exit
  fi
else
  echo >&2 "$me: error: dsp generation is not supported when absolute paths"
  echo >&2 "   are necessary to locate files."
  exit
fi

# **************************************************************************
# preliminary variable exploration

# echo "me:       $me_u"
# echo "medir:    $medir_u"
# echo "srcdir:   $srcdir_u"
# echo "thisdir:  $thisdir_u"

# exit

# run this where needed: me=`echo $me | sed 's%^.*/%%g'`

# **************************************************************************
# The following block (the --registar-public-header part) generates
# 1) the public headers part of the .dsp file
# 2) the install-headers.bat file
# It is invoked from a "make ... install-data"-command far down in this script

if test x"$1" = x"--register-public-header"; then
  studiofile=$2
  headerfile=$3
  installpath=$4
  finalheader=`echo "$installpath" | sed -e "s,.*$prefix/\\(include\\|data\\)/,%COINDIR%/\\1/," -e "s,/\\./,/,g" -e "$sed_u2d"`
  sim_ac_relative_src_dir_q=`echo "@sim_ac_relative_src_dir@" | sed -e 's,\.,\\\\.,g'`

  # echo "========================="
  # echo "source dir:   $src_dir"
  # echo "build dir:    $build_dir"
  # echo "install dir:  $installpath"
  # echo "header:       $headerfile"

  # echo "relative:     $sim_ac_relative_src_dir"

  tested=true
  case $headerfile in
  *$sim_ac_relative_src_dir/* )
    headerfile=`echo $headerfile | sed -e "s%.*$sim_ac_relative_src_dir_q%$sim_ac_relative_src_dir%"`
    ;;
  $build_dir/* )
    tested=false
    echo "EXPLICIT IN BUILD DIR"
    headerfile=`echo $headerfile | sed -e "s%$build_dir/%%"`
    ;;
  $src_dir* )
    tested=false
    echo "EXPLICIT IN SOURCE DIR - CONVERT TO RELATIVE"
    headerfile=`echo $headerfile | sed -e "s%$src_dir%$sim_ac_relative_src_dir%"`
    ;;
  *)
    headerfile=`pwd`/$headerfile
    headerfile=`echo $headerfile | sed -e "s%$build_dir/%%"`
    ;;
  esac

  # echo "final header: $headerfile"
  # echo "FINAL header: $finalheader"
  # echo "========================="

  headerfile=`echo $headerfile | sed -e "$sed_u2d"`

  if $tested; then :; else
    echo "untested case - manual inspection required";
    exit 1;
  fi

  echo "# Begin Source File" >>"$studiofile"
  echo "" >>"$studiofile"
  echo "SOURCE=$headerfile" >>"$studiofile"
  echo "# End Source File" >>"$studiofile"

  # and the installation script
  installheadersfile=`echo $studiofile | sed -e 's,\([^\\/0-9]*\)[0-9][^\\/]*\.dsp,install-headers.bat,'`

  # sourcedirq=`echo "$sourcedir" | sed -e 's,\\\\,\\\\,g'`
  # builddirq=`echo "$builddir" | sed -e 's,\\\\,\\\\,g'`
  # relheader=`echo "$headerfile" | sed -e "s,$builddirq,.,g" -e "s,$sourcedirq,..\\\\..,g" -e 's,\\\\,\\\\\\\\,g'`
  # finalheader=`echo "$relheader" | sed -e 's,.*include,include,g'`
  # relheader=`echo "$relheader"`
  # finalheader=`echo "$finalheader"`

  echo "copy /Y $headerfile $finalheader >nul:" >>"$installheadersfile"
  exit 0
fi

# **************************************************************************
#

# this variable should contain the list of variables we want to use in the
# project file setup, instead of just having the values.

reversevars="QTDIR COINDIR"

sourcefile=
objectfile=
dependfile=
studiofile=
outputfile=

LIBRARY=
library=
Library=

for arg
do
  if test x"$outputfile" = x"next"; then
    outputfile=$arg
  else
    case $arg in
    -c )
      # -c only means _compile_ some file, not that the source file is
      # the next argument, hence we need to do it differently than for
      # the -o option
      sourcefile=get
      ;;
    -o ) outputfile=next ;;
    -MF | -MD | -MP )
      # haven't investigated if one of these are defined to be last
      # before the dep-file, so i've done it this way.
      dependfile=get
      ;;
    -Wp,-MD,* )
      dependfile=`echo $arg | cut -c9-`
      ;;
    -D*_INTERNAL )
      LIBRARY=`echo $arg | cut -d_ -f1 | cut -c3-`
      library=`echo $LIBRARY | tr A-Z a-z`
      case $library in
      coin ) Library=Coin ;;
      soqt ) Library=SoQt ;;
      sowin ) Library=SoWin ;;
      * ) Library=$library ;;
      esac
      ;;
    -Ddspfile=* | -Wl,-Ddspfile=* )
      # the build system is hacked to pass us the path to the .dsp file
      # this way.
      studiofile=`echo $arg | cut -d= -f2-`
      # FIXME: we don't get the -D*_INTERNAL flag when closing, so we
      # have to set up the variables here too.
      library=`echo "$studiofile" | sed -e 's%.*[\\/]%%g' -e 's%[0-9].*$%%'`
      LIBRARY=`echo $library | tr a-z A-Z`
      case $library in
      coin ) Library=Coin ;;
      soqt ) Library=SoQt ;;
      sowin ) Library=SoWin ;;
      * ) Library=$library ;;
      esac
      ;;
    -* )
      ;;
    * )
      if test x"$sourcefile" = x"get"; then
        sourcefile=$arg
      elif test x"$dependfile" = x"get"; then
        dependfile=$arg
      fi
      ;;
    esac
  fi
done

if test x"$studiofile" = x""; then
  exit 0
fi

if test x"$sourcefile" = x""; then :; else
  if test x"$objectfile" = x""; then
    objectfile=`echo $sourcefile | sed -e 's%^.*[/\\\\]%%g' -e 's%\.\(cpp\|c\)$%.o%'`
  fi
fi

if test x"$objectfile" = x""; then :; else
  date >$objectfile
fi

if test x"$dependfile" = x""; then :; else
  echo "" >$dependfile
fi

if test -f "$studiofile"; then :; else
  # file does not exist yet
  echo "# Microsoft Developer Studio Project File - Name=\"${library}@${LIBRARY}_MAJOR_VERSION@\" - Package Owner=<4>" >>"$studiofile"
  echo "# Microsoft Developer Studio Generated Build File, Format Version 6.00" >>"$studiofile"
  echo "# ** DO NOT EDIT **" >>"$studiofile"
  echo "" >>"$studiofile"
  echo "# TARGTYPE \"Win32 (x86) Dynamic-Link Library\" 0x0102" >>"$studiofile"
  echo "" >>"$studiofile"
  echo "CFG=${library}@${LIBRARY}_MAJOR_VERSION@ - Win32 DLL (Debug)" >>"$studiofile"
  echo "!MESSAGE This is not a valid makefile. To build this project using NMAKE," >>"$studiofile"
  echo "!MESSAGE use the Export Makefile command and run" >>"$studiofile"
  echo "!MESSAGE" >>"$studiofile"
  echo "!MESSAGE NMAKE /f \"${library}@${LIBRARY}_MAJOR_VERSION@.mak\"." >>"$studiofile"
  echo "!MESSAGE" >>"$studiofile"
  echo "!MESSAGE You can specify a configuration when running NMAKE" >>"$studiofile"
  echo "!MESSAGE by defining the macro CFG on the command line. For example:" >>"$studiofile"
  echo "!MESSAGE" >>"$studiofile"
  echo "!MESSAGE NMAKE /f \"${library}@${LIBRARY}_MAJOR_VERSION@.mak\" CFG=\"${library}@${LIBRARY}_MAJOR_VERSION@ - Win32 DLL (Debug)\"" >>"$studiofile"
  echo "!MESSAGE" >>"$studiofile"
  echo "!MESSAGE Possible choices for configuration are:" >>"$studiofile"
  echo "!MESSAGE" >>"$studiofile"
  # last configuration mentioned seems to become default / selected by IDE
  if $enable_static; then
    echo "!MESSAGE \"${library}@${LIBRARY}_MAJOR_VERSION@ - Win32 LIB (Release)\" (based on \"Win32 (x86) Static Library\")" >>"$studiofile"
    echo "!MESSAGE \"${library}@${LIBRARY}_MAJOR_VERSION@ - Win32 LIB (Debug)\" (based on \"Win32 (x86) Static Library\")" >>"$studiofile"
  fi
  echo "!MESSAGE \"${library}@${LIBRARY}_MAJOR_VERSION@ - Win32 DLL (Release)\" (based on \"Win32 (x86) Dynamic-Link Library\")" >>"$studiofile"
  echo "!MESSAGE \"${library}@${LIBRARY}_MAJOR_VERSION@ - Win32 DLL (Debug)\" (based on \"Win32 (x86) Dynamic-Link Library\")" >>"$studiofile"
  echo "!MESSAGE" >>"$studiofile"
  echo "" >>"$studiofile"
  echo "# Begin Project" >>"$studiofile"
  echo "# PROP AllowPerConfigDependencies 0" >>"$studiofile"
  echo "# PROP Scc_ProjName \"\"" >>"$studiofile"
  echo "# PROP Scc_LocalPath \"\"" >>"$studiofile"
  echo "CPP=cl.exe" >>"$studiofile"
  echo "MTL=midl.exe" >>"$studiofile"
  echo "RSC=rc.exe" >>"$studiofile"
  echo "" >>"$studiofile"
  echo "!IF  \"\$(CFG)\" == \"${library}@${LIBRARY}_MAJOR_VERSION@ - Win32 DLL (Release)\"" >>"$studiofile"
  echo "" >>"$studiofile"
  echo "# PROP BASE Use_MFC 0" >>"$studiofile"
  echo "# PROP BASE Use_Debug_Libraries 0" >>"$studiofile"
  echo "# PROP BASE Output_Dir \"Release\"" >>"$studiofile"
  echo "# PROP BASE Intermediate_Dir \"Release\"" >>"$studiofile"
  echo "# PROP BASE Target_Dir \"\"" >>"$studiofile"
  echo "# PROP Use_MFC 0" >>"$studiofile"
  echo "# PROP Use_Debug_Libraries 0" >>"$studiofile"
  echo "# PROP Output_Dir \"Release\"" >>"$studiofile"
  echo "# PROP Intermediate_Dir \"Release\"" >>"$studiofile"
  echo "# PROP Ignore_Export_Lib 0" >>"$studiofile"
  echo "# PROP Target_Dir \"\"" >>"$studiofile"
  echo "# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"${LIBRARY}_DEBUG=0\" @${LIBRARY}_DSP_DEFS@ @${LIBRARY}_DSP_INCS@ /YX /FD /c" >>"$studiofile"
  echo "# ADD CPP /nologo /MD /W3 /GX /O1 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"${LIBRARY}_DEBUG=0\" @${LIBRARY}_DSP_DEFS@ @${LIBRARY}_DSP_INCS@ /YX /FD /c" >>"$studiofile"
  echo "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32" >>"$studiofile"
  echo "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32" >>"$studiofile"
  echo "# ADD BASE RSC /l 0x409 /d \"NDEBUG\"" >>"$studiofile"
  echo "# ADD RSC /l 0x409 /d \"NDEBUG\"" >>"$studiofile"
  echo "BSC32=bscmake.exe" >>"$studiofile"
  echo "# ADD BASE BSC32 /nologo" >>"$studiofile"
  echo "# ADD BSC32 /nologo" >>"$studiofile"
  echo "LINK32=link.exe" >>"$studiofile"
  echo "# ADD BASE LINK32 @${LIBRARY}_DSP_LIBS@ /nologo /dll /machine:I386" >>"$studiofile"
  echo "# ADD LINK32 @${LIBRARY}_DSP_LIBS@ /nologo /dll /machine:I386 /out:\"${library}@${LIBRARY}_MAJOR_VERSION@.dll\" /opt:nowin98" >>"$studiofile"
  echo "# SUBTRACT LINK32 /pdb:none" >>"$studiofile"
  echo "# Begin Special Build Tool" >>"$studiofile"
  echo "SOURCE=\"\$(InputPath)\"" >>"$studiofile"
  echo "PostBuild_Cmds=install-dll-release.bat" >>"$studiofile"
  echo "# End Special Build Tool" >>"$studiofile"
  echo "" >>"$studiofile"

  echo "!ELSEIF  \"\$(CFG)\" == \"${library}@${LIBRARY}_MAJOR_VERSION@ - Win32 DLL (Debug)\"" >>"$studiofile"
  echo "" >>"$studiofile"
  echo "# PROP BASE Use_MFC 0" >>"$studiofile"
  echo "# PROP BASE Use_Debug_Libraries 1" >>"$studiofile"
  echo "# PROP BASE Output_Dir \"Debug\"" >>"$studiofile"
  echo "# PROP BASE Intermediate_Dir \"Debug\"" >>"$studiofile"
  echo "# PROP BASE Target_Dir \"\"" >>"$studiofile"
  echo "# PROP Use_MFC 0" >>"$studiofile"
  echo "# PROP Use_Debug_Libraries 1" >>"$studiofile"
  echo "# PROP Output_Dir \"Debug\"" >>"$studiofile"
  echo "# PROP Intermediate_Dir \"Debug\"" >>"$studiofile"
  echo "# PROP Target_Dir \"\"" >>"$studiofile"
  echo "# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"${LIBRARY}_DEBUG=1\" @${LIBRARY}_DSP_DEFS@ @${LIBRARY}_DSP_INCS@ /YX /FD /GZ /c" >>"$studiofile"
  echo "# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"${LIBRARY}_DEBUG=1\" @${LIBRARY}_DSP_DEFS@ @${LIBRARY}_DSP_INCS@ /YX /FD /GZ /c" >>"$studiofile"
  echo "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32" >>"$studiofile"
  echo "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32" >>"$studiofile"
  echo "# ADD BASE RSC /l 0x409 /d \"_DEBUG\"" >>"$studiofile"
  echo "# ADD RSC /l 0x409 /d \"_DEBUG\"" >>"$studiofile"
  echo "BSC32=bscmake.exe" >>"$studiofile"
  echo "# ADD BASE BSC32 /nologo" >>"$studiofile"
  echo "# ADD BSC32 /nologo" >>"$studiofile"
  echo "LINK32=link.exe" >>"$studiofile"
  echo "# ADD BASE LINK32 @${LIBRARY}_DSP_LIBS@ /nologo /dll /debug /machine:I386 /pdbtype:sept" >>"$studiofile"
  echo "# ADD LINK32 @${LIBRARY}_DSP_LIBS@ /nologo /dll /debug /machine:I386 /pdbtype:sept /out:\"${library}@${LIBRARY}_MAJOR_VERSION@d.dll\"" >>"$studiofile"
  echo "# Begin Special Build Tool" >>"$studiofile"
  echo "SOURCE=\"\$(InputPath)\"" >>"$studiofile"
  echo "PostBuild_Cmds=install-dll-debug.bat" >>"$studiofile"
  echo "# End Special Build Tool" >>"$studiofile"
  echo "" >>"$studiofile"

  if $enable_static; then
    echo "!ELSEIF  \"\$(CFG)\" == \"${library}@${LIBRARY}_MAJOR_VERSION@ - Win32 LIB (Release)\"" >>"$studiofile"
    echo "" >>"$studiofile"
    echo "# PROP BASE Use_MFC 0" >>"$studiofile"
    echo "# PROP BASE Use_Debug_Libraries 0" >>"$studiofile"
    echo "# PROP BASE Output_Dir \"StaticRelease\"" >>"$studiofile"
    echo "# PROP BASE Intermediate_Dir \"StaticRelease\"" >>"$studiofile"
    echo "# PROP BASE Target_Dir \"\"" >>"$studiofile"
    echo "# PROP Use_MFC 0" >>"$studiofile"
    echo "# PROP Use_Debug_Libraries 0" >>"$studiofile"
    echo "# PROP Output_Dir \"StaticRelease\"" >>"$studiofile"
    echo "# PROP Intermediate_Dir \"StaticRelease\"" >>"$studiofile"
    echo "# PROP Target_Dir \"\"" >>"$studiofile"
    echo "# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_LIB\" /D \"${LIBRARY}_DEBUG=0\" @${LIBRARY}_LIB_DSP_DEFS@ @${LIBRARY}_DSP_INCS@ /YX /FD /c" >>"$studiofile"
    echo "# ADD CPP /nologo /MD /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_LIB\" /D \"${LIBRARY}_DEBUG=0\" @${LIBRARY}_LIB_DSP_DEFS@ @${LIBRARY}_DSP_INCS@ /YX /FD /c" >>"$studiofile"
    echo "# ADD BASE RSC /l 0x414 /d \"NDEBUG\"" >>"$studiofile"
    echo "# ADD RSC /l 0x414 /d \"NDEBUG\"" >>"$studiofile"
    echo "BSC32=bscmake.exe" >>"$studiofile"
    echo "# ADD BASE BSC32 /nologo" >>"$studiofile"
    echo "# ADD BSC32 /nologo" >>"$studiofile"
    echo "LIB32=link.exe -lib" >>"$studiofile"
    echo "# ADD BASE LIB32 /nologo /machine:I386 /out:\"${library}@${LIBRARY}_MAJOR_VERSION@s.lib\"" >>"$studiofile"
    echo "# ADD LIB32 /nologo /machine:I386 /out:\"${library}@${LIBRARY}_MAJOR_VERSION@s.lib\"" >>"$studiofile"
    echo "# Begin Special Build Tool" >>"$studiofile"
    echo "SOURCE=\"\$(InputPath)\"" >>"$studiofile"
    echo "PostBuild_Cmds=install-lib-release.bat" >>"$studiofile"
    echo "# End Special Build Tool" >>"$studiofile"
    echo "" >>"$studiofile"
  
    echo "!ELSEIF  \"\$(CFG)\" == \"${library}@${LIBRARY}_MAJOR_VERSION@ - Win32 LIB (Debug)\"" >>"$studiofile"
    echo "" >>"$studiofile"
    echo "# PROP BASE Use_MFC 0" >>"$studiofile"
    echo "# PROP BASE Use_Debug_Libraries 1" >>"$studiofile"
    echo "# PROP BASE Output_Dir \"StaticDebug\"" >>"$studiofile"
    echo "# PROP BASE Intermediate_Dir \"StaticDebug\"" >>"$studiofile"
    echo "# PROP BASE Target_Dir \"\"" >>"$studiofile"
    echo "# PROP Use_MFC 0" >>"$studiofile"
    echo "# PROP Use_Debug_Libraries 1" >>"$studiofile"
    echo "# PROP Output_Dir \"StaticDebug\"" >>"$studiofile"
    echo "# PROP Intermediate_Dir \"StaticDebug\"" >>"$studiofile"
    echo "# PROP Target_Dir \"\"" >>"$studiofile"
    echo "# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_LIB\" /D \"${LIBRARY}_DEBUG=1\" @${LIBRARY}_LIB_DSP_DEFS@ @${LIBRARY}_DSP_INCS@ /YX /FD /c" >>"$studiofile"
    echo "# ADD CPP /nologo /MD /W3 /GX /O2 /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_LIB\" /D \"${LIBRARY}_DEBUG=1\" @${LIBRARY}_LIB_DSP_DEFS@ @${LIBRARY}_DSP_INCS@ /YX /FD /c" >>"$studiofile"
    echo "# ADD BASE RSC /l 0x414 /d \"_DEBUG\"" >>"$studiofile"
    echo "# ADD RSC /l 0x414 /d \"_DEBUG\"" >>"$studiofile"
    echo "BSC32=bscmake.exe" >>"$studiofile"
    echo "# ADD BASE BSC32 /nologo" >>"$studiofile"
    echo "# ADD BSC32 /nologo" >>"$studiofile"
    echo "LIB32=link.exe -lib" >>"$studiofile"
    echo "# ADD BASE LIB32 /nologo /machine:I386 /out:\"${library}@${LIBRARY}_MAJOR_VERSION@sd.lib\"" >>"$studiofile"
    echo "# ADD LIB32 /nologo /machine:I386 /out:\"${library}@${LIBRARY}_MAJOR_VERSION@sd.lib\"" >>"$studiofile"
    echo "# Begin Special Build Tool" >>"$studiofile"
    echo "SOURCE=\"\$(InputPath)\"" >>"$studiofile"
    echo "PostBuild_Cmds=install-lib-debug.bat" >>"$studiofile"
    echo "# End Special Build Tool" >>"$studiofile"
    echo ""
  fi

  echo "!ENDIF" >>"$studiofile"


  echo "" >>"$studiofile"
  echo "# Begin Target" >>"$studiofile"
  echo "" >>"$studiofile"
  echo "# Name \"${library}@${LIBRARY}_MAJOR_VERSION@ - Win32 DLL (Release)\"" >>"$studiofile"
  echo "# Name \"${library}@${LIBRARY}_MAJOR_VERSION@ - Win32 DLL (Debug)\"" >>"$studiofile"
  if $enable_static; then
    echo "# Name \"${library}@${LIBRARY}_MAJOR_VERSION@ - Win32 LIB (Release)\"" >>"$studiofile"
    echo "# Name \"${library}@${LIBRARY}_MAJOR_VERSION@ - Win32 LIB (Debug)\"" >>"$studiofile"
  fi
  echo "# Begin Group \"Source Files\"" >>"$studiofile"
  echo "" >>"$studiofile"
  echo "# PROP Default_Filter \"cpp;c;ic;icc\"" >>"$studiofile"
fi

if test `grep -c "# End Project" "$studiofile"` -gt 0; then
  me=`echo $me | sed 's%^.*/%%g'`
  echo >&2 "$me: error: project file is closed - you must start from scratch (make clean)"
  exit 1
fi

if test x"$sourcefile" = x""; then :; else
  # set up section for the source file
  case $sourcefile in
  [a-zA-Z]:* | /* ) ;;
  * )
    # this is a relative path
    sourcefile="`pwd`/$sourcefile"
    ;;
  esac
  echo "# Begin Source File" >>"$studiofile"
  echo "" >>"$studiofile"
  sourcefile=`CYGWIN= cygpath -w "$sourcefile" 2>/dev/null || echo "$sourcefile"`
  echo "SOURCE=$sourcefile" >>"$studiofile"
  sourcefileunixname=`CYGWIN= cygpath -u "$sourcefile"`
  sourcefiledir=`dirname "$sourcefileunixname"`
  sourcefiledirdir=`dirname "$sourcefiledir"`
  targetdir=`echo $sourcefiledir | sed "s%^$sourcefiledirdir%%" | sed s%/%%g`
  echo '!IF  "$(CFG)" == "'${library}@${LIBRARY}_MAJOR_VERSION@' - Win32 DLL (Release)"' >>"$studiofile"
  echo "# PROP Intermediate_Dir \"Release\\$targetdir\"" >>"$studiofile"
  echo '!ELSEIF  "$(CFG)" == "'${library}@${LIBRARY}_MAJOR_VERSION@' - Win32 DLL (Debug)"' >>"$studiofile"
  echo "# PROP Intermediate_Dir \"Debug\\$targetdir\"" >>"$studiofile"
  if $enable_static; then
    echo '!ELSEIF  "$(CFG)" == "'${library}@${LIBRARY}_MAJOR_VERSION@' - Win32 LIB (Release)"' >>"$studiofile"
    echo "# PROP Intermediate_Dir \"StaticRelease\\$targetdir\"" >>"$studiofile"
    echo '!ELSEIF  "$(CFG)" == "'${library}@${LIBRARY}_MAJOR_VERSION@' - Win32 LIB (Debug)"' >>"$studiofile"
    echo "# PROP Intermediate_Dir \"StaticDebug\\$targetdir\"" >>"$studiofile"
  fi
  echo '!ENDIF ' >>"$studiofile"
  echo "# End Source File" >>"$studiofile"

  if egrep "moc_.*.icc" "$sourcefileunixname" >/dev/null 2>&1; then
    # The sourcefile needs MOC to be executed before building.
    # The assumptions here are that the header is in the same directory in the
    # hierarchy, and that the moc file contains the magic text telling the
    # header file name.  It is also assumed that the moc file is not built
    # on its own but included in the source file, and named moc_*.icc.
    mocfile=`egrep "moc_.*.icc" "$sourcefileunixname" | sed -e 's,.*<\(.*icc\)>.*,\1,'`
    mocfile=`echo $mocfile | sed -e 's,.*/,,'`
    headerfile=`egrep "from reading C" $mocfile | sed -e "s,.*'\(.*\)'\$,\1,"`
    mocfile="`pwd`/$mocfile"
    mocfile=`echo $mocfile | sed -e "s%$build_dir/%%"`
    mocfile=`echo $mocfile | sed -e "$sed_u2d"`
    headerfilepath="`pwd`/$headerfile"
    headerfilepath=`echo $headerfilepath | sed -e "s%$build_dir/%%"`
    if test -f "$headerfile"; then
      headerfile="$headerfilepath"
    else
      headerfile="$sim_ac_relative_src_dir/$headerfilepath"
    fi
    headerfile=`echo $headerfile | sed -e "$sed_u2d"`

    echo "# Begin Source File" >>"$studiofile"
    echo "" >>"$studiofile"
    echo "SOURCE=$headerfile" >>"$studiofile"
    echo "" >>"$studiofile"

    echo '!IF  "$(CFG)" == "'${library}@${LIBRARY}_MAJOR_VERSION@' - Win32 DLL (Release)"' >>"$studiofile"
    echo "" >>"$studiofile"
    echo "# PROP IgnoreDefaultTool 1" >>"$studiofile"
    echo "#Begin Custom Build - moc'ing \$(InputPath)" >>"$studiofile"
    echo "InputPath=$headerfile" >>"$studiofile"
    echo "" >>"$studiofile"
    echo "\"$mocfile\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"" >>"$studiofile"
    echo "	\$(QTDIR)\bin\moc -o $mocfile $headerfile" >>"$studiofile"
    echo "" >>"$studiofile"
    echo "# End Custom Build" >>"$studiofile"
    echo "" >>"$studiofile"

    echo '!ELSEIF  "$(CFG)" == "'${library}@${LIBRARY}_MAJOR_VERSION@' - Win32 DLL (Debug)"' >>"$studiofile"
    echo "" >>"$studiofile"
    echo "# PROP IgnoreDefaultTool 1" >>"$studiofile"
    echo "#Begin Custom Build - moc'ing \$(InputPath)" >>"$studiofile"
    echo "InputPath=$headerfile" >>"$studiofile"
    echo "" >>"$studiofile"
    echo "\"$mocfile\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"" >>"$studiofile"
    echo "	\$(QTDIR)\bin\moc -o $mocfile $headerfile" >>"$studiofile"
    echo "" >>"$studiofile"
    echo "# End Custom Build" >>"$studiofile"
    echo "" >>"$studiofile"

    if $enable_static; then
      echo '!ELSEIF  "$(CFG)" == "'${library}@${LIBRARY}_MAJOR_VERSION@' - Win32 LIB (Release)"' >>"$studiofile"
      echo "" >>"$studiofile"
      echo "# PROP IgnoreDefaultTool 1" >>"$studiofile"
      echo "#Begin Custom Build - moc'ing \$(InputPath)" >>"$studiofile"
      echo "InputPath=$headerfile" >>"$studiofile"
      echo "" >>"$studiofile"
      echo "\"$mocfile\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"" >>"$studiofile"
      echo "	\$(QTDIR)\bin\moc -o $mocfile $headerfile" >>"$studiofile"
      echo "" >>"$studiofile"
      echo "# End Custom Build" >>"$studiofile"
      echo "" >>"$studiofile"
  
      echo '!ELSEIF  "$(CFG)" == "'${library}@${LIBRARY}_MAJOR_VERSION@' - Win32 LIB (Debug)"' >>"$studiofile"
      echo "" >>"$studiofile"
      echo "# PROP IgnoreDefaultTool 1" >>"$studiofile"
      echo "#Begin Custom Build - moc'ing \$(InputPath)" >>"$studiofile"
      echo "InputPath=$headerfile" >>"$studiofile"
      echo "" >>"$studiofile"
      echo "\"$mocfile\" : \$(SOURCE) \"\$(INTDIR)\" \"\$(OUTDIR)\"" >>"$studiofile"
      echo "	\$(QTDIR)\bin\moc -o $mocfile $headerfile" >>"$studiofile"
      echo "" >>"$studiofile"
      echo "# End Custom Build" >>"$studiofile"
      echo "" >>"$studiofile"
    fi

    echo "!ENDIF " >>"$studiofile"
    echo "" >>"$studiofile"
    echo "# End Source File" >>"$studiofile"
  fi
fi

case "$outputfile" in
*.so.* )
  # this is how we detect the last command in the build process
  date >>"$outputfile"
  # "close" the dsp file
  echo '# End Group' >>"$studiofile"

  # We need to know about the root build dir and source dir to trigger the
  # header installation rule, and to locate the additional source files we
  # should put in the .dsp file
  builddir=`echo "$studiofile" | sed -e 's%/[^/]*$%%'`
  builddir_unix=$builddir
  builddir=`CYGWIN= cygpath -w "$builddir" 2>/dev/null || echo "$builddir"`

  sourcedir=`echo "$0" | sed -e 's%/cfg/gendsp.sh$%%' -e 's,\\cfg\\gendsp.sh,,'`
  sourcedir_unix=$sourcedir
  sourcedir=`CYGWIN= cygpath -w "$sourcedir" 2>/dev/null || echo "$sourcedir"`

  # PUBLIC HEADERS
  # To get the list of public header files, we run "make install" into a
  # temporary directory, while overriding the header-install program to be
  # this script with a magic option as the first argument.  Afterwards we
  # clean out the temporary install dir.
  echo '# Begin Group "Public Headers"' >>"$studiofile"
  echo "" >>"$studiofile"
  echo '# PROP Default_Filter "h"' >>"$studiofile"
  tmpdir=/tmp/dsp-install.tmp
  ( cd $builddir_unix;
    make INSTALL_HEADER="$0 --register-public-header $studiofile" DESTDIR="$tmpdir" install-data )
  rm -rf $tmpdir
  echo '# End Group' >>"$studiofile"

  # PRIVATE HEADERS
  # I don't know how to properly construct a list of private headers yet,
  # but we can for sure assume that all .ic/.icc source files are includes
  # used from other source files.  We also assume that header files that
  # check for <lib>_INTERNAL and emits a #error with a message containing
  # "private" or "internal" is an internal header file.
  echo '# Begin Group "Private Headers"' >>"$studiofile"
  echo "" >>"$studiofile"
  echo '# PROP Default_Filter "h;ic;icc"' >>"$studiofile"
  for file in `find $sourcedir_unix $builddir_unix -name "*.h" | xargs grep -l "_INTERNAL\$" | xargs grep -i -l "#error.*private"`; do
    echo "# Begin Source File" >>"$studiofile"
    echo "" >>"$studiofile"
    filepath=`CYGWIN= cygpath -w "$file" 2>/dev/null || echo "$file"`
    echo "SOURCE=$filepath" >>"$studiofile"
    echo "# PROP Exclude_From_Build 1" >>"$studiofile"
    echo "# End Source File" >>"$studiofile"
  done
  for file in `find $sourcedir_unix $builddir_unix -name "*.ic" -o -name "*.icc"`; do
    echo "# Begin Source File" >>"$studiofile"
    echo "" >>"$studiofile"
    filepath=`CYGWIN= cygpath -w "$file" 2>/dev/null || echo "$file"`
    echo "SOURCE=$filepath" >>"$studiofile"
    echo "# PROP Exclude_From_Build 1" >>"$studiofile"
    echo "# End Source File" >>"$studiofile"
  done
  echo '# End Group' >>"$studiofile"
  # close the .dsp file
  echo '# End Target' >>"$studiofile"
  echo '# End Project' >>"$studiofile"

  # create the .dsw file
  workspacefile=`echo "$studiofile" | sed 's/\.dsp/.dsw/'`
  echo "Microsoft Developer Studio Workspace File, Format Version 6.00" >>"$workspacefile.in"
  echo "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!" >>"$workspacefile.in"
  echo "" >>"$workspacefile.in"
  echo "###############################################################################" >>"$workspacefile.in"
  echo "" >>"$workspacefile.in"
  echo "Project: \"${library}@${LIBRARY}_MAJOR_VERSION@\"=.\\${library}@${LIBRARY}_MAJOR_VERSION@.dsp - Package Owner=<4>" >>"$workspacefile.in"
  echo "" >>"$workspacefile.in"
  echo "Package=<5>" >>"$workspacefile.in"
  echo "{{{" >>"$workspacefile.in"
  echo "}}}" >>"$workspacefile.in"
  echo "" >>"$workspacefile.in"
  echo "Package=<4>" >>"$workspacefile.in"
  echo "{{{" >>"$workspacefile.in"
  echo "}}}" >>"$workspacefile.in"
  echo "" >>"$workspacefile.in"
  echo "###############################################################################" >>"$workspacefile.in"
  echo "" >>"$workspacefile.in"
  echo "Global:" >>"$workspacefile.in"
  echo "" >>"$workspacefile.in"
  echo "Package=<5>" >>"$workspacefile.in"
  echo "{{{" >>"$workspacefile.in"
  echo "}}}" >>"$workspacefile.in"
  echo "" >>"$workspacefile.in"
  echo "Package=<3>" >>"$workspacefile.in"
  echo "{{{" >>"$workspacefile.in"
  echo "}}}" >>"$workspacefile.in"
  echo "" >>"$workspacefile.in"
  echo "###############################################################################" >>"$workspacefile.in"
  echo "" >>"$workspacefile.in"

  # Make everything peachy for MS DOS

  mv "$studiofile" "$studiofile.in2"
  ( cd "$builddir_unix"; ./config.status --file="-:-" <"$workspacefile.in" >"$workspacefile.txt" )
  ( cd "$builddir_unix"; ./config.status --file="-:-" <"$studiofile.in2" >"$studiofile.in" )

  # If we are making the Win32 precompiled SDK installer, we need to make
  # the .dsp-file contain relative paths that works from where the sources and
  # build files are going to be installed...
  # The first two rules are for individual source files, the next two are for
  # the include directive settings.

  sed -e "s%^SOURCE=.:.*\\(${Library}-[0-9]\\.[^/\\\\]*\\)%SOURCE=..\\\\source\\\\\\1%" \
      -e 's%^SOURCE=.:.*build-files%SOURCE=.%' \
      -e "s%.:[^ ]*\\(${Library}-[0-9]\\.[^/\\\\\"]*\\)%..\\\\source\\\\\\1%" \
      -e 's%.:[^ ]*build-files\([^"]*\)%.\1%g' \
      <"$studiofile.in" >"$studiofile.txt2"

  sourcedirregexp=`echo "$sourcedir" | sed -e 's%\\\\%\\\\\\\\%g'`
  builddirregexp=`echo "$builddir" | sed -e 's%\\\\%\\\\\\\\%g'`

  # Transform paths to be relative paths for non-installer-builds too.
  # This should probably be configurable in some way though.
  if test x"$sourcedir" = x"$builddir"; then
    relsourcedir="."
  else
    num=1
    while true; do
      presource=`echo $sourcedir | cut -d'\' -f1-$num`
      prebuild=`echo $builddir | cut -d'\' -f1-$num`
      if test x"$presource" = x"$prebuild"; then :; else
        break
      fi
      num=`expr $num + 1`
    done
    num=`expr $num - 1`
    if test $num -eq 0; then
      # relative path impossible
      relsourcedir=$sourcedirregexp
    else
      numplus=`expr $num + 1`
      # prefix=`echo $sourcedir | cut -d'\' -f1-$num`
      upfix=`echo "$builddir\\\\" | cut -d'\' -f$numplus- | sed -e 's%[^\\\\]*\\\\%..\\\\%g' -e 's%\\\\%\\\\\\\\%g'`
      postfix=`echo $sourcedir | cut -d'\' -f$numplus- | sed -e 's%\\\\%\\\\\\\\%g'`
      relsourcedir="$upfix$postfix"
    fi
  fi
  sed -e "s%$sourcedirregexp%$relsourcedir%g" \
      -e "s%$builddirregexp\\\\%.\\\\%g" \
      -e "s%$builddirregexp%.\\\\%g" \
    <"$studiofile.txt2" >"$studiofile.txt"

  # here we try to reverse some environment variable values back to their
  # variable references, to make the project less system-dependent.
  for var in $reversevars; do
    eval varval="\$$var"
    varval=`CYGWIN= cygpath -w "$varval" 2>/dev/null || echo "$varval"`
    varval="`echo $varval | sed -e 's%\\\\%\\\\\\\\%g'`"
    if test x"$varval" = x""; then :; else
      mv "$studiofile.txt" "$studiofile.txt2"
      sed -e "s%$varval%\\\$($var)%g" <"$studiofile.txt2" >"$studiofile.txt"
    fi
    if test -f "$studiofile.txt"; then :; else
      echo "error doing substitutions"
      echo "cmd: s%$varval%\\\$($var)%g"
      exit 1
    fi
  done

  # we want to link debug versions of this project with debug versions of the
  # libs they depend on.  we only do this for our own known libraries though.
  debuglibs="coin[0-9] soqt[0-9] sowin[0-9]"
  for lib in $debuglibs; do
    mv "$studiofile.txt" "$studiofile.txt2"
    sed -e '/\/debug/ s%\<\('$lib'\)\.lib\>%\1d.lib%g' <"$studiofile.txt2" >"$studiofile.txt"
    if test -f "$studiofile.txt"; then :; else
      echo "error doing substitutions"
      echo "cmd: s%$varval%\\\$($var)%g"
      exit 1
    fi
  done

  # do unix2dos conversion (\n -> \r\n) on the DevStudio files
  echo -e "s/\$/\r/;\np;" >unix2dos.sed
  sed -n -f unix2dos.sed "$studiofile.txt" >"$studiofile"
  sed -n -f unix2dos.sed "$workspacefile.txt" >"$workspacefile"
  # clean out temporary files
  rm -f "$studiofile.txt2" "$studiofile.txt" "$studiofile.in2" "$studiofile.in" "$workspacefile.txt" "$workspacefile.in" unix2dos.sed
  ;;
esac