[Cook] How to force version.c to recompile if it exists prior to linking an executable

Henderson, Michael D michael.d.henderson at lmco.com
Wed Aug 6 02:28:02 EST 2008


I have a question on how to force a version.c file to recompile if the
executable is relinked. Basically, the version.c has a function that
return the timestamp that the version.c file was compiled on.

const char *Version(void)
{
  return "version " PKG_VER " compiled on " __DATE__ " at " __TIME__;
}

I saw something in the docs about forcing the version.c file to
recompile, but it looked liked that example assumed that version.c
always existed. In this project, some of the client executables have
version.c files, but not all of them. They will in the future, but
that's the way it is right now.

I'd like to fix up my cook file so that the version.c is recompiled
whenever the executable is relinked. I have some variables
[[target]_dep] and [[target]_obj] that list the dependencies and object
files for the binary. Is there some way to filter the [[target]_obj] to
see if it contains version.o and only do the force if it exists?

I use the following recipe to link the binary.

/*==================================================================
 * create an executable from object files and special libraries
 *   example: bin/sbll: [bin/sbll_dep]
 */
bin/%: [[target]_dep]
  set unlink
{
  [cc] -o [target]
    [[target]_obj]
    [[target]_ldflags]
    [all_libs]
    ;
}

I use the following recipe to set up the dependencies and objects to
link. The [lstBinPackages] is set previously. The xxx_ldflags and
xxx_inc variables are helpers in case a package needs an external
library or special flags.

/*==================================================================
 * build the dependencies for binary packages
 *   example: bin/sbll will depend on files in src/bin/sbll
 */
loop local pkgPath = [lstBinPackages] {
  ourTarget = bin/[fromto src/%1/%2 %2 [pkgPath]];

  if [not [defined [ourTarget]_dep    ]] then [ourTarget]_dep     = ;
  if [not [defined [ourTarget]_inc    ]] then [ourTarget]_inc     = ;
  if [not [defined [ourTarget]_ldflags]] then [ourTarget]_ldflags = ;

  [ourTarget]_src  = [stringset [match_mask [pkgPath]/%0%.c [MANIFEST]];
  [ourTarget]_obj  = [fromto %0%.%1 %0%.o [[ourTarget]_src]];
  [ourTarget]_dep += [[ourTarget]_obj];
}

Thanks,
Mike

2008 - The Year of The Rockies

 (\__/)
 (='.'=)	This is Bunny. Copy and paste Bunny into your
 (")_(")	signature to help him gain world domination.




More information about the Cook-users mailing list