[Distutils] wininst.exe source

Rene Liebscher R.Liebscher@gmx.de
Wed Apr 4 04:00:00 2001


This is a multi-part message in MIME format.
--------------B0A07778FAF8B9235ECAAC8D
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Thomas Heller wrote:
> 
> > where is the source for the WININST.EXE stub executable
> > that is used for bdist_winist? i looked around but did
> > not see it. is it created from some other 'installation
> > tool', or is it simply a compiled program.
> It's available via CVS, start here:
> http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/?cvsroot=python
> 
> Unfortunately, it is not yet built with distutils (what a shame).
> 
It is no problem to build it with distutils.
See the attached file.

Copy it to your misc directory and double-click.
(It needs the zlib library and header files in a subdirectory
"zlib" and the UPX packer in the current directory or somewhere
else in the path, if want the exe-file compressed as the 
original wininst.exe is.)

It uses the msvc compiler class, it would work with other compilers
too, if you change some places in the code (unnamed unions and the 
resource file) which are handled a little bit different in other
compilers.

Kind regards
Rene Liebscher
--------------B0A07778FAF8B9235ECAAC8D
Content-Type: text/plain; charset=us-ascii;
 name="build_wininst.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="build_wininst.py"

"""
    Build the windows installer executable.
    We let distutils figure out how to compile. 

    Most parameters are the same as distutils uses
    for its Extensions specification.

"""
# created 2000/09/05, Rene Liebscher

__revision__ = "$Id: build_wininst.py $"

import os,sys
from distutils.sysconfig import customize_compiler
from distutils.ccompiler import new_compiler
from distutils.dep_util import newer_group

# compile some source files to an executable
def build_exe(
    compiler = None, # "msvc","mingw32",..
                     # see distutils --help-compiler
    verbose = 1, # 0
    dry_run = 0, # 1
    force = 1, # 1
    debug = 0, # 1
    extra_compile_args = [],
    extra_link_args = [],  
    build_temp = ".",
    sources = [],
    include_dirs = ["."],
    output_name = "noname",
    output_dir = ".",
    export_symbols = None,
    libraries = [],
    library_dirs = ["."],
    runtime_library_dirs = None
    ):

    # Setup the CCompiler object that we'll use to do all the
    # compiling and linking
    compiler_obj = new_compiler (compiler=compiler,
                             verbose=verbose,
                             dry_run=dry_run,
                             force=force)
    customize_compiler(compiler_obj)

    # how to call the result on this platform
    output_filename = compiler_obj.executable_filename(
                    basename=output_name,
                    output_dir=output_dir)

    # check if really compiling is really needed
    if not (force or newer_group(sources, output_filename, 'newer')):
        sys.stderr.write ("skipping '%s' (up-to-date)\n" % output_filename)  
    else:
        sys.stderr.write ("building '%s'\n" % output_filename)

    # Next, compile the source code to object files.

    extra_args = extra_compile_args or []

    if os.environ.has_key('CFLAGS'):
        extra_args.extend(string.split(os.environ['CFLAGS']))

    # compile all source files                
    objects = compiler_obj.compile (sources,
                            output_dir=build_temp,
                            #macros=macros,
                            include_dirs=include_dirs,
                            debug=debug,
                            extra_postargs=extra_args)

    extra_args = extra_link_args or []

    # link all object files to the exe
    compiler_obj.link (compiler_obj.EXECUTABLE,
                objects, output_filename, 
                libraries=libraries,
                library_dirs=library_dirs,
                runtime_library_dirs=runtime_library_dirs,
                extra_postargs=extra_args,
                export_symbols=export_symbols, 
                debug=debug,
                build_temp=build_temp)

    from distutils.spawn import find_executable,spawn
    upx_exe = find_executable("upx")
    if upx_exe:
        spawn([upx_exe,output_filename]) 

    
    
# build_exe

# and now use build_exe to do the actual build
build_exe(
    #compiler="bcpp",
    output_name = "wininst",
    sources=["install.c","extract.c","install.rc"],
    include_dirs=["zlib"], 
    library_dirs=["zlib"], # zlib is in subdirectory zlib
    libraries=["zlib","gdi32","comctl32", "user32","advapi32"],
)
--------------B0A07778FAF8B9235ECAAC8D--