<commit_before># Macro for finding a substring
macro (find_string find_regex input_string output_string)
    if (NOT DEFINED ${output_string}${ARGN})
        message (STATUS "Finding value for LuaJIT:${output_string}${ARGN}")
        string (REGEX MATCH ${find_regex} matched ${input_string})
        if (matched)
            string (REGEX MATCH "\\(.*\\)" captured ${find_regex})
            if (captured) 
                string (REGEX REPLACE ${find_regex} \\1 matched ${matched})
            endif ()
            set (${output_string}${ARGN} ${matched} CACHE INTERNAL "LUAJIT INTERNAL - ${output_string}${ARGN}")
            message (STATUS "Finding value for LuaJIT:${output_string}${ARGN} - found (${matched})")
        else ()
            set (${output_string}${ARGN} 0 CACHE INTERNAL "LUAJIT INTERNAL - ${output_string}${ARGN}")
        endif ()
    endif ()
    if (${ARGC} EQUAL 4)
        list (GET ${output_string}${ARGN} 0 ${output_string})
   endif ()
endmacro ()

# Makefile: Architecture detection
find_string ("LJ_TARGET_(X64|X86|ARM|PPC|PPCSPE|MIPS) 1" "${TARGET_TESTARCH}" TARGET_LJARCH ${VARIANT})
if (TARGET_LJARCH)
    string (TOLOWER ${TARGET_LJARCH} TARGET_LJARCH)
    set (TARGET_LJARCH${VARIANT} ${TARGET_LJARCH} CACHE INTERNAL "LUAJIT INTERNAL - TARGET_LJARCH${VARIANT}")
    if (TARGET_LJARCH STREQUAL x64 AND NOT ENABLE_64BIT)
        set (TARGET_LJARCH x86)
    endif ()
else ()
    message (FATAL_ERROR "Unsupported target architecture") 
endif () 
if (TARGET_LJARCH STREQUAL mips)
    find_string ("MIPSEL (1)" "${TARGET_TESTARCH}" MIPSEL ${VARIANT})
    if (MIPSEL)
        set (TARGET_ARCH ${TARGET_ARCH} -D__MIPSEL__=1)
    endif ()
endif ()

find_string ("LJ_TARGET_PS3 (1)" "${TARGET_TESTARCH}" PS3 ${VARIANT})
if (PS3)
    set (TARGET_SYS PS3)
    set (TARGET_ARCH ${TARGET_ARCH} -D__CELLOS_LV2__)
    add_definitions (-DLUAJIT_USE_SYSMALLOC)
endif ()

find_string ("LJ_NO_UNWIND (1)" "${TARGET_TESTARCH}" NO_UNWIND ${VARIANT})
if (NO_UNWIND)
    set (TARGET_ARCH ${TARGET_ARCH} -DLUAJIT_NO_UNWIND)
endif ()

set (TARGET_ARCH ${TARGET_ARCH} -DLUAJIT_TARGET=LUAJIT_ARCH_${TARGET_LJARCH})

# Makefile: System detection
if (WIN32)
    set (HOST_SYS Windows)
else ()
    execute_process (COMMAND uname -s OUTPUT_VARIABLE HOST_SYS ERROR_QUIET)
endif ()
if (CMAKE_CROSSCOMPILING OR IOS)
    if (IOS)
        set (TARGET_SYS iOS)
        set (HOST_XCFLAGS ${HOST_XCFLAGS} -DLUAJIT_OS=LUAJIT_OS_OSX)
    else ()
        if (NOT TARGET_SYS)
            set (TARGET_SYS ${CMAKE_SYSTEM_NAME})
        endif ()        
        if (TARGET_SYS STREQUAL Windows)
            set (HOST_XCFLAGS ${HOST_XCFLAGS} -malign-double -DLUAJIT_OS=LUAJIT_OS_WINDOWS)
        elseif (TARGET_SYS STREQUAL Linux)
            set (HOST_XCFLAGS ${HOST_XCFLAGS} -DLUAJIT_OS=LUAJIT_OS_LINUX)
        elseif (TARGET_SYS STREQUAL Darwin)
            set (HOST_XCFLAGS ${HOST_XCFLAGS} -DLUAJIT_OS=LUAJIT_OS_OSX)
        else ()
            set (HOST_XCFLAGS ${HOST_XCFLAGS} -DLUAJIT_OS=LUAJIT_OS_OTHER)
        endif ()
    endif ()
else ()
    # Not cross compiling
    set (TARGET_SYS ${HOST_SYS})
endif ()

# Makefile: Files and pathnames
set (DASM_DIR ${PROJECT_SOURCE_DIR}/ThirdParty/LuaJIT/dynasm)
set (DASM_ARCH ${TARGET_LJARCH})

# Below regex is a workaround for "LJ_ARCH_BITS (.*?)\\n" as CMake does not understand non-greedy quantifier
find_string ("LJ_ARCH_BITS ([^\\n]*)" "${TARGET_TESTARCH}" ARCH_BITS ${VARIANT})
if (ARCH_BITS EQUAL 64)
    if (ENABLE_64BIT)
        set (DASM_AFLAGS ${DASM_AFLAGS} -D P64)
    else ()
        set (ARCH_BITS 32)
    endif ()
endif ()
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m${ARCH_BITS}")

find_string ("LJ_HASJIT (1)" "${TARGET_TESTARCH}" HASJIT ${VARIANT})
if (HASJIT)
    set (DASM_AFLAGS ${DASM_AFLAGS} -D JIT)
endif ()

find_string ("LJ_HASFFI (1)" "${TARGET_TESTARCH}" HASFFI ${VARIANT})
if (HASFFI)<commit_msg>Fixed LuaJIT native build on Raspberry Pi.<commit_after># Macro for finding a substring
macro (find_string find_regex input_string output_string)
    if (NOT DEFINED ${output_string}${ARGN})
        message (STATUS "Finding value for LuaJIT:${output_string}${ARGN}")
        string (REGEX MATCH ${find_regex} matched ${input_string})
        if (matched)
            string (REGEX MATCH "\\(.*\\)" captured ${find_regex})
            if (captured) 
                string (REGEX REPLACE ${find_regex} \\1 matched ${matched})
            endif ()
            set (${output_string}${ARGN} ${matched} CACHE INTERNAL "LUAJIT INTERNAL - ${output_string}${ARGN}")
            message (STATUS "Finding value for LuaJIT:${output_string}${ARGN} - found (${matched})")
        else ()
            set (${output_string}${ARGN} 0 CACHE INTERNAL "LUAJIT INTERNAL - ${output_string}${ARGN}")
        endif ()
    endif ()
    if (${ARGC} EQUAL 4)
        list (GET ${output_string}${ARGN} 0 ${output_string})
   endif ()
endmacro ()

# Makefile: Architecture detection
find_string ("LJ_TARGET_(X64|X86|ARM|PPC|PPCSPE|MIPS) 1" "${TARGET_TESTARCH}" TARGET_LJARCH ${VARIANT})
if (TARGET_LJARCH)
    string (TOLOWER ${TARGET_LJARCH} TARGET_LJARCH)
    set (TARGET_LJARCH${VARIANT} ${TARGET_LJARCH} CACHE INTERNAL "LUAJIT INTERNAL - TARGET_LJARCH${VARIANT}")
    if (TARGET_LJARCH STREQUAL x64 AND NOT ENABLE_64BIT)
        set (TARGET_LJARCH x86)
    endif ()
else ()
    message (FATAL_ERROR "Unsupported target architecture") 
endif () 
if (TARGET_LJARCH STREQUAL mips)
    find_string ("MIPSEL (1)" "${TARGET_TESTARCH}" MIPSEL ${VARIANT})
    if (MIPSEL)
        set (TARGET_ARCH ${TARGET_ARCH} -D__MIPSEL__=1)
    endif ()
endif ()

find_string ("LJ_TARGET_PS3 (1)" "${TARGET_TESTARCH}" PS3 ${VARIANT})
if (PS3)
    set (TARGET_SYS PS3)
    set (TARGET_ARCH ${TARGET_ARCH} -D__CELLOS_LV2__)
    add_definitions (-DLUAJIT_USE_SYSMALLOC)
endif ()

find_string ("LJ_NO_UNWIND (1)" "${TARGET_TESTARCH}" NO_UNWIND ${VARIANT})
if (NO_UNWIND)
    set (TARGET_ARCH ${TARGET_ARCH} -DLUAJIT_NO_UNWIND)
endif ()

set (TARGET_ARCH ${TARGET_ARCH} -DLUAJIT_TARGET=LUAJIT_ARCH_${TARGET_LJARCH})

# Makefile: System detection
if (WIN32)
    set (HOST_SYS Windows)
else ()
    execute_process (COMMAND uname -s OUTPUT_VARIABLE HOST_SYS ERROR_QUIET)
endif ()
if (CMAKE_CROSSCOMPILING OR IOS)
    if (IOS)
        set (TARGET_SYS iOS)
        set (HOST_XCFLAGS ${HOST_XCFLAGS} -DLUAJIT_OS=LUAJIT_OS_OSX)
    else ()
        if (NOT TARGET_SYS)
            set (TARGET_SYS ${CMAKE_SYSTEM_NAME})
        endif ()        
        if (TARGET_SYS STREQUAL Windows)
            set (HOST_XCFLAGS ${HOST_XCFLAGS} -malign-double -DLUAJIT_OS=LUAJIT_OS_WINDOWS)
        elseif (TARGET_SYS STREQUAL Linux)
            set (HOST_XCFLAGS ${HOST_XCFLAGS} -DLUAJIT_OS=LUAJIT_OS_LINUX)
        elseif (TARGET_SYS STREQUAL Darwin)
            set (HOST_XCFLAGS ${HOST_XCFLAGS} -DLUAJIT_OS=LUAJIT_OS_OSX)
        else ()
            set (HOST_XCFLAGS ${HOST_XCFLAGS} -DLUAJIT_OS=LUAJIT_OS_OTHER)
        endif ()
    endif ()
else ()
    # Not cross compiling
    set (TARGET_SYS ${HOST_SYS})
endif ()

# Makefile: Files and pathnames
set (DASM_DIR ${PROJECT_SOURCE_DIR}/ThirdParty/LuaJIT/dynasm)
set (DASM_ARCH ${TARGET_LJARCH})

# Below regex is a workaround for "LJ_ARCH_BITS (.*?)\\n" as CMake does not understand non-greedy quantifier
find_string ("LJ_ARCH_BITS ([^\\n]*)" "${TARGET_TESTARCH}" ARCH_BITS ${VARIANT})
if (ARCH_BITS EQUAL 64)
    if (ENABLE_64BIT)
        set (DASM_AFLAGS ${DASM_AFLAGS} -D P64)
    else ()
        set (ARCH_BITS 32)
    endif ()
endif ()
if (TARGET_LJARCH STREQUAL x64)
    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m${ARCH_BITS}")
endif ()

find_string ("LJ_HASJIT (1)" "${TARGET_TESTARCH}" HASJIT ${VARIANT})
if (HASJIT)
    set (DASM_AFLAGS ${DASM_AFLAGS} -D JIT)
endif ()

find_string ("LJ_HASFFI (1)" "${TARGET_TESTARCH}" HASFFI ${VARIANT})
if (HASFFI)
{'fraction_non_alphanumeric': 0.12772226492441713, 'fraction_numerical': 0.009479887266205482, 'mean_word_length': 3.674850299401198, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6983402', 'n_tokens_mistral': 3018, 'n_tokens_neox': 2889, 'n_words': 666}