Cygwin: (mostly) drop NT4 and Samba < 3.0 support
[newlib-cygwin.git] / winsup / cygwin / scripts / mkvers.sh
blob38f439cd0d628bff1db9e25df58087cfc7d917a5
1 #!/bin/sh
2 # mkvers.sh - Make version information for cygwin DLL
4 # This file is part of Cygwin.
6 # This software is a copyrighted work licensed under the terms of the
7 # Cygwin license. Please consult the file "CYGWIN_LICENSE" for
8 # details.
10 exec 9> version.cc
13 # Arg 1 is the name of the version include file
15 incfile="$1"; shift
16 rcfile="$1"; shift
17 windres="$1"; shift
18 iflags=
19 # Find header file locations
20 while [ -n "$*" ]; do
21 case "$1" in
22 -I*)
23 iflags="$iflags $1"
25 -idirafter)
26 shift
27 iflags="$iflags -I$1"
29 esac
30 shift
31 done
33 [ -r $incfile ] || {
34 echo "**** Couldn't open file '$incfile'. Aborting."
37 parse_preproc_flags() {
38 # Since we're manually specifying the preprocessor, pass the default flags
39 # normally defined.
40 ccflags="--preprocessor=$1 --preprocessor-arg=-E \
41 --preprocessor-arg=-xc-header --define=RC_INVOKED "
42 shift
43 while [ -n "$*" ]; do
44 case "$1" in
45 # We need to be able to find the just-built cc1 binary.
46 -B*)
47 ccflags="$ccflags --preprocessor-arg=$1"
49 esac
50 shift
51 done
54 parse_preproc_flags $CC
59 # Load the current date (or SOURCE_DATE_EPOCH) so we can work on individual fields
61 set -$- $(date ${SOURCE_DATE_EPOCH:+-d @}${SOURCE_DATE_EPOCH} -u +"%m %d %Y %H:%M")
62 m=$1 d=$2 y=$3 hhmm=$4
64 # Set date into YYYY-MM-DD HH:MM:SS format
66 builddate="$y-$m-$d $hhmm"
67 echo "$builddate"
69 set -$- ''
72 # Output the initial part of version.cc
74 cat <<EOF 1>&9
75 #include "config.h"
76 #include "cygwin_version.h"
78 #define strval(x) #x
79 #define str(x) strval(x)
80 #define shared_data_version str(CYGWIN_VERSION_SHARED_DATA)
82 const char *cygwin_version_strings =
83 "BEGIN_CYGWIN_VERSION_INFO\n"
84 EOF
87 # Split version file into dir and filename components
89 dir=$(dirname $incfile)
90 fn=$(basename $incfile)
93 # Look in the include file CVS directory for a CVS Tag file. This file,
94 # if it exists, will contain the name of the sticky tag associated with
95 # the current build. Save that for output later.
97 cvs_tag="$(sed -e '/dontuse/d' -e 's%^.\(.*\)%\1%' $dir/CVS/Tag 2>/dev/null)"
99 wv_cvs_tag="$cvs_tag"
100 [ -n "$cvs_tag" ] && cvs_tag=" CVS tag"'
101 '"$cvs_tag"
104 # Look in the source directory containing the include/cygwin/version.h
105 # and set dir accordingly.
106 dir=$(echo $dir | sed -e 's%/include/cygwin.*$%%' -e 's%include/cygwin.*$%.%')
109 # Scan the version.h file for strings that begin with CYGWIN_INFO or
110 # CYGWIN_VERSION. Perform crude parsing on the lines to get the values
111 # associated with these values and then pipe it into a while loop which
112 # outputs these values in C palatable format for inclusion in the DLL
113 # with a '%% ' identifier that will introduce "interesting" strings.
114 # These strings are strictly for use by a user to scan the DLL for
115 # interesting information.
118 sed -n -e 's%#define CYGWIN_INFO_\([A-Z_]*\)[ ][ ]*\([a-zA-Z0-9"][^/]*\).*%_\1\
119 \2%p' -e 's%#define CYGWIN_VERSION_\([A-Z_]*\)[ ][ ]*\([a-zA-Z0-9"][^/]*\).*%_\1\
120 \2%p' $incfile | sed -e 's/["\\]//g' -e '/^_/y/ABCDEFGHIJKLMNOPQRSTUVWXYZ_/abcdefghijklmnopqrstuvwxyz /';
121 echo ' build date'; echo $build_date;
122 [ -n "$cvs_tag" ] && echo "$cvs_tag";
123 ) | while read var; do
124 read val
125 cat <<EOF
126 "%%% Cygwin $var: $val\n"
128 done | tee /tmp/mkvers.$$ 1>&9
130 trap "rm -f /tmp/mkvers.$$" 0 1 2 15
133 # Finally, output the shared ID and set up the cygwin_version structure
134 # for use by Cygwin itself.
136 cat <<EOF 1>&9
137 #ifdef DEBUGGING
138 "%%% Cygwin shared id: " CYGWIN_VERSION_DLL_IDENTIFIER "S" shared_data_version "-$builddate\n"
139 #else
140 "%%% Cygwin shared id: " CYGWIN_VERSION_DLL_IDENTIFIER "S" shared_data_version "\n"
141 #endif
142 "END_CYGWIN_VERSION_INFO\n\0";
143 cygwin_version_info cygwin_version =
145 CYGWIN_VERSION_API_MAJOR, CYGWIN_VERSION_API_MINOR,
146 CYGWIN_VERSION_DLL_MAJOR, CYGWIN_VERSION_DLL_MINOR,
147 CYGWIN_VERSION_SHARED_DATA,
148 CYGWIN_VERSION_MOUNT_REGISTRY,
149 "$builddate",
150 #ifdef DEBUGGING
151 CYGWIN_VERSION_DLL_IDENTIFIER "S" shared_data_version "-$builddate"
152 #else
153 CYGWIN_VERSION_DLL_IDENTIFIER "S" shared_data_version
154 #endif
159 # Generate winver.o using cygwin/version.h information.
160 # Turn the cygwin major number from some large number to something like 1.1.0.
162 eval $(sed -n 's/^.*dll \(m[ai][jn]or\): \([0-9]*\)[^0-9]*$/\1=\2/p' /tmp/mkvers.$$)
163 cygverhigh=$(expr $major / 1000)
164 cygverlow=$(expr $major % 1000)
165 cygwin_ver="$cygverhigh.$cygverlow.$minor"
166 if [ -n "$cvs_tag" ]
167 then
168 cvs_tag="$(echo $wv_cvs_tag | sed -e 's/-branch.*//')"
169 cygwin_ver="$cygwin_ver-$cvs_tag"
172 echo "Version $cygwin_ver"
173 set -$- $builddate
174 $windres $iflags $ccflags \
175 --define CYGWIN_BUILD_DATE="$1" \
176 --define CYGWIN_BUILD_TIME="$2" \
177 --define CYGWIN_BUILD_YEAR=$y \
178 --define CYGWIN_VERSION='"'"$cygwin_ver"'"' \
179 $rcfile winver.o