Eclipse setup.pl
Jump to navigation
Jump to search
This script creates the necessary Ecplise files to open mythtv sources with Eclipse on Windows. For an unknown reason, import fails.
#!c:/perl/bin/perl.exe -w
##############################################################################
### =file
### Eclipse_setup.pl
###
### =location
###
###
### =description
### Tool for automating Eclipse projects for mythtv on MS Windows XP (and compatible)
### Meant as a temporary solution until incorporated into win32-packager.pl
###
### =examples
### Eclipse_setup.pl -h
### Print usage
### win32-packager.pl -p <path>
### Setup project environment in path. Assumes mythtv, mythplugins and myththemes are underneath
###
### =revision
### $Id$
###
### =author
### Arnon Meshoulam
##############################################################################
use strict;
use File::Find;
use Getopt::Std;
use IO::File;
$| = 1; # autoflush stdout;
my $install_root = "c:/mythtv"; # default installation path
my $msys = "c:/msys/1.0";
my $qt_path = $ENV{'QTDIR'}; # default QT PATH
my $qt_path_double = perl2double($qt_path);
my $unix_qt_path = perl2unix($qt_path);
my @components = ( 'mythtv', 'myththemes', 'mythplugins' );
my @eclipse_files = ( '.project', '.cproject');
my @eclipse_dirs = ('.externalToolBuilders', '.metadata', '.settings');
my @cproject_content;
##############################################################################
# get command line options
my $opt_string = 'hp:';
my %opt = ();
getopts( "$opt_string", \%opt );
usage() if $opt{h};
if (defined $opt{p}) {
$install_root = $opt{p};
}
#Check that sub-dirs exist and that we are not overwritting an existing project
foreach my $comp( @components ) {
if (! -d $install_root.'/'.$comp ) {
die "Expected directory $install_root/$comp not found ";
}
foreach my $files (@eclipse_files) {
if (-f $install_root.'/'.$comp.'/'.$files ) {
die "Existing Eclipse project files found: $install_root/$comp/$files";
}
}
foreach my $dirs (@eclipse_dirs) {
if (-d $install_root.'/'.$comp.'/'.$dirs) {
die "Existing Ecplise project directory found: $install_root/$comp/$dirs ";
}
}
}
die "Please set QTDIR to point to QT Directory and run this script again" if ($qt_path eq "");
die "Could not find directory $qt_path" if !(-d perl2dos($qt_path));
die "Could not find msys directory: $msys" if !(-d perl2dos($msys));
# Create Root .metadata
mkdirs($install_root.'/'.'.metadata');
mkdirs($install_root.'/'.'.metadata/.plugins');
mkdirs($install_root.'/'.'.metadata/.plugins/org.eclipse.core.runtime/.settings');
writefile($install_root.'/'.'.metadata/.plugins/org.eclipse.core.runtime/.settings/com.trolltech.qtcppproject.prefs', '
eclipse.preferences.version=1
com.trolltech.qtcppproject.qtversionname.0=QT 4.4.0
com.trolltech.qtcppproject.qtautosetmkspec=true
com.trolltech.qtcppproject.qtversiondefault=QT 4.4.0
com.trolltech.qtcppproject.qtversioncount=1
com.trolltech.qtcppproject.qtautosetmkcmd=true
com.trolltech.qtcppproject.qtversionincludepath.0='.$qt_path_double.'\\\\include
com.trolltech.qtcppproject.qtversionbinpath.0='.$qt_path_double.'\\\\bin
');
writefile($install_root.'/'.'.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.resources.prefs', '
version=1
eclipse.preferences.version=1
description.autobuilding=false');
foreach my $comp( @components ) {
@cproject_content = "";
writefile($install_root.'/'.$comp.'/'.'.project', '<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>mythtv</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.trolltech.qtcppproject.QtMakefileGenerator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.make.core.makeBuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
<dictionary>
<key>org.eclipse.cdt.make.core.build.arguments</key>
<value></value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.core.errorOutputParser</key>
<value>org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GLDErrorParser;</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.environment</key>
<value>QMAKESPEC=win32-g++|TARGET_OS=COMSPEC|INSTALL_ROOT=|PATH='.$qt_path.'\bin;${env_var:PATH}|</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableAutoBuild</key>
<value>false</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableFullBuild</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enabledIncrementalBuild</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.build.location</key>
<value></value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.build.command</key>
<value>mingw32-make</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.build.target.clean</key>
<value></value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableCleanBuild</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.append_environment</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
<value>false</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.build.target.auto</key>
<value>debug</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.stopOnError</key>
<value>false</value>
</dictionary>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.make.core.ScannerConfigBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.make.core.makeNature</nature>
<nature>org.eclipse.cdt.make.core.ScannerConfigNature</nature>
<nature>com.trolltech.qtcppproject.QtNature</nature>
</natures>
</projectDescription>
');
push @cproject_content, "
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<?fileVersion 4.0.0?>
<cproject>
<storageModule moduleId=\"org.eclipse.cdt.core.settings\">
<cconfiguration id=\"org.eclipse.cdt.core.default.config.1395462625\">
<storageModule buildSystemId=\"org.eclipse.cdt.core.defaultConfigDataProvider\" id=\"org.eclipse.cdt.core.default.config.354312420\" moduleId=\"org.eclipse.cdt.core.settings\" name=\"Configuration\">
<externalSettings/>
<extensions/>
</storageModule>
<storageModule moduleId=\"org.eclipse.cdt.core.pathentry\"/>
<pathentry kind=\"src\" path=\"\"/>
<pathentry kind=\"out\" path=\"\"/>
</storagemodule>
<storageModule moduleId=\"org.eclipse.cdt.core.externalSettings\"/>
<storageModule moduleId=\"scannerConfiguration\">
<autodiscovery enabled=\"true\" problemReportingEnabled=\"true\" selectedProfileId=\"org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile\"/>
<profile id=\"org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile\">
<buildOutputProvider>
<openAction enabled=\"true\" filePath=\"\"/>
<parser enabled=\"true\"/>
</buildOutputProvider>
<scannerInfoProvider id=\"specsFile\">
<runAction arguments=\"-E -P -v -dD \${plugin_state_location}/\${specs_file}\" command=\"gcc\" useDefault=\"true\"/>
<parser enabled=\"true\"/>
</scannerInfoProvider>
</profile>
<profile id=\"org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile\">
<buildOutputProvider>
<openAction enabled=\"true\" filePath=\"\"/>
<parser enabled=\"true\"/>
</buildOutputProvider>
<scannerInfoProvider id=\"makefileGenerator\">
<runAction arguments=\"-f \${project_name}_scd.mk\" command=\"make\" useDefault=\"true\"/>
<parser enabled=\"true\"/>
</scannerInfoProvider>
</profile>
<profile id=\"org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfile\">
<buildOutputProvider>
<openAction enabled=\"true\" filePath=\"\"/>
<parser enabled=\"true\"/>
</buildOutputProvider>
<scannerInfoProvider id=\"specsFile\">
<runAction arguments=\"-E -P -v -dD \${plugin_state_location}/\${specs_file}\" command=\"gcc\" useDefault=\"true\"/>
<parser enabled=\"true\"/>
</scannerInfoProvider>
</profile>
<profile id=\"org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP\">
<buildOutputProvider>
<openAction enabled=\"true\" filePath=\"\"/>
<parser enabled=\"true\"/>
</buildOutputProvider>
<scannerInfoProvider id=\"specsFile\">
<runAction arguments=\"-E -P -v -dD \${plugin_state_location}/specs.cpp\" command=\"g++\" useDefault=\"true\"/>
<parser enabled=\"true\"/>
</scannerInfoProvider>
</profile>
<profile id=\"org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC\">
<buildOutputProvider>
<openAction enabled=\"true\" filePath=\"\"/>
<parser enabled=\"true\"/>
</buildOutputProvider>
<scannerInfoProvider id=\"specsFile\">
<runAction arguments=\"-E -P -v -dD \${plugin_state_location}/specs.c\" command=\"gcc\" useDefault=\"true\"/>
<parser enabled=\"true\"/>
</scannerInfoProvider>
</profile>
<profile id=\"org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfile\">
<buildOutputProvider>
<openAction enabled=\"true\" filePath=\"\"/>
<parser enabled=\"true\"/>
</buildOutputProvider>
<scannerInfoProvider id=\"specsFile\">
<runAction arguments=\"-E -P -v -dD \${plugin_state_location}/\${specs_file}\" command=\"gcc\" useDefault=\"true\"/>
<parser enabled=\"true\"/>
</scannerInfoProvider>
</profile>
<profile id=\"org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileCPP\">
<buildOutputProvider>
<openAction enabled=\"true\" filePath=\"\"/>
<parser enabled=\"true\"/>
</buildOutputProvider>
<scannerInfoProvider id=\"specsFile\">
<runAction arguments=\"-E -P -v -dD \${plugin_state_location}/specs.cpp\" command=\"g++\" useDefault=\"true\"/>
<parser enabled=\"true\"/>
</scannerInfoProvider>
</profile>
<profile id=\"org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfileC\">
<buildOutputProvider>
<openAction enabled=\"true\" filePath=\"\"/>
<parser enabled=\"true\"/>
</buildOutputProvider>
<scannerInfoProvider id=\"specsFile\">
<runAction arguments=\"-E -P -v -dD \${plugin_state_location}/specs.c\" command=\"gcc\" useDefault=\"true\"/>
<parser enabled=\"true\"/>
</scannerInfoProvider>
</profile>
</storageModule>
<storageModule moduleId=\"org.eclipse.cdt.core.language.mapping\"/>";
push @cproject_content, "
<storageModule moduleId=\"org.eclipse.cdt.make.core.buildtargets\">
<buildTargets>
";
# for each directory in project, find .pro file and create the pattern
find(\&TargetMakes, $install_root.'/'.$comp);
push @cproject_content, "</buildTargets>
</storageModule>
</cconfiguration>
</storageModule>
</cproject>
";
writefile($install_root.'/'.$comp.'/'.'.cproject', @cproject_content);
mkdirs($install_root.'/'.$comp.'/'.'.externalToolBuilders');
mkdirs($install_root.'/'.$comp.'/'.'.metadata');
mkdirs($install_root.'/'.$comp.'/'.'.metadata/.plugins');
writefile($install_root.'/'.$comp.'/'.'.metadata/version.ini', 'org.eclipse.core.runtime=1');
mkdirs($install_root.'/'.$comp.'/'.'.settings');
}
sub TargetMakes {
my ($name, $ext) = split /./, $_;
my ($rel_path) = $File::Find::dir;
$File::Find::prune=1;
push @cproject_content, "<target name=\"$name\" path=\"$name\" targetID=\"org.eclipse.cdt.make.MakeTargetBuilder\">
<buildCommand>mingw32-make</buildCommand>
<buildArguments></buildArguments>
<buildTarget></buildTarget>
<stopOnError>false</stopOnError>
<useDefaultCommand>false</useDefaultCommand>
<runAllBuilders>false</runAllBuilders>
</target>";
push @cproject_content, "<target name=\"Install\" path=\"$rel_path\" targetID=\"org.eclipse.cdt.make.MakeTargetBuilder\">
<buildCommand>mingw32-make</buildCommand>
<buildArguments></buildArguments>
<buildTarget>install</buildTarget>
<stopOnError>false</stopOnError>
<useDefaultCommand>false</useDefaultCommand>
<runAllBuilders>false</runAllBuilders>
</target>";
}
# creates a directory with name given. Always creates off $install_root.
sub writedir {
my ($dirname) = @_;
mkdirs($install_root.'/'.$dirname);
}
sub mkdirs {
my $path = shift;
die "backslash in foldername not allowed in mkdirs function:($path)\n"
if $path =~ m#\\#;
$path = perl2dos($path);
print "mkdir $path\n";
# reduce path to just windows,
# incase we have a rogue unix mkdir command elsewhere!
print `set PATH=C:\\WINDOWS\\system32;c:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem && mkdir $path`;
}
#creates a file with the name and contents given
sub writefile {
my ( $filename, @contents) = @_;
my $fh = new IO::File ("> $filename")
|| die "error opening $filename for writing: $!\n";
$fh->binmode();
$fh->print(join('',@contents));
print "Creating $filename\n";
$fh->close();
}
#------------------------------------------------------------------------------
# DOS executable CMD.exe versions of the paths (for when we [exec] to DOS mode):
sub perl2dos {
my $p = shift;
$p =~ s#/#\\#g; # single forward to single backward
return $p;
}
#------------------------------------------------------------------------------
# DOS executable CMD.exe versions of the paths (for when we [exec] to DOS mode):
sub perl2double {
my $p = shift;
$p =~ s#/#\\\\#g; # single forward to double backward
$p =~ s#\\#\\\\#g; # single forward to double backward
$p =~ s#:#\\:#g; # colon to escaped colon
return $p;
}
#------------------------------------------------------------------------------
# unix compatible versions of the perl paths (for when we [shell] to unix/bash mode):
sub perl2unix {
my $p = shift;
print "perl2unix: $p\n";
$p =~ s#$msys#/#i; # remove superfluous msys folders if they are there
$p =~ s#^([CD]):#/$1#ig; #change c:/ into /c (or a D:) so c:/msys becomes /c/msys etc.
$p =~ s#//#/#ig; # reduce any double forward slashes to single ones.
return $p;
}
sub usage {
print << 'END_USAGE';
-h This message
END_USAGE
exit;
}
#------------------------------------------------------------------------------