summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/mkvers.sh
blob: 5aecb141bc79584fed21eba2dc54afe8be8c6557 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/bin/sh
# mkvers.sh - Make version information for cygwin DLL
#
# This file is part of Cygwin.
#
# This software is a copyrighted work licensed under the terms of the
# Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
# details.

exec 9> version.cc

#
# Arg 1 is the name of the version include file
#
incfile="$1"; shift
rcfile="$1"; shift
windres="$1"; shift
iflags=
# Find header file locations
while [ -n "$*" ]; do
  case "$1" in
  -I*)
    iflags="$iflags $1"
    ;;
  -idirafter)
    shift
    iflags="$iflags -I$1"
      ;;
  esac
  shift
done

[ -r $incfile ] || {
  echo "**** Couldn't open file '$incfile'.  Aborting."
}

parse_preproc_flags() {
  # Since we're manually specifying the preprocessor, pass the default flags
  # normally defined.
  ccflags="--preprocessor=$1 --preprocessor-arg=-E \
	   --preprocessor-arg=-xc-header --define=RC_INVOKED "
  shift
  while [ -n "$*" ]; do
    case "$1" in
    # We need to be able to find the just-built cc1 binary.
    -B*)
      ccflags="$ccflags --preprocessor-arg=$1"
      ;;
    esac
    shift
  done
}

parse_preproc_flags $CC



#
# Load the current date so we can work on individual fields
#
set -$- $(date +"%m %d %Y %H:%M")
m=$1 d=$2 y=$3 hhmm=$4
#
# Set date into YYYY-MM-DD HH:MM:SS format
#
builddate="$y-$m-$d $hhmm"
echo "$builddate"

set -$- ''

#
# Output the initial part of version.cc
#
cat <<EOF 1>&9
#include "config.h"
#include "cygwin_version.h"

#define strval(x) #x
#define str(x) strval(x)
#define shared_data_version str(CYGWIN_VERSION_SHARED_DATA)

const char *cygwin_version_strings =
  "BEGIN_CYGWIN_VERSION_INFO\n"
EOF

#
# Split version file into dir and filename components
#
dir=$(dirname $incfile)
fn=$(basename $incfile)

#
# Look in the include file CVS directory for a CVS Tag file.  This file,
# if it exists, will contain the name of the sticky tag associated with
# the current build.  Save that for output later.
#
cvs_tag="$(sed -e '/dontuse/d' -e 's%^.\(.*\)%\1%' $dir/CVS/Tag 2>/dev/null)"

wv_cvs_tag="$cvs_tag"
[ -n "$cvs_tag" ] && cvs_tag=" CVS tag"'
'"$cvs_tag"

#
# Look in the source directory containing the include/cygwin/version.h
# and set dir accordingly.
dir=$(echo $dir | sed -e 's%/include/cygwin.*$%%' -e 's%include/cygwin.*$%.%')

# Look in $dir for a a ".snapshot-date" file.  If one is found then this
# information will be saved for output to the DLL.
#
if [ -r "$dir/.snapshot-date" ]; then
  read snapshotdate < "$dir/.snapshot-date"
  snapshot="snapshot date
$snapshotdate"
fi

#
# Scan the version.h file for strings that begin with CYGWIN_INFO or
# CYGWIN_VERSION.  Perform crude parsing on the lines to get the values
# associated with these values and then pipe it into a while loop which
# outputs these values in C palatable format for inclusion in the DLL
# with a '%% ' identifier that will introduce "interesting" strings.
# These strings are strictly for use by a user to scan the DLL for
# interesting information.
#
(
  sed -n -e 's%#define CYGWIN_INFO_\([A-Z_]*\)[ 	][ 	]*\([a-zA-Z0-9"][^/]*\).*%_\1\
\2%p' -e 's%#define CYGWIN_VERSION_\([A-Z_]*\)[ 	][ 	]*\([a-zA-Z0-9"][^/]*\).*%_\1\
\2%p' $incfile | sed -e 's/["\\]//g'  -e '/^_/y/ABCDEFGHIJKLMNOPQRSTUVWXYZ_/abcdefghijklmnopqrstuvwxyz /';
  echo ' build date'; echo $build_date;
  [ -n "$cvs_tag" ] && echo "$cvs_tag";
  [ -n "$snapshot" ] && echo "$snapshot"
) | while read var; do
    read val
cat <<EOF
  "%%% Cygwin $var: $val\n"
EOF
done | tee /tmp/mkvers.$$ 1>&9

trap "rm -f /tmp/mkvers.$$" 0 1 2 15

if [ -n "$snapshotdate" ]; then
  usedate="$(echo $snapshotdate | sed 's/-\\(..:..[^-]*\\).*$/ \1SNP/')"
else
  usedate="$builddate"
fi

#
# Finally, output the shared ID and set up the cygwin_version structure
# for use by Cygwin itself.
#
cat <<EOF 1>&9
#ifdef DEBUGGING
  "%%% Cygwin shared id: " CYGWIN_VERSION_DLL_IDENTIFIER "S" shared_data_version "-$builddate\n"
#else
  "%%% Cygwin shared id: " CYGWIN_VERSION_DLL_IDENTIFIER "S" shared_data_version "\n"
#endif
  "END_CYGWIN_VERSION_INFO\n\0";
cygwin_version_info cygwin_version =
{
  CYGWIN_VERSION_API_MAJOR, CYGWIN_VERSION_API_MINOR,
  CYGWIN_VERSION_DLL_MAJOR, CYGWIN_VERSION_DLL_MINOR,
  CYGWIN_VERSION_SHARED_DATA,
  CYGWIN_VERSION_MOUNT_REGISTRY,
  "$usedate",
#ifdef DEBUGGING
  CYGWIN_VERSION_DLL_IDENTIFIER "S" shared_data_version "-$builddate"
#else
  CYGWIN_VERSION_DLL_IDENTIFIER "S" shared_data_version
#endif
};
EOF

#
# Generate winver.o using cygwin/version.h information.
# Turn the cygwin major number from some large number to something like 1.1.0.
#
eval $(sed -n 's/^.*dll \(m[ai][jn]or\): \([0-9]*\)[^0-9]*$/\1=\2/p' /tmp/mkvers.$$)
cygverhigh=$(expr $major / 1000)
cygverlow=$(expr $major % 1000)
cygwin_ver="$cygverhigh.$cygverlow.$minor"
if [ -n "$cvs_tag" ]
then
  cvs_tag="$(echo $wv_cvs_tag | sed -e 's/-branch.*//')"
  cygwin_ver="$cygwin_ver-$cvs_tag"
fi

echo "Version $cygwin_ver"
set -$- $builddate
$windres $iflags $ccflags \
	 --define CYGWIN_BUILD_DATE="$1" \
	 --define CYGWIN_BUILD_TIME="$2" \
	 --define CYGWIN_BUILD_YEAR=$y \
	 --define CYGWIN_VERSION='"'"$cygwin_ver"'"' \
	 $rcfile winver.o