summaryrefslogtreecommitdiffstats
path: root/bin/build_release_package.pl
blob: 62390eb9bc7b044b2d15caae2669b099cb2289df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#######################################################################
#
# A script for creating binary release package
#
# Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
# Contact: Qt Software Information (qt-info@nokia.com)
#
#######################################################################

my $buildContentDemoValue = "libs+demo";

if (@ARGV)
{
    my $buildContent = shift(@ARGV);
    my $platform = shift(@ARGV);
    my $build = shift(@ARGV);
    my $cert = shift(@ARGV);
    my $certKey = shift(@ARGV);
    my $releaseDir = shift(@ARGV);
    my $qtRootDir = shift(@ARGV);
    my $epocroot = shift(@ARGV);

    if ($buildContent eq "")
    {
        print("Build content parameter required!\n");
        exit 2;
    }

    if ($platform eq "")
    {
        print("HW platform parameter required!\n");
        exit 2;
    }

    if ($build eq "")
    {
        print("HW build parameter required!\n");
        exit 2;
    }

    if ($cert eq "")
    {
        print("Signing certificate parameter required!\n");
        exit 2;
    }

    if ($certKey eq "")
    {
        print("Signing certificate key parameter required!\n");
        exit 2;
    }

    if ($releaseDir eq "")
    {
        print("Release directory parameter required!\n");
        exit 2;
    }

    if ($qtRootDir eq "")
    {
        print("Qt root directory parameter required!\n");
        exit 2;
    }

    if ($epocroot eq "")
    {
        print("Epocroot directory parameter required!\n");
        exit 2;
    }

    # Lose the ending separator if any
    $qtRootDir =~ s/\\$//;
    $epocroot =~ s/\\$//;

    chdir($qtRootDir);

    # Lose the drive designator from epocroot
    $epocroot =~ s/.://;

    my $releaseDirQt = "${releaseDir}\\qt";
    my $releaseDirEpocroot = "${releaseDir}\\epocroot";
    my $releaseDirSis = $releaseDirQt; # Put sis files to Qt source dir root

    my $qtRootDirForMatch = $qtRootDir; # Double backslashes so that variable can be used in matching
    $qtRootDirForMatch =~ s/\\/\\\\/g;

    my $pkgFileName = "src\\s60installs\\qt_libs_${platform}_${build}.pkg";
    my $demoAppPkgFileName = "demos\\embedded\\fluidlauncher\\fluidlauncher_${platform}_${build}.pkg";
    my $sisFileNameBase = "qt_libs";
    my $demoAppSisFileNameBase = "fluidlauncher";

    my $hwBuildDir = "${epocroot}\\epoc32\\release\\$platform\\$build";
    my $armDbgDir = "epoc32\\release\\armv5\\udeb";
    my $armRelDir = "epoc32\\release\\armv5\\urel";
    my $armLibDir = "epoc32\\release\\armv5\\lib";
    my $winscwDbgDir = "epoc32\\release\\winscw\\udeb";

    # clean up old stuff
    system("rd /S /Q ${releaseDir} 2> NUL");
    system("rd /S /Q ${epocroot}\\epoc32\\build 2> NUL"); # Just in case env is not clean

    # Copy the whole thing over to the release dir before it gets polluted
    print("Copying clean tree...\n");
    my $tempExcludeFile = "${releaseDir}\\__temp_exclude.txt";
    system("mkdir ${releaseDir} 2>NUL");
    runSystemCmd("echo ${qtRootDir}\\.git\\ > ${tempExcludeFile}");
    runSystemCmd("echo ${qtRootDir}\\tests\\ >> ${tempExcludeFile}");
    runSystemCmd("echo ${qtRootDir}\\util\\ >> ${tempExcludeFile}");
    runSystemCmd("xcopy ${qtRootDir} ${releaseDirQt} /E /I /H /Q /EXCLUDE:${tempExcludeFile}");
    system("del /F /Q ${tempExcludeFile} 2> NUL");

    # Clear archive flag from all items in \epoc32\release\armv5\urel and \epoc32\release\armv5\lib
    # as those will have the binaries used for all platforms and builds.
    runSystemCmd("attrib -A ${hwBuildDir}\\*");
    runSystemCmd("attrib -A ${epocroot}\\${armLibDir}\\*");
    runSystemCmd("attrib -A ${epocroot}\\${winscwDbgDir}\\*");

    # Build Qt
    runSystemCmd("configure -platform win32-mwc -xplatform symbian-abld -qt-sql-sqlite -system-sqlite -confirm-license -opensource");
    buildDir("src", $qtRootDir, $platform, $build, "winscw");

    # Copy misc stuff
    runSystemCmd("xcopy ${qtRootDir}\\bin\\* ${releaseDirQt}\\bin /F /R /Y /I /D");
    runSystemCmd("xcopy ${qtRootDir}\\lib\\*.prl ${releaseDirQt}\\lib /F /R /Y /I /D /E");
    runSystemCmd("xcopy ${qtRootDir}\\mkspecs\\* ${releaseDirQt}\\mkspecs /F /R /Y /I /D /E");
    print("Copying includes...\n");
    runSystemCmd("xcopy ${qtRootDir}\\include\\* ${releaseDirQt}\\include /F /R /Y /I /D /E /Q");
    runSystemCmd("copy src\\corelib\\global\\qconfig.h ${releaseDirQt}\\src\\corelib\\global\\qconfig.h");
    runSystemCmd("copy .qmake.cache ${releaseDirQt}\\.qmake.cache");

    # Copy stuff indicated by pkg file for emulator
    parsePkgFile($pkgFileName, $epocroot, $build, $platform, $releaseDirEpocroot, $qtRootDirForMatch, $releaseDirQt);

    # Copy any other binaries and related files built not included in pkg
    runSystemCmd("xcopy ${hwBuildDir}\\* ${releaseDirEpocroot}\\${armDbgDir} /A /F /R /Y /I /D ");
    runSystemCmd("xcopy ${releaseDirEpocroot}\\${armDbgDir}\\* ${releaseDirEpocroot}\\${armRelDir} /F /R /Y /I /D");
    system("del /F /Q ${releaseDirEpocroot}\\${armRelDir}\\*.sym 2> NUL");
    runSystemCmd("xcopy ${epocroot}\\${armLibDir}\\* ${releaseDirEpocroot}\\${armLibDir} /A /F /R /Y /I /D");
    runSystemCmd("xcopy ${epocroot}\\${winscwDbgDir}\\* ${releaseDirEpocroot}\\${winscwDbgDir} /A /F /R /Y /I /D");

    if ($buildContent eq $buildContentDemoValue)
    {
        # Also build demos & examples and add fluidlauncher sis
        buildDir("examples", $qtRootDir, $platform, $build);
        buildDir("demos", $qtRootDir, $platform, $build);
        # Do not include binaries for demo apps as winscw versions are not BC accross all S60 platform versions
        #parsePkgFile($demoAppPkgFileName, $epocroot, $build, $platform, $releaseDirEpocroot, $qtRootDirForMatch, $releaseDirQt);
        createSis($demoAppPkgFileName, $releaseDirSis, "selfsigned.cer", "selfsigned.key", $demoAppSisFileNameBase);
    }

    # Create unsigned sis and Rnd signed sisx
    createSis($pkgFileName, $releaseDirSis, $cert, $certKey, $sisFileNameBase);

}
else
{
    print("Usage:\n");
    print("build_release_package.pl <build content (${buildContentDemoValue}|libs)> <hw platform> <hw build> <signing cert> <signing cert key> <release directory> <QTROOT> <EPOCROOT>\n");
    print("1) Clean up the env. (abld reallyclean & delete \\my\\epoc\\root\\build folder)\n");
    print("2) Run \"build_release_package.pl armv5 udeb \\rd.cer \\rd-key.pem \\my_release_dir [\\my\\qt\\root\\] [\\my\\epoc\\root\\]>\"\n");
    print("   to build Qt and create the release package structure and sis file.\n");
    print("   Note: Run in the Qt root directory.\n");
    print("3) Optional: Get the sis signed with commercial certificate (can be found in qt directory under release directory)\n");
    print("4) Zip up the release directory contents\n");
}

