> Waffling on to my own posts... but it would seem I have to build Zope from
> source to get it to use another version of python since the use of
> python15.dll is entrenched in Zope... All the install scripts seem to be
> based on unix.
> 
> Can DC give me a hand here on pointers to how they build it for Windows?

Hi Andy - 

We have a little python script that creates NMAKE compatible 
makefiles out of the Setup files. I've attached it + the .bat 
file we use to run it. Hope this helps!


Brian Lloyd        [EMAIL PROTECTED]
Software Engineer  540.371.6909              
Digital Creations  http://www.digicool.com 



'''Build t Python extension using Visual C++ 40

This script generates and runs a series of .mak and .def
files for extensions defined in a Setup file.

Note that you must have set up your environment to run VC command-line
ustilities.  This can be done by running the vcvar32.bat file in the
VC++ bin directory.

Usage: python ext.py [options]

Options:

   -r     Run nmake to build release version
   -d     Run nmake to build debug version
   -c     If used with -r or -d, runs nmake on clean target.
   -p     Specify location of Python source tree.  Default
          is ..\.. (assuming you are in Extensions/some_name)

The script reads a file named "Setup" in the current directory.  The
Setup file has lines that describe the contents of an extension.
Here\'s an example:

  ExtensionClass ExtensionClass.c
  Acquisition Acquisition.c

Note that I\'ve intented for readability.  The Setup file shouldn\'t
be indented.  Basically, the first token on the line is the module
name, and the second token on the line is the sorce file. Additional
source files and include directories may be included as well, as in:

  pyexpat pyexpat.c -DXML_NS -Iexpat/xmlparse -Iexpat/xmltok expat/xmlparse/xmlparse.c 
expat/xmlparse/hashtable.c expat/xmltok/xmlrole.c expat/xmltok/xmltok.c


''' # '

import sys, getopt, os, string, regex

def die(m):
        print m
        print
        print __doc__
        sys.exit(1)

def setup():

    poptlist,pargs=getopt.getopt(sys.argv[1:],'p:drcI:o:h')
    if opt(poptlist,'h'): print __doc__
    if poptlist==[('-h','')]: sys.exit(0)

    pargs and die('Unrecognized arguments: %s', string.join(args))

    ext_regex = regex.compile('\([a-z][a-z0-9_]*\)[ \t]'
                              '\([.a-z][./a-z0-9_]*[.]c\)[ \t\n]',
                              regex.casefold)
            
    for line in open('Setup').readlines():
            
        if ext_regex.match(line) >= 0:
            sargs=string.split(line)
            module=sargs[0]
            src=sargs[1]
            if src[:2]=='./': continue
            soptlist, sargs = getopt.getopt(sargs[2:],'I:D:')

            filter(lambda a: a[:1]=='-' or string.find(a,'.') < 0,
                   sargs) and die('Invalid arguments in Setup file: %s' %
                                  string.join(sargs))

            sargs=map(lambda a: string.replace(a, '/','\\'), sargs)
            simple(module,poptlist+soptlist, sargs)
            

main=setup

def filebase(o,
             splitext=os.path.splitext,
             split=os.path.split):
        return splitext(split(o)[1])[0]



