Subject: Hacktivity: An Automatic Win32 Building Script for Freecell Solver

From: Shlomi Fish <[email-masked]>
Date: Tue, 30 Jul 2002 06:45:59 +0300 (IDT)

Included below is a Win32 batch file that can be used to automatically
download and compile Freecell Solver. I prepared it tonight, since I was
not sleepy and became wary of preparing the package myself.

The script depends on Win2K, as well as on the cURL executable be present
in the path. (cURL is a nice wget-like tool that runs fine on Win32). It
also requires MS Visual C.

What it does is

1. Download zip.exe and unzip.exe (two command line tools that can be used
to manipulate zip files)

2. Download the archive (a zip file - prepared from the tar.gz at the HTTP
server side)

3. Unpack the archive, set the MSVC environment and build the programs
using make.

4. Make a directory and copy the relevant files there.

5. Create an archive using zip.exe.

And all of this in Win32 batch language...

Chen, is this what you talked about automating Windows NT? ;-)

Regards,

	Shlomi Fish

There is no IGLU Cabal! The old IGLU cabal became deprecated and one has
yet to automate the creation of replacement cabals.

REM REM REM REM REM       SNIP HERE          REM REM REM REM

REM         Let's clean the files of the previous run
del /q zip.exe
del /q unzip.exe
del /q fcs.zip
del /q freecell-solver-*.zip
rmdir /s /q src
rmdir /s /q freecell-solver-*

REM Assign the base URL of the site
SET SERVER_URL=http://132.68.52.118/fc-solve/

REM Assign the relative place where all the files required for
REM Building the Win32 package can be found
SET SERVER_W32_BUILD_URL=%SERVER_URL%win32_build/

REM REM REM
REM
REM     Cancelled
REM
REM REM REM
REM Retrieve the Version Number from the Web
REM curl -o ver.txt %SERVER_W32_BUILD_URL%dynamic/ver.txt

REM Fetch zip.exe and unzip.exe
curl -o zip.exe %SERVER_W32_BUILD_URL%static/zip.exe
curl -o unzip.exe %SERVER_W32_BUILD_URL%static/unzip.exe

REM Retrieve the archive
curl -o fcs.zip %SERVER_W32_BUILD_URL%dynamic/fcs.zip

mkdir src
cd src
..\unzip ..\fcs.zip

REM Set the MSVC building parameters

SET MSVC_PATH=C:\Program Files\Microsoft Visual Studio\VC98\Bin

call "%MSVC_PATH%\vcvars32"

REM Build Everything
copy config.h.win32 config.h
nmake /f Makefile.win32
cd board_gen
nmake /f Makefile.win32
cd ..\..\

REM Put the version number inside the variable VERSION
FOR /F " tokens=1 delims=, " %%i in (.\src\ver.txt) do set VERSION=%%i

REM           Prepare a directory to contain the distribution files
REM           and put them there.

SET ARC_DIR=freecell-solver-%VERSION%-bin
mkdir %ARC_DIR%
FOR %%i in (ChangeLog fc-solve.exe freecell-solver-range-parallel-solve.exe README README.win32.txt TODO USAGE) do copy src\%%i %ARC_DIR%\
mkdir %ARC_DIR%\board_gen
FOR %%i in (COPYING make_pysol_freecell_board.py make-aisleriot-freecell-board.exe make-gnome-freecell-board.exe make-microsoft-freecell-board.exe README) do copy src\board_gen\%%i %ARC_DIR%\board_gen

REM           Prepare a zip file

zip -r freecell-solver-%VERSION%.win32.bin.zip %ARC_DIR%

----------------------------------------------------------------------
Shlomi Fish        [email-masked]
Home Page:         http://t2.technion.ac.il/~shlomif/
Home E-mail:       [email-masked]

"Let's suppose you have a table with 2^n cups..."
"Wait a second - is n a natural number?"

---

From: "Nadav Har'El" <[email-masked]>
Date: Tue, 30 Jul 2002 10:01:51 +0300

> The script depends on Win2K, as well as on the cURL executable be present

How is this "Win32 batch file" any different from the DOS batch files that
also worked in MS-DOS 1.0 from 1980? Where do you rely on "Win2K"?
Maybe it's that "FOR /F" stuff - I don't remember ever seing that...

> also requires MS Visual C.

By the way, how can you assume someone has curl, but not unzip/zip?
And if you assume someone has CURL, you can just assume he has zsh (or
bash) for Windows, and be done with it ;)

> Chen, is this what you talked about automating Windows NT? ;-)

Note that some of the stuff you're using (curl, zip) is hardly natural
on Windows. Starting the script with downloading utilities like zip
is hardly a good sign of a complete easy-to-automomate OS...

By the way, is it perhaps possible to use someone's preinstalled utility
that handles zip files (e.g., winzip) instead of downloading zip/unzip?

