-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathbuild.pl
More file actions
executable file
·131 lines (107 loc) · 3.36 KB
/
build.pl
File metadata and controls
executable file
·131 lines (107 loc) · 3.36 KB
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
#!/usr/bin/env perl
use Cwd qw(getcwd);
use File::Path qw(make_path);
use File::Spec;
use Getopt::Long qw(:config gnu_getopt);
my $help = 0;
my $vis_studio = undef;
my $jdk_home = undef;
my $result = GetOptions(
"h|help" => \$help,
"j|jdk-home=s" => \$jdk_home,
"v|visual-studio=s" => \$vis_studio,
);
if ($help) {
usage();
}
if (not defined $jdk_home) {
usage("-j <jdk-home> is required");
}
if (not defined $vis_studio) {
usage("-v <visual-studio-ide-dir> is required");
}
$jdk_home = File::Spec->canonpath($jdk_home);
$ENV{'TEMP'} = File::Spec->canonpath(File::Spec->catdir(getcwd()), 'target', 'msbuild');
make_path($ENV{'TEMP'});
my $contents = "";
print "Updating JAVA_HOME in build files...\n";
open (FILEIN, "win32/jicmp.vcxproj") or die "unable to read from jicmp.vcxproj: $!";
while (my $line = <FILEIN>) {
$line =~ s,C\:\\Program Files\\Java\\jdk1\.6\.0_30,${jdk_home},g;
$contents .= $line;
}
close (FILEIN) or die "unable to close jicmp.vcxproj: $!";
open (FILEOUT, '>win32/jicmp.vcxproj') or die "unable to write to jicmp.vcxproj: $!";
print FILEOUT $contents;
close (FILEOUT);
print "Building Java Code\n";
mkdir("classes");
run("$jdk_home\\bin\\javac", "-d", "classes", "-sourcepath", "src/main/java", "src/main/java/org/opennms/protocols/icmp/IcmpSocket.java");
print "Generating JNI Headers\n";
run("$jdk_home\\bin\\javah","-classpath", "classes", "org.opennms.protocols.icmp.IcmpSocket");
print "Building x86 MSM Modules\n";
run("$vis_studio\\devenv", ".\\win32\\jicmp.sln", "/out", "release-win32.out", "/log", "release-win32.log", "-rebuild", "Release|Win32");
print "Building x64 MSM Modules\n";
run("$vis_studio\\devenv", ".\\win32\\jicmp.sln", "/out", "release-x64.out", "/log", "release-x64.log", "-rebuild", "Release|x64");
sub run {
print(join(" ", @_));print("...");
handle_errors_and_exit_on_failure(system(@_));
print("done.\n");
}
sub print_logfiles {
for my $type ('win32', 'x64') {
for my $ext ('out', 'log') {
my $file = 'release-' . $type . '.' . $ext;
if (-e $file) {
error($file . " contents:");
open (FILEIN, $file);
while (my $line = <FILEIN>) {
chomp($line);
error($line);
}
close (FILEIN);
}
}
}
}
sub handle_errors {
my $exit = shift;
if ($exit == 0) {
info("finished successfully");
} elsif ($exit == -1) {
error("failed to execute: $!");
print_logfiles();
} elsif ($exit & 127) {
error("child died with signal " . ($exit & 127));
print_logfiles();
} else {
error("child exited with value " . ($exit >> 8));
print_logfiles();
}
return $exit;
}
sub handle_errors_and_exit_on_failure {
my $exit = handle_errors(@_);
if ($exit != 0) {
exit ($exit >> 8);
}
}
sub usage {
my $error = shift;
print <<END;
usage: $0 [-h] -j <jdk-home> -v visual_studio
-h : print this help
-j : Home Directory of JDK
-v : IDE directory for Visual Studio
END
if (defined $error) {
print "ERROR: $error\n\n";
}
exit 1;
}
sub error {
print "[ERROR] " . join(' ', @_) . "\n";
}
sub info {
print "[INFO] " . join(' ', @_) . "\n";
}