def simple(module,optlist,others):
    tdef,tmak=templates()

    pyhome=opt(optlist,'p')
    pyhome=pyhome and pyhome[0] or '..\\..'
    cfg=opt(optlist,'d') and 'Debug' or 'Release'
    parms={'module': module, 'pyhome':pyhome, 'cfg': cfg}
    parms['includes']=string.join(
        map(lambda i: '/I "%s"' % i,
            opt(optlist,'I')) +
        map(lambda i: '/D "%s"' % i,
            opt(optlist,'D'))
        , ' ') 
    parms['other_clean_release']=string.join(
        map(lambda o:
            '\n\t-@erase ".\\Release\\%s.obj"' % filebase(o),
            others),'')
    parms['other_clean_debug']=string.join(
        map(lambda o:
            '\n\t-@erase ".\\Debug\\%s.obj"' % filebase(o),
            others),'')
    parms['other_rule']=string.join(
        map(lambda o:
            '"$(INTDIR)\%s.obj" : .\%s $(DEP_CPP_MOD) "$(INTDIR)"\n'
            '\t$(CPP) $(CPP_PROJ)  .\%s '
            % (filebase(o), o, o),
            others),'\n')
    parms['other_link']=string.join(
        map(lambda o:
            '\n\t"$(INTDIR)\%s.obj" \\' % filebase(o),
            others),'')

    open(module+'.def','w').write(tdef % parms)
    open(module+'.mak','w').write(tmak % parms)
    cfg_=' CFG="%s - Win32 %s"' % (module,cfg)
    os.system('nmake /nologo /f %s.mak%s' % (module,cfg_))
    os.system('copy %s\%s.dll %s.pyd' % (cfg,module,module))
    if opt(optlist,'c'):
        os.system("nmake /f %s.mak%s CLEAN" % (module,cfg_))



def opt(optlist,name):
    l=filter(lambda t, name='-'+name: t[0]==name, optlist)
    return map(lambda t: t[1], l)

