
This directory <apcupsd>/src/win32 contains the build
environment for building the native Win32 version of apcupsd.
Note!!! This process is not yet totally working as the code is
still being developed.

The directory structure that you need to have is:
  apcupsd/src/win32     Makefiles and scripts
     apcupsd            Visual Studio Files
      Release           Release objects, and apcupsd.exe
       Debug            Debug object, and apcupsd.exe produced
                           by VC++
    lib                 Links to core lib code

  depkgs-win32
    pthreads            The POSIX pthreads library (third party)

depkgs-win32 is released in a separate .tar.gz file that contains the
source for the pthreads library needed to build the
Win32 apcupsd.  

To build it:
- We are using Microsoft Visual Studio .NET 2003 as the compiler,
  but the build is done via scripting using the latest Cygwin
  environment.
- For this version of apcupsd, you must have msvcr71.dll
  installed in c:/windows/system32 (i.e. Windows VC++ 2003)
  The newwinbacula.nsi.in files have this hard coded in.
- Make sure nmake is on your PATH.
- Make sure your COMSPEC is properly setup (see full dump of
  my cygwin environment below).
- Running the following command may help setup the environment
  variables used by VC++ (I don't use this command, but it might
  just solve your problems).
    run "<vc++ install dir>\VC\PlatformSDK\SetEnv.Cmd"
- The build is done in an rxvt window under the latest version
  of cygwin.
