Added Lua recipe.
This commit is contained in:
parent
0dcd8b383c
commit
42a433582c
49
recipes/lua/recipe.py
Normal file
49
recipes/lua/recipe.py
Normal file
@ -0,0 +1,49 @@
|
||||
|
||||
|
||||
|
||||
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']
|
||||
lib_lua = env.StaticLibrary(
|
||||
CCFLAGS = env['CCFLAGS'] + ['-Wno-pedantic'], # 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]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user