DEBUG=1 should be set before make executes Makefile, so it sets debugging flags before compiling, take a look at the screenshot, or better:
DBGFLAGS = -g -O0
ifdef DEBUG
CFLAGS = $(DBGFLAGS) -Wall -std=c99
else
CFLAGS = -Wall -std=c99 -O2 -march=native -mtune=native
endif
My point is that either setting up environment/global/temporary variables is broken in codeblocks or it is very hard to do.