Skip to content

Commit

Permalink
Add scripts to generate projects for other buildsystems (MSVC vcproj,…
Browse files Browse the repository at this point in the history
… QMake)

These scripts generate projects for the MSVC IDE (.vcproj files) or
QMake (.pro files), based on the output of a 'make -n MSVC=1 V=1' run.

This enables us to simply do the necesarry changes in the Makefile, and you
can update the other buildsystems by regenerating the files. Keeping the
other buildsystems up-to-date with main development.

The generator system is designed to easily drop in pm's for other
buildsystems as well, if someone has an itch. However, the focus has been
Windows development, so the 'engine' might need patches to support any
platform.

Also add some .gitignore entries for MSVC files.

Signed-off-by: Marius Storm-Olsen <[email protected]>
Acked-by: Johannes Sixt <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
mstormo authored and gitster committed Sep 19, 2009
1 parent a2c6bf0 commit 259d87c
Show file tree
Hide file tree
Showing 8 changed files with 1,503 additions and 1 deletion.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,14 @@ configure
tags
TAGS
cscope*
*.obj
*.lib
*.sln
*.suo
*.ncb
*.vcproj
*.user
*.idb
*.pdb
Debug/
Release/
13 changes: 12 additions & 1 deletion compat/vcbuild/README
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,18 @@ The Steps of Build Git with VS2008
make common-cmds.h
to generate the common-cmds.h file needed to compile git.

4. Then build Git with the GNU Make Makefile in the Git projects root
4. Then either build Git with the GNU Make Makefile in the Git projects
root
make MSVC=1
or generate Visual Studio solution/projects (.sln/.vcproj) with the
command
perl contrib/buildsystems/generate -g Vcproj
and open and build the solution with the IDE
devenv git.sln /useenv
or build with the IDE build engine directly from the command line
devenv git.sln /useenv /build "Release|Win32"
The /useenv option is required, so Visual Studio picks up the
environment variables for the support libraries required to build
Git, which you set up in step 1.

Done!
42 changes: 42 additions & 0 deletions contrib/buildsystems/Generators.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package Generators;
require Exporter;

use strict;
use File::Basename;
no strict 'refs';
use vars qw($VERSION @AVAILABLE);

our $VERSION = '1.00';
our(@ISA, @EXPORT, @EXPORT_OK, @AVAILABLE);
@ISA = qw(Exporter);

BEGIN {
local(*D);
my $me = $INC{"Generators.pm"};
die "Couldn't find myself in \@INC, which is required to load the generators!" if ("$me" eq "");
$me = dirname($me);
if (opendir(D,"$me/Generators")) {
foreach my $gen (readdir(D)) {
next if ($gen =~ /^\.\.?$/);
require "${me}/Generators/$gen";
$gen =~ s,\.pm,,;
push(@AVAILABLE, $gen);
}
closedir(D);
my $gens = join(', ', @AVAILABLE);
}

push @EXPORT_OK, qw(available);
}

sub available {
return @AVAILABLE;
}

sub generate {
my ($gen, $git_dir, $out_dir, $rel_dir, %build_structure) = @_;
return eval("Generators::${gen}::generate(\$git_dir, \$out_dir, \$rel_dir, \%build_structure)") if grep(/^$gen$/, @AVAILABLE);
die "Generator \"${gen}\" is not available!\nAvailable generators are: @AVAILABLE\n";
}

1;
189 changes: 189 additions & 0 deletions contrib/buildsystems/Generators/QMake.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
package Generators::QMake;
require Exporter;

use strict;
use vars qw($VERSION);

our $VERSION = '1.00';
our(@ISA, @EXPORT, @EXPORT_OK, @AVAILABLE);
@ISA = qw(Exporter);

BEGIN {
push @EXPORT_OK, qw(generate);
}

sub generate {
my ($git_dir, $out_dir, $rel_dir, %build_structure) = @_;

my @libs = @{$build_structure{"LIBS"}};
foreach (@libs) {
createLibProject($_, $git_dir, $out_dir, $rel_dir, %build_structure);
}

my @apps = @{$build_structure{"APPS"}};
foreach (@apps) {
createAppProject($_, $git_dir, $out_dir, $rel_dir, %build_structure);
}

createGlueProject($git_dir, $out_dir, $rel_dir, %build_structure);
return 0;
}

