#!/usr/bin/perl # This script sets up the local environment, and then launches # a shell for the user. The shell can be specified by the user # as an environment variable or on the commandline. use File::Spec; use Cwd; # Instantiate lists @libPaths; @newPaths; $program; sub selectPlatform { if ( $^O eq "linux") { $PLATFORM = "unix"; $pathDelim = ":"; } # Is it darwin? if ( $^O eq "darwin") { $PLATFORM = "darwin"; $pathDelim = ":"; } # Is it Windows? if ( $^O eq "MSWin32") { $PLATFORM = "win32"; $pathDelim = ";"; } } sub selectProgram { # Start $ARGV[0] if set # Start MSDev on Windows # Start $SHELL if set on Linux and Mac if ( $^O eq "linux") { $program = $ENV{SHELL}; } if ( $^O eq "MSWin32") { $program = "start msdev.exe $CRA_PREFIX$CRA_PROJECT.dsw"; } if ( $ARGV[0] ne "") { $program = $ARGV[0]; } } sub setupVisionKit { if ( $ENV{VISIONKIT_ROOT} eq "" ) { print "Error! VISIONKIT_ROOT not available!\n"; exit; } $ENV{VISIONKIT_THIRDPARTY_ROOT}=File::Spec->catfile($VISIONKIT_ROOT, "ThirdParty"); $ENV{VISIONKIT_TEMP}=File::Spec->tmpdir(); $ENV{VISIONKIT_PREFIX}="CraVisionKit"; $ENV{VISIONKIT_VERSION}="09"; if ($^O eq "linux") { $ENV{VISIONKIT_PLATFORM}="LinuxGcc"; $ENV{VISIONKIT_OS}=`uname -s`; chomp $ENV{VISIONKIT_OS}; } elsif ($^O eq "MSWin32") { $ENV{VISIONKIT_PLATFORM}="Win32Msvc"; } # If VISIONKIT_LOG isn't set... if ($ENV{VISIONKIT_LOG} eq "") { $ENV{VISIONKIT_LOG}=File::Spec->catfile(File::Spec->curdir(), "CraVisionKit.log"); } # If VISIONKIT_DATA_ROOT isn't set... if ($ENV{VISIONKIT_DATA_ROOT} eq "") { $ENV{VISIONKIT_DATA_ROOT}=File::Spec->curdir(); } # Setup ld-paths needed by VK push @libPaths, File::Spec->catfile($ENV{VISIONKIT_ROOT}, "CraVisionKit", "Debug"); push @libPaths, File::Spec->catfile($ENV{VISIONKIT_ROOT}, "CraVisionKit", "Release"); push @libPaths, File::Spec->catfile($ENV{VISIONKIT_THIRDPARTY_ROOT}, "Tiff", "lib"); push @libPaths, File::Spec->catfile($ENV{VISIONKIT_THIRDPARTY_ROOT}, "SmallVisionSystems", "lib"); # Setup paths needed by VK push @newPaths, File::Spec->catfile($ENV{VISIONKIT_ROOT}, "CraVisionKit", "Debug"); push @newPaths, File::Spec->catfile($ENV{VISIONKIT_ROOT}, "CraVisionKit", "Release"); } sub exportDefaults() { if ( $^O eq "linux" and -e "/usr/lib/qt-3.2.3" ) { $ENV{QTDIR}="/usr/lib/qt-3.2.3"; push @newPaths, File::Spec->catfile($ENV{QTDIR}, "bin"); push @libPaths, File::Spec->catfile($ENV{QTDIR}, "lib"); } } sub exportPaths() { # Export extra paths foreach $path (@newPaths) { if ($ENV{PATH} =~ m/$path/) { print "$path already in PATH\n"; } else { $ENV{PATH} = $path . $pathDelim . $ENV{PATH}; } } # Don't need to export LD_LIBRARY_PATH on Windows if ($^O ne "MSWin32") { foreach $path (@libPaths) { if ($ENV{LD_LIBRARY_PATH} =~ m/$path/) { print "$path already in LD_LIBRARY_PATH\n"; } else { $ENV{LD_LIBRARY_PATH} = $path . $pathDelim . $ENV{LD_LIBRARY_PATH}; } } } } # Perform the platform selection selectPlatform(); # What platform are we on? exportDefaults(); # Default Qt location, etc open IN, or die "Unable to open project file!"; while ($line = ) { chomp; if ($line =~ s/\\$//) { $line .= ; redo unless eof; } if ($line =~ /^\s*CRA_PREFIX\s*=\s*(\w+)$/s) { $CRA_PREFIX = $1; } if ($line =~ /^\s*CRA_PROJECT\s*=\s*(\w+)$/s) { $CRA_PROJECT = $1; } } close IN or warn "Unable to close project file!"; print "Setting up $CRA_PREFIX$CRA_PROJECT for $^O\n"; # This could be done in a list and while-loop if I knew how if ( -e "UserCfg.pri" ) { $CONFIG_FILE="UserCfg.pri"; } elsif ( -e "$ENV{HOME}/.$CRA_PREFIX$CRA_PROJECT.UserCfg.pri" ) { $CONFIG_FILE="$ENV{HOME}/.$CRA_PREFIX$CRA_PROJECT.UserCfg.pri"; } elsif ( -e "$ENV{USERPROFILE}/$CRA_PREFIX$CRA_PROJECT.UserCfg.pri" ) { $CONFIG_FILE="$ENV{USERPROFILE}/$CRA_PREFIX$CRA_PROJECT.UserCfg.pri"; } else { print "Unable to locate user config file!\n"; exit; } open IN, $CONFIG_FILE or die "Unable to open user config file!"; while ($line = ) { chomp $line; if ($line =~ s/\\$//) { $line .= ; redo unless eof; } if ($line =~ /^\s*((\w+)\:)?(\w+)\s*=\s*(.*)/s ) { if ( $2 eq "") { $platformSpec = "default"; } else { $platformSpec = $2; } $variable = $3; $value = $4; if ($PLATFORM eq $platformSpec | "default" eq $platformSpec) { print "Found $platformSpec setting for $variable to $value\n"; #Set the environment variable $ENV{$variable}=$value; # Handle Special Variables here? if ($variable eq "QTDIR" ) { print "Setting up QTDIR\n"; push @newPaths, File::Spec->catfile($value, "bin"); push @libPaths, File::Spec->catfile($value, "lib"); } } } } close IN or warn "Unable to close user config file!"; # Call SetupVisionKit.bsh # We can't actually call the bash (or bat) script, so we duplicate # The functionality here. This will not be needed when VK moves to the # new system as well... setupVisionKit(); # It would be nice to add the debug and release directories # to the PATH (and LD_LIBRARY_PATH for Unix) push @libPaths, File::Spec->rel2abs(File::Spec->catfile(File::Spec->curdir(), "Debug")); push @libPaths, File::Spec->rel2abs(File::Spec->catfile(File::Spec->curdir(), "Release")); push @newPaths, File::Spec->rel2abs(File::Spec->catfile(File::Spec->curdir(), "Debug")); push @newPaths, File::Spec->rel2abs(File::Spec->catfile(File::Spec->curdir(), "Release")); # Now send the paths we've constructed to the environment exportPaths(); system("perl Scripts/Configure.pl"); selectProgram(); # Which program to launch after setup print "Going to run $program\n"; exec $program;