Author Topic: Set build directory in makefile depending on active configuration?  (Read 164 times)

patrickkox

  • Senior Community Member
  • Posts: 117
  • Hero Points: 6
  • Debian GNU/Linux user
Is it possible to configure a user maintained makefile so that it will build in a directory called Debug or Release depending on the the Active configuration that's set in SlickEdit?
I now use a makefile that has a separate Debug and Release option, but it would be easier if it was possible to control this from within SlickEdit.

LBCEi

  • Senior Community Member
  • Posts: 217
  • Hero Points: 21
Re: Set build directory in makefile depending on active configuration?
« Reply #1 on: February 07, 2021, 02:37:00 pm »
Here is an example of how I've been doing that (using gcc). Obviously you will need to adapt.

In your project properties on the Tools tab, use the following for the Debug configuration: make debug.
For the Release configuration: make release.

You may need to create these configurations.  Click the Configurations... button at the top of the Project Properties dialog.

Code: [Select]
#The below statement should be true the first time the makefile is called
#This allows me to pick which directory to do the build in (debug or release)
ifeq ($(FIRSTTIMECALLED),)

#These are the options for the makefile (make debug, make release, make clean)
.PHONY: release debug clean

#Defaults to release if nothing given
release:
@#Make directory if doesn't exist
@mkdir -p ./release
@#Call the makefile from that directory
@$(MAKE) release -C ./release -f ../Makefile FIRSTTIMECALLED=no

debug:
@#Make directory if doesn't exist
@mkdir -p ./debug
@#Call the makefile from that directory
@$(MAKE) debug -C ./debug -f ../Makefile FIRSTTIMECALLED=no

clean:
rm -rf release
rm -rf debug

#This is where the second entry (once in release or debug directory starts)
else

CROSS_COMPILER=arm-eabi-

CC=$(CROSS_COMPILER)gcc

INCLUDE_DIRS=./../inc ./../uncertified/inc

CFLAGS=-c -Wall -fverbose-asm -fno-exceptions -std=c11 $(addprefix -I, $(INCLUDE_DIRS))

LIB_DIRS=

LDFLAGS=$(addprefix -L, $(LIB_DIRS)) -nostartfiles -specs=nosys.specs

LIBS=-lm

ASM_SOURCES=startup.s

C_SOURCES=  main.c ...

EXECUTABLE=app

OBJECTS=$(ASM_SOURCES:.s=.o) $(C_SOURCES:.c=.o) $(CID_SOURCE:.cid=.cid.o) $(BMP_SOURCES:.bmp=.bmp.o)

LINKERSCRIPT=./../MCIMX6Y2xxx08_ddr_ram.ld

OPTIMIZATION_FLAGS=omit-frame-pointer no-defer-pop auto-inc-dec keep-static-functions keep-static-consts  merge-constants ipa-pure-const

#Clear all vpath settings, and then set each directory where to look for sources
vpath
vpath %.h ./../inc
vpath %.c ./../src
vpath %.s ./../src
vpath %.S ./../src

#These are the options for this makefile
.PHONY: release debug

#For debug turn off optimizations and set the debug flag (so debug symbols get built in)
#Also creates a map file used for debugging purposes
debug: elf
debug: ASMFLAGS+= -gdwarf -O0
debug: CFLAGS+= -gdwarf -O0
debug: LDFLAGS+= -Wl,-Map,$(EXECUTABLE).map,--cref,--no-warn-mismatch,--gc-sections

#For release turn off optimizations
#Place in flash memory
release: elf
release: ASMFLAGS+= -gdwarf -O0
release: CFLAGS+= -gdwarf -O0 $(addprefix -f, $(OPTIMIZATION_FLAGS)) -fstack-usage -Wdouble-promotion
release: LDFLAGS+= -Wl,-Map,$(EXECUTABLE).map,--cref,--no-warn-mismatch,--gc-sections

#Builds the executable
elf: $(EXECUTABLE).elf

#Builds the executable from all objects
$(EXECUTABLE).elf: $(CID_SOURCE) $(OBJECTS)
@echo -e "${GREEN}[LINKING]${NC}  Linking " $@
@$(CC) $(LDFLAGS) -T$(LINKERSCRIPT) -Wl,-Map,$(EXECUTABLE).map,--cref,--no-warn-mismatch,--print-memory-usage -o $@ $(OBJECTS) $(LIBS)

##Rule to build all .c files into .o files
%.o: %.c
@echo -e "[CODE] Building" $@
@$(CC) $(CFLAGS) $< -o $@

#Rule to build all .s files into .o files
%.o: %.s
@echo -e "[CODE] Building" $@
@$(CC) $(ASMFLAGS) $< -o $@

#Rule to build all .S files into .o files
%.o: %.S
@echo -e "[CODE] Building" $@
@$(CC) $(ASMFLAGS) $< -o $@

endif


patrickkox

  • Senior Community Member
  • Posts: 117
  • Hero Points: 6
  • Debian GNU/Linux user
Re: Set build directory in makefile depending on active configuration?
« Reply #2 on: February 07, 2021, 03:20:34 pm »
Thanks!
That was way easier than I was expecting  ;D

LBCEi

  • Senior Community Member
  • Posts: 217
  • Hero Points: 21
Re: Set build directory in makefile depending on active configuration?
« Reply #3 on: February 07, 2021, 04:32:39 pm »
I'm glad that helped.

patrickkox

  • Senior Community Member
  • Posts: 117
  • Hero Points: 6
  • Debian GNU/Linux user
Re: Set build directory in makefile depending on active configuration?
« Reply #4 on: February 07, 2021, 04:37:10 pm »
Unfortunately when I add this to a custom project, these settings are not stored.
I made a new GCC Project based on the default C/C++ project, and set build system to "Build with user-maintained makefile or custom build command" and added these settings.

But when I start a new project with that custom project, the default build system is set to the SlickEdit default (witthout a makefile) and the custom command for both Debug and Release is make

It would be nice if SlickEdit would store these settings, and not require to manually edit it every time a new project is started.
« Last Edit: February 07, 2021, 04:40:59 pm by patrickkox »