[Scons-users] Doing a build time Glob()

William Deegan bill at baddogconsulting.com
Fri Nov 29 14:03:37 EST 2013


Pico,

On Nov 29, 2013, at 6:52 AM, Pico Geyer <picogeyer at gmail.com> wrote:


> On Fri, Nov 29, 2013 at 2:10 AM, Bill Deegan <bill at baddogconsulting.com> wrote:

> Marc,

>

> In your example A install a bunch,etc.. make will not know about the dependencies until you run make again.

>

> Hi Bill,

>

> I don't know if this is exactly what Marc was referring to, but I'd like to provide my own example of how Make does not require you to specify all the dependencies explicitly.

> Perhaps you can help me clear up my misunderstanding.

> I'll just paste my sample code here but let me know if you'd like a tarball.

> So here's the Makefile:

> ### Code start ###

> all: test

> test: myhdrs

> gcc -Iinc -o test test.c

> myhdrs: genhdrs

> mkdir -p inc

> cp build_dir/*.h inc/

> genhdrs:

> ./genhdrs.py

> clean:

> rm -rf inc build_dir test test.o

> .PHONY : genhdrs clean

> ### Code end ###

>

> genhdrs.py is just a very simple script that generates some headers for us:

> ### Code start ###

> import os

> for i in range(10):

> if not os.path.exists('build_dir'):

> os.mkdir('build_dir')

> f = open('build_dir/hdr{}.h'.format(i),'w')

> f.write('#define num{} {}\n'.format(i,i))

> f.close()

> ### Code end ###

>

> And then we have our test app (test.c):

> ### Code start ###

> #include <stdio.h>

> #include "hdr1.h"

> #include "hdr3.h"

> int main()

> {

> printf("the value of num1 is %d\n", num1);

> }

> ### Code end ###

>

> Now when we run make, it manages to copy and install the headers without actually knowing in advance what header files we were going to put in build_dir:

> % make

> ./genhdrs.py

> mkdir -p inc

> cp build_dir/*.h inc/

> gcc -Iinc -o test test.c

>

> So this might seem like a contrived example but this is exactly what's going to happen when your software depends on some third party library.

> Lets say for example we want to build our application with a certain version of boost.

> So we run the boost build commands in a Command builder:

>

> env.Command('some/install/dir/.boost_built', [],

> ['./bootstrap.sh --prefix=some/install/dir',

> './b2 install'])

>

> Now we might want to only Install() a subset of the libraries that get produced in some/install/dir/lib to be packaged into your final application.

> I would have thought this would be a very common thing to do with a build system.

> So is Marc correct in saying that there is no way to do that without listing every single file that boost produces?

> Is there no "pattern" on how to do this without shooting yourself in the foot?



You can make an Alias() whose action is genhdrspy and then you'd have to make all your source or perhaps your object files Depend() on that alias.
That might do it.
To be clear, what you are doing above is an inexact description of the dependency graph of your build.
It may be good enough, but it's not complete.

That said if your genhdrs.py script's output is easy to predict, then an emitter for a builder which runs this action could be written to fill in the blanks on the generated file(s).

To be clear I'm not saying I don't understand your desire to have a simplified Sconstruct/SConscript(s), I'm saying that such a build system would not be complete without the list of files generated at each step,
Also I don't know of any build system which does scan (for example) an output directory after a tool is run to add those files to it's dependency graph. Also without the information that such files are made by a given step, it's not possible for SCons to properly order the execution of the generation step..

I'm also not saying it can't be done with SCons.
I am saying that SCons is unlikely to make changes to its focus on building correct build systems.

-Bill

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://four.pairlist.net/pipermail/scons-users/attachments/20131129/fb6e9163/attachment-0001.html


More information about the Scons-users mailing list