this repo has no description
1#!/usr/bin/perl -w
2
3##################################################################
4#
5# Convenince script to invoke make on CMake projects for Android
6# for each architecture and build them.
7# Copyright (C) PlayControl Software, LLC.
8# Eric Wing <ewing . public @ playcontrol.net>
9#
10##################################################################
11
12
13use strict;
14use warnings;
15
16# Function to help with command line switches
17use Getopt::Long;
18# Allows extra "unknown options" to be specified which I will use to pass directly to the cmake executable.
19Getopt::Long::Configure("pass_through");
20
21# Function to get the basename of a file
22use File::Basename;
23# Used for tilde expansion
24use File::Glob;
25
26# Provides functions to convert relative paths to absolute paths.
27use Cwd;
28
29# Global constants
30my %kArchToDirectoryNameMap =
31(
32# mips => "mips",
33 armeabi => "armeabi",
34 "armeabi-v7a" => "armeabi-v7a",
35# "armeabi-v7a with NEON" => "armeabi-v7a",
36# "armeabi-v7a with VFPV3" => "armeabi-v7a",
37# "armeabi-v6 with VFP" => "armeabi",
38 x86 => "x86"
39);
40
41# Global constants
42my %kArchToCompilerNameMap =
43(
44# mips => "mips",
45 armeabi => "arm-linux-androideabi",
46 "armeabi-v7a" => "arm-linux-androideabi",
47# "armeabi-v7a with NEON" => "armeabi",
48# "armeabi-v7a with VFPV3" => "armeabi",
49# "armeabi-v6 with VFP" => "armeabi",
50 x86 => "x86"
51);
52
53
54my @kSupportedArchitectures =
55(
56# "mips",
57 "armeabi",
58 "armeabi-v7a",
59# "armeabi-v7a with NEON",
60# "armeabi-v7a with VFPV3",
61# "armeabi-v6 with VFP",
62 "x86",
63);
64
65
66# Function prototypes
67
68# main routine
69sub main();
70# call main
71main();
72
73sub main()
74{
75 my ($targetdir, $make, @remaining_options) = extract_parameters();
76 # Save in case we need to return to the original current working directory.
77# my $original_current_working_directory = Cwd::cwd();
78
79# print("targetdir: ", $targetdir, "\n");
80# print("make: ", $make, "\n");
81# print("remaining_options: ", @remaining_options, "\n");
82
83
84 foreach my $arch(@kSupportedArchitectures)
85 {
86 chdir($targetdir) or die("Could not change directory to $targetdir: $!\n");
87 my $arch_dir = $kArchToDirectoryNameMap{$arch};
88 print("Building $arch\n");
89 chdir($arch_dir) or die("Could not change directory to $arch_dir: $!\n");
90
91 my $error_status = system($make, @remaining_options);
92 if($error_status != 0)
93 {
94 die "Invoking make failed: $?\n";
95 }
96
97 }
98
99 return;
100
101}
102
103
104sub helpmenu()
105{
106 my $basename = basename($0);
107 print "Convenience script for invoking make on CMake based projects for Android (multiple architectures).\n\n";
108
109 print "Usage: perl $basename [-h | -help] --targetdir=<path to build dir> [--make=<Make exectuable>] [<other flags passed to Make>]\n";
110
111 print "Options:\n";
112 print " -h or -help Brings up this help display.\n";
113 print " --targetdir=<path to build directory> (Optional) Path to where the root of the build directory is. Default is the current working directory.\n";
114 print " --make=<Make executable> (Optional) Allows you to specify the path and file to the Make executable.\n";
115 print "\n";
116 print "Example Usage:\n";
117 print "$basename clean\n";
118 print "$basename VERBOSE=1\n";
119
120 return;
121}
122
123sub home_dir()
124{
125 return File::Glob::bsd_glob("~");
126}
127
128sub expand_tilde($)
129{
130 my $path = shift;
131 my $home_dir = home_dir();
132
133 $path =~ s/^~/$home_dir/;
134 return $path;
135}
136
137sub absolute_path($)
138{
139 my $file = shift;
140 return Cwd::abs_path(expand_tilde($file));
141}
142
143# Subroutine to extract and process command line parameters
144sub extract_parameters()
145{
146 my %params = (
147 h => \(my $hflag = 0),
148 help => \(my $helpflag = 0),
149 targetdir => \(my $targetdir),
150 make => \(my $make)
151 );
152
153 # Call Library function which will extract and remove all switches and
154 # their corresponding values.
155 # These parameters will be removed from @ARGV
156 my $errorval = &GetOptions(\%params, "h", "help",
157 "targetdir=s",
158 "make=s"
159 );
160 # the exclaimation point allows for the negation
161 # of the switch (i.e. -nobackup/-nobody is a switch)
162
163
164 # Error value should have returned 1 if nothing went wrong
165 # Otherwise, an unlisted parameter was specified.
166 if($errorval !=1)
167 {
168 # Expecting GetOptions to state error.
169
170 print "Exiting Program...\n";
171 exit 0;
172 }
173
174 if( ($hflag == 1) || ($helpflag == 1) )
175 {
176 helpmenu();
177 exit 0;
178 }
179
180 if(not defined($targetdir))
181 {
182 $targetdir = Cwd::cwd();
183 }
184
185 if(not defined($make))
186 {
187 $make = "make";
188 }
189 else
190 {
191 $make = absolute_path($make);
192 }
193 $targetdir = absolute_path($targetdir);
194
195 my @remaining_options = @ARGV;
196 my @sorted_options = ($targetdir, $make, @remaining_options);
197
198 return @sorted_options;
199}
200
201