modify git-completion.bash so git PS1 works correctly
[git/mingw/4msysgit/gitPS1fix.git] / contrib / buildsystems / Generators / QMake.pm
blobff3b657e610575091e43cccc8c74139166b8d0d2
1 package Generators::QMake;
2 require Exporter;
4 use strict;
5 use vars qw($VERSION);
7 our $VERSION = '1.00';
8 our(@ISA, @EXPORT, @EXPORT_OK, @AVAILABLE);
9 @ISA = qw(Exporter);
11 BEGIN {
12 push @EXPORT_OK, qw(generate);
15 sub generate {
16 my ($git_dir, $out_dir, $rel_dir, %build_structure) = @_;
18 my @libs = @{$build_structure{"LIBS"}};
19 foreach (@libs) {
20 createLibProject($_, $git_dir, $out_dir, $rel_dir, %build_structure);
23 my @apps = @{$build_structure{"APPS"}};
24 foreach (@apps) {
25 createAppProject($_, $git_dir, $out_dir, $rel_dir, %build_structure);
28 createGlueProject($git_dir, $out_dir, $rel_dir, %build_structure);
29 return 0;
32 sub createLibProject {
33 my ($libname, $git_dir, $out_dir, $rel_dir, %build_structure) = @_;
34 print "Generate $libname lib project\n";
35 $rel_dir = "../$rel_dir";
37 my $sources = join(" \\\n\t", sort(map("$rel_dir/$_", @{$build_structure{"LIBS_${libname}_SOURCES"}})));
38 my $defines = join(" \\\n\t", sort(@{$build_structure{"LIBS_${libname}_DEFINES"}}));
39 my $includes= join(" \\\n\t", sort(map("$rel_dir/$_", @{$build_structure{"LIBS_${libname}_INCLUDES"}})));
40 my $cflags = join(" ", sort(@{$build_structure{"LIBS_${libname}_CFLAGS"}}));
42 my $cflags_debug = $cflags;
43 $cflags_debug =~ s/-MT/-MTd/;
44 $cflags_debug =~ s/-O.//;
46 my $cflags_release = $cflags;
47 $cflags_release =~ s/-MTd/-MT/;
49 my @tmp = @{$build_structure{"LIBS_${libname}_LFLAGS"}};
50 my @tmp2 = ();
51 foreach (@tmp) {
52 if (/^-LTCG/) {
53 } elsif (/^-L/) {
54 $_ =~ s/^-L/-LIBPATH:$rel_dir\//;
56 push(@tmp2, $_);
58 my $lflags = join(" ", sort(@tmp));
60 my $target = $libname;
61 $target =~ s/\//_/g;
62 $defines =~ s/-D//g;
63 $defines =~ s/"/\\\\"/g;
64 $includes =~ s/-I//g;
65 mkdir "$target" || die "Could not create the directory $target for lib project!\n";
66 open F, ">$target/$target.pro" || die "Could not open $target/$target.pro for writing!\n";
67 print F << "EOM";
68 TEMPLATE = lib
69 TARGET = $target
70 DESTDIR = $rel_dir
72 CONFIG -= qt
73 CONFIG += static
75 QMAKE_CFLAGS =
76 QMAKE_CFLAGS_RELEASE = $cflags_release
77 QMAKE_CFLAGS_DEBUG = $cflags_debug
78 QMAKE_LIBFLAGS = $lflags
80 DEFINES += \\
81 $defines
83 INCLUDEPATH += \\
84 $includes
86 SOURCES += \\
87 $sources
88 EOM
89 close F;
92 sub createAppProject {
93 my ($appname, $git_dir, $out_dir, $rel_dir, %build_structure) = @_;
94 print "Generate $appname app project\n";
95 $rel_dir = "../$rel_dir";
97 my $sources = join(" \\\n\t", sort(map("$rel_dir/$_", @{$build_structure{"APPS_${appname}_SOURCES"}})));
98 my $defines = join(" \\\n\t", sort(@{$build_structure{"APPS_${appname}_DEFINES"}}));
99 my $includes= join(" \\\n\t", sort(map("$rel_dir/$_", @{$build_structure{"APPS_${appname}_INCLUDES"}})));
100 my $cflags = join(" ", sort(@{$build_structure{"APPS_${appname}_CFLAGS"}}));
102 my $cflags_debug = $cflags;
103 $cflags_debug =~ s/-MT/-MTd/;
104 $cflags_debug =~ s/-O.//;
106 my $cflags_release = $cflags;
107 $cflags_release =~ s/-MTd/-MT/;
109 my $libs;
110 foreach (sort(@{$build_structure{"APPS_${appname}_LIBS"}})) {
111 $_ =~ s/\//_/g;
112 $libs .= " $_";
114 my @tmp = @{$build_structure{"APPS_${appname}_LFLAGS"}};
115 my @tmp2 = ();
116 foreach (@tmp) {
117 # next if ($_ eq "-NODEFAULTLIB:MSVCRT.lib");
118 if (/^-LTCG/) {
119 } elsif (/^-L/) {
120 $_ =~ s/^-L/-LIBPATH:$rel_dir\//;
122 push(@tmp2, $_);
124 my $lflags = join(" ", sort(@tmp));
126 my $target = $appname;
127 $target =~ s/\.exe//;
128 $target =~ s/\//_/g;
129 $defines =~ s/-D//g;
130 $defines =~ s/"/\\\\"/g;
131 $includes =~ s/-I//g;
132 mkdir "$target" || die "Could not create the directory $target for app project!\n";
133 open F, ">$target/$target.pro" || die "Could not open $target/$target.pro for writing!\n";
134 print F << "EOM";
135 TEMPLATE = app
136 TARGET = $target
137 DESTDIR = $rel_dir
139 CONFIG -= qt embed_manifest_exe
140 CONFIG += console
142 QMAKE_CFLAGS =
143 QMAKE_CFLAGS_RELEASE = $cflags_release
144 QMAKE_CFLAGS_DEBUG = $cflags_debug
145 QMAKE_LFLAGS = $lflags
146 LIBS = $libs
148 DEFINES += \\
149 $defines
151 INCLUDEPATH += \\
152 $includes
154 win32:QMAKE_LFLAGS += -LIBPATH:$rel_dir
155 else: QMAKE_LFLAGS += -L$rel_dir
157 SOURCES += \\
158 $sources
160 close F;
163 sub createGlueProject {
164 my ($git_dir, $out_dir, $rel_dir, %build_structure) = @_;
165 my $libs = join(" \\ \n", map("\t$_|$_.pro", @{$build_structure{"LIBS"}}));
166 my $apps = join(" \\ \n", map("\t$_|$_.pro", @{$build_structure{"APPS"}}));
167 $libs =~ s/\.a//g;
168 $libs =~ s/\//_/g;
169 $libs =~ s/\|/\//g;
170 $apps =~ s/\.exe//g;
171 $apps =~ s/\//_/g;
172 $apps =~ s/\|/\//g;
174 my $filename = $out_dir;
175 $filename =~ s/.*\/([^\/]+)$/$1/;
176 $filename =~ s/\/$//;
177 print "Generate glue project $filename.pro\n";
178 open F, ">$filename.pro" || die "Could not open $filename.pro for writing!\n";
179 print F << "EOM";
180 TEMPLATE = subdirs
181 CONFIG += ordered
182 SUBDIRS += \\
183 $libs \\
184 $apps
186 close F;