all: sample
-sample: sample.o sample-tp.o
+sample: sample.o sample_tracepoint.o
$(CC) $(LIBS) -o $@ $^
sample.o: sample.c sample_tracepoint.h
$(CC) $(CFLAGS) -c -o $@ $<
-sample-tp.o: sample_tracepoint.c sample_tracepoint.h
- $(CC) $(CFLAGS) -I. -c -o $@ $<
+# Use this command to compile the .c manually
+#sample_tracepoint.o: sample_tracepoint.c sample_tracepoint.h
+# $(CC) $(CFLAGS) -I. -c -o $@ $<
+
+# This rule generate .o only and depends on rules for generating
+# the .h and .c
+%.o: %.tp %.c %.h
+ tools/lttng-gen-tp -o $@ $<
+
+# The following rule can be used to generate all files instead of having one
+# for each file type. Note that the sample.o has a dependency on the
+# .h, so you need to change that if you remove the %.h rule.
+#%.o: %.tp
+# lttng-gen-tp $<
%.h: %.tp
lttng-gen-tp -o $@ $<
+
%.c: %.tp
lttng-gen-tp -o $@ $<
files. It takes a simple template file and generate the necessary code to use the defined tracepoints in your application.
The section TEMPLATE FILE FORMAT describe the content of the template file.
-Currently, the tool can generate the .h and .c associated to your
+Currently, the tool can generate the .h, .c and .o associated to your
tracepoint. The generated .h can be directly included in your application.
-You need to compile the .c into a .o, .a or .so at your choice and
-link it with your application. Refer to the UST documentation for the
+You can let the tool generate the .o or compile the .c yourself.
+You can compile the .c into a .o, .a or .so at your choice and
+link it with your application.
+Refer to the UST documentation for the
advantages and disadvantage of each form.
To compile the resulting .c file, you need to add the options
"-llttng-ust -I."
.TP
.BR "\-o, \-\-output"
Specify the generated file. The type of the generated file depend on the file
-extension (.h, .c).
+extension (.h, .c, .o).
This option can be specfied multiple times to generate different file type.
.PP
-When no output is specified de default files are generated with the same base filename as the template file. The default files are: .h, .c.
+When no output is specified de default files are generated with the same base filename as the template file. The default files are: .h, .c, .o.
.SH "TEMPLATE FILE FORMAT"
ctf_string(message, text)
)
)
+.SH "ENVIRONMENT VARIABLES"
+.PP
+When the tool generate an .o file, it will look for the following environment variables
+.PP
+
+.PP
+.IP "CC"
+Specifer which C compiler to use. If the variable is not specified, the
+tool will try "cc" and "gcc"
+
+.IP "CFLAGS"
+Flags directly passed to the compiler
.SH "SEE ALSO"
.PP
import sys
import getopt
import re
+import os
+import subprocess
class Usage(Exception):
def __init__(self, msg):
headerFilename = headerFilename))
outputFile.close()
+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())
+
class TemplateFile:
def __init__(self, filename):
self.domain = ""
If no OUTPUT_FILE is given, the .h and .c file will be generated.
(The basename of the template file with be used for the generated file.
- for example sample.tp will generate sample.h and sample.c)
+ for example sample.tp will generate sample.h, sample.c and sample.o)
- When using the -o option, the OUTPUT_FILE must end with either .h or .c
+ When using the -o option, the OUTPUT_FILE must end with either .h, .c or .o
The -o option can be repeated multiple times.
The template file must contains TRACEPOINT_EVENT and TRACEPOINT_LOGLEVEL
doCFile = None
doHeader = None
+ doObj = None
headerFilename = None
cFilename = None
+ objFilename = None
if len(outputNames) > 0:
if len(args) > 1:
doCFile = True
cFilename = outputName
elif outputName[-2:] == ".o":
- print "Not yet implemented, sorry"
+ doObj = True
+ objFilename = outputName
else:
print "output file type unsupported"
return(4)
else:
doHeader = True
doCFile = True
+ doObj = True
# process arguments
for arg in args:
curFilename = re.sub("\.tp$",".c",arg)
dotc = CFile(curFilename, tpl)
dotc.write()
+ if doObj:
+ if objFilename:
+ curFilename = objFilename
+ else:
+ curFilename = re.sub("\.tp$",".o",arg)
+ dotobj = ObjFile(curFilename, tpl)
+ dotobj.write()
if __name__ == "__main__":
sys.exit(main())