#!/bin/ksh
# Q: witch version is this ?
# Q: when compiled, which compiler ?
# Q: on witch system ?
# Q: where are the src ?
# this is a shell example, sure it's better (so do i)
# to implement all the stuff dynamically in Makefile
# change if needed
export MYVERSION=0.0.1
# on which system was this code compiled
# purge blancs, so only one quoting level is needed
export MYSYSTEM=`uname -a|sed -e 's/ /_/g'`
# use the full date output, purge blancs
export MYDATE=`date|sed -e 's/ /_/g'`
# remember compiler version
export MYCOMPILER=abc_2.2.3.4.5_123
export MYAUTHOR=guggach@yahoo.com
# to faster locate the src-code
export MYSRCNAME=`pwd`
# feel free to define other relevant data
# source this file and
# append to cc lines all values, see below
# start make
cc -o sample version.c -DMYSRCNAME=\"$MYSRCNAME/version.c\" -DMYCOMPILER=\"$MYCOMPILER\" -DMYVERSION=\"$MYVERSION\" -DMYSYSTEM=\"$MYSYSTEM\" -DMYAUTHOR=\"$MYAUTHOR\" -DMYDATE=\"$MYDATE\"
# execute sample, you should get
sample --version
sample: is /export/home/c-src/version.c
sample: src-version 0.0.1
sample: compiled with abc_2.2.3.4.5_123
sample: on SunOS_uno_5.7_Generic_sun4u_sparc_SUNW,Ultra-1
sample: at Wed_Jun_16_09:04:27_MET_DST_2004
sample: by guggach@yahoo.com
NOTA: the macros
__TIME__ is not known on all systems
__DATE__ is too short, prefer the full date output
__FILE__ is the src-name at compiling time not the
exec-name at running time (could be a symlink)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.