1#!/bin/sh
2
3#
4# make-bindist_win32.sh - Make a binary distribution for the Windows SDL ports.
5#
6# Written by
7#  Marco van den Heuvel <blackystardust68@yahoo.com>
8#  Bas Wassink <b.wassink@ziggo.nl>
9#  Greg King <gregdk@users.sf.net>
10#
11# This file is part of VICE, the Versatile Commodore Emulator.
12# See README for copyright notice.
13#
14#  This program is free software; you can redistribute it and/or modify
15#  it under the terms of the GNU General Public License as published by
16#  the Free Software Foundation; either version 2 of the License, or
17#  (at your option) any later version.
18#
19#  This program is distributed in the hope that it will be useful,
20#  but WITHOUT ANY WARRANTY; without even the implied warranty of
21#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22#  GNU General Public License for more details.
23#
24#  You should have received a copy of the GNU General Public License
25#  along with this program; if not, write to the Free Software
26#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27#  02111-1307  USA.
28#
29# Usage: make-bindist.sh <strip=$1> <vice-version=$2> <--enable-arch=$3> <zip|nozip=$4> <x64-included=$5>
30#                        <top-srcdir=$6> <top-builddir=$7> <cpu=$8> <SDL-version=$9> <sdl-config=$10>
31#                        <cross=$11> <objdump=$12> <compiler=$13> <--enable-html-docs=$14>
32#
33
34STRIP=$1
35VICEVERSION=$2
36ENABLEARCH=$3
37ZIPKIND=$4
38X64INC=$5
39TOPSRCDIR=$6
40TOPBUILDDIR=$7
41CPU=$8
42SDLVERSION=$9
43
44shift   # $10
45SDLCONFIG=$9
46
47shift   # $11
48CROSS=$9
49
50shift   # $12
51OBJDUMP=$9
52
53shift   # $13
54COMPILER=$9
55
56shift   # $14
57HTML_DOCS=$9
58
59
60# Try to get the SVN revision
61#echo "Trying to get SVN revision"
62SVN_SUFFIX=""
63svnrev_string=`svnversion $TOPSRCDIR`
64if test "$?" = "0"; then
65    # Choose the second number (usually higher) if it exists; drop letter suffixes.
66    svnrev=`echo "$svnrev_string" | sed 's/^\([0-9]*:\)*\([0-9]*\)*.*/\2/'`
67    #echo "svnrev string: $svnrev"
68    # Only a number is extracted.
69    test -n "$svnrev"&&SVN_SUFFIX="-r$svnrev"
70else
71    #echo "No svnversion found"
72    # nop:
73    :
74fi
75
76
77if test x"$CPU" = "xx86_64" -o x"$CPU" = "xamd64"
78then WINXX="win64"
79else WINXX="win32"
80fi
81
82
83# Check if we have the old x64.exe binary.
84if test x"$X64INC" = "xyes"
85then X64FILE="x64"
86else X64FILE=""
87fi
88
89EMULATORS="$X64FILE x64sc xscpu64 x64dtv x128 xcbm2 xcbm5x0 xpet xplus4 xvic vsid"
90CONSOLE_TOOLS="c1541 cartconv petcat"
91EXECUTABLES="$EMULATORS $CONSOLE_TOOLS"
92
93unset CONSOLE_TOOLS EMULATORS X64FILE svnrev svnrev_string CPU X64INC
94
95for i in $EXECUTABLES; do
96  if [ ! -e $TOPBUILDDIR/src/$i.exe ]; then
97    echo 'Error: executable files not found; do a "make" first.'
98    exit 1
99  fi
100done
101
102
103if test x"$SDLVERSION" = "x2"; then
104  echo "Generating a $WINXX SDL2 port binary distribution..."
105  SDLNAME="SDL2VICE"
106else
107  echo "Generating a $WINXX SDL port binary distribution..."
108  SDLNAME="SDLVICE"
109fi
110
111BINDIST_DIR="$SDLNAME-$VICEVERSION-$WINXX$SVN_SUFFIX"
112
113if test -e "$BINDIST_DIR"; then
114    echo "Removing an old $BINDIST_DIR"
115    rm -f -r $BINDIST_DIR
116fi
117mkdir $BINDIST_DIR
118
119
120# Copy binaries.  Strip them unless VICE is configured with "--enable-debug".
121for i in $EXECUTABLES; do
122  cp $TOPBUILDDIR/src/$i.exe $BINDIST_DIR
123  $STRIP $BINDIST_DIR/$i.exe
124done
125
126
127if test x"$CROSS" != "xtrue"; then
128  # Assume MSYS2 on Windows here.
129  dlls=`ntldd -R $BINDIST_DIR/x64sc.exe|gawk '/\\\\bin\\\\/{print $3;}'|cygpath -f -`
130  test -n "$dlls"&&cp $dlls $BINDIST_DIR
131
132else
133  # Assume a cross-builder for Windows here.
134  get_dll_deps()
135  {
136    for j in `find $BINDIST_DIR -name '*.dll'`; do
137      dlls=`$OBJDUMP -p $j|gawk '/^\\tDLL N/{print " -o -name",$3;}'`
138      dlls=`find $dlldirs -false$dlls`
139      test -n "$dlls"&&cp -u $dlls $BINDIST_DIR||:
140    done
141  }
142
143  # Find the paths of DLL directories.
144  libm=`$COMPILER -print-file-name=libm.a`
145  location=`dirname $libm`
146  loc=`dirname $location`
147  dlldirs="$loc/bin $location"
148  test -d "$loc/dll"&&dlldirs="$dlldirs $loc/dll"
149  libgcc=`$COMPILER -print-file-name=libgcc.a`
150  gccdir=`dirname $libgcc`
151  sdldir=`$SDLCONFIG --exec-prefix`/bin
152  dlldirs="$dlldirs $gccdir $sdldir"
153  # Find the DLLs that are needed by VICE.
154  dlls=`$OBJDUMP -p $BINDIST_DIR/x64sc.exe|gawk '/^\\tDLL N/{print " -o -name",$3;}'`
155  echo "dlls = $dlls"
156  dlls=`find $dlldirs -false $dlls`
157  echo "dlls = $dlls"
158  test -n "$dlls"&&cp $dlls $BINDIST_DIR
159  # Find the DLLs that are needed by other DLLs.
160  get_dll_deps
161fi
162
163
164cp -a $TOPSRCDIR/data/C128 $TOPSRCDIR/data/C64 $BINDIST_DIR
165cp -a $TOPSRCDIR/data/C64DTV $TOPSRCDIR/data/CBM-II $BINDIST_DIR
166cp -a $TOPSRCDIR/data/DRIVES $TOPSRCDIR/data/PET $BINDIST_DIR
167cp -a $TOPSRCDIR/data/PLUS4 $TOPSRCDIR/data/PRINTER $BINDIST_DIR
168cp -a $TOPSRCDIR/data/SCPU64 $TOPSRCDIR/data/VIC20 $BINDIST_DIR
169rm -f `find $BINDIST_DIR -name "Makefile*"`
170rm -f `find $BINDIST_DIR -name "gtk3_*"`
171mkdir $BINDIST_DIR/doc
172if test x"$HTML_DOCS" = "xyes"; then
173    cp -a $TOPSRCDIR/doc/html/* $BINDIST_DIR/doc
174    cp -a -u $TOPBUILDDIR/doc/html/* $BINDIST_DIR/doc
175fi
176rm -f $BINDIST_DIR/doc/Makefile* $BINDIST_DIR/doc/texi2html
177rm -f $BINDIST_DIR/doc/checklinks.sh $BINDIST_DIR/doc/sitemap.xml
178rm -f $BINDIST_DIR/doc/robots.txt $BINDIST_DIR/doc/COPYING $BINDIST_DIR/doc/NEWS
179cp $TOPSRCDIR/NEWS $TOPSRCDIR/COPYING $TOPSRCDIR/README $BINDIST_DIR
180cp $TOPSRCDIR/doc/readmes/Readme-SDL.txt $BINDIST_DIR
181test -e "$TOPBUILDDIR/doc/vice.pdf"&&cp "$TOPBUILDDIR/doc/vice.pdf" $BINDIST_DIR/doc
182
183
184if test x"$ZIPKIND" = "xzip" -o x"$ZIPKIND" = "x7zip"; then
185  if test x"$ZIPKIND" = "xzip" -o x"$ZIPKIND" = "x"; then
186    ZIPEXT=zip
187  else
188    ZIPEXT=7z
189  fi
190  rm -f $BINDIST_DIR.$ZIPEXT
191
192  if test x"$ZIPKIND" = "x7zip"; then
193    7z a -t7z -m0=lzma2 -mx=9 -ms=on $BINDIST_DIR.$ZIPEXT $BINDIST_DIR
194  else
195    if test x"$ZIP" = "x"; then
196      zip -r -9 -q $BINDIST_DIR.zip $BINDIST_DIR
197    else
198      $ZIP $BINDIST_DIR.zip $BINDIST_DIR
199    fi
200  fi
201  rm -f -r $BINDIST_DIR
202  echo $WINXX SDL$SDLVERSION port binary distribution archive generated as
203  echo "(Bash path): $BINDIST_DIR.zip"
204  test x"$CROSS" != "xtrue"&&echo "(Windows path): '`cygpath -wa \"$BINDIST_DIR.zip\"`'"
205else
206  echo $WINXX SDL$SDLVERSION port binary distribution directory generated as
207  echo "(Bash path): $BINDIST_DIR/"
208  test x"$CROSS" != "xtrue"&&echo "(Windows path): '`cygpath -wa \"$BINDIST_DIR/\"`'"
209fi
210if test x"$ENABLEARCH" = "xyes"; then
211  echo ''
212  echo 'Warning: The binaries are optimized for your system.'
213  echo 'They might not run on a different system.'
214  echo 'Configure with --disable-arch to avoid it.'
215  echo ''
216fi
217