cgal/wininst/developer_scripts/examples/C2vcproj

139 lines
3.9 KiB
Bash
Executable File

#!/bin/sh
echo "Creating VC71/VC80 solution & project files..."
# NOTE: This is hard-coded
SCRIPTDIR="../../developer_scripts/examples"
# Creates a VC71/VC80 .vcproj file corresponding to a source file
# $1 is the source file
# $2 is the extension of the source file
# $3 is the target compiler version: "71" or "80"
# $4 is the parent solution file
#
create_project_file()
{
srcfile=${1};
ext=${2};
ver=${3};
slnfile=${4};
# $srcname is a string of the form "source" were "source.some_extension" is the of the source file
srcname=`echo $srcfile|sed -e "s/\.$ext//"`;
# $projfile is a filename of the form "source.vcproj" were "source" is the basename of the source file
projfile=`echo $srcfile|sed -e "s/\.$ext/\.vcproj/"`;
# Creates a vcroj IFF it doesn't exist
if [[ ! -e $projfile ]]; then
GUID=`printf "%012d" $RANDOM`
echo "Creating $projfile under VC$ver folder with GUID={00000000-0000-0000-0000-$GUID}"
outdir='$(ConfigurationName)_'$srcname
#
# Takes a master .vcproj file, replaces the keywords
# SOURCE for $srcname
# EXT for $ext
# OUTDIR for $outdir
# And moves the generated project file into the final folder
#
sed -e"s/SOURCE/$srcname/g" $SCRIPTDIR/master_${ver}.vcproj > ./src2sln_/temp.txt;
sed -e"s/EXT/$ext/g" ./src2sln_/temp.txt > ./src2sln_/temp2.txt;
sed -e"s/ZZZZZZZZZZZZ/$GUID/g" ./src2sln_/temp2.txt > ./src2sln_/temp3.txt;
sed -e"s/OUTDIR/$outdir/g" ./src2sln_/temp3.txt > ./src2sln_/$projfile;
mv ./src2sln_/$projfile ./VC$ver;
#
# Takes a master .sln entry line, replaces the keywords
# TARGET for $srcname
# PROJECT for $projfile
# And adds the line to parent solution file
#
echo "Adding $projfile to $slnfile"
sed -e"s/TARGET/$srcname/g" $SCRIPTDIR/master_${ver}_proj_line.sln > ./src2sln_/temp.txt;
sed -e"s/ZZZZZZZZZZZZ/$GUID/g" ./src2sln_/temp.txt > ./src2sln_/temp2.txt;
sed -e"s,PROJECT,VC$ver/$projfile,g" ./src2sln_/temp2.txt > ./src2sln_/temp3.txt;
mv ./src2sln_/$slnfile ./src2sln_/$slnfile.tmp
cat ./src2sln_/$slnfile.tmp ./src2sln_/temp3.txt > ./src2sln_/$slnfile
rm ./src2sln_/$slnfile.tmp
rm -rf ./src2sln_/temp.txt
rm -rf ./src2sln_/temp2.txt
rm -rf ./src2sln_/temp3.txt
fi
}
#
# Create a .vcproj Visual C++ makefile for each .C and .cpp file
# Usage: C2vcproj folder1 ...
#
# For each folder in parameters list
for h in $@ ; do
if [[ -d $h ]]; then
cd $h;
echo "In " $h;
pkg=`basename $h`
# Create a VC71 subdirectory IFF it doesn't already exists
if [[ ! -e "VC71" ]]; then
mkdir VC71
fi
# Create a VC80 subdirectory IFF it doesn't already exists
if [[ ! -e "VC80" ]]; then
mkdir VC80
fi
# ALWAYS create temporary subdirectory "src2sln_"
if [[ -e src2sln_ ]]; then
rm -r src2sln_;
fi
mkdir src2sln_;
# $sp71 is the filename of the solution for for VC71
sp71=$pkg"_VC71.sln"
# $sp80 is the filename of the solution for for VC80
sp80=$pkg"_VC80.sln"
echo "Creating $sp71"
cat $SCRIPTDIR/master_71_head.sln > ./src2sln_/$sp71
echo "Creating $sp80"
cat $SCRIPTDIR/master_80_head.sln > ./src2sln_/$sp80
# For each .C and .cpp file file
for ext in C cpp ; do
for i in *.$ext ; do
if [[ ! $i = "*.$ext" ]]; then
# if $i contains a function "main()"
zgrep main $i >/dev/null 2>&1
if [[ $? == 0 ]]; then
create_project_file $i $ext "71" $sp71
create_project_file $i $ext "80" $sp80
fi
fi
done
done
mv ./src2sln_/$sp71 ./$sp71;
mv ./src2sln_/$sp80 ./$sp80;
# Remove temporary subdirectory "src2sln_"
rm -r src2sln_
cd ..;
fi
done