- You need the Platform SDK installed.
- You need Visual Studio installed.
- You need to load depkgs-win32, then
    (make the two patches described below to in Nicolas' notes to wx)
    cd depkgs-win32
    make
- cd apcupsd
  ./configure (appropriate options, see below)
  cd src/win32
- ensure that the docs fully built docs are in the doc directory
  (normally they are prebuilt on Unix/Linux).
  make -f newMakefile

Some technical points:
- The Microsoft compiler will refuse to build x.c files that contain
  C++ code, so for all existing C++ files that are in a .c file, we
  keep the "source" in src/win32/lib as a .cpp file that simply includes
  the original .c file. This allows x.c to be compiled.  
- The directory src/win32/apcupsd contains the necessary makefiles, ...
  for Microsoft C++ to build apcupsd.  It also has all the object files
  in either src/win32/apcupsd/Release or src/win32/apcupsd/Debug depending
  on the build you are doing.
  A few important files in src/win32/apcupsd are:
    filelist  -- the list of all the files that need to be compiled.
                 The extension is not specified and is assumed to be .cpp
    genmake.sh -- when this file is executed, it will take as input
                  (automatically) filelist and use apcupsd-obj.mak.in 
                  and apcupsd.mak.in as templates to build apcupsd.mak,
    apcupsd.mak -- this is the makefile that is processed by nmake to
                   compile and link apcupsd.

  Everytime you add a new source file or rename one, you must update
  filelist and re-run genmake.sh ("./genmake.sh").    
  Note for the moment, there are no dependencies, so you must explicitly
  start with a clean build environment or do a make clean before doing
  a make.




Here is the script that I use under cygwin to build it:
==== build script =========
#!/bin/sh

#  rm -rf k winapcupsd-*.tar.gz
# cp -a k:/home/kern/apcupsd/n k
cp kernswinconfig k
cd k
./kernswinconfig
make
cd src/win32
make winapcupsd.exe
VERSION=`sed -n -e 's/^.*VERSION.*"\(.*\)"$/\1/p' ../../include/version.h`
cp -pf winapcupsd-$VERSION.exe k:/home/kern/apcupsd
if test $? -eq 0 ; then
   echo "Build failed ..."
fi
ls -l k:/home/kern/apcupsd/winapcupsd-$VERSION.exe
======== end build script ==============

=== kernswinconfig ===
#!/bin/sh
# This is Kern's configure script for the Win32 version of apcupsd
./configure \
  --prefix=/apcupsd \
  --sbindir=/apcupsd/bin \
  --sysconfdir=/apcupsd/etc/apcupsd \
  --with-pid-dir=/apcupsd/etc/apcupsd \
  --mandir=/apcupsd \
  --with-cgi-bin=/apcupsd/etc/apcupsd/cgi \
  --enable-master-slave \
  --enable-net \
  --enable-apcsmart \
  --enable-dumb \
  --enable-pthreads
exit 0
=====

===== a suitable environment -- most important are INCLUDE, LIB, and PATH
!::='::\'
!C:='C:\cygwin\home\kern'
ALLUSERSPROFILE='C:\Documents and Settings\All Users'
APPDATA='C:\Documents and Settings\kern\Application Data'
BASH=/usr/bin/bash
BASH_ARGC=()
BASH_ARGV=()
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="3" [1]="00" [2]="16" [3]="7" [4]="release" [5]="i686-pc-cygwin")
BASH_VERSION='3.00.16(7)-release'
CLIENTNAME=Console
COLORFGBG='0;default;15'
COLORTERM=rxvt-xpm
COMMONPROGRAMFILES='C:\Program Files\Common Files'
COMPUTERNAME=OMALLY
COMSPEC='C:\WINDOWS\system32\cmd.exe'
DIRSTACK=()
DISPLAY=:0
EDHELP=/home/kern/bin/ed.hlp
EDTRM=/home/kern/bin/ed.trm
EUID=1007
GROUPS=()
HISTFILE=/home/kern/.bash_history
HISTFILESIZE=500
HISTSIZE=500
HOME=/home/kern
HOMEDRIVE=C:
HOMEPATH='\Documents and Settings\kern'
HOSTNAME=Omally
HOSTTYPE=i686
IFS=$' \t\n'
INCLUDE='c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include;C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\include\;C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include;c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\include'
LIB='c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\lib;C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Lib\;C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Lib;C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\lib'
LOGONSERVER='\\OMALLY'
MACHTYPE=i686-pc-cygwin
MAILCHECK=60
NUMBER_OF_PROCESSORS=1
OLDPWD=/home/kern
OPTERR=1
OPTIND=1
OS=Windows_NT
OSTYPE=cygwin
PATH='/cygdrive/c/WINDOWS/system32:/cygdrive/c/WINDOWS:/cygdrive/c/WINDOWS/System32/Wbem:/cygdrive/c/Program Files/Common Files/Adaptec Shared/System:/cygdrive/c/Program Files/Microsoft Visual Studio .NET 2003/Vc7/bin:/cygdrive/c/Program Files/Microsoft Visual Studio .NET 2003/SDK/v1.1/bin:/cygdrive/c/Program Files/Microsoft Visual Studio .NET 2003/Common7/IDE:/usr/bin:/home/kern/bin:/cygdrive/c/program files/microsoft visual studio/vc98/bin:c:/cygwin/bin:/usr/bin:/home/kern/bin:/sbin:/usr/sbin::c:/cygwin/bin:/usr/bin:/home/kern/bin:/sbin:/usr/sbin:'
PATHEXT='.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH'
PIPESTATUS=([0]="0")
PPID=2112
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER='x86 Family 6 Model 13 Stepping 6, GenuineIntel'
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=0d06
PROGRAMFILES='C:\Program Files'
PROMPT='$P$G'
PS1='\e[34m\]\w\[\e[0m\]$\040'
PS2='> '
PS4='+ '
PWD=/home/kern/apcupsd
SESSIONNAME=Console
SHELL=/bin/bash
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
SHLVL=1
SYSTEMDRIVE=C:
SYSTEMROOT='C:\WINDOWS'
TEMP=/cygdrive/c/DOCUME~1/kern/LOCALS~1/Temp
TERM=xterm
TMP=/cygdrive/c/DOCUME~1/kern/LOCALS~1/Temp
UID=1007
USERDOMAIN=OMALLY
USERNAME=kern
USERPROFILE='C:\Documents and Settings\kern'
VS71COMNTOOLS='C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Tools\'
WINDIR='C:\WINDOWS'
WINDOWID=6815888
WXWIN='c:\home\kern\bacula\depkgs-win32\wx'
_=e:/
====