def templates():
    tdef = '''EXPORTS
        init%(module)s
'''

    tmak = '''# Microsoft Developer Studio Generated NMAKE File, Format Version 4.00
# ** DO NOT EDIT **

# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102

!IF "$(CFG)" == ""
CFG=%(module)s - Win32 Debug
!MESSAGE No configuration specified.  Defaulting to %(module)s - Win32 Debug.
!ENDIF 

!IF "$(CFG)" != "%(module)s - Win32 Release" && "$(CFG)" !=\\
 "%(module)s - Win32 Debug"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE on this makefile
!MESSAGE by defining the macro CFG on the command line.  For example:
!MESSAGE 
!MESSAGE NMAKE /f "%(module)s.mak" CFG="%(module)s - Win32 Debug"
!MESSAGE 
!MESSAGE Possible choices for configuration are:
!MESSAGE 
!MESSAGE "%(module)s - Win32 Release" (based on\\
 "Win32 (x86) Dynamic-Link Library")
!MESSAGE "%(module)s - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE 
!ERROR An invalid configuration is specified.
!ENDIF 

!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE 
NULL=nul
!ENDIF 
################################################################################
# Begin Project
# PROP Target_Last_Scanned "%(module)s - Win32 Debug"
CPP=cl.exe
RSC=rc.exe
MTL=mktyplib.exe

!IF  "$(CFG)" == "%(module)s - Win32 Release"

# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
OUTDIR=.\\Release
INTDIR=.\\Release

ALL : "$(OUTDIR)\\%(module)s.dll"

CLEAN : 
        -@erase ".\\Release\\%(module)s.dll"
        -@erase ".\\Release\\%(module)s.obj"%(other_clean_release)s
        -@erase ".\\Release\\%(module)s.lib"
        -@erase ".\\Release\\%(module)s.exp"
        -@erase ".\\Release\\%(module)s.pch"

"$(OUTDIR)" :
    if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"

# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /MD /W3 /GX /O2 /I "%(pyhome)s\\Include" /I "%(pyhome)s\\PC" 
%(includes)s /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
CPP_PROJ=/nologo /MD /W3 /GX /O2 /I "%(pyhome)s\\Include" /I "%(pyhome)s\\PC" 
%(includes)s /D "WIN32" /D\\
 "NDEBUG" /D "_WINDOWS" /Fp"$(INTDIR)/%(module)s.pch" /YX /Fo"$(INTDIR)/" /c 
CPP_OBJS=.\\Release/
CPP_SBRS=
# ADD BASE MTL /nologo /D "NDEBUG" /win32
# ADD MTL /nologo /D "NDEBUG" /win32
MTL_PROJ=/nologo /D "NDEBUG" /win32 
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
BSC32_FLAGS=/nologo /o"$(OUTDIR)/%(module)s.bsc" 
BSC32_SBRS=
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib 
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib 
/nologo /subsystem:windows /dll /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib 
shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo 
/subsystem:windows /dll /machine:I386
LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib\\
 advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib\\
 odbccp32.lib /nologo /subsystem:windows /dll /incremental:no\\
 /pdb:"$(OUTDIR)/%(module)s.pdb" /machine:I386 /def:".\\%(module)s.def"\\
 /out:"$(OUTDIR)/%(module)s.dll" /implib:"$(OUTDIR)/%(module)s.lib" 
DEF_FILE= \\
        ".\\%(module)s.def"
LINK32_OBJS= \\
        "$(INTDIR)/%(module)s.obj" \\%(other_link)s
        "%(pyhome)s\\pcbuild\\%(cfg)s\\python15.lib"

"$(OUTDIR)\\%(module)s.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
    $(LINK32) @<<
  $(LINK32_FLAGS) $(LINK32_OBJS)
<<

!ELSEIF  "$(CFG)" == "%(module)s - Win32 Debug"

# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
OUTDIR=.\\Debug
INTDIR=.\\Debug

ALL : "$(OUTDIR)\\%(module)s.dll"

CLEAN : 
        -@erase ".\\Debug\\%(module)s.dll"
        -@erase ".\\Debug\\%(module)s.obj"%(other_clean_debug)s
        -@erase ".\\Debug\\%(module)s.ilk"
        -@erase ".\\Debug\\%(module)s.lib"
        -@erase ".\\Debug\\%(module)s.exp"
        -@erase ".\\Debug\\%(module)s.pdb"
        -@erase ".\\Debug\\%(module)s.pch"
        -@erase ".\\Debug\\pcbuild.pdb"
        -@erase ".\\Debug\\pcbuild.idb"

"$(OUTDIR)" :
    if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"

# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" 
/YX /c
# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "%(pyhome)s\\Include" /I 
"%(pyhome)s\\PC" %(includes)s /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c
CPP_PROJ=/nologo /MDd /W3 /Gm /GX /Zi /Od /I "%(pyhome)s\\Include" /I "%(pyhome)s\\PC" 
%(includes)s /D "WIN32"\\
 /D "_DEBUG" /D "_WINDOWS" /Fp"$(INTDIR)/%(module)s.pch" /YX /Fo"$(INTDIR)/"\\
 /Fd"$(INTDIR)/" /c 
CPP_OBJS=.\\Debug/
CPP_SBRS=
# ADD BASE MTL /nologo /D "_DEBUG" /win32
# ADD MTL /nologo /D "_DEBUG" /win32
MTL_PROJ=/nologo /D "_DEBUG" /win32 
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
BSC32_FLAGS=/nologo /o"$(OUTDIR)/%(module)s.bsc" 
BSC32_SBRS=
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib 
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib 
/nologo /subsystem:windows /dll /debug /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib 
shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo 
/subsystem:windows /dll /debug /machine:I386
LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib\\
 advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib\\
 odbccp32.lib /nologo /subsystem:windows /dll /incremental:yes\\
 /pdb:"$(OUTDIR)/%(module)s.pdb" /debug /machine:I386 /def:".\\%(module)s.def"\\
 /out:"$(OUTDIR)/%(module)s.dll" /implib:"$(OUTDIR)/%(module)s.lib" 
DEF_FILE= \\
        ".\\%(module)s.def"
LINK32_OBJS= \\
        "$(INTDIR)/%(module)s.obj" \\%(other_link)s
        "%(pyhome)s\\pcbuild\\%(cfg)s\\python15.lib"

"$(OUTDIR)\\%(module)s.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
    $(LINK32) @<<
  $(LINK32_FLAGS) $(LINK32_OBJS)
<<

!ENDIF 

.c{$(CPP_OBJS)}.obj:
   $(CPP) $(CPP_PROJ) $<  

.cpp{$(CPP_OBJS)}.obj:
   $(CPP) $(CPP_PROJ) $<  

.cxx{$(CPP_OBJS)}.obj:
   $(CPP) $(CPP_PROJ) $<  

.c{$(CPP_SBRS)}.sbr:
   $(CPP) $(CPP_PROJ) $<  

.cpp{$(CPP_SBRS)}.sbr:
   $(CPP) $(CPP_PROJ) $<  

.cxx{$(CPP_SBRS)}.sbr:
   $(CPP) $(CPP_PROJ) $<  

################################################################################
# Begin Target

# Name "%(module)s - Win32 Release"
# Name "%(module)s - Win32 Debug"

!IF  "$(CFG)" == "%(module)s - Win32 Release"

!ELSEIF  "$(CFG)" == "%(module)s - Win32 Debug"

!ENDIF 

################################################################################
# Begin Source File

SOURCE=.\\%(module)s.c
DEP_CPP_MOD=\\
        "%(pyhome)s\\Include\\Python.h"\\
        "%(pyhome)s\\PC\\config.h"\\
        "%(pyhome)s\\Include\\myproto.h"\\
        "%(pyhome)s\\Include\\object.h"\\
        "%(pyhome)s\\Include\\objimpl.h"\\
        "%(pyhome)s\\Include\\pydebug.h"\\
        "%(pyhome)s\\Include\\intobject.h"\\
        "%(pyhome)s\\Include\\longobject.h"\\
        "%(pyhome)s\\Include\\floatobject.h"\\
        "%(pyhome)s\\Include\\complexobject.h"\\
        "%(pyhome)s\\Include\\rangeobject.h"\\
        "%(pyhome)s\\Include\\stringobject.h"\\
        "%(pyhome)s\\Include\\tupleobject.h"\\
        "%(pyhome)s\\Include\\listobject.h"\\
        "%(pyhome)s\\Include\\methodobject.h"\\
        "%(pyhome)s\\Include\\moduleobject.h"\\
        "%(pyhome)s\\Include\\funcobject.h"\\
        "%(pyhome)s\\Include\\classobject.h"\\
        "%(pyhome)s\\Include\\fileobject.h"\\
        "%(pyhome)s\\Include\\cobject.h"\\
        "%(pyhome)s\\Include\\traceback.h"\\
        "%(pyhome)s\\Include\\sliceobject.h"\\
        "%(pyhome)s\\Include\\pyerrors.h"\\
        "%(pyhome)s\\Include\\mymalloc.h"\\
        "%(pyhome)s\\Include\\modsupport.h"\\
        "%(pyhome)s\\Include\\ceval.h"\\
        "%(pyhome)s\\Include\\pythonrun.h"\\
        "%(pyhome)s\\Include\\sysmodule.h"\\
        "%(pyhome)s\\Include\\intrcheck.h"\\
        "%(pyhome)s\\Include\\import.h"\\
        "%(pyhome)s\\Include\\abstract.h"\\
        "%(pyhome)s\\Include\\rename2.h"\\
        "%(pyhome)s\\Include\\thread.h"\\
        

"$(INTDIR)\\%(module)s.obj" : $(SOURCE) $(DEP_CPP_MOD) "$(INTDIR)"
%(other_rule)s

# End Source File
################################################################################
# Begin Source File

SOURCE=.\\%(module)s.def

!IF  "$(CFG)" == "%(module)s - Win32 Release"

!ELSEIF  "$(CFG)" == "%(module)s - Win32 Debug"

!ENDIF 

# End Source File
################################################################################
# Begin Source File

SOURCE=%(pyhome)s\\pcbuild\\%(cfg)s\\python15.lib

!IF  "$(CFG)" == "%(module)s - Win32 Release"

!ELSEIF  "$(CFG)" == "%(module)s - Win32 Debug"

!ENDIF 

# End Source File
################################################################################
# Begin Source File

SOURCE=.\\readme.txt

!IF  "$(CFG)" == "%(module)s - Win32 Release"

!ELSEIF  "$(CFG)" == "%(module)s - Win32 Debug"

!ENDIF 

# End Source File
# End Target
# End Project
################################################################################
'''
    return tdef, tmak

if __name__=='__main__': main()

ext15.bat

Reply via email to