<commit_before># Functions to help with the OpenBLAS build

# Reads string from getarch into CMake vars. Format of getarch vars is VARNAME=VALUE
function(ParseGetArchVars GETARCH_IN)
  string(REGEX MATCHALL "[0-9_a-zA-Z]+=[0-9_a-zA-Z]+" GETARCH_RESULT_LIST "${GETARCH_IN}")
  foreach (GETARCH_LINE ${GETARCH_RESULT_LIST})
    # split the line into var and value, then assign the value to a CMake var
    string(REGEX MATCHALL "[0-9_a-zA-Z]+" SPLIT_VAR "${GETARCH_LINE}")
    list(GET SPLIT_VAR 0 VAR_NAME)
    list(GET SPLIT_VAR 1 VAR_VALUE)
    set(${VAR_NAME} ${VAR_VALUE} PARENT_SCOPE)
  endforeach ()
endfunction ()

# Reads a Makefile into CMake vars.
macro(ParseMakefileVars MAKEFILE_IN)
  message(STATUS "Reading vars from ${MAKEFILE_IN}...")
  file(STRINGS ${MAKEFILE_IN} makefile_contents)
  foreach (makefile_line ${makefile_contents})
    string(REGEX MATCH "([0-9_a-zA-Z]+)[ \t]*=[ \t]*(.+)$" line_match "${makefile_line}")
    if (NOT "${line_match}" STREQUAL "")
      set(var_name ${CMAKE_MATCH_1})
      set(var_value ${CMAKE_MATCH_2})
      # check for Makefile variables in the string, e.g. $(TSUFFIX)
      string(REGEX MATCHALL "\\$\\(([0-9_a-zA-Z]+)\\)" make_var_matches ${var_value})
      foreach (make_var ${make_var_matches})
        # strip out Makefile $() markup
        string(REGEX REPLACE "\\$\\(([0-9_a-zA-Z]+)\\)" "\\1" make_var ${make_var})
        # now replace the instance of the Makefile variable with the value of the CMake variable (note the double quote)
        string(REPLACE "$(${make_var})" "${${make_var}}" var_value ${var_value})
      endforeach ()
      set(${var_name} ${var_value})
    else ()
      string(REGEX MATCH "include \\$\\(KERNELDIR\\)/(.+)$" line_match "${makefile_line}")
      if (NOT "${line_match}" STREQUAL "")
        ParseMakefileVars(${KERNELDIR}/${CMAKE_MATCH_1})
      endif ()
    endif ()
  endforeach ()
endmacro ()

# Returns all combinations of the input list, as a list with colon-separated combinations
# E.g. input of A B C returns A B C A:B A:C B:C
# N.B. The input is meant to be a list, and to past a list to a function in CMake you must quote it (e.g. AllCombinations("${LIST_VAR}")).<commit_msg>Have CMAKE parse conditional lines in KERNEL files<commit_after># Functions to help with the OpenBLAS build

# Reads string from getarch into CMake vars. Format of getarch vars is VARNAME=VALUE
function(ParseGetArchVars GETARCH_IN)
  string(REGEX MATCHALL "[0-9_a-zA-Z]+=[0-9_a-zA-Z]+" GETARCH_RESULT_LIST "${GETARCH_IN}")
  foreach (GETARCH_LINE ${GETARCH_RESULT_LIST})
    # split the line into var and value, then assign the value to a CMake var
    string(REGEX MATCHALL "[0-9_a-zA-Z]+" SPLIT_VAR "${GETARCH_LINE}")
    list(GET SPLIT_VAR 0 VAR_NAME)
    list(GET SPLIT_VAR 1 VAR_VALUE)
    set(${VAR_NAME} ${VAR_VALUE} PARENT_SCOPE)
  endforeach ()
endfunction ()

# Reads a Makefile into CMake vars.
macro(ParseMakefileVars MAKEFILE_IN)
  message(STATUS "Reading vars from ${MAKEFILE_IN}...")
        set (IfElse 0)
        set (ElseSeen 0)
  file(STRINGS ${MAKEFILE_IN} makefile_contents)
  foreach (makefile_line ${makefile_contents})
#message(STATUS "parsing ${makefile_line}")
    if (${IfElse} GREATER 0)
      string(REGEX MATCH "endif[ \t]*" line_match "${makefile_line}")
      if (NOT "${line_match}" STREQUAL "")
#           message(STATUS "ENDIF ${makefile_line}")
        set (IfElse 0)
        set (ElseSeen 0)
        continue ()
      endif ()
      string(REGEX MATCH "else[ \t]*" line_match "${makefile_line}")
        if (NOT "${line_match}" STREQUAL "") 
#           message(STATUS "ELSE ${makefile_line}")
           set (ElseSeen 1)        
           continue ()  
        endif()
      if ( (${IfElse} EQUAL 2 AND ${ElseSeen} EQUAL 0) OR ( ${IfElse} EQUAL 1 AND ${ElseSeen} EQUAL 1))
#           message(STATUS "skipping ${makefile_line}")
         continue ()
      endif ()    
    endif ()    
    string(REGEX MATCH "([0-9_a-zA-Z]+)[ \t]*=[ \t]*(.+)$" line_match "${makefile_line}")
    if (NOT "${line_match}" STREQUAL "")
#message(STATUS "match on ${line_match}")
      set(var_name ${CMAKE_MATCH_1})
      set(var_value ${CMAKE_MATCH_2})
      # check for Makefile variables in the string, e.g. $(TSUFFIX)
      string(REGEX MATCHALL "\\$\\(([0-9_a-zA-Z]+)\\)" make_var_matches ${var_value})
      foreach (make_var ${make_var_matches})
        # strip out Makefile $() markup
        string(REGEX REPLACE "\\$\\(([0-9_a-zA-Z]+)\\)" "\\1" make_var ${make_var})
        # now replace the instance of the Makefile variable with the value of the CMake variable (note the double quote)
        string(REPLACE "$(${make_var})" "${${make_var}}" var_value ${var_value})
      endforeach ()
      set(${var_name} ${var_value})
    else ()
      string(REGEX MATCH "include \\$\\(KERNELDIR\\)/(.+)$" line_match "${makefile_line}")
      if (NOT "${line_match}" STREQUAL "")
#message(STATUS "match on include ${line_match}")
        ParseMakefileVars(${KERNELDIR}/${CMAKE_MATCH_1})
      else ()
#        message(STATUS "unmatched line ${line_match}")
        string(REGEX MATCH "ifeq \\(\\$\\(([_A-Z]+)\\),[ \t]*([0-9_A-Z]+)\\)" line_match "${makefile_line}")
        if (NOT "${line_match}" STREQUAL "")
#          message(STATUS "IFEQ: ${line_match} first: ${CMAKE_MATCH_1} second: ${CMAKE_MATCH_2}")
          if (${${CMAKE_MATCH_1}} STREQUAL ${CMAKE_MATCH_2})
#            message (STATUS "condition is true")
            set (IfElse 1)
          else ()
            set (IfElse 2)
          endif ()
        else ()
          string(REGEX MATCH "ifneq \\(\\$\\(([_A-Z]+)\\),[ \t]*([0-9_A-Z]+)\\)" line_match "${makefile_line}")
          if (NOT "${line_match}" STREQUAL "")
#            message(STATUS "IFNEQ: ${line_match} first: ${CMAKE_MATCH_1} second: ${CMAKE_MATCH_2}")
            if (NOT ( ${${CMAKE_MATCH_1}} STREQUAL ${CMAKE_MATCH_2}))
              message (STATUS "condition is true")
              set (IfElse 1)
            else ()
              set (IfElse 2)
            endif ()
          endif ()
        endif ()
      endif ()
    endif ()
  endforeach ()
endmacro ()

# Returns all combinations of the input list, as a list with colon-separated combinations
# E.g. input of A B C returns A B C A:B A:C B:C
# N.B. The input is meant to be a list, and to past a list to a function in CMake you must quote it (e.g. AllCombinations("${LIST_VAR}")).
{'fraction_non_alphanumeric': 0.15428033866415805, 'fraction_numerical': 0.009720915647538414, 'mean_word_length': 3.1261319534282017, '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': '1307578', 'n_tokens_mistral': 2284, 'n_tokens_neox': 2177, 'n_words': 606}