-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathBuild.pl
More file actions
116 lines (104 loc) · 4.5 KB
/
Copy pathBuild.pl
File metadata and controls
116 lines (104 loc) · 4.5 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
################################################################################
# (c) 2005-2014 Copyright, Real-Time Innovations, Inc. All rights reserved.
# RTI grants Licensee a license to use, modify, compile, and create derivative
# works of the Software. Licensee has the right to distribute object form only
# for use with RTI products. The Software is provided "as is", with no warranty
# of any type, including any warranty for fitness for any purpose. RTI is under
# no obligation to maintain or support the Software. RTI shall not be liable
# for any incidental or consequential damages arising out of the use or
# inability to use the software.
################################################################################
#!C:/Perl64/bin/perl.exe -w
use Cwd;
# The first command prompt argument is the directory to check
$ARCHITECTURE = $ARGV[0];
if ($ARCHITECTURE eq "") {
print "ERROR: You have to write an architecture to run this script, e.g.:\n";
print "\tperl ./scripts/Build.pl i86Win32VS2010\n";
exit(-1);
}
if (!defined $ENV{'NDDSHOME'}) {
print "ERROR: You have to set NDDSHOME environment variable\n";
exit(-1);
}
system "cmake -H./src -B./projects -DARCHITECTURE=" . $ARCHITECTURE;
if ( $? != 0 ) {
print "ERROR trying to execute cmake\n";
exit(1);
}
# $OS is the operating system
$OS = $^O;
# if the operating system is windows, then we will use the msbuild compiler,
# else will use make
if ($OS =~ /[\s\S]*?Win[\s\S]*?/) {
system "msbuild ./projects/ChocolateFactory.sln";
if ( $? != 0 ) {
print "ERROR compiling ./projects/ChocolateFactory.sln example\n";
exit(1);
}
create_running_scripts("./scripts/ChocolateFactory_windows.txt",
"StationController", $ARCHITECTURE, "StationController");
create_running_scripts("./scripts/ChocolateFactory_windows.txt",
"RecipeGenerator", $ARCHITECTURE, "RecipeGenerator");
create_running_scripts("./scripts/ChocolateFactory_windows.txt",
"ManufacturingExecutionSystem", $ARCHITECTURE, "MES");
create_running_scripts("./scripts/ChocolateFactory_windows.txt",
"StationController", $ARCHITECTURE, "AllStationController");
print "\nCreated running scripts\n";
} elsif ($OS eq "linux") {
chdir "./projects";
system "make";
if ( $? != 0 ) {
print "ERROR compiling ChocolateFactory example\n";
exit(1);
}
chdir "..";
create_running_scripts("./scripts/ChocolateFactory_linux.txt",
"StationController", $ARCHITECTURE, "StationController");
create_running_scripts("./scripts/ChocolateFactory_linux.txt",
"RecipeGenerator", $ARCHITECTURE, "RecipeGenerator");
create_running_scripts("./scripts/ChocolateFactory_linux.txt",
"ManufacturingExecutionSystem", $ARCHITECTURE, "MES");
create_running_scripts("./scripts/ChocolateFactory_linux.txt",
"StationController", $ARCHITECTURE, "AllStationController");
print "\nCreated running scripts\n";
} elsif ($OS eq "darwin") {
chdir "./projects";
system "make";
if ( $? != 0 ) {
print "ERROR compiling ChocolateFactory example\n";
exit(1);
}
chdir "..";
create_running_scripts("./scripts/ChocolateFactory_linux.txt",
"StationController", $ARCHITECTURE, "StationController");
create_running_scripts("./scripts/ChocolateFactory_linux.txt",
"RecipeGenerator", $ARCHITECTURE, "RecipeGenerator");
create_running_scripts("./scripts/ChocolateFactory_linux.txt",
"ManufacturingExecutionSystem", $ARCHITECTURE, "MES");
create_running_scripts("./scripts/ChocolateFactory_linux.txt",
"StationController", $ARCHITECTURE, "AllStationController");
print "\nCreated running scripts\n";
}
sub create_running_scripts {
my ($template_name, $exe_name, $arch, $script_name) = @_;
open(my $fh, '<:utf8', $template_name)
or die "Could not open file '$template_name' $!";
# To copy all the file in a string
local $/ = undef;
$buffer = <$fh>;
$buffer =~ s/\$\{ARCHITECTURE\}/$arch/g;
$buffer =~ s/\$\{EXE_NAME\}/$exe_name/g;
close $fh;
if ($OS =~ /[\s\S]*?Win[\s\S]*?/) {
$new_file = "./scripts/$script_name" . ".bat";
$exe_name = $exe_name . ".exe";
} else {
$new_file = "./scripts/$script_name" . ".sh";
}
open(my $fh, '>:utf8', $new_file)
or die "Could not create file <$script_name> $!";
chmod 0775, $new_file;
print $fh $buffer;
close $fh;
}