Any way to parse a preprocessed source with an external tool before compiling it?

I want the compiler to pre-process, generate all .i files, as usual, if I just use the “generate pre-processed file” option and then run an external tool, waiting for it to finish, and then continue with compiling these .i files ( which can now be changed, of course).

If this is not possible, is there a way to run an external tool for each file that compiles before preprocessing and compiling? (Perhaps it would be hell to debug in such an environment, but still).

If there is no such option, can it even be done? I mean, does the compiler even use these .i files, or are they just displayed to the user in some way?

Basically, is there a way to automatically interfere with the source code before compiling it, but without changing the actual files?

Just for reference: I'm trying to come up with a clever way to obfuscate all lines with minimal modification to the source.

+2
source share
5 answers

Let x.cpp be your file that you want to reprogram.

  • Set the compiler option to generate pre-processed output for x.cpp, let it be xi
  • Add xi to the project and set the "custom build tool" in the properties. Set the "output files" to x.preprocessed.cpp.
  • Add x.preprocessed.cpp to the project.

See msdn for details .

+3
source

Yes, you just upgrade your build system to have a preprocess step, obfuscate the step, and then the compilation step to the object. By default, most build systems simply combine all of this into one step (and skip the obfuscation step). There should be nothing to do with any “real” build system such as Scons, waf, or even Make.

If you are using Visual Studio, then this is a bit more. Microsoft wants you to write your build operations in MSBuild, and this is pretty much work, IMHO. This is not easy because MSVS is basically an IDE for iterative development and is NOT intended to create a build tool. It will not and never will be a build tool (even if it happens to “build things”, but only standard and very simple “build things”). But you can still use the IDE with another build tool. For example, we use Scons for our assembly and generate MSVS *.sln and *.vcproj , and these files are simply built using Scons (but all files are edited in the MSVS environment).

The simple answer is: your question is just a build problem. This should be very straightforward with any “toy” assembly system.

The distcc (distributed collector) function effectively preprocesses all the files locally, then sends *.i to remote compilers (which do not even require the installation of headers), and then sends *.obj back. So what you say is pretty straight forward.

+4
source

You should be able to run the "Pre-Build Event" and connect any external tools to it. In VS200x, it is located under "Configuration Properties" → "Build Events"> "Pre-Builds."

+1
source

Just use a decent build system. SCons , waf or something else if you don't like these two.

0
source

You can use the make file to generate .i files first, start processing them, and then compile them.

0
source

All Articles