@@ -11,10 +11,20 @@ def initialize(info = {})
11
11
super
12
12
register_options ( [
13
13
OptEnum . new ( 'COMPILE' , [ true , 'Compile on target' , 'Auto' , [ 'Auto' , 'True' , 'False' ] ] ) ,
14
- OptEnum . new ( 'COMPILER' , [ true , 'Compiler to use on target' , 'gcc ' , [ 'gcc' , 'clang' ] ] ) ,
14
+ OptEnum . new ( 'COMPILER' , [ true , 'Compiler to use on target' , 'Auto ' , [ 'Auto' , 'gcc' , 'clang' ] ] ) ,
15
15
] , self . class )
16
16
end
17
17
18
+ def get_compiler
19
+ if has_gcc?
20
+ return 'gcc'
21
+ elsif has_clang?
22
+ return 'clang'
23
+ else
24
+ return nil
25
+ end
26
+ end
27
+
18
28
def live_compile?
19
29
return false unless %w{ Auto True } . include? ( datastore [ 'COMPILE' ] )
20
30
@@ -24,6 +34,8 @@ def live_compile?
24
34
elsif datastore [ 'COMPILER' ] == 'clang' && has_clang?
25
35
vprint_good 'clang is installed'
26
36
return true
37
+ elsif datastore [ 'COMPILER' ] == 'Auto' && get_compiler . present?
38
+ return true
27
39
end
28
40
29
41
unless datastore [ 'COMPILE' ] == 'Auto'
@@ -36,7 +48,13 @@ def live_compile?
36
48
def upload_and_compile ( path , data , compiler_args = '' )
37
49
write_file "#{ path } .c" , strip_comments ( data )
38
50
39
- compiler_cmd = "#{ datastore [ 'COMPILER' ] } -o '#{ path } ' '#{ path } .c'"
51
+ compiler = datastore [ 'COMPILER' ]
52
+ if datastore [ 'COMPILER' ] == 'Auto'
53
+ compiler = get_compiler
54
+ fail_with ( Module ::Failure ::BadConfig , "Unable to find a compiler on the remote target." ) unless compiler . present?
55
+ end
56
+
57
+ compiler_cmd = "#{ compiler } -o '#{ path } ' '#{ path } .c'"
40
58
if session . type == 'shell'
41
59
compiler_cmd = "PATH=\" $PATH:/usr/bin/\" #{ compiler_cmd } "
42
60
end
0 commit comments