3
# $Id: one2all.sh,v 1.40 2003/10/23 16:02:07 ucko Exp $
4
# ===========================================================================
7
# National Center for Biotechnology Information
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.
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
24
# Please cite the author in any work or product based on this material.
26
# ===========================================================================
28
# Author: Anton Lavrentiev
30
# MSVC project file converter. Expand a signle configuration project file
31
# to multi-configuration project file.
33
# ===========================================================================
36
cat $1 | while read p; do
37
test -z "$p" && continue
44
# Argument checking first.
46
if [ _$1 = _--without-dizzy ]; then
52
if [ _$1 = _ -o \! -f $1 ]; then
53
echo "ERROR: File \"$1\" inexistent. Stop."
56
if [ _$2 != _Debug -a _$2 != _Release ]; then
57
echo "ERROR: Unknown release parameter \"$2\". Stop."
63
elif [ $3 = MT ]; then
65
elif [ $3 = DLL ]; then
68
echo "ERROR: Unknown configuration \"$3\". Stop."
73
# Our config is ${DEBUG}${SFX}. Compiler switch is ${CFG}.
75
if [ $DEBUG = Debug ]; then
79
# Init the sed script, which will make conversion.
81
cat /dev/null >/tmp/$$_cmd.sed
83
# First replace config name wherever appropriate.
85
for p in Release Debug ; do
87
cat <<-EOF >>/tmp/$$_cmd.sed
88
/^# PROP / !s|$p$q|$p|g
89
/^# PROP .*"[^ ]*$p$q[^ ]*"/ s|$p$q|$p|g
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
100
# Replace debugging macro.
102
if [ $DEBUG = Debug ]; then
103
echo 's|NDEBUG|_DEBUG|g' >>/tmp/$$_cmd.sed
105
echo 's|_DEBUG|NDEBUG|g' >>/tmp/$$_cmd.sed
108
# Does the project use wxWindows (or is a part of wxWindows)?
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
115
# Flag proper macros for DLL mode.
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"'
121
WXDLL='/D "WXUSINGDLL=1"'
127
# Is this an FLTK-dependent project?
129
elif [ `grep -c '^# ADD .*LINK32 .*fltk[a-z]*[.]lib' $1` != 0 ]; then
135
# Either replace with hooks, or just remove the compiler switches,
136
# which may be configuration-dependent or inconsistent.
138
cat <<-EOF >>/tmp/$$_cmd.sed
140
s| */O[0-9A-Za-z]*| @O|
141
s| */O[0-9A-Za-z]*||g
154
s| */D *"\{0,1\}DEBUG=*[0-9]*"\{0,1\}| @D|g
157
# Remove some wxWindows macros, which are surely configuration-dependent.
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
167
# Clear the linker debug option.
169
cat <<-EOF >>/tmp/$$_cmd.sed
171
/^# ADD .*LINK32 / s| */debug||g
174
# When requested, remove include/library paths, which refer to DIZZY.
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
184
# Configuration-dependent changes: replace hooks and
185
# add more compiler options where appropriate.
187
if [ $DEBUG = Debug ]; then
188
cat <<-EOF >>/tmp/$$_cmd.sed
189
/^# PROP / s| *Use_Debug_Libraries *0| Use_Debug_Libraries 1|
192
s|/mach|/pdb:none /debug &|
204
cat <<-EOF >>/tmp/$$_cmd.sed
205
/^# PROP / s| *Use_Debug_Libraries *1| Use_Debug_Libraries 0|
206
/^# ADD .*LINK32 / s| */pdbtype[^ ]*||g
215
# Now replace the code generation switch.
217
for p in "/MD" "/ML" "/MT" ; do
218
cat <<-EOF >>/tmp/$$_cmd.sed
224
# Finish with code generation switch, and then make sure
225
# that incremental linking is on except for wxWindows DLLs (slow).
227
cat <<-EOF >>/tmp/$$_cmd.sed
238
/^# ADD .*LINK32 / s| */incremental[:yesno]*||g
240
if [ `grep -c '^# ADD .*LINK32 .*/dll' $1` = 0 ]; then
242
elif [ -n "$GUI" -a `echo "$WXDLL" | grep -c '^# ADD .*CPP .*WXMAKINGDLL'` != 0 ]; then
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
252
# wxWindows-specific changes from now on.
254
if [ "$GUI" = "wxwin" ]; then
255
# Define __WXDEBUG__ for debug configs.
257
if [ $DEBUG = Debug ]; then
258
WXDEBUG='/D "__WXDEBUG__=1"'
263
# ${WX} is to be added to compiler options.
265
WX=`echo $WXDEBUG $WXDLL`
267
if [ -n "$WX" ]; then
268
cat <<-EOF >>/tmp/$$_cmd.sed
284
# Enforce /subsystem:windows.
286
cat <<-EOF >>/tmp/$$_cmd.sed
287
/^# ADD .*LINK32 / s|/subsystem:[A-Za-z]*|@s|g
291
s|@s|/subsystem:windows|
293
s|/nologo|& /subsystem:windows|
295
s|\$| /subsystem:windows|
298
/^# ADD .*LINK32 / s| *@s||g
301
# Take care of libraries: remove all wxWindows ones
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
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.
317
#if [ _$SFX != _DLL ]; then
318
cat <<-EOF >>/tmp/$$_cmd.sed
319
s/@wx/jpeg.lib png.lib tiff.lib zlib.lib wx.lib/
322
# cat <<-EOF >>/tmp/$$_cmd.sed
326
cat <<-EOF >>/tmp/$$_cmd.sed
332
# FLTK specific changes from now on
334
if [ "$GUI" = "fltk" ]; then
335
# Enforce /subsystem:windows.
337
cat <<-EOF >>/tmp/$$_cmd.sed
338
/^# ADD .*LINK32 / s|/subsystem:[A-Za-z]*|@s|g
342
s|@s|/subsystem:windows|
344
s|/nologo|& /subsystem:windows|
346
s|\$| /subsystem:windows|
349
/^# ADD .*LINK32 / s| *@s||g
352
# Take care of libraries: remove all FLTK ones
354
cat <<-EOF >>/tmp/$$_cmd.sed
355
/^# ADD .*LINK32 * fltk[a-z]*[.]lib/ {
356
s/ *fltk[a-z]*[.]lib/ @fltk/g
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.
362
#if [ _$SFX != _DLL ]; then
363
# cat <<-EOF >>/tmp/$$_cmd.sed
364
# s/@fltk/fltkforms.lib fltkimages.lib fltkgl.lib fltk.lib/
367
cat <<-EOF >>/tmp/$$_cmd.sed
371
cat <<-EOF >>/tmp/$$_cmd.sed
377
# Print name of configuration, which was created, and run the script.
379
echo "${DEBUG}${SFX}" ${GUI:+"("$GUI")"}
381
sed -f /tmp/$$_cmd.sed $1 >/tmp/$$_new
383
rm -f /tmp/$$_cmd.sed /tmp/$$_new
390
cat /dev/null >/tmp/$$_cmd.sed
392
# First replace config name wherever appropriate.
394
for p in Release Debug ; do
396
cat <<-EOF >>/tmp/$$_cmd.sed
400
if [ $p != $2$3 ]; then
401
cat <<-EOF >>/tmp/$$_cmd.sed
406
sed -f /tmp/$$_cmd.sed $1
407
rm -f /tmp/$$_cmd.sed
411
echo 'Automatic multi config for Microsoft Visual C++ Project File V 6.0'
413
echo `basename $0` '[--without-dizzy] filename'
417
if [ _$1 = _--without-dizzy ]; then
426
elif [ \! -f $1 ]; then
427
echo "ERROR: File \"$1\" must exist. Stop."
431
if [ _$2 != _ ]; then
432
if [ $2 != 4 -a $2 != 3 -a $2 != 2 ]; then
433
echo "ERROR: Unknown special parameter \"$2\". Stop."
438
elif [ $2 = 3 ]; then
448
# DOS-2-UNIX conversion (shouldn't be here, but just in case for sanity).
454
cat <<-"EOF" >/tmp/$$_genusign
455
# Microsoft Developer Studio Project File
456
# Microsoft Developer Studio Generated Build File, Format Version 6.00
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
467
rm -f /tmp/$$_filesign /tmp/$$_genusign
468
if [ $exit != 0 ]; then
469
echo "ERROR: $1 doesn't look like MSVC++ Project File. Stop."
474
# Extract configuration part of the project file and count configurations.
476
cat <<-EOF >/tmp/$$_.sed
483
NCFG=`sed -n -f /tmp/$$_.sed $file | egrep -c '^[!ELS]+IF '`
485
if [ $NCFG -gt 1 ]; then
486
echo "ERROR: $1 contains more than one configuration ($NCFG). Stop."
491
# Check for per-config dependencies, and warn if any.
493
DEP=`grep -c '^# PROP *AllowPerConfigDependencies *1' $file`
494
cat <<-EOF >/tmp/$$_prop.sed
495
/^# Begin Target/,\$ p
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.'
503
rm -f /tmp/$$_prop.sed
505
# Extract beginning of the file.
507
cat <<-EOF >/tmp/$$_head.sed
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
521
# Extract the middle part.
523
cat <<-EOF >/tmp/$$_mid.sed
524
/^# Begin Project/,/^!IF / {
525
/^# PROP *AllowPerConfigDependencies / s/ *1/ 0/
536
sed -n -f /tmp/$$_mid.sed $file >/tmp/$$_mid
537
rm -f /tmp/$$_mid.sed
539
# Now extract configuration-dependent part, and make required configs.
541
cat <<-EOF >/tmp/$$_cut.sed
543
s/^!ELSEIF .*\$/!ENDIF /
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/ {
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
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
576
cp /tmp/$$_cfgtmpl /tmp/$$_cfg_$i$j
577
config $without_dizzy /tmp/$$_cfg_$i$j $i $j >>/tmp/$$_message
579
tail -1 /tmp/$$_message
583
grep '^!IF ' /tmp/$$_cfg_$i$j >>/tmp/$$_title
584
cat /tmp/$$_cfg_$i$j >>/tmp/$$_cfg
585
rm -f /tmp/$$_cfg_$i$j
588
echo "${1}:" `cat /tmp/$$_message`
589
rm -f /tmp/$$_cfgtmpl /tmp/$$_message
591
# Summarize configurations in the header and tail parts of the project.
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
601
sed -e 's/ .*$/ /' /tmp/$$_cmp >>/tmp/$$_msg
605
# Extract the tail part and modify name list on-the-fly.
607
cat <<-EOF >/tmp/$$_tail.sed
608
/^# Begin Target/,/^# End Project/ {
618
sed -n -f /tmp/$$_tail.sed $file >/tmp/$$_tail
619
rm -f /tmp/$$_tail.sed /tmp/$$_name $file
621
# Glue all parts but the tail.
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
627
# Replace ENDIF..IF with ELSEIF.
629
cat <<-EOF >/tmp/$$_elseif.sed
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
643
grep '^SOURCE=' $1 | sed 's/^SOURCE=//;s/[\\]/\\\\/g;s/[.]/[.]/g' >/tmp/$$_flist
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=/ {
650
/^[#] End Source File/ !H
655
/^[#] End Custom Build/ {
663
sed -f /tmp/$$_cbext.sed $1 >$file
665
rm -f /tmp/$$_cbext.sed
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
676
echo '!ENDIF ' >>$file.1
679
cat /dev/null >$file.new
680
for i in Release Debug ; do
681
for j in $CFGSET ; do
682
if [ $j = '""' ]; then
685
configcb $file $i $j >>$file.new
690
# Replace ENDIF..IF with ELSEIF.
692
cat <<-EOF >/tmp/$$_elseif.sed
698
sed -f /tmp/$$_elseif.sed $file.new >>$file
699
rm -f /tmp/$$_elseif.sed $file.new
704
cat <<-EOF >>/tmp/$$_cb.sed
705
/^SOURCE=$k\$/,/^[#] End Source File/ {
711
/^[#] End Source File/ p
717
sed -f /tmp/$$_cb.sed /tmp/$$_tail >/tmp/$$_tail.1
719
# Final catenation of results to a single project file.
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'`"
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.
733
cat <<-EOF >/tmp/$$_pretty.sed
749
PATH=$PATH:/usr/sbin:/sbin
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
755
test "`ls -l $1 | tr '\t' ' ' | sed 's/ */ /g' | cut -f5 -d' '`" != "1" && \
758
sed -n -f /tmp/$$_pretty.sed /tmp/$$_proj | $doser >$1
759
rm -f /tmp/$$_pretty.sed /tmp/$$_proj