[Cook] How to create a more generic recipie
Jerry Pendergraft
jerry at endocardial.com
Thu Jan 8 06:04:13 EST 2004
You can use patterns in many ways with cook, including as part of a
variable name. So given your definitions you can do:
%1/lib/lib%2.a: [%1_%2_obj]
{
echo creating %1/lib/lib%2.a set silent;
/* Note that is equivalent to
echo "creating" [target] set silent;
but shows how to use the "matches" anywhere in the body
*/
}
bin/%1: engine/main.o %1/lib/libnew.a %1/lib/libold.a;
Note that somewhere you will have to have a target that specifies the
total list of what you want to build. Something like:
programs = foo frob other;
all : [addprefix bin/ [programs]] set default;
And you will need some lists to define what goes in each library.
Hope that helps.
--
Jerry Pendergraft jerry.pendergraft at endocardial.com
Endocardial Solutions voice: 651-523-6935
1350 Energy Lane, Suite 110 fax: 651-644-7897
St Paul, MN 55108-5254 mobile: 651-491-0163
On Wed, 7 Jan 2004, Henderson, Michael D wrote:
> 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
> _______________________________________________
> Cook-users mailing list
> Cook-users at auug.org.au
> http://www.auug.org.au/mailman/listinfo/cook-users
>
More information about the Cook-users
mailing list