+class ObjFile:
+ def __init__(self, filename, template):
+ self.outputFilename = filename
+ self.template = template
+ def _detectCC(self):
+ cc = ""
+ if os.environ.has_key('CC'):
+ cc = os.environ['CC']
+ try:
+ subprocess.call(cc,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ except OSError, msg:
+ print "Invalid CC environment variable"
+ cc = ""
+
+ else:
+ # Try c first, if that fails try gcc
+ try:
+ useCC = True
+ subprocess.call("cc",
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ except OSError, msg:
+ useCC = False
+ if useCC:
+ cc = "cc"
+
+ else:
+ try:
+ useGCC = True
+ subprocess.call("gcc",
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ except OSError, msg:
+ useGCC = False
+ if useGCC:
+ cc = "gcc"
+ return cc
+
+ def write(self):
+ cFilename = self.outputFilename.replace(".o",".c")
+ cc = self._detectCC()
+ if cc == "":
+ raise RuntimeError("No C Compiler detected")
+ if os.environ.has_key('CFLAGS'):
+ cflags = os.environ['CFLAGS']
+ else:
+ cflags = ""
+
+ command = cc + " -c " + cflags + " -I. -llttng-ust" + " -o " + self.outputFilename + " " + cFilename
+ subprocess.call(command.split())
+