Creating a what string
Learn how to create a what string.
The what program searches for a null-terminated string that starts with a special four-character sequence:
@(#)
To include this string in a C-language executable, define a global character-string variable. For example, these source statements produce the two-line what listing above:
char *version_string = "@(#)monet R2.0 Baselevel 1";
char *version_time = "@(#)Thu Feb 11 17:33:23 EST 2003;
As an alternative, you can generate the time stamp dynamically when the monet program is linked:
- Create a new source file that contains the statements that define the what
strings. Instead of hard-coding a date string, use a cpp(1) macro in the source file. This
example uses a source file named version_info.h, which contains a macro named DATE:
char *version_string = "@(#)monet R2.0 Baselevel 1"; char *version_time = DATE;
- Use shell command substitution to incorporate the current time dynamically into the value for
the DATE macro:
SHELL = /bin/sh OTHER_OBJS = main.o cmd_line.o (and so on) monet: version_info.h $(OTHER_OBJS) cc -o monet -DDATE="\"@(#)'date'\"" $(OTHER_OBJS)
A rebuild of
monet
is also triggered if theversion_string
variable is edited manually inversion_info.h
.The
version_string
can be generated dynamically, too (for example, with environment variables). But it is more likely that the project manager edits this string's value before major builds.
monet
, you need not declare
version_info.h
as an explicit dependency.