Skip to content

tools: add a convert tool to help migrate from make to cmake #9782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

raiden00pl
Copy link
Member

Summary

A simple tool that convert arch/board makefiles to cmake files. Tested with stm32, don't know if it'll work with other architectures.

It's a really dumb not finished tool that is not ready for upstream so I keep it as a draft.
Maybe someone will find it useful. The results usually require minor manual adjustments, but this makes the job much easier.

Usage:
python tools/nxmake2cmake.py arch/arm/src/stm32f0l0g0
python tools/nxmake2cmake.py boards/arm/stm32/nucleo-f302r8

Impact

Testing

@acassis
Copy link
Contributor

acassis commented Jul 11, 2023

@raiden00pl that is a great idea! In fact working on two build systems at same time it not easy, at least this script will help to simplify the process!

@raiden00pl
Copy link
Member Author

@acassis That's right, using two build systems is a pain. I personally migrate all my NuttX based code to CMake now.

I was a bit skeptical about CMake as I don't know it at all, but once it's upstream it's a good motivation to learn. After a few days of using it, I can confidently say that it is a positive change. Faster build and out-of-source builds convince me. The CMake syntax isn't even that disgusting once you get used to it for a while ;)

@acassis
Copy link
Contributor

acassis commented Jul 11, 2023

I agree @raiden00pl !!! It will make NuttX integration easier!

@midokura-xavi92
Copy link
Contributor

midokura-xavi92 commented Jul 12, 2023

Thank you a lot for your contribution! Please let me share a few comments and minor concerns:

Usage:
python tools/nxmake2cmake.py arch/arm/src/stm32f0l0g0
python tools/nxmake2cmake.py boards/arm/stm32/nucleo-f302r8

I am not sure if there any systems out there still mapping python to python2, so IMHO it might be sensible to enforce the use of python3 for this script or, considering it already defines a shebang, just calling it directly i.e., tools/nxmake2cmake.py ....

Of course, the latter syntax would not be acceptable for non-POSIX environments e.g.: MS Windows, although I am not sure whether these a supported target within this project.

@midokura-xavi92
Copy link
Contributor

Usage:
python tools/nxmake2cmake.py arch/arm/src/stm32f0l0g0

Coincidentally, the example provided above includes another Makefile:

include armv6-m/Make.defs

The file referred to above seems to define another bunch of source files. However, nxmake2cmake.py seems to explicitly ignore lines with include, so none of these source files are being appended to the generated CMakeLists.txt. Is this intended?

@midokura-xavi92
Copy link
Contributor

Nit: similar tools, such as parsememdump.py, have their +x bit set. Considering nxmake2cmake.py also defines a shebang (i.e., #!/usr/bin/env python3), maybe this was a leftover?

@raiden00pl
Copy link
Member Author

Usage:
python tools/nxmake2cmake.py arch/arm/src/stm32f0l0g0

Coincidentally, the example provided above includes another Makefile:

include armv6-m/Make.defs

The file referred to above seems to define another bunch of source files. However, nxmake2cmake.py seems to explicitly ignore lines with include, so none of these source files are being appended to the generated CMakeLists.txt. Is this intended?

The included Makefile is handled elsewhere (https://github.com/apache/nuttx/blob/f43c7e99bedd8ea0cc2e3e6c2c796c38dbb8f354/arch/arm/src/cmake/armv7-m.cmake), so we can just ignore it.

Nit: similar tools, such as parsememdump.py, have their +x bit set. Considering nxmake2cmake.py also defines a shebang (i.e., #!/usr/bin/env python3), maybe this was a leftover?

I see that all .py files in tools/ have +x set, so I changed it here as well

@github-actions github-actions bot added Area: Tooling Size: M The size of the change in this PR is medium labels Apr 23, 2025
content = content.replace("ifeq ($", "if")
content = content.replace("ifneq ($(", "if(NOT ")
content = content.replace("else", "else()")
content = content.replace("endif", "endif()")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    content = content.replace("else ifeq ($", "elseif")   
    content = content.replace("ifeq ($", "if")
    content = content.replace("ifneq ($(", "if(NOT ")

added “else ifeq”

    content = content.replace("else\n", "else()\n")
    content = content.replace("endif\n", "endif()\n")

Need to add \n to not replace “else ifeq”

content = ""
with open(mpath, "r") as fm:
content = fm.read()
content = content.replace(mpath, cpath)
Copy link
Contributor

@simbit18 simbit18 Apr 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows, it does not replace the filename (Windows paths are different from Unix)
simple change
content = content.replace(mpath, cpath)
with
content = content.replace("src/Make.defs", "src/CMakeLists.txt")

content = ""
with open(mdpath, "r") as fm:
content = fm.read()
content = content.replace(mdpath, cpath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows, it does not replace the filename (Windows paths are different from Unix)
simple change
content = content.replace(mpath, cpath)
with
content = content.replace("src/Make.defs", "src/CMakeLists.txt")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Tooling Size: M The size of the change in this PR is medium
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants