#+STARTUP: showall
These are notes on building a Demeter build environment from scratch on a Windows machine.

* Strawberry

Start by grabbing the latest and greatest from
http://strawberryperl.com.  This has a decent selection of MinGW
cooked right in, so many things will be buildable immediately.

This document is being written for Strawberry using some version of
perl 5.18.  This required excising all uses of given/when from the
source tree to avoid the ubiquitous warning about smart matching being
an experimental feature.

* GnuWin32

 + from http://gnuwin32.sourceforge.net/packages.html install the
   packages for PdCurses, Readline, and Make.  These will be installed
   into ~C:\GnuWin32~.  Make is required to build pgplot.

 + grab all file from ~C:\GnuWin32\lib~ with "curses", "readline", or
   "history" in the file name.  Copy them to ~C:\strawberry\c\lib~ 

 + from ~C:\GnuWin32\bin~, copy ~readline5.dll~ and ~curses2.dll~ to
   ~C:\strawberry\c\bin~   

* mingw

 + start from scratch (i.e. uninstall and reinstall) to avoid conflict
   with what's in Strawberry.  download from http://www.mingw.org
 + install mingw32-base and msys-base
 + do not install fortran or any other compilation tools -- usable
   packages come with Strawberry
 + note the batch file in ~C:\MinGW\msys\1.0\msys.bat~.  You will want
   to use this shell in the next step when you compile pgplot.

* pgplot

 + from http://spdg1.sci.shizuoka.ac.jp/grwinlib/english/ download the
   GrWinC toolkit.  unpack it.  Do not install one of the "prebuilt"
   packages.  I have no idea what they are for.
 + at the top of the toolkit, unpack the pgplot package from
   http://www.astro.caltech.edu/~tjp/pgplot/.  This will make a folder
   called ~pgplot~ at top of the toolkit.
 + Move the stuff from the PATCH folder into the appropriate places in
   ~pgplot~. 
 + cd to ~build/MinGw-gfortran~.  The Makefile should just run at this
   point. 
 + make a folder in ~C:\strawberry\c\lib\~ called ~pgplot~.  Move the
   following there
    1. grfont.dat  
    2. libCalcomp.a
    3. libGrWin.a
    4. libGrWin0.a
    5. libcpgplot.a
    6. libpgplot.a
    7. rgb.txt
 + You can now compile ifeffit
   
Are any of the executables from GrWin needed?

* Git and GitHub

