@@ -11,10 +11,20 @@ def initialize(info = {})
1111 super
1212 register_options ( [
1313 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' ] ] ) ,
1515 ] , self . class )
1616 end
1717
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+
1828 def live_compile?
1929 return false unless %w{ Auto True } . include? ( datastore [ 'COMPILE' ] )
2030
@@ -24,6 +34,8 @@ def live_compile?
2434 elsif datastore [ 'COMPILER' ] == 'clang' && has_clang?
2535 vprint_good 'clang is installed'
2636 return true
37+ elsif datastore [ 'COMPILER' ] == 'Auto' && get_compiler . present?
38+ return true
2739 end
2840
2941 unless datastore [ 'COMPILE' ] == 'Auto'
@@ -36,7 +48,13 @@ def live_compile?
3648 def upload_and_compile ( path , data , compiler_args = '' )
3749 write_file "#{ path } .c" , strip_comments ( data )
3850
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'"
4058 if session . type == 'shell'
4159 compiler_cmd = "PATH=\" $PATH:/usr/bin/\" #{ compiler_cmd } "
4260 end
0 commit comments