Back to index

python3.2  3.2.2
Functions
build_ssl Namespace Reference

Functions

def find_all_on_path
def find_working_perl
def find_best_ssl_dir
def fix_makefile
def run_configure
def cmp
def copy
def main
def create_makefile64

Function Documentation

def build_ssl.cmp (   f1,
  f2 
)

Definition at line 123 of file build_ssl.py.

00123 
00124 def cmp(f1, f2):
00125     bufsize = 1024 * 8
00126     with open(f1, 'rb') as fp1, open(f2, 'rb') as fp2:
00127         while True:
00128             b1 = fp1.read(bufsize)
00129             b2 = fp2.read(bufsize)
00130             if b1 != b2:
00131                 return False
00132             if not b1:
00133                 return True

Here is the caller graph for this function:

def build_ssl.copy (   src,
  dst 
)

Definition at line 134 of file build_ssl.py.

00134 
00135 def copy(src, dst):
00136     if os.path.isfile(dst) and cmp(src, dst):
00137         return
00138     shutil.copy(src, dst)

Here is the call graph for this function:

Here is the caller graph for this function:

def build_ssl.create_makefile64 (   makefile,
  m32 
)
Create and fix makefile for 64bit

Replace 32 with 64bit directories

Definition at line 98 of file build_ssl.py.

00098 
00099 def create_makefile64(makefile, m32):
00100     """Create and fix makefile for 64bit
00101 
00102     Replace 32 with 64bit directories
00103     """
00104     if not os.path.isfile(m32):
00105         return
00106     with open(m32) as fin:
00107         with open(makefile, 'w') as fout:
00108             for line in fin:
00109                 line = line.replace("=tmp32", "=tmp64")
00110                 line = line.replace("=out32", "=out64")
00111                 line = line.replace("=inc32", "=inc64")
00112                 # force 64 bit machine
00113                 line = line.replace("MKLIB=lib", "MKLIB=lib /MACHINE:X64")
00114                 line = line.replace("LFLAGS=", "LFLAGS=/MACHINE:X64 ")
00115                 # don't link against the lib on 64bit systems
00116                 line = line.replace("bufferoverflowu.lib", "")
00117                 fout.write(line)
00118     os.unlink(m32)

Here is the call graph for this function:

def build_ssl.find_all_on_path (   filename,
  extras = None 
)

Definition at line 24 of file build_ssl.py.

00024 
00025 def find_all_on_path(filename, extras = None):
00026     entries = os.environ["PATH"].split(os.pathsep)
00027     ret = []
00028     for p in entries:
00029         fname = os.path.abspath(os.path.join(p, filename))
00030         if os.path.isfile(fname) and fname not in ret:
00031             ret.append(fname)
00032     if extras:
00033         for p in extras:
00034             fname = os.path.abspath(os.path.join(p, filename))
00035             if os.path.isfile(fname) and fname not in ret:
00036                 ret.append(fname)
00037     return ret
00038 
00039 # Find a suitable Perl installation for OpenSSL.
00040 # cygwin perl does *not* work.  ActivePerl does.
00041 # Being a Perl dummy, the simplest way I can check is if the "Win32" package
# is available.

Here is the call graph for this function:

Here is the caller graph for this function:

def build_ssl.find_best_ssl_dir (   sources)

Definition at line 62 of file build_ssl.py.

00062 
00063 def find_best_ssl_dir(sources):
00064     candidates = []
00065     for s in sources:
00066         try:
00067             # note: do not abspath s; the build will fail if any
00068             # higher up directory name has spaces in it.
00069             fnames = os.listdir(s)
00070         except os.error:
00071             fnames = []
00072         for fname in fnames:
00073             fqn = os.path.join(s, fname)
00074             if os.path.isdir(fqn) and fname.startswith("openssl-"):
00075                 candidates.append(fqn)
00076     # Now we have all the candidates, locate the best.
00077     best_parts = []
00078     best_name = None
00079     for c in candidates:
00080         parts = re.split("[.-]", os.path.basename(c))[1:]
00081         # eg - openssl-0.9.7-beta1 - ignore all "beta" or any other qualifiers
00082         if len(parts) >= 4:
00083             continue
00084         if parts > best_parts:
00085             best_parts = parts
00086             best_name = c
00087     if best_name is not None:
00088         print("Found an SSL directory at '%s'" % (best_name,))
00089     else:
00090         print("Could not find an SSL directory in '%s'" % (sources,))
00091     sys.stdout.flush()
00092     return best_name

Here is the call graph for this function:

Here is the caller graph for this function:

def build_ssl.find_working_perl (   perls)

Definition at line 42 of file build_ssl.py.

00042 
00043 def find_working_perl(perls):
00044     for perl in perls:
00045         fh = os.popen('"%s" -e "use Win32;"' % perl)
00046         fh.read()
00047         rc = fh.close()
00048         if rc:
00049             continue
00050         return perl
00051     print("Can not find a suitable PERL:")
00052     if perls:
00053         print(" the following perl interpreters were found:")
00054         for p in perls:
00055             print(" ", p)
00056         print(" None of these versions appear suitable for building OpenSSL")
00057     else:
00058         print(" NO perl interpreters were found on this machine at all!")
00059     print(" Please install ActivePerl and ensure it appears on your path")
00060     return None
00061 
# Locate the best SSL directory given a few roots to look into.

Here is the call graph for this function:

Here is the caller graph for this function:

def build_ssl.fix_makefile (   makefile)
Fix some stuff in all makefiles

Definition at line 93 of file build_ssl.py.

00093 
00094 def fix_makefile(makefile):
00095     """Fix some stuff in all makefiles
00096     """
00097     if not os.path.isfile(makefile):
00098         return
00099     with open(makefile) as fin:
00100         lines = fin.readlines()
00101     with open(makefile, 'w') as fout:
00102         for line in lines:
00103             if line.startswith("PERL="):
00104                 continue
00105             if line.startswith("CP="):
00106                 line = "CP=copy\n"
00107             if line.startswith("MKDIR="):
00108                 line = "MKDIR=mkdir\n"
00109             if line.startswith("CFLAG="):
00110                 line = line.strip()
00111                 for algo in ("RC5", "MDC2", "IDEA"):
00112                     noalgo = " -DOPENSSL_NO_%s" % algo
00113                     if noalgo not in line:
00114                         line = line + noalgo
00115                 line = line + '\n'
00116             fout.write(line)

Here is the caller graph for this function:

def build_ssl.main ( void  )

Definition at line 139 of file build_ssl.py.

00139 
00140 def main():
00141     debug = "-d" in sys.argv
00142     build_all = "-a" in sys.argv
00143     if 1: # Win32
00144         arch = "x86"
00145         configure = "VC-WIN32"
00146         do_script = "ms\\do_nasm"
00147         makefile="ms\\nt.mak"
00148         m32 = makefile
00149         dirsuffix = "32"
00150     configure += " no-idea no-rc5 no-mdc2"
00151     make_flags = ""
00152     if build_all:
00153         make_flags = "-a"
00154     # perl should be on the path, but we also look in "\perl" and "c:\\perl"
00155     # as "well known" locations
00156     perls = find_all_on_path("perl.exe", ["\\perl\\bin", "C:\\perl\\bin"])
00157     perl = find_working_perl(perls)
00158     if perl:
00159         print("Found a working perl at '%s'" % (perl,))
00160     else:
00161         print("No Perl installation was found. Existing Makefiles are used.")
00162     sys.stdout.flush()
00163     # Look for SSL 3 levels up from PC/VC6 - ie, same place zlib etc all live.
00164     ssl_dir = find_best_ssl_dir(("..\\..\\..",))
00165     if ssl_dir is None:
00166         sys.exit(1)
00167 
00168     old_cd = os.getcwd()
00169     try:
00170         os.chdir(ssl_dir)
00171         # If the ssl makefiles do not exist, we invoke Perl to generate them.
00172         # Due to a bug in this script, the makefile sometimes ended up empty
00173         # Force a regeneration if it is.
00174         if not os.path.isfile(makefile) or os.path.getsize(makefile)==0:
00175             if perl is None:
00176                 print("Perl is required to build the makefiles!")
00177                 sys.exit(1)
00178 
00179             print("Creating the makefiles...")
00180             sys.stdout.flush()
00181             # Put our working Perl at the front of our path
00182             os.environ["PATH"] = os.path.dirname(perl) + \
00183                                           os.pathsep + \
00184                                           os.environ["PATH"]
00185             run_configure(configure, do_script)
00186             if debug:
00187                 print("OpenSSL debug builds aren't supported.")
00188             #if arch=="x86" and debug:
00189             #    # the do_masm script in openssl doesn't generate a debug
00190             #    # build makefile so we generate it here:
00191             #    os.system("perl util\mk1mf.pl debug "+configure+" >"+makefile)
00192 
00193             fix_makefile(makefile)
00194             copy(r"crypto\buildinf.h", r"crypto\buildinf_%s.h" % arch)
00195             copy(r"crypto\opensslconf.h", r"crypto\opensslconf_%s.h" % arch)
00196 
00197         # If the assembler files don't exist in tmpXX, copy them there
00198         if perl is None and os.path.exists("asm"+dirsuffix):
00199             if not os.path.exists("tmp"+dirsuffix):
00200                 os.mkdir("tmp"+dirsuffix)
00201             for f in os.listdir("asm"+dirsuffix):
00202                 if not f.endswith(".asm"): continue
00203                 if os.path.isfile(r"tmp%s\%s" % (dirsuffix, f)): continue
00204                 shutil.copy(r"asm%s\%s" % (dirsuffix, f), "tmp"+dirsuffix)
00205 
00206         # Now run make.
00207         copy(r"crypto\buildinf_%s.h" % arch, r"crypto\buildinf.h")
00208         copy(r"crypto\opensslconf_%s.h" % arch, r"crypto\opensslconf.h")
00209 
00210         #makeCommand = "nmake /nologo PERL=\"%s\" -f \"%s\"" %(perl, makefile)
00211         makeCommand = "nmake /nologo -f \"%s\"" % makefile
00212         print("Executing ssl makefiles:", makeCommand)
00213         sys.stdout.flush()
00214         rc = os.system(makeCommand)
00215         if rc:
00216             print("Executing "+makefile+" failed")
00217             print(rc)
00218             sys.exit(rc)
00219     finally:
00220         os.chdir(old_cd)
00221     # And finally, we can build the _ssl module itself for Python.
00222     defs = "SSL_DIR=%s" % (ssl_dir,)
00223     if debug:
00224         defs = defs + " " + "DEBUG=1"
00225     rc = os.system('nmake /nologo -f _ssl.mak ' + defs + " " + make_flags)
00226     sys.exit(rc)

Here is the call graph for this function:

Here is the caller graph for this function:

def build_ssl.run_configure (   configure,
  do_script 
)

Definition at line 117 of file build_ssl.py.

00117 
00118 def run_configure(configure, do_script):
00119     print("perl Configure "+configure)
00120     os.system("perl Configure "+configure)
00121     print(do_script)
00122     os.system(do_script)

Here is the caller graph for this function: