preprocessor output target
Hi, I apologize if this is not the correct list but maybe someone here can answer ... I have a project that uses autoconf/automake and libtool. I was wondering if there is already a macro that will create Makefile targets for getting the preprocessor output. For example, if I have a source file called init.c, I would like to be able to type something like 'make init.i' and get the output of the preprocessor only (e.g., gcc -E). The main reason is that I want to be able to see the headers that are being included and where they are getting pulled from. Is this already built in to the tools I am using? Thanks. Jason
Re: preprocessor output target
Hello, was wondering if there is already a macro that will create Makefile targets for getting the preprocessor output. For example, if I have a source file called init.c, I would like to be able to type something like 'make init.i' and get the output of the preprocessor only (e.g., gcc -E). The main I'm not aware about anything like that. For my debugging needs, for example, it was always enough to cut and paste the command which failed, with -E, without -c -o something.o and direct the output to less. Stepan Kasal
Re: preprocessor output target
Hi Jason, * Jason Roscoe wrote on Thu, Jun 05, 2008 at 04:13:31PM CEST: I apologize if this is not the correct list It's dead on. In addition to Stepan's answer: The main reason is that I want to be able to see the headers that are being included and where they are getting pulled from. Is this already built in to the tools I am using? Thanks. If all you care about is the set of headers used for init.o, then typically you can peek at the dependency file, .deps/init.Po, which was generated during the last compilation of init.o. Cheers, Ralf
Re: preprocessor output target
Jason Roscoe wrote: I apologize if this is not the correct list but maybe someone here can answer ... I have a project that uses autoconf/automake and libtool. I was wondering if there is already a macro that will create Makefile targets for getting the preprocessor output. For example, if I have a source file called init.c, I would like to be able to type something like 'make init.i' and get the output of the preprocessor only (e.g., gcc -E). The main reason is that I want to be able to see the headers that are being included and where they are getting pulled from. Is this already built in to the tools I am using? Thanks. If you are using gcc then you can add -save-temps to CFLAGS, e.g. rm init.o make CFLAGS=-save-temps -g -O2 Assuming that everything else in the build dir was up-to-date at that point, this will rebuild just init.o but it will leave init.i and init.s as a side effect. The .s assembler output is handy if you want to inspect the code generated by the compiler -- however if that's your intent it's usually easier to read if you omit -g (and add -fverbose-asm.) I find that this method is also handy when debugging. Say that there's a static function in foo.c that the compiler has inlined (or some other condition that generally makes life in the debugger more difficult.) You can simply rebuild foo.o without optimization, leaving everything else the same from the previous build. Note however that if you wish to override a variable on the make command in order to add an option, you have to specify the full contents of the current value (which for CFLAGS is typically -g -O2 if using gcc and you didn't explicitly specify a CFLAGS when configuring.) If you just do make CFLAGS=-save-temps then you lose all the settings that the build system might have added, which could be significant. In those cases where CFLAGS is nontrivial I first look at the generated Makefile to see what the substituted value is, and then to that I add or remove whatever flags I'm interested in. I wish there was a way to invoke make with a += override instead of a = override but this does not exist AFAIK. Brian
Re: preprocessor output target
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Brian Dessent wrote: Note however that if you wish to override a variable on the make command in order to add an option, you have to specify the full contents of the current value (which for CFLAGS is typically -g -O2 if using gcc and you didn't explicitly specify a CFLAGS when configuring.) If you just do make CFLAGS=-save-temps then you lose all the settings that the build system might have added, which could be significant. In those cases where CFLAGS is nontrivial I first look at the generated Makefile to see what the substituted value is, and then to that I add or remove whatever flags I'm interested in. I wish there was a way to invoke make with a += override instead of a = override but this does not exist AFAIK. This is the primary reason, as I understand it, for the statement made in the Autoconf manual that these variables (CFLAGS, LDFLAGS, CC, etc), are User variables, and shouldn't be set to anything by the Autotools. The default for normal builds is usually something simple like -g -O2. Autotools scripts should use tool-specific variables, such as AM_CFLAGS, etc. Regards, John -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.4-svn0 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iD8DBQFISBW4dcgqmRY/OH8RAgEfAKCMYkU5rbvlEh2pZcZoMEquxxqBswCfQd96 PVRnKYjMvd/Ug8fI2+Eo23A= =CaLJ -END PGP SIGNATURE-
Re: preprocessor output target
On Thu, Jun 05, 2008 at 09:19:31AM -0700, Brian Dessent wrote: If you are using gcc then you can add -save-temps to CFLAGS, e.g. rm init.o make CFLAGS=-save-temps -g -O2 Assuming that everything else in the build dir was up-to-date at that point, this will rebuild just init.o but it will leave init.i and init.s as a side effect. The .s assembler output is handy if you want to inspect the code generated by the compiler -- however if that's your intent it's usually easier to read if you omit -g (and add -fverbose-asm.) I find that this method is also handy when debugging. Say that there's a static function in foo.c that the compiler has inlined (or some other condition that generally makes life in the debugger more difficult.) You can simply rebuild foo.o without optimization, leaving everything else the same from the previous build. Note however that if you wish to override a variable on the make command in order to add an option, you have to specify the full contents of the current value (which for CFLAGS is typically -g -O2 if using gcc and you didn't explicitly specify a CFLAGS when configuring.) If you just do make CFLAGS=-save-temps then you lose all the settings that the build system might have added, which could be significant. In those cases where CFLAGS is nontrivial I first look at the generated Makefile to see what the substituted value is, and then to that I add or remove whatever flags I'm interested in. I wish there was a way to invoke make with a += override instead of a = override but this does not exist AFAIK. I use this technique as well, for a C++ app I'm working on. The way I get around this limitation is this: Our makefiles set up CXXFLAGS with some extensive modifications, but they don't touch CPPFLAGS. It seems as if the Makefiles are passing both CXXFLAGS and CPPFLAGS to g++, so I'm able to do: make CPPFLAGS=-save-temps ...and get exactly what I want. I don't think there's an analogue for CFLAGS, but this might help C++ guys. As an aside, the += capability would still be very nice to see. Mike
Re: preprocessor output target
Ralf Wildenhues wrote: Hi Jason, * Jason Roscoe wrote on Thu, Jun 05, 2008 at 04:13:31PM CEST: I apologize if this is not the correct list It's dead on. In addition to Stepan's answer: The main reason is that I want to be able to see the headers that are being included and where they are getting pulled from. Is this already built in to the tools I am using? Thanks. If all you care about is the set of headers used for init.o, then typically you can peek at the dependency file, .deps/init.Po, which was generated during the last compilation of init.o. Cheers, Ralf Ok, the .deps directory is indeed useful for what I am trying to find out. And, I do have lots of experience doing exactly what Stepan mentioned but now that technique is getting to be too complicated with the large compile lines I have (and with libtool in the mix). Thanks for the tips.
Re: preprocessor output target
* Jason Roscoe wrote on Thu, Jun 05, 2008 at 09:00:16PM CEST: What is the equivalent to: rm init.o make init.o when using libtool? rm init.lo make init.lo will possible recreate init.o, .libs/init.o, and init.lo. The latter is merely a small helper script. BTW, you should note that if you use per-target flags, your intermediate object files may have been renamed to something like program_init.o or similar. In that case it is important that you remake these, as making init.o may use different flags. Cheers, Ralf
Re: preprocessor output target
Brian Dessent wrote: If you are using gcc then you can add -save-temps to CFLAGS, e.g. rm init.o make CFLAGS=-save-temps -g -O2 Assuming that everything else in the build dir was up-to-date at that point, this will rebuild just init.o but it will leave init.i and init.s as a side effect. The .s assembler output is handy if you want to inspect the code generated by the compiler -- however if that's your intent it's usually easier to read if you omit -g (and add -fverbose-asm.) I find that this method is also handy when debugging. Say that there's a static function in foo.c that the compiler has inlined (or some other condition that generally makes life in the debugger more difficult.) You can simply rebuild foo.o without optimization, leaving everything else the same from the previous build. Note however that if you wish to override a variable on the make command in order to add an option, you have to specify the full contents of the current value (which for CFLAGS is typically -g -O2 if using gcc and you didn't explicitly specify a CFLAGS when configuring.) If you just do make CFLAGS=-save-temps then you lose all the settings that the build system might have added, which could be significant. In those cases where CFLAGS is nontrivial I first look at the generated Makefile to see what the substituted value is, and then to that I add or remove whatever flags I'm interested in. I wish there was a way to invoke make with a += override instead of a = override but this does not exist AFAIK. Brian This is excellent. I was not aware of the '-save-temps' gcc option. And thanks for reminding me about overriding the configured CFLAGS. Normally, if I am interested in the preprocessor output it is only temporary while I am trying to debug the compile. Anyway, your suggestion about removing the .o brings me to another question which might be better suited for the libtool list but I'm sure someone on here can answer it. I am using libtool in my example and so I do not have an init.o object. What is the equivalent to: rm init.o make init.o when using libtool? Thanks for the help. Jason
Re: preprocessor output target
Jason Roscoe [EMAIL PROTECTED] writes: For example, if I have a source file called init.c, I would like to be able to type something like 'make init.i' and get the output of the preprocessor only (e.g., gcc -E). I sometimes do: rm init.o make CC='gcc -E' init.o mv init.o init.i -- Ben Pfaff http://benpfaff.org