List Info

Thread: Creating a header to be automatically included in all source files




Creating a header to be automatically included in all source files
user name
2006-12-11 17:32:25
I'd like to make a target that would work something like
this:

    endian foo : <endian-little>IS_LITTLE_ENDIAN
<endian-bin>IS_BIG_ENDIAN ;


It would generate a header file that would be like this:

    #ifndef _BJAM_FOO_CONFIG_H_
    #define _BJAM_FOO_CONFIG_H_
    #ifdef __APPLE__
    #       ifdef __BIG_ENDIAN__
    #               define IS_BIG_ENDIAN 1
    #       elif defined(__LITTLE_ENDIAN__)
    #               define IS_LITTLE_ENDIAN 1
    #       endif
    #endif
    #endif /* _BJAM_FOO_CONFIG_H_ */


The target would have <dependency>bjam_foo_config.h, 
<implicit-dependency>bjam_foo_config.h, and 
<forced-include>bjam_foo_config.h in its usage
requirements so that a 
target that put it in its sources would build it and include
it while 
compiling source files.

The <forced-include> would translate to the -include
option for gcc and 
the -FI option for msvc, both of which make the compiler act
is if the 
header file were included on the first line of each file
compiled.

The reason I'd like to do this is that I'm compiling
"universal" builds 
on Mac OS X.  When you pass in "-arch i386 -arch
ppc", it calls the 
compiler twice, once with __BIG_ENDIAN__ defined and once
with 
__LITTLE_ENDIAN__ defined.  It generates a single
"fat"/"universal" .o 
file.  Since I'm only running the compiler once, I obviously
can't pass 
in the defines the third-party library wants on the
command-line, but I 
don't want to modify (and potentially miss a file) the
third-party sources.

It also helps with my goal of modifying third-party library 
distributions as little as possible.  

I've been looking through some of the other .jam files in
the tools 
directory to see if I can find what I need, but I'm not sure
what to 
override in a new target, how to get the output filename for
use in the 
usage requirements, where to determine the usage
requirements, etc.

If someone could give me some pointers, I'd really
appreciate it.

Thanks,

Phillip
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost-build
Creating a header to be automatically included in all source files
user name
2006-12-12 03:31:03
Phillip Seaver wrote:
> The <forced-include> would translate to the
-include option for gcc and 

Instead of having to add a new feature you could add
<cxxflags> and/or 
<cflags> to the usage requirements.

> It also helps with my goal of modifying third-party
library 
> distributions as little as possible.  

I have the same goal in the third-party libs I use and
build.

> If someone could give me some pointers, I'd really
appreciate it.

For the generation of the file itself take a look at the
wxWidgets 
support I wrote in the vault 
<http://boost-consulting.com/va
ult/index.php?&directory=Tools/Build/grafik>. 
It creates the wx/setup.h dynamically using the built in
"make" target. 
With the added <implicit-dependency> the directory
where the generated 
header is added to the include path automatically so you
only need to 
specify the name of the header file, without the path, in
the flags. I 
have more complicated example of using this technique to
also generate 
source files to compile that do things like predef and
include other 
sources so that I can do things like disable and rewrite
parts of the 
thrid-party libs.


-- 
-- Grafik - Don't Assume Anything
-- Redshift Software, Inc. - http://redshift-software
.com
-- rrivera/acm.org - grafik/redshift-software.com
-- 102708583/icq - grafikrobot/aim - grafikrobot/yahoo
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost-build
Creating a header to be automatically included in all source files
user name
2006-12-12 17:14:23
Rene Rivera wrote, on 12/11/2006 10:31 PM:
> For the generation of the file itself take a look at
the wxWidgets 
> support I wrote in the vault 
> <http://boost-consulting.com/va
ult/index.php?&directory=Tools/Build/grafik>. 
> It creates the wx/setup.h dynamically using the built
in "make" target. 
> With the added <implicit-dependency> the
directory where the generated 
> header is added to the include path automatically so
you only need to 
> specify the name of the header file, without the path,
in the flags. I 
> have more complicated example of using this technique
to also generate 
> source files to compile that do things like predef and
include other 
> sources so that I can do things like disable and
rewrite parts of the 
> thrid-party libs.

Actually, I already stole your setup.h code.    It's just
that I'm 
using it in 5 different projects so far, and I'd like to
make a 
rule/target that encapsulates all that to make it simpler
and keep my 
projects easier to read.  I'm going to go ahead with that
and change it 
to use the rule if I ever get it written.

Thanks,

Phillip
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost-build
Creating a header to be automatically included in all source files
user name
2006-12-26 22:43:04
On Monday 11 December 2006 20:32, Phillip Seaver wrote:

[personal cc for convenience, please reply to list]

> I'd like to make a target that would work something
like this:
> 
>     endian foo : <endian-little>IS_LITTLE_ENDIAN
<endian-bin>IS_BIG_ENDIAN ;
> 
> 
> It would generate a header file that would be like
this:
> 
>     #ifndef _BJAM_FOO_CONFIG_H_
>     #define _BJAM_FOO_CONFIG_H_
>     #ifdef __APPLE__
>     #       ifdef __BIG_ENDIAN__
>     #               define IS_BIG_ENDIAN 1
>     #       elif defined(__LITTLE_ENDIAN__)
>     #               define IS_LITTLE_ENDIAN 1
>     #       endif
>     #endif
>     #endif /* _BJAM_FOO_CONFIG_H_ */
> 
> 
> The target would have
<dependency>bjam_foo_config.h, 
> <implicit-dependency>bjam_foo_config.h, and 
> <forced-include>bjam_foo_config.h in its usage
requirements so that a 
> target that put it in its sources would build it and
include it while 
> compiling source files.

I suspect that you don't need both <dependency> and
<implicit-dependency>.
The former unconditionally sets up a dependency, so the
latter does not
adds anything.

> The <forced-include> would translate to the
-include option for gcc and 
> the -FI option for msvc, both of which make the
compiler act is if the 
> header file were included on the first line of each
file compiled.

Did you implement such feature?

> It also helps with my goal of modifying third-party
library 
> distributions as little as possible.  
> 
> I've been looking through some of the other .jam files
in the tools 
> directory to see if I can find what I need, but I'm not
sure what to 
> override in a new target, how to get the output
filename for use in the 
> usage requirements, where to determine the usage
requirements, etc.
> 
> If someone could give me some pointers, I'd really
appreciate it.

Start with example/generator. Make the 'run' method just
call the base method
and return the result.

After that, modify the method so that it:

	1. Takes first element returned by the base method -- which
should be a target.
	2. Creates a property-set with

			<dependency> $(that-target-returned-by-base-rule)

	3. Return

		$(property-set-created-in-2)
$(targets-returned-in-the-base-method)

Once you implement <force-include> -- which should be
a dependency feature,
and the extender manual describes how to add those -- you
should also
create <force-include> in (2).

To clarify, if the first element in the return value of then
run method is a property-set,
it is taken to contain extra usage requirements this
generator wants to return
to dependents.

Hope this help. Ask if something is not clear.

- Volodya
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost-build
[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )