1 package Generators::QMake;
 
   8 our(@ISA, @EXPORT, @EXPORT_OK, @AVAILABLE);
 
  12     push @EXPORT_OK, qw(generate);
 
  16     my ($git_dir, $out_dir, $rel_dir, %build_structure) = @_;
 
  18     my @libs = @{$build_structure{"LIBS"}};
 
  20         createLibProject($_, $git_dir, $out_dir, $rel_dir, %build_structure);
 
  23     my @apps = @{$build_structure{"APPS"}};
 
  25         createAppProject($_, $git_dir, $out_dir, $rel_dir, %build_structure);
 
  28     createGlueProject($git_dir, $out_dir, $rel_dir, %build_structure);
 
  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"}};
 
  54             $_ =~ s/^-L/-LIBPATH:$rel_dir\//;
 
  58     my $lflags = join(" ", sort(@tmp));
 
  60     my $target = $libname;
 
  63     $defines =~ s/"/\\\\"/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";
 
  76 QMAKE_CFLAGS_RELEASE = $cflags_release
 
  77 QMAKE_CFLAGS_DEBUG = $cflags_debug
 
  78 QMAKE_LIBFLAGS = $lflags
 
  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/;
 
 110     foreach (sort(@{$build_structure{"APPS_${appname}_LIBS"}})) {
 
 114     my @tmp  = @{$build_structure{"APPS_${appname}_LFLAGS"}};
 
 117         # next if ($_ eq "-NODEFAULTLIB:MSVCRT.lib");
 
 120             $_ =~ s/^-L/-LIBPATH:$rel_dir\//;
 
 124     my $lflags = join(" ", sort(@tmp));
 
 126     my $target = $appname;
 
 127     $target =~ s/\.exe//;
 
 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";
 
 139 CONFIG -= qt embed_manifest_exe
 
 143 QMAKE_CFLAGS_RELEASE = $cflags_release
 
 144 QMAKE_CFLAGS_DEBUG = $cflags_debug
 
 145 QMAKE_LFLAGS = $lflags
 
 154 win32:QMAKE_LFLAGS += -LIBPATH:$rel_dir
 
 155 else: QMAKE_LFLAGS += -L$rel_dir
 
 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"}}));
 
 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";