PY_O_BASENAME

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
Tetraeder
Posts: 53
Joined: Thu Mar 05, 2015 1:12 pm
Location: Germany

PY_O_BASENAME

Post by Tetraeder » Tue Nov 10, 2015 10:13 am

Hello,
can someone explain me how the makefile compile the python object files (https://github.com/micropython/micropyt ... /py.mk#L61), although the file extension is .c /.s?

Is the solution in the file mkrules.mk https://github.com/micropython/micropyt ... ules.mk#L1 ??

stijn
Posts: 406
Joined: Thu Apr 24, 2014 9:13 am

Re: PY_O_BASENAME

Post by stijn » Tue Nov 10, 2015 10:30 am

Tetraeder wrote:Is the solution in the file mkrules.mk https://github.com/micropython/micropyt ... ules.mk#L1 ??
see the comments in that file, https://github.com/micropython/micropyt ... ules.mk#L7, and specifically the implementation at https://github.com/micropython/micropyt ... les.mk#L46:

Code: Select all

$(BUILD)/%.o: %.c
	$(call compile_c)
so any c file which has a matching object name will be handled using compile_c

User avatar
platforma
Posts: 258
Joined: Thu May 28, 2015 5:08 pm
Location: Japan

Re: PY_O_BASENAME

Post by platforma » Tue Nov 10, 2015 12:32 pm

It is confusing at first, the best thing is to read up more on pattern rules and implicit rules and look at a few examples:
https://www.gnu.org/software/make/manua ... tern-Match

User avatar
dhylands
Posts: 3268
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: PY_O_BASENAME

Post by dhylands » Tue Nov 10, 2015 4:33 pm

I think that one of the biggest problems with understanding make is that people start at the source and try to build an executable.

make actually works the reverse way around. It's all about dependencies.

So you start at the executable, and you say, what does this executable depend on? And how do I build those dependencies?
The executable (an .elf file) depends on objects, and those objects depend on source and header files. Some sources and/or headers are generated, and those then depend the files used to generate them.

It's a subtle distinction, but a very important one to understand when trying to understand how make works.

User avatar
platforma
Posts: 258
Joined: Thu May 28, 2015 5:08 pm
Location: Japan

Re: PY_O_BASENAME

Post by platforma » Tue Nov 10, 2015 4:55 pm

That's right, think of them as recipes for building your application. There's no straight flow as such when you read a make file, although can be. You can also read up on the declarative programming paradigm. I genuinely find gnumake manual the best thing to read through if you have time :)

Post Reply