[jamming] Complete, and utter automation with Jam

Craig Allsop cjamallsop at gmail.com
Wed Sep 13 16:01:41 PDT 2006


On 9/6/06, Daniel White <twinbee41 at skytopia.com> wrote:
>
> > What I mean is that there is no "stdlib.c" file that gets
> > automatically put along with your sources.
> > In fact, the functions in stdlib.h are defined in a variety of
> > different .c files - the rand() function is in rand.c, strtod() is in
> > strtod.c, and so on.
> > They are all compiled into a library so they can be included as a
> > single unit by your program.
>
> Woudln't it be more space efficient for C to only include the necessary
> functions required for the operation of a particular program? Mind
> you, I suppose the cost would having to recompile the source each
> time...


Some linkers will attempt to eliminate redundant functions that aren't
referenced.

What you're saying may be true of small projects but for larger ones
recompiling the source is not desirable due to the size (and yes, time). We
break large projects into smaller translation units for many reasons, not
for C, but for practical reasons such as, easier for us humans to digest,
encapsulation, less recompiling time when a few functions change,
distribution across many computers, etc. Further to this is the organisation
of libraries of code, sometimes to enforce a hierarchy of dependencies so
that low level code doesn't access high level code. Without these designs a
large program can become a real big mess to maintain and understand. This
means there is a need for a convention of declaring what is in these units
so that each c file may "include" the declarations referenced by it and that
later the linker will use to resolve.

Back to your original question to me.. If you have several programs in the
same directory then in Jam you would just list them:

Main progA : progA.cpp ;
Main progB : progB.cpp ;
Main progC : progC.cpp ;

If you use a naming convention you can Glob for the main program sources:

PROGRAMS = [ Glob $(SUBDIR) : prog*.cpp ] ;

Make a rule in your jamrules to compile a batch:

rule BulkMain
{
  local i ;
  for i in $(<)
  {
    Main $(i:B) : $(i:BS) ;
  }
}

And in your jamfiles:

BulkMain $(PROGRAMS) ;

If you use this method, just be aware that if you need different options,
e.g. LINKFLAGS for each program you'll need to invent some more utility
rules to help tell jam what to do.

Craig.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://maillist.perforce.com/pipermail/jamming/attachments/20060913/178cbcb5/attachment.html


More information about the jamming mailing list