[Cook] How to create a more generic recipie
Henderson, Michael D
michael.d.henderson at lmco.com
Thu Jan 8 04:59:50 EST 2004
I'm trying to set up a program with cook and I'd appreciate some advice. Basically, it's a set of regression test programs that use a common engine to compare new and old formats. The directory setup looks like the following
~/
+ bin/
+ engine/
+ main.cpp
+ foo/
+ lib/
+ new/
+ layout/
+ bazz.cpp
+ record/
+ body.cpp
+ body.hpp
+ old/
+ layout/
+ bazz.cpp
+ record/
+ body.cpp
+ body.hpp
+ frob/
+ lib/
+ new/
+ layout/
+ bazz.cpp
+ record/
/* note: can have many record types */
+ body.cpp
+ body.hpp
+ trailer.cpp
+ trailer.hpp
+ old/
+ layout/
+ bazz.cpp
+ record/
+ body.cpp
+ body.hpp
+ trailer.cpp
+ trailer.hpp
I want to end up with two library files in ~/foo/lib/, libnew.a and libold.a. Eventually, they'll be linked with engin/main.o to create ~/bin/foo.
I'm using the following rule to compile the source files, it's working like a champ.
/*===========================================================================
* generic rule to compile a C++ source file in it's source directory.
* the -I%0 forces local header files to be used before the globals.
*/
%0%.o: %0%.cpp: [collect c_incl -i src -api %0%.cpp]
{
[c++] -I%0 [c++_flags] -c %0%.cpp -o [target];
}
Since the new and old sub-directories can have any number of source files, I use collect to create a manifest. It works like I'd expect.
foo_new_src = [fromto ./%0% %0% [collect find foo/new -type f -name *.cpp]];
foo_new_obj = [fromto %0%.cpp %0%.o [foo_new_src]];
foo_old_src = [fromto ./%0% %0% [collect find foo/old -type f -name *.cpp]];
foo_old_obj = [fromto %0%.cpp %0%.o [foo_old_src]];
Where I'm getting honked up is with creating the rules for creating the library targets and the executables.
foo/lib/libnew.a: [foo_new_obj]
{
echo creating foo/lib/libnew.a set silent;
}
foo/lib/libold.a: [foo_old_obj]
{
echo creating foo/lib/libold.a set silent;
}
bin/foo: engine/main.o foo/lib/libnew.a foo/lib/libold.a;
I have to do this setup for many different files (eg, foo, frob, and about thirty more) and I don't want to copy and paste the foo_ rules. That's what I'd have to do for make and I think that cook will let me set up a generic solution for the libraries and executables, even for the manifests. I've looked at Section 14 in the tutorial and can't see how I'd apply it here. I'd appreciate any pointers on how to best approach this.
Thanks,
Mike
More information about the Cook-users
mailing list