module LangCModule include Process; class LangC def find_compiler print 'Looking for C compiler... '; if $settings.cache['CC'] print '(cached) '; cc = $settings.cache['CC']; elsif ENV['CC'] cc = ENV['CC'] else # Go looking for cc, gcc, then other proprietary compilers guess_compiler = ['gcc', 'cc', 'suncc']; cc = nil; ENV['PATH'].split(':').each {|path| guess_compiler.each {|compiler| begin statbuf = File::stat(path + '/' + compiler); rescue next; end #printf "%s size %d\n", path+'/'+compiler, statbuf.size; cc = compiler; break; } } end $settings.cache['CC'] = 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 + '.c'; 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['CC'], 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', LangC.new; end include LangCModule;