sub runSystemCmd
{
    my $error_code = system($_[0]);
    if ($error_code != 0)
    {
        print("'$_[0]' call failed: error code == $error_code\n");
        exit 9;
    }
}

sub parsePkgFile
{
    my $epocroot = $_[1];
    my $build = $_[2];
    my $platform = $_[3];
    my $releaseDirEpocroot = $_[4];
    my $qtRootDirForMatch = $_[5];
    my $releaseDirQt = $_[6];

    open (PKG, "<".$_[0]);
    while (<PKG>)
    {
        my $line = $_;
        chomp ($line);

        # If the line specifies a file, parse the source and destination locations.
        if ($line =~ m/\"([^\"]+)\"\s*\-\s*\"([^\"]+)\"/)
        {
            my $sourcePath = $1;
            my $pkgDestinationPath = $2;
            $sourcePath =~ s/\//\\/g;

            # Copy stuff required for creating deployment package
            my $destinationPath = $sourcePath;

            if($destinationPath =~ m/($qtRootDirForMatch)/i)
            {
                $destinationPath =~ s/($qtRootDirForMatch)//i;
                $destinationPath = $releaseDirQt.$destinationPath;
            }
            else
            {
                $destinationPath =~ s/.://;
                if ($epocroot !~ m/\\/)
                {
                    $destinationPath =~ s/($epocroot)//i;
                }
                $destinationPath = $releaseDirEpocroot.$destinationPath;
            }

            runSystemCmd("echo f|xcopy ${sourcePath} ${destinationPath} /F /R /Y /I /D");

            if ($sourcePath !~ m/\\epoc32\\release\\([^\\]+)\\(udeb|urel)\\(\w+(\.dll|\.exe))/i)
            {
                # Copy non-binaries also over for emulator to use
                if ($pkgDestinationPath =~ m/(private\\10003a3f\\import\\apps|resource\\apps)/i)
                {
                    $pkgDestinationPath =~ s/!:/${releaseDirEpocroot}\\epoc32\\release\\winscw\\udeb\\z/g;
                }
                else
                {
                    $pkgDestinationPath =~ s/!:/${releaseDirEpocroot}\\epoc32\\winscw\\c/g;
                }

                runSystemCmd("echo f|xcopy ${sourcePath} ${pkgDestinationPath} /F /R /Y /I /D");
            }
            else
            {
                # For binaries, copy also winscw versions (needed for deployed binaries that are not actually built)
                $sourcePath =~ s/epoc32\\release\\${platform}\\${build}/epoc32\\release\\winscw\\udeb/;
                $destinationPath =~ s/epoc32\\release\\${platform}\\${build}/epoc32\\release\\winscw\\udeb/;
                runSystemCmd("echo f|xcopy ${sourcePath} ${destinationPath} /F /R /Y /I /D");
            }

        }
    }
    close (PKG);
}

sub createSis
{
    my $pkgFileName = $_[0];
    my $releaseDirSis = $_[1];
    my $cert = $_[2];
    my $certKey = $_[3];
    my $sisFileNameBase = $_[4];
    my $signedSuffix = ".sis";
    my $unsignedSuffix = "_unsigned.sis";

    if ($cert =~ m/rd\.cer/i)
    {
        $signedSuffix = "_rnd.sis";
    }

    my $sisFileName = $sisFileNameBase.$unsignedSuffix;
    my $signedSisFileName = $sisFileNameBase.$signedSuffix;
    system("mkdir ${releaseDirSis} 2> NUL");
    runSystemCmd("makesis ${pkgFileName} ${releaseDirSis}\\${sisFileName}");
    runSystemCmd("signsis ${releaseDirSis}\\${sisFileName} ${releaseDirSis}\\${signedSisFileName} ${cert} ${certKey}");
}

sub buildDir
{
    my $buildDir = $_[0];
    my $qtRootDir = $_[1];
    my $platform = $_[2];
    my $build = $_[3];
    my $extra = $_[4];

    chdir($buildDir);
    runSystemCmd("qmake");
    runSystemCmd("bldmake bldfiles");
    runSystemCmd("abld build ${platform} ${build}");
    if ($extra =~ m/winscw/i)
    {
        runSystemCmd("abld build winscw udeb");
    }
    chdir($qtRootDir);
}