Reputation: 1375
When I execute several different compilation commands via a makefile on one specific sourcecode (c-code). Is there a way to add these compilation commands as a comment to the source code for documentation reason?
Upvotes: 2
Views: 122
Reputation: 99084
Maybe I misunderstand the question, but this doesn't seem too difficult:
foo.o: foo.cc
@command="$(CXX) $(CPPFLAGS) -c $< -o $@"; echo $$command ;\
sed -i .bak "1{x;s|^|//$$command|;G;}" $< ; \
$$command
Upvotes: 0
Reputation: 409136
You can do it by adding a preprocessor macro defined as a string containing the compiler flags, and then use this macro in an assignment to a constant string pointer.
Something like this in the Makefile
$(CC) $(CFLAGS) -DCFLAGS="$(CFLAGS)" ...
And in one source file do e.g.
const char cflags[] = CFLAGS;
There is no generic way to get it as a part of a comment though.
You could have a special marker in a comment block in a source file, and replace that using e.g. sed
in a POSIX enviromnent (like Linux or OSX).
Something like this:
sed -i.bak -e 's@// CFLAGS: .*$@// CFLAGS: $(CFLAGS)@' some_source_file.c
Upvotes: 3