+
+class ObjFile:
+ def __init__(self, filename, template):
+ self.outputFilename = filename
+ self.template = template
+
+ def _detectCC(self):
+ cc = ""
+ if 'CC' in os.environ:
+ cc = os.environ['CC']
+ try:
+ subprocess.call(cc.split(),
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ except OSError as 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 as msg:
+ useCC = False
+ if useCC:
+ cc = "cc"
+
+ else:
+ try:
+ useGCC = True
+ subprocess.call("gcc",
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ except OSError as msg:
+ useGCC = False
+ if useGCC:
+ cc = "gcc"
+ return cc
+
+ def write(self):
+ cFilename = self.outputFilename
+ if cFilename.endswith(".o"):
+ cFilename = cFilename[:-2] + ".c"
+
+ cc = self._detectCC()
+ if cc == "":
+ raise RuntimeError("No C Compiler detected")
+ if 'CPPFLAGS' in os.environ:
+ cppflags = " " + os.environ['CPPFLAGS']
+ else:
+ cppflags = ""
+ if 'CFLAGS' in os.environ:
+ cflags = " " + os.environ['CFLAGS']
+ else:
+ cflags = ""
+ if 'LDFLAGS' in os.environ:
+ ldflags = " " + os.environ['LDFLAGS']
+ else:
+ ldflags = ""
+
+ command = cc + " -c" + cppflags + cflags + ldflags + " -I. -llttng-ust" + " -o " + self.outputFilename + " " + cFilename
+ if verbose:
+ print("Compile command: " + command)
+ subprocess.call(command.split())
+
+