sub createLibProject {
my ($libname, $git_dir, $out_dir, $rel_dir, %build_structure) = @_;
print "Generate $libname lib project\n";
$rel_dir = "../$rel_dir";

my $sources = join(" \\\n\t", sort(map("$rel_dir/$_", @{$build_structure{"LIBS_${libname}_SOURCES"}})));
my $defines = join(" \\\n\t", sort(@{$build_structure{"LIBS_${libname}_DEFINES"}}));
my $includes= join(" \\\n\t", sort(map("$rel_dir/$_", @{$build_structure{"LIBS_${libname}_INCLUDES"}})));
my $cflags = join(" ", sort(@{$build_structure{"LIBS_${libname}_CFLAGS"}}));

my $cflags_debug = $cflags;
$cflags_debug =~ s/-MT/-MTd/;
$cflags_debug =~ s/-O.//;

my $cflags_release = $cflags;
$cflags_release =~ s/-MTd/-MT/;

my @tmp = @{$build_structure{"LIBS_${libname}_LFLAGS"}};
my @tmp2 = ();
foreach (@tmp) {
if (/^-LTCG/) {
} elsif (/^-L/) {
$_ =~ s/^-L/-LIBPATH:$rel_dir\//;
}
push(@tmp2, $_);
}
my $lflags = join(" ", sort(@tmp));

my $target = $libname;
$target =~ s/\//_/g;
$defines =~ s/-D//g;
$defines =~ s/"/\\\\"/g;
$includes =~ s/-I//g;
mkdir "$target" || die "Could not create the directory $target for lib project!\n";
open F, ">$target/$target.pro" || die "Could not open $target/$target.pro for writing!\n";
print F << "EOM";
TEMPLATE = lib
TARGET = $target
DESTDIR = $rel_dir
CONFIG -= qt
CONFIG += static
QMAKE_CFLAGS =
QMAKE_CFLAGS_RELEASE = $cflags_release
QMAKE_CFLAGS_DEBUG = $cflags_debug
QMAKE_LIBFLAGS = $lflags
DEFINES += \\
$defines
INCLUDEPATH += \\
$includes
SOURCES += \\
$sources
EOM
close F;
}

sub createAppProject {
my ($appname, $git_dir, $out_dir, $rel_dir, %build_structure) = @_;
print "Generate $appname app project\n";
$rel_dir = "../$rel_dir";

my $sources = join(" \\\n\t", sort(map("$rel_dir/$_", @{$build_structure{"APPS_${appname}_SOURCES"}})));
my $defines = join(" \\\n\t", sort(@{$build_structure{"APPS_${appname}_DEFINES"}}));
my $includes= join(" \\\n\t", sort(map("$rel_dir/$_", @{$build_structure{"APPS_${appname}_INCLUDES"}})));
my $cflags = join(" ", sort(@{$build_structure{"APPS_${appname}_CFLAGS"}}));

my $cflags_debug = $cflags;
$cflags_debug =~ s/-MT/-MTd/;
$cflags_debug =~ s/-O.//;

my $cflags_release = $cflags;
$cflags_release =~ s/-MTd/-MT/;

my $libs;
foreach (sort(@{$build_structure{"APPS_${appname}_LIBS"}})) {
$_ =~ s/\//_/g;
$libs .= " $_";
}
my @tmp = @{$build_structure{"APPS_${appname}_LFLAGS"}};
my @tmp2 = ();
foreach (@tmp) {
# next if ($_ eq "-NODEFAULTLIB:MSVCRT.lib");
if (/^-LTCG/) {
} elsif (/^-L/) {
$_ =~ s/^-L/-LIBPATH:$rel_dir\//;
}
push(@tmp2, $_);
}
my $lflags = join(" ", sort(@tmp));

my $target = $appname;
$target =~ s/\.exe//;
$target =~ s/\//_/g;
$defines =~ s/-D//g;
$defines =~ s/"/\\\\"/g;
$includes =~ s/-I//g;
mkdir "$target" || die "Could not create the directory $target for app project!\n";
open F, ">$target/$target.pro" || die "Could not open $target/$target.pro for writing!\n";
print F << "EOM";
TEMPLATE = app
TARGET = $target
DESTDIR = $rel_dir
CONFIG -= qt embed_manifest_exe
CONFIG += console
QMAKE_CFLAGS =
QMAKE_CFLAGS_RELEASE = $cflags_release
QMAKE_CFLAGS_DEBUG = $cflags_debug
QMAKE_LFLAGS = $lflags
LIBS = $libs
DEFINES += \\
$defines
INCLUDEPATH += \\
$includes
win32:QMAKE_LFLAGS += -LIBPATH:$rel_dir
else: QMAKE_LFLAGS += -L$rel_dir
SOURCES += \\
$sources
EOM
close F;
}

sub createGlueProject {
my ($git_dir, $out_dir, $rel_dir, %build_structure) = @_;
my $libs = join(" \\ \n", map("\t$_|$_.pro", @{$build_structure{"LIBS"}}));
my $apps = join(" \\ \n", map("\t$_|$_.pro", @{$build_structure{"APPS"}}));
$libs =~ s/\.a//g;
$libs =~ s/\//_/g;
$libs =~ s/\|/\//g;
$apps =~ s/\.exe//g;
$apps =~ s/\//_/g;
$apps =~ s/\|/\//g;

my $filename = $out_dir;
$filename =~ s/.*\/([^\/]+)$/$1/;
$filename =~ s/\/$//;
print "Generate glue project $filename.pro\n";
open F, ">$filename.pro" || die "Could not open $filename.pro for writing!\n";
print F << "EOM";
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS += \\
$libs \\
$apps
EOM
close F;
}

1;
Loading

0 comments on commit 259d87c

Please sign in to comment.