-- 
Nadav Har'El                        |         Tuesday, Jul 30 2002, 21 Av 5762
[email-masked]             |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |"A witty saying proves nothing." --
http://nadav.harel.org.il           |Voltaire

---

From: Tzafrir Cohen <[email-masked]>
Date: Tue, 30 Jul 2002 11:20:59 +0300 (IDT)

> bash) for Windows, and be done with it ;)

Another thing: in this script you download executables from "somewhere"
and run them. Sounds a bit scary to me.

> > And all of this in Win32 batch language...

What about error handling? What happens if the download fails, for
instance?

What happens if there is no didsk space? What if you don't have
permissions to write there? Is your script guaranteed to do something sane
(like: stop immeditely and not cause any more damage)

Consider building te whole thing as a makefile. Error handling can become
a bit simpler.

> > Chen, is this what you talked about automating Windows NT? ;-)

One last thing: make, bash, wget and zip/unzip are available from
cygwin. So automation is indeed possible under win32 :-p

-- 
Tzafrir Cohen                        /"\
mailto:[email-masked]        \ /  ASCII Ribbon Campaign
Taub 229, 972-4-829-3942,             X   Against  HTML  Mail
http://www.technion.ac.il/~tzafrir   / \

---

From: Shlomi Fish <[email-masked]>
Date: Tue, 30 Jul 2002 14:10:15 +0300 (IDT)

On Tue, 30 Jul 2002, Nadav Har'El wrote:

> also worked in MS-DOS 1.0 from 1980?

It's not much different. %-). They added a few more constructs but it's
still the same horridity.

> Where do you rely on "Win2K"?

Maybe it can also run on NT 4 - did not check. I don't think it would run
on Win95, though. But it's a start.

> By the way, how can you assume someone has curl, but not unzip/zip?

I wanted to assume as little as possible. Since I can download zip and
unzip I don't need to keep them around. curl is something I need to fetch
other programs and files from the Net.

> bash) for Windows, and be done with it ;)

Unfortunately, I cannot expect people to have cygwin around... At least
not here on the Technion. Does Win2K/WinXP installs Interix by default? I
don't think so.

> is hardly a good sign of a complete easy-to-automomate OS...

I did not say it was. But basically, if you took a look at Autoconf and
the dirty bourne shell tricks it does to automate the build process, you
would not be too much impressed either. In fact, the Software Carptentry
project wanted to design the entire building process (make + autoconf) in
Python. Considering the fact that Python/Perl/Ruby/whatever is very
portable and can be assumed to be present, there is little incentive not
to depend on it. Better bootstrap one program, then ten thoushand. ;-)

> that handles zip files (e.g., winzip) instead of downloading zip/unzip?

I wanted to use WinZip. I really did. But I could not find any command
line interface or OLE automation in its documentation (or on Google).
YHBT.

Regards,

	Shlomi Fish

> To unsubscribe from this group, send an email to:
> [email-masked]
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>

---

From: Tzafrir Cohen <[email-masked]>
Date: Tue, 30 Jul 2002 14:25:27 +0300 (IDT)

> > > not sleepy and became wary of preparing the package myself.

And this keeps us busy the day after ;-)

> > Maybe it's that "FOR/F" stuff - I don't remember ever seing that...
> >
>

From a breif look of it, I'm not sure that there is anything there that
doesn't work on dos 6 and maybe even older (except some of the programs,
of course).

> not here on the Technion. Does Win2K/WinXP installs Interix by default? I

But you expect them to run untrusted bunaries. And to re-download them on
each invocation of the script!

> the dirty bourne shell tricksit does to automate the build process, you

autoconf meets problems of the system. If ever that project becomes
successful, you would notice just how unportable is python
(|perl|ruby|whatever}). I'm not talking about simple scripts. I'm talking
about all the little features.

You will also notice that some systems will have different versions of
python (or whatever) than what you expect. This is already the case with
perl (perl4, anybody? This is what I get if I run a script that uses
/usr/bin/perl on this particialr system)

-- 
Tzafrir Cohen
mailto:[email-masked]
http://www.technion.ac.il/~tzafrir

---

From: "Nadav Har'El" <[email-masked]>
Date: Tue, 30 Jul 2002 14:45:46 +0300

> /usr/bin/perl on this particialr system)

Right :) And the Technion is an excellent proving-ground for this, with
all kinds of antique versions of Perl (and other free software and libraries)
floating around because of system-administrators who couldn't be bothered
to lift a finger for their users.
You wouldn't believe what kinds of complaints I got about my sendsms script,
which basically ammount to "Perl from 5 years ago didn't support this feature
correctly!" or "I have Perl from 5 years ago and perl-modules from 3 years ago
and they misbehave together!", and things like that.
It's not much better than what is happening with the various versions of
shells and UNIXes... Slightly better (because we're dealing with a linear
version tree, not a tree of versions) but not the perfect "solution".