At this point, you may want to install [[http://windows.github.com/][GitHub for Windows]].  It takes a
while....

Regardless, you will need to clone a few things from GitHub.

Clone a copy of Demeter from https://github.com/bruceravel/demeter

* compiling Ifeffit

 + Clone from https://github.com/newville/ifeffit

 + Replace ~iconf_pgplot~, ~iconf_term~, and ~iconf_iff~ with the
   versions from ~win/~ in the Demeter distribution 

 + Modify line 85 of the main Makefile.in to read 
   :  SUBDIRS = src
   (i.e. remove ~readline~ so it does not get compiled.)

 + Modify line 90 in ~src/cmdline/Makefile.in~ to read 
   :  readline_LIB =   $(TERMCAP_LIB)

 + ~./configure --prefix='/c/strawberry/c'~  (Note: this should be done
   in the MinGW window and *not* in the Windows command prompt.) 

 + Edit ~src/lib/sys.h~, changing the ~sysdir~ and ~pgdev~ lines like so:
   :  c{sys.h  -*-fortran-*- 
   :  c system and build specific stuff goes here
   :  c to be included in iff_config.f
   :         sysdir = 'C:\strawberry\c\share\ifeffit'
   :         pgdev  = '/gw'
   :         inifile= 'startup.iff  .ifeffit'
   :         build = '1.2.11d'//
   :       $   ' Copyright (c) 2008 Matt Newville, Univ of Chicago'
   :  c}
   Note that this somewhat changes how the Ifeffit build procedure
   works.  By setting the prefix at configuration time to be different
   from the ~sysdir~, Ifeffit will get installed into Strawberry.

 + +Edit iconf pgplot to change -lg2c to -lgfortran+ (Fixed for 0.9.19)

 + In a MinGW terminal, do 
   : ./configure --prefix='/c/strawberry/c'
   note the unix style delimiters.

 + Now ~make~ and ~make install~ 

 + Where did the \etc\fonts\ folder come from???

 + The demeter installer sets a couple of environment variables, which
   may need to be set by hand for testing while building
    1. ~PGPLOT_DIR~ to ~C:\strawberry\c\lib\pgplot~
    2. ~FONTCONFIG_FILE~ to ~C:\strawberry\c\bin\etc\fonts\fonts.conf~

* Gnuplot

 + grab the gnuplot installer from the gnuplot download site
 + install to C:\strawberry\c\bin\gnuplot
 + the executables are in C:\strawberry\c\bin\gnuplot\bin (*this is
   different from previous versions of the installer!*)
 + changes for 0.9.19,
   * reset default windows executable to ~__PERL_BASE__\c\bin\gnuplot\bin\gnuplot.exe~
   * +need to write some code to check for this and reset config value
     as needed+ (check_exe in Demeter::Tools should work)

* using CPAN

 + at brookhaven, configuring for the proxy is required:
   * o conf http_proxy http://192.168.1.130:3128
   * o conf ftp_proxy http://192.168.1.130:3128
 + this allows you to walk away during the build:
   * o conf build_requires_install_policy yes
   * o conf prerequisites_policy follow
 + o conf commit

At this point ~Build installdeps~ should run.

+Is MooseX::Singleton necessary?  Nope!+ (Removed MX::S from the
dependency list in 0.9.19)

* Demeter, prerequisites

You have already cloned or pulled the latest version of [[https://github.com/bruceravel/demeter][Demeter]], right?

 : perl Build.PL
 : perl Build installdeps

 + wait...
 + wait...
 + wait...
 + on the first pass through, the following 4 (not bad!) did not
   install cleanly on my WinXP build system
    1. ~Archive::Zip~ >= 1.31 (Strawberry comes with 1.30)
    2. ~PDL::Stats~
    3. ~Syntax::Highlight::Perl~
    4. ~File::Monitor::Lite~
 + from the DOS command line, run cpan.bat
    1. A::Z failed a test having someting to do with writing to a place
       without adequate permission.  seems safe to ~force install Archive::Zip~
    2. P::S does not fail, it's unclear to me why it did not install
       earlier.  installed from cpan with ~install PDL::Stats~
    3. S::H::P (build) failed to unarchive cleanly.  This is a fairly
       simple module.  It's easily installed by hand.
    4. F::M::L (recommended) failed tests all involve incorrect
       handling of path delimiters on Windows.  seems safe to ~force
       install File ::Monitor::Lite~

* Demeter, build

  : perl Build.PL  # (once more, to verify that all dependencies are now met)
  : perl Build

for some reason, the wrapper did not get compiled (need to look into that), so had to do

  : perl Build touch_wrapper

Then the tests were failing because the gnuplot executable could not
be found in the build environment.  This should not be a problem in an
installation (tested: indeed not!).  To fix, I edited
~%APPDATA%\demeter\demeter.ini~ to point at
~C:\strawberry\c\bin\gnuplot\bin\gnuplot.exe~

Then tests passed!

  : perl Build test
  : perl Build install

* Inno build

Add the following to the root of the installer package

 1. Demeter.ico
 2. Demeter.license.txt
 3. Demeter.readme.txt
 4. Demeter_installer.bmp
 5. modify_path.pl.bat
 6. munge_pathenv.pl.bat
 7. post_update.txt
 8. pre_update.txt
 9. relocation.pl.bat
 10. update_env.pl.bat

Need to uninstall an earlier package.  Installing over lead to the
gxx_personality issue.  Uninstall followed by install worked perfectly.

This was solved by swiping the code from here http://stackoverflow.com/a/2099805
This uninstalls before installing.  Seems to work just fine.

* Preparing to build Metis

 1. Install the non-PDL prereqs
 2. In cpan, ~force install PDL::Graphics::Simple~, leaning on the return key through the tests that fail
 3. In the shell, add ~C:\strawberry\c\bin\gnuplot\bin~ to the path (or ~/c/strawberry/c/bin/gnuplot/bin~)
 4. In cpan, ~install PDL::Graphics::Gnuplot~

