Initial commit

This commit is contained in:
Fierelier 2023-10-04 19:31:56 +02:00
commit fe9447d0c9
4 changed files with 250 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/openssl_source/

19
LICENSE Normal file
View File

@ -0,0 +1,19 @@
Copyright (c) 2023
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

28
README.txt Normal file
View File

@ -0,0 +1,28 @@
Build OpenSSL for Windows, from Linux.
--- CONFIG ---
You can change the build configuration by setting environment variables:
* ofw_mirror="https://github.com/openssl/openssl" - Which mirror to pull from. Defaults to "https://github.com/openssl/openssl".
* ofw_target="x86/x86-64" - Build for 32-bit/64-bit. Defaults to "x86".
* ofw_version="*/3.1/1/..." - Which version to pull. * pulls the newest version, 3.1 would download the newest 3.1.* release, 1 the newest 1.* release, 3 the newest 3.*, etc. The script will only download stable releases. Defaults to "*".
* ofw_config="" - Which options to pass to ./config. Read: https://wiki.openssl.org/index.php/Compilation_and_Installation#Configuration
--- BUILDING ---
You can find the compiled binaries in openssl_source/usr/bin.
* Compile for 32-bit (defaults):
ofw_target="x86" ./compile
* Compile for 64-bit (defaults):
ofw_target="x86-64" ./compile
* Compile for 32-bit with legacy compatibility (Pentium II (somehow), Windows 2000 (?)):
ofw_target="x86" ofw_config="386" CFLAGS="-D_WIN32_WINNT=0x0500 -march=i586" CXXFLAGS="$CFLAGS" CPPFLAGS="$CFLAGS" ./compile
* Compile for 64-bit with legacy compatibility (All x86-64 chips, Windows XP):
ofw_target="x86-64" CFLAGS="-march=x86-64 -mtune=generic -D_WIN32_WINNT=0x0501" CXXFLAGS="$CFLAGS" CPPFLAGS="$CFLAGS" ./compile
* For a list of Windows versions, see: https://web.archive.org/web/20111001070837if_/https://msdn.microsoft.com/en-us/library/windows/desktop/aa383745(v=vs.85).aspx#macros_for_conditional_declarations
* This version of the document also lists newer windows revisions:
https://web.archive.org/web/20230709170326if_/https://learn.microsoft.com/en-us/windows/win32/winprog/using-the-windows-headers#macros-for-conditional-declarations

202
compile Executable file
View File

@ -0,0 +1,202 @@
#!/usr/bin/env python3
import sys, os
p = os.path.join
pUp = os.path.dirname
s = False
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
s = os.path.realpath(sys.executable)
else:
s = os.path.realpath(__file__)
sp = pUp(s)
import subprocess, shutil, shlex
# ENVIRONMENT
# All of these can be overridden by setting environment variables starting with ofw_
# So to set mirror, set ofw_mirror
mirror="https://github.com/openssl/openssl"
version="*" # * = newest stable version, 3 = newest stable 3.x.x version, 3.1 = newest stable 3.1.x version, etc...
target="x86" # x86 for 32-bit, x86-64 for 64-bit
config="" # Configuration for ./Configure script
os.environ["PATH"] = p(sp,"bin") + ":" + os.environ["PATH"]
def perr(rtn,cmd = None,op = None):
if rtn == 0: return
if cmd == None: cmd = []
exc = subprocess.CalledProcessError(rtn,cmd,op)
raise exc
def pcall(*args,**kwargs):
rtn = subprocess.Popen(*args,**kwargs).wait()
perr(rtn,args[0])
def pcallStr(*args,**kwargs):
proc = subprocess.Popen(*args,**kwargs, stdout=subprocess.PIPE)
response = proc.stdout.read().decode("utf-8").strip("\n")
rtn = proc.wait()
perr(rtn,args[0])
return response
def git(path,*args,gitwait=True,**kwargs):
cmd = ["git"] + list(args)
if gitwait == True:
pcall(cmd,cwd=path,**kwargs)
else:
return subprocess.Popen(cmd,cwd=path,**kwargs)
def splitAtNumber(st):
nrs = "0123456789"
for nr in nrs:
nst = st.split(nr,1)
if len(nst) > 1:
if nst[1] != "": continue
return [nst[0],int(nr + nst[1])]
return [st,0]
def splitLetterVersion(st):
version = [0,0]
letters = "abcdefghijklmnopqrstuvwxyz"
for letter in letters:
if st[-1] == letter:
version[1] = letters.find(letter) + 1
version[0] = int(st[0])
return version
version[0] = int(st)
return version
def parseTags(tags):
parsedTags = {}
for tag in tags:
tagType = -1
if tag.startswith("OpenSSL_1"): tagType = 1
if tag.startswith("openssl-"): tagType = 3
# major, minor, patch, oldpatch (1.x letter converted to integer), release type, release iteration
versionData = [-1,0,0,0,"stable",0]
try:
if tagType == 1:
version = tag.split("_",1)[-1]
version = version.split("-",1)
if len(version) > 1:
release = splitAtNumber(version[1])
else:
release = ["stable",0]
version = version[0].split("_")
letter = splitLetterVersion(version.pop(2))
version.append(letter[0])
version.append(letter[1])
version[0] = int(version[0])
version[1] = int(version[1])
versionData = version + release
if tagType == 3:
version = tag.split("-",1)[-1]
version = version.split("-")
if len(version) > 1:
release = splitAtNumber(version[1])
else:
release = ["stable",0]
version = version[0].split(".")
version[0] = int(version[0])
version[1] = int(version[1])
version[2] = int(version[2])
version.append(0)
versionData = version + release
except Exception:
pass
if versionData[0] == -1: continue
parsedTags[tag] = versionData
return parsedTags
def main():
global mirror,version,target,config
for e in os.environ:
if e.startswith("ofw_"):
globals()[e.replace("ofw_","",1)] = os.environ[e]
ossl_source = p(sp,"openssl_source")
ossl_source_tmp = ossl_source + ".tmp"
if os.path.isdir(ossl_source_tmp):
shutil.rmtree(ossl_source_tmp)
if version != "*":
version = version.split(".")
length = len(version)
index = 0
while index < length:
version[index] = int(version[index])
index += 1
ossl_target="mingw"
ossl_prefix="i686-w64-mingw32-"
if target == "x86-64":
ossl_target="mingw64"
ossl_prefix="x86_64-w64-mingw32-"
cmd = ["./config",ossl_target,"no-asm","--cross-compile-prefix=" +ossl_prefix,"--prefix=" +p(ossl_source,"usr")]
if config != "": cmd = cmd + shlex.split(config)
print("Config:",cmd)
print("Managing git repo ...")
if os.path.isdir(ossl_source):
git(ossl_source,"checkout","--",".")
git(ossl_source,"clean","-f","-d","-x")
git(ossl_source,"checkout","master")
git(ossl_source,"fetch","--tags")
git(ossl_source,"pull")
else:
git(sp,"clone",mirror,ossl_source_tmp)
os.rename(ossl_source_tmp,p(sp,ossl_source))
gitc = ["tag","-l"]
proc = git(ossl_source,*gitc,gitwait=False,stdout=subprocess.PIPE)
tags = proc.stdout.read().decode("utf-8").strip("\n").split("\n")
perr(proc.wait(),["git"] + gitc)
#for tag in tags:
# print(tag)
ossl_versions = parseTags(tags)
#for tag in ossl_versions:
# print(tag,ossl_versions[tag])
nversion = ["",[0,0,0,0]]
if version == "*":
for ver in ossl_versions:
versionData = ossl_versions[ver]
if versionData[:4] < nversion[1]: continue
if versionData[4] != "stable": continue
nversion[0] = ver
nversion[1] = versionData[:4]
else:
vlength = len(version)
for ver in ossl_versions:
versionData = ossl_versions[ver]
if versionData[:4] < nversion[1]: continue
if versionData[4] != "stable": continue
if versionData[:vlength] > version: continue
if versionData[:vlength] < version: continue
nversion[0] = ver
nversion[1] = versionData[:4]
if nversion[0] == "":
print("Matching version for '" +str(version)+ "' not found")
sys.exit(1)
print("Building OpenSSL " +nversion[0]+ " ...")
try:
git(ossl_source,"branch","-D","ofw-" +nversion[0])
except subprocess.CalledProcessError:
pass
git(ossl_source,"checkout","tags/" +nversion[0],"-b","ofw-" +nversion[0])
pcall(cmd,cwd=ossl_source)
pcall(["make","depend","-j" +pcallStr("nproc")],cwd=ossl_source)
pcall(["make","-j" +pcallStr("nproc")],cwd=ossl_source)
pcall(["make","install_sw"],cwd=ossl_source)
main()