-- 
Nadav Har'El                        |         Tuesday, Jul 30 2002, 21 Av 5762
[email-masked]             |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |Linux is just like a wigwam: no Windows,
http://nadav.harel.org.il           |no Gates and an Apache inside.

---

From: Shlomi Fish <[email-masked]>
Date: Tue, 30 Jul 2002 16:46:45 +0300 (IDT)

> and run them. Sounds a bit scary to me.

Got a better option? I think that's what apt-get, urpmi and friends do,
too. That's life. I could add RSA authenthication or MD5 checksums
(IANA crypto expert) in the next patch release if that would make you
happy...

> (like: stop immeditely and not cause any more damage)

I purposely ignore such rare sanity loses. The script is meant for me, so
it qualifies as internal use. It's PD, but with absolutely no strings
attached, and I do not claim it is good Batch programming. (nor is
Freecell Solver, because it may segfault if it runs out of memory)

> Consider building te whole thing as a makefile. Error handling can become

And how do I invoke Nmake on it?

> cygwin. So automation is indeed possible under win32 :-p

Yes, but I cannot depend on them being around on every Windows system out
there. And requiring a user to download a batch file and curl.exe is not a
big deal.

Regards,

	Shlomi Fish

---

From: Shlomi Fish <[email-masked]>
Date: Tue, 30 Jul 2002 16:54:25 +0300 (IDT)

> version tree, not a tree of versions) but not the perfect "solution".

That's part of the reason why Linux with its RPM/.deb files and
apt/urpmi/whatever, as well as frequent distribution upgrades is taking
the world by storm. Lately I have become even picky about my distribution
and cannot imagine operating in a non Mandrake-environment. Maybe it's
time for me to switch distributions. Debian? Gentoo? Nah... if it's
working don't touch.

In any case if you say : I depend on Perl 5.6.1 with CPAN modules version
this and this, you're in pretty good shape. Or Python 3.0 or whatever.
You'd still have a much better foundation to build upon than Bourne shell
and POSIX. I am toying with the idea of studying for a masters degree and
one of the things I'd like to explore is package management and build
processes. I'm not sure the current
Make+Automake+Autoconf+Libtool+RPM+urpmi scheme is the best one we can
have, but I'd also like to find something that would be able to default to
it. Instead of making something incompatible that no one will use because
it won't allow them to switch back[1].

Regards,

	Shlomi Fish

[1] - YA one of Spolsky's gems:

http://www.joelonsoftware.com/articles/fog0000000052.html

Regards,

	Shlomi Fish

---

From: Shlomi Fish <[email-masked]>
Date: Tue, 30 Jul 2002 17:06:28 +0300 (IDT)

> And this keeps us busy the day after ;-)

LOL.

> doesn't work on dos 6 and maybe even older (except some of the programs,

I think the FOR loop does not work on DOS.

> each invocation of the script!

This is a known issue. I plan to fix it in later revisions. And like I
said the script is not intended for everyday folks. It's primarily
targetted at my convenience.

> /usr/bin/perl on this particialr system)

If you use external APIs, then there is a problem of compatibility. But if
you stick to the bare language, you can usually have at least backwards
compatibility. Oh well - who is John Galt? Maybe we need a specialized
language for the task.

Regards,

	Shlomi Fish

---

From: Shlomi Fish <[email-masked]>
Date: Tue, 30 Jul 2002 21:34:01 +0300 (IDT)

Here is a more up-to-date version of the script. Changes since last time:

1. I do not download zip.exe and unzip.exe over and over again. (that's
for you - Tzafrir)

2. The URL is now vipe.technion.ac.il instead of the IP of my Com-Net lab
workstation, which may not be accessible everywhere.

I'd appreciate any help in making this script Win95/98-compatible. For
once I'd like to know how to read a file into a variable. For more
information check here:

http://www.labmice.net/scripting/batchfiles.htm

Regards,

	Shlomi Fish

REM REM REM            CUT HERE           REM REM REM

REM Assign the base URL of the site
SET SERVER_URL=http://vipe.technion.ac.il/~shlomif/freecell-solver/

REM REM REM
REM
REM     Cancelled
REM
REM REM REM

REM           Fetch zip.exe and unzip.exe
REM           If they were not already fetched.
IF NOT EXIST zip.exe curl -o zip.exe %SERVER_W32_BUILD_URL%static/zip.exe
IF NOT EXIST unzip.exe curl -o unzip.exe %SERVER_W32_BUILD_URL%static/unzip.exe

REM Retrieve the archive

mkdir src
cd src
..\unzip ..\fcs.zip

REM Build Everything