1#!/usr/bin/perl
2#
3# Copyright (c) 2013 No Face Press, LLC
4# License http://opensource.org/licenses/mit-license.php MIT License
5#
6
7# This script builds and packages a Windows release.
8# It requires ActiveState Perl to use and is intended
9# to be run from the its directory under the
10# VS Developer Command Prompt.
11
12# Create a Zip file
13use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
14my $zip = Archive::Zip->new();
15
16my $src = "..";
17
18sub getCivetwebVersion {
19    print "Fetching CivetWeb version...\n";
20    open HEADER, "${src}/include/civetweb.h";
21    while (<HEADER>) {
22        if (m/define\s+CIVETWEB_VERSION\s+"(.+)"/) {
23            close HEADER;
24            return $1;
25        }
26    }
27    close HEADER;
28    return "UNKNOWN_VERSION";
29}
30
31my $CIVETWEB_VERSION = getCivetwebVersion();
32my $basename         = "civetweb-$CIVETWEB_VERSION";
33my $dir              = "${basename}";
34
35sub build32() {
36    print "\nBuilding Win32 Release version...\n";
37    system("msbuild /p:Configuration=Release /p:Platform=Win32 civetweb.sln");
38}
39
40sub build64() {
41    print "\nBuilding x64 Release version...\n";
42    system("msbuild /p:Configuration=Release /p:Platform=x64 civetweb.sln");
43}
44
45sub writeArchive() {
46    my $archive = "${basename}-win.zip";
47    print "Creating archive $archive ...\n";
48
49    $zip->addDirectory("${dir}/");
50
51    $zip->addFile( "${src}/LICENSE.md",            "${dir}/LICENSE.md" );
52    $zip->addFile( "${src}/README.md",             "${dir}/README.md" );
53    $zip->addFile( "${src}/resources/systray.ico", "${dir}/systray.ico" );
54    $zip->addFile( "${src}/resources/civetweb_64x64.png",
55        "${dir}/civetweb_64x64.png" );
56    $zip->addFile( "${src}/resources/itworks.html", "${dir}/index.html" );
57    $zip->addFile( "${src}/VS2012/Release/Win32/civetweb_lua.exe",
58        "${dir}/civetweb32.exe" );
59    $zip->addFile( "${src}/VS2012/Release/x64/civetweb_lua.exe",
60        "${dir}/civetweb64.exe" );
61
62    unless ( $zip->writeToFileNamed($archive) == AZ_OK ) {
63        die 'write error';
64    }
65
66}
67
68build32();
69build64();
70writeArchive();
71exit 0;
72