Is there a best practice for supporting C / C ++ preprocessor flag dependencies like -DCOMPILE_WITHOUT_FOO ? Here is my problem:
> setenv COMPILE_WITHOUT_FOO > make <Make system reads environment, sets -DCOMPILE_WITHOUT_FOO> <Compiles nothing, since no source file has changed>
I would like all files that rely on #ifdef statements to #ifdef recompiled:
> setenv COMPILE_WITHOUT_FOO > make g++ FileWithIfdefFoo.cpp
I do not want to recompile everything if the COMPILE_WITHOUT_FOO value has not changed.
I have a primitive Python script working (see below) that basically writes the header file FooDefines.h and then delimits it to see something else. If so, it replaces FooDefines.h , and then the usual dependency of the source file begins to be used. The definition is not passed on the command line with -D . The downside is that now I have to include FooDefines.h in any source file that uses #ifdef , and also I have a new dynamically generated header file for each #ifdef . If there is a tool for this or a way to avoid using a preprocessor, I'm all ears.
import os, sys def makeDefineFile(filename, text): tmpDefineFile = "/tmp/%s%s"%(os.getenv("USER"),filename) #Use os.tempnam? existingDefineFile = filename output = open(tmpDefineFile,'w') output.write(text) output.close() status = os.system("diff -q %s %s"%(tmpDefineFile, existingDefineFile)) def checkStatus(status): failed = False if os.WIFEXITED(status): #Check return code returnCode = os.WEXITSTATUS(status) failed = returnCode != 0 else: #Caught a signal, coredump, etc. failed = True return failed,status #If we failed for any reason (file didn't exist, different, etc.) if checkStatus(status)[0]: #Copy our tmp into the new file status = os.system("cp %s %s"%(tmpDefineFile, existingDefineFile)) failed,status = checkStatus(status) print failed, status if failed: print "ERROR: Could not update define in makeDefine.py" sys.exit(status)
Walter nissen
source share