Skip to content

Commit 141998d

Browse files
authored
Merge pull request #2584 from martin-frbg/issue2583
[WIP] Have CMAKE parse conditional lines in KERNEL files
2 parents b6795db + 3bd5684 commit 141998d

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

cmake/utils.cmake

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,33 @@ endfunction ()
1515
# Reads a Makefile into CMake vars.
1616
macro(ParseMakefileVars MAKEFILE_IN)
1717
message(STATUS "Reading vars from ${MAKEFILE_IN}...")
18+
set (IfElse 0)
19+
set (ElseSeen 0)
1820
file(STRINGS ${MAKEFILE_IN} makefile_contents)
1921
foreach (makefile_line ${makefile_contents})
22+
#message(STATUS "parsing ${makefile_line}")
23+
if (${IfElse} GREATER 0)
24+
string(REGEX MATCH "endif[ \t]*" line_match "${makefile_line}")
25+
if (NOT "${line_match}" STREQUAL "")
26+
# message(STATUS "ENDIF ${makefile_line}")
27+
set (IfElse 0)
28+
set (ElseSeen 0)
29+
continue ()
30+
endif ()
31+
string(REGEX MATCH "else[ \t]*" line_match "${makefile_line}")
32+
if (NOT "${line_match}" STREQUAL "")
33+
# message(STATUS "ELSE ${makefile_line}")
34+
set (ElseSeen 1)
35+
continue ()
36+
endif()
37+
if ( (${IfElse} EQUAL 2 AND ${ElseSeen} EQUAL 0) OR ( ${IfElse} EQUAL 1 AND ${ElseSeen} EQUAL 1))
38+
# message(STATUS "skipping ${makefile_line}")
39+
continue ()
40+
endif ()
41+
endif ()
2042
string(REGEX MATCH "([0-9_a-zA-Z]+)[ \t]*=[ \t]*(.+)$" line_match "${makefile_line}")
2143
if (NOT "${line_match}" STREQUAL "")
44+
#message(STATUS "match on ${line_match}")
2245
set(var_name ${CMAKE_MATCH_1})
2346
set(var_value ${CMAKE_MATCH_2})
2447
# check for Makefile variables in the string, e.g. $(TSUFFIX)
@@ -33,7 +56,31 @@ macro(ParseMakefileVars MAKEFILE_IN)
3356
else ()
3457
string(REGEX MATCH "include \\$\\(KERNELDIR\\)/(.+)$" line_match "${makefile_line}")
3558
if (NOT "${line_match}" STREQUAL "")
59+
#message(STATUS "match on include ${line_match}")
3660
ParseMakefileVars(${KERNELDIR}/${CMAKE_MATCH_1})
61+
else ()
62+
# message(STATUS "unmatched line ${line_match}")
63+
string(REGEX MATCH "ifeq \\(\\$\\(([_A-Z]+)\\),[ \t]*([0-9_A-Z]+)\\)" line_match "${makefile_line}")
64+
if (NOT "${line_match}" STREQUAL "")
65+
# message(STATUS "IFEQ: ${line_match} first: ${CMAKE_MATCH_1} second: ${CMAKE_MATCH_2}")
66+
if (${${CMAKE_MATCH_1}} STREQUAL ${CMAKE_MATCH_2})
67+
# message (STATUS "condition is true")
68+
set (IfElse 1)
69+
else ()
70+
set (IfElse 2)
71+
endif ()
72+
else ()
73+
string(REGEX MATCH "ifneq \\(\\$\\(([_A-Z]+)\\),[ \t]*([0-9_A-Z]+)\\)" line_match "${makefile_line}")
74+
if (NOT "${line_match}" STREQUAL "")
75+
# message(STATUS "IFNEQ: ${line_match} first: ${CMAKE_MATCH_1} second: ${CMAKE_MATCH_2}")
76+
if (NOT ( ${${CMAKE_MATCH_1}} STREQUAL ${CMAKE_MATCH_2}))
77+
# message (STATUS "condition is true")
78+
set (IfElse 1)
79+
else ()
80+
set (IfElse 2)
81+
endif ()
82+
endif ()
83+
endif ()
3784
endif ()
3885
endif ()
3986
endforeach ()

0 commit comments

Comments
 (0)