Makefile question

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
ExXec
Posts: 71
Joined: Sat Oct 20, 2018 4:02 pm

Makefile question

Post by ExXec » Sun Jul 07, 2019 4:38 pm

Hey,
I have a problem with the "DEBUG" variable in my makefile.
It is set to 1 in the first line of my makefile and when i print it in my target it shows as "1", but the conditional for the compiler flags sees "0".

If I call make DEBUG=1 it works as expected again.

Does anyone know why this happens?
Thanks a lot!
-ExXec

Code: Select all

DEBUG ?= 1 
LINK_TIME_OPT = 1 
...
ifeq ($(DEBUG), 1)
CFLAGS += -ggdb -DDEBUG -g -DPENDSV_DEBUG
COPT += -O0 
else
COPT += -Os -DNDEBUG
# Flags for Link Time Optimization
ifeq ($(LINK_TIME_OPT), 1)
CFLAGS += -flto -fuse-linker-plugin
endif
endif
Example:

Code: Select all

Input: 
	make DEBUG=1
Output:
+---------------------------------------------------
+ DEBUG = 1
+---------------------------------------------------
+ Size = 257224 + 624 kiB
+---------------------------------------------------
+ OPT-Flags: -O0
+---------------------------------------------------
ok bc no optimization happening as intended

Code: Select all

Input: 
	make
Output:
+---------------------------------------------------
+ DEBUG = 1
+---------------------------------------------------
+ Size = 157568 + 624 kiB
+---------------------------------------------------
+ OPT-Flags: -Os -DNDEBUG
+---------------------------------------------------
Bad, optimization even though its turned off

Link to the file: https://github.com/ExXeptional/micropyt ... 3/Makefile

Code for output:

Code: Select all

@echo +---------------------------------------------------
@echo + DEBUG = $(DEBUG)
@echo +---------------------------------------------------
@echo + Size = $(word 7, $(shell $(CROSS_COMPILE)size -Bd $(PROJECT_NAME).axf)) + $(word 8, $(shell $(CROSS_COMPILE)size -Bd $(PROJECT_NAME).axf)) kiB
@echo +---------------------------------------------------
@echo + OPT-Flags: $(COPT)
@echo +---------------------------------------------------
(also if anyone knows how to prperly display the size of the final binary, please do tell)

Online
User avatar
jimmo
Posts: 420
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

Re: Makefile question

Post by jimmo » Sun Jul 07, 2019 11:25 pm

It's the same issue as viewtopic.php?f=18&t=6573&p=37412

(You're setting DEBUG to "1 ". Remove the comment at the end of the line)

See how the stm32 prints out the elf size (I'm pretty sure using "size")

ExXec
Posts: 71
Joined: Sat Oct 20, 2018 4:02 pm

Re: Makefile question

Post by ExXec » Mon Jul 08, 2019 10:19 am

Yes that fixed it, thanks a lot! :D

Post Reply