module LangCPPModule class LangCPP def find_compiler printf 'Looking for C++ compiler... '; if $settings.cache['CXX'] print '(cached) '; cc = $settings.cache['CXX']; elsif ENV['CXX'] cc = ENV['CXX'] else # Go looking for cc, gcc, then other proprietary compilers guess_compiler = ['g++', 'c++', 'null']; cc = nil; ENV['PATH'].split(':').each {|path| guess_compiler.each {|compiler| begin statbuf = File::stat(path + '/' + compiler); rescue next; end cc = compiler; break; } } end $settings.cache['CXX'] = cc; printf "%s\n", cc; end def run_compiler (source, cl_flags=String.new(nil.to_s)) if $rc_show_cc_source printf "\nIt(%d) wants us to linky doo this:%s\n", uid, source; end tmppath = sprintf('/tmp/infile-%s-%s', uid, pid); objpath=tmppath + '.o'; tmppath=tmppath + '.cpp'; if File.exists?(tmppath) printf "\nTemp C++ compiler or object file exists oops.\n"; return 1; else tmpfile = File.open(tmppath, File::CREAT|File::RDWR|File::EXCL, 0600); end tmpfile.print(source + "\n"); tmpfile.close; cflags=''; lflags=''; exec_str = sprintf("%s %s -c %s -o %s %s", $settings.cache['CXX'], cflags, tmppath, objpath, lflags); rcRedirect('/dev/null') { system(exec_str); } retval = $?; begin File.delete(tmppath); File.delete(objpath); rescue ; end # On success return 0, otherwise an error return retval; end end # Register rcRegisterLanguage 'C++', LangCPP.new; end include LangCPPModule;