is there a way to compile a c/c++ program from python?
Currently I'm coding a python script to compile a C/C++ Linux kernel in the following way:
subprocess.check_call(["make", "-j5"]) subprocess.check_call(["make", "-j5", "modules_install"]) subprocess.check_call(["make", "-j5", "install"])
With these approach the commands are executed in the shell. So I was wondering if there is another way to compile the kernel using python build in libraries?
Ultimately, python isn't a C/C++ compiler, so you need to ship out the compiling to an external program (e.g. gcc). So, there is no way to do this entirely in python.
Note that here python doesn't spawn any shells (although make might). You could try to reproduce what make does entirely in python, (there is a version of make written in python FWIW), but honestly, it's not worth it. You need to spawn subprocesses anyway -- you might as well use the tools which are already in place and "tried and true".