| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
s |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
from __future__ import print_function |
| 25 |
|
| 26 |
import os |
| 27 |
import re |
| 28 |
import sys |
| 29 |
import subprocess |
| 30 |
from shutil import copy |
| 31 |
|
| 32 |
|
| 33 |
def find_all_on_path(filename, extras=None): |
| 34 |
entries = os.environ["PATH"].split(os.pathsep) |
| 35 |
ret = [] |
| 36 |
for p in entries: |
| 37 |
fname = os.path.abspath(os.path.join(p, filename)) |
| 38 |
if os.path.isfile(fname) and fname not in ret: |
| 39 |
ret.append(fname) |
| 40 |
if extras: |
| 41 |
for p in extras: |
| 42 |
fname = os.path.abspath(os.path.join(p, filename)) |
| 43 |
if os.path.isfile(fname) and fname not in ret: |
| 44 |
ret.append(fname) |
| 45 |
return ret |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
def find_working_perl(perls): |
| 53 |
for perl in perls: |
| 54 |
try: |
| 55 |
subprocess.check_output([perl, "-e", "use Win32;"]) |
| 56 |
except subprocess.CalledProcessError: |
| 57 |
continue |
| 58 |
else: |
| 59 |
return perl |
| 60 |
|
| 61 |
if perls: |
| 62 |
print("The following perl interpreters were found:") |
| 63 |
for p in perls: |
| 64 |
print(" ", p) |
| 65 |
print(" None of these versions appear suitable for building OpenSSL") |
| 66 |
else: |
| 67 |
print("NO perl interpreters were found on this machine at all!") |
| 68 |
print(" Please install ActivePerl and ensure it appears on your path") |
| 69 |
|
| 70 |
|
| 71 |
def create_asms(makefile, tmp_d): |
| 72 |
|
| 73 |
asm_makefile = os.path.splitext(makefile)[0] + '.asm.mak' |
| 74 |
with open(makefile) as fin, open(asm_makefile, 'w') as fout: |
| 75 |
for line in fin: |
| 76 |
|
| 77 |
if line.startswith('install: all'): |
| 78 |
break |
| 79 |
fout.write(line) |
| 80 |
asms = [] |
| 81 |
for line in fin: |
| 82 |
if '.asm' in line and line.strip().endswith('.pl'): |
| 83 |
asms.append(line.split(':')[0]) |
| 84 |
while line.strip(): |
| 85 |
fout.write(line) |
| 86 |
line = next(fin) |
| 87 |
fout.write('\n') |
| 88 |
|
| 89 |
fout.write('asms: $(TMP_D) ') |
| 90 |
fout.write(' '.join(asms)) |
| 91 |
fout.write('\n') |
| 92 |
os.system('nmake /f {} PERL=perl TMP_D={} asms'.format(asm_makefile, tmp_d)) |
| 93 |
|
| 94 |
|
| 95 |
def copy_includes(makefile, suffix): |
| 96 |
dir = 'include'+suffix+'\\openssl' |
| 97 |
try: |
| 98 |
os.makedirs(dir) |
| 99 |
except OSError: |
| 100 |
pass |
| 101 |
copy_if_different = r'$(PERL) $(SRC_D)\util\copy-if-different.pl' |
| 102 |
with open(makefile) as fin: |
| 103 |
for line in fin: |
| 104 |
if copy_if_different in line: |
| 105 |
perl, script, src, dest = line.split() |
| 106 |
if not '$(INCO_D)' in dest: |
| 107 |
continue |
| 108 |
|
| 109 |
src = src.replace('$(SRC_D)', '.').strip('"') |
| 110 |
dest = dest.strip('"').replace('$(INCO_D)', dir) |
| 111 |
print('copying', src, 'to', dest) |
| 112 |
copy(src, dest) |
| 113 |
|
| 114 |
|
| 115 |
def run_configure(configure, do_script): |
| 116 |
print("perl Configure "+configure+" no-idea no-mdc2") |
| 117 |
os.system("perl Configure "+configure+" no-idea no-mdc2") |
| 118 |
print(do_script) |
| 119 |
os.system(do_script) |
| 120 |
|
| 121 |
|
| 122 |
def prep(arch): |
| 123 |
makefile_template = "ms\\nt{}.mak" |
| 124 |
generated_makefile = makefile_template.format('') |
| 125 |
if arch == "x86": |
| 126 |
configure = "VC-WIN32" |
| 127 |
do_script = "ms\\do_nasm" |
| 128 |
suffix = "32" |
| 129 |
elif arch == "amd64": |
| 130 |
configure = "VC-WIN64A" |
| 131 |
do_script = "ms\\do_win64a" |
| 132 |
suffix = "64" |
| 133 |
|
| 134 |
else: |
| 135 |
raise ValueError('Unrecognized platform: %s' % arch) |
| 136 |
|
| 137 |
print("Creating the makefiles...") |
| 138 |
sys.stdout.flush() |
| 139 |
|
| 140 |
run_configure(configure, do_script) |
| 141 |
makefile = makefile_template.format(suffix) |
| 142 |
try: |
| 143 |
os.unlink(makefile) |
| 144 |
except FileNotFoundError: |
| 145 |
pass |
| 146 |
os.rename(generated_makefile, makefile) |
| 147 |
copy_includes(makefile, suffix) |
| 148 |
|
| 149 |
print('creating asms...') |
| 150 |
create_asms(makefile, 'tmp'+suffix) |
| 151 |
|
| 152 |
|
| 153 |
def main(): |
| 154 |
if len(sys.argv) == 1: |
| 155 |
print("Not enough arguments: directory containing OpenSSL", |
| 156 |
"sources must be supplied") |
| 157 |
sys.exit(1) |
| 158 |
|
| 159 |
if len(sys.argv) > 2: |
| 160 |
print("Too many arguments supplied, all we need is the directory", |
| 161 |
"containing OpenSSL sources") |
| 162 |
sys.exit(1) |
| 163 |
|
| 164 |
ssl_dir = sys.argv[1] |
| 165 |
|
| 166 |
if not os.path.isdir(ssl_dir): |
| 167 |
print(ssl_dir, "is not an existing directory!") |
| 168 |
sys.exit(1) |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
perls = find_all_on_path("perl.exe", [r"\perl\bin", |
| 173 |
r"C:\perl\bin", |
| 174 |
r"\perl64\bin", |
| 175 |
r"C:\perl64\bin", |
| 176 |
]) |
| 177 |
perl = find_working_perl(perls) |
| 178 |
if perl: |
| 179 |
print("Found a working perl at '%s'" % (perl,)) |
| 180 |
else: |
| 181 |
sys.exit(1) |
| 182 |
if not find_all_on_path('nmake.exe'): |
| 183 |
print('Could not find nmake.exe, try running env.bat') |
| 184 |
sys.exit(1) |
| 185 |
if not find_all_on_path('nasm.exe'): |
| 186 |
print('Could not find nasm.exe, please add to PATH') |
| 187 |
sys.exit(1) |
| 188 |
sys.stdout.flush() |
| 189 |
|
| 190 |
|
| 191 |
os.environ["PATH"] = os.path.dirname(perl) + \ |
| 192 |
os.pathsep + \ |
| 193 |
os.environ["PATH"] |
| 194 |
|
| 195 |
old_cwd = os.getcwd() |
| 196 |
try: |
| 197 |
os.chdir(ssl_dir) |
| 198 |
for arch in ['amd64', 'x86']: |
| 199 |
prep(arch) |
| 200 |
finally: |
| 201 |
os.chdir(old_cwd) |
| 202 |
|
| 203 |
if __name__=='__main__': |
| 204 |
main() |