55 lines
2.0 KiB
Python
55 lines
2.0 KiB
Python
|
|
|
|
|
|
import json
|
|
import os
|
|
import re
|
|
import requests
|
|
from SCons.Script import *
|
|
|
|
_VERSIONS_URL = 'https://www.lua.org/ftp/'
|
|
_VERSION_PATTERN = re.compile(r'HREF="lua-([0-9]+)\.([0-9]+)\.([0-9]+)\.tar\.gz"')
|
|
|
|
def versions(env: Environment, update: bool = False):
|
|
versions_file = os.path.join(env['DOWNLOAD_DIR'], 'lua_versions.json')
|
|
if update or not os.path.exists(versions_file):
|
|
req = requests.get(_VERSIONS_URL)
|
|
result = []
|
|
for match in _VERSION_PATTERN.finditer(req.text):
|
|
result.append((int(match.groups()[0]), int(match.groups()[1]), int(match.groups()[2])))
|
|
with open(versions_file, 'w') as f:
|
|
json.dump(result, f)
|
|
return result
|
|
else:
|
|
try:
|
|
with open(versions_file, 'r') as f:
|
|
return [tuple(v) for v in json.load(f)]
|
|
except:
|
|
print('lua_versions.json is empty or broken, redownloading.')
|
|
return versions(env, update=True)
|
|
|
|
def dependencies(env: Environment, version) -> 'dict':
|
|
return {}
|
|
|
|
def cook(env: Environment, version) -> dict:
|
|
url = f'https://www.lua.org/ftp/lua-{version[0]}.{version[1]}.{version[2]}.tar.gz'
|
|
repo = env.DownloadAndExtract(f'lua_{version[0]}.{version[1]}.{version[2]}', url = url, skip_folders = 1)
|
|
checkout_root = repo['extracted_root']
|
|
src_folder = os.path.join(checkout_root, 'src')
|
|
lua_source_files = [f for f in env.RGlob(src_folder, '*.c') if f.name != 'lua.c']
|
|
additional_ccflags = []
|
|
if env['COMPILER_FAMILY'] in ('gcc', 'clang'):
|
|
additional_ccflags.append('-Wno-pedantic')
|
|
elif env['COMPILER_FAMILY'] == 'cl':
|
|
additional_ccflags.extend(['/wd4244', '/wd4310', '/wd4324', '/wd4701'])
|
|
lib_lua = env.StaticLibrary(
|
|
CCFLAGS = env['CCFLAGS'] + additional_ccflags, # Lua uses a GNU extension for taking addresses of labels
|
|
target = env['LIB_DIR'] + '/lua_full',
|
|
source = lua_source_files
|
|
)
|
|
|
|
return {
|
|
'CPPPATH': [src_folder],
|
|
'LIBS': [lib_lua]
|
|
}
|