I have project folder with src, obj and inc dirs.
I declare var with obj - OBJS
SDIR = src
ODIR = obj
# I change /src/*.c to /obj/*.o
_OBJS = $(patsubst %.c, %.o, $(wildcard $(SDIR)/*.c))
# I need to change /src/*.o to /obj/*.o
OBJS = $(??? $ODIR ??? $_OBJS ???)
Now in _OBJS - ./src/*.o, How to change in OBJS /src/ to /obj/?
Thanks.
What about this (if I understand the question correctly):
SDIR = src
ODIR = obj
# I change /src/*.c to /obj/*.o
_OBJS = $(patsubst %.c, %.o, $(wildcard $(SDIR)/*.c))
# I need to change /src/*.o to /obj/*.o
_OBJS := $(subst $(SDIR), $(ODIR), $(_OBJS))
debug:
#echo $(_OBJS)
Output/Test:
$ mkdir ./src/
$ touch ./src/a.c
$ touch ./src/b.c
$ touch ./src/c.c
$ ls ./src/
a.c b.c c.c
$ make debug
obj/a.o obj/b.o obj/c.o
_OBJS = $(patsubst %.c, %.o, $(wildcard $(SDIR)/*.c))
_OBJS := $(notdir $(_OBJS))
OBJS = $(patsubst %,$(ODIR)/%,$(_OBJS))
But, I think, its bad way
Related
I have this makefile and when I compile with make cygwin it says:
make: collect2.exe: error: ld returned 1 exit status
######################################
# target
######################################
TARGET = blinkingled
######################################
# building variables
######################################
# debug build?
#DEBUG = 1
# optimization
OPT = -Og
#######################################
# paths
#######################################
# Build path
BUILD_DIR = build
######################################
# source
######################################
# C sources
SRCS = main_cm0plus.c
SRCS += system_tviibe1m_cm0plus.c
SRCS += startup.c
SRCS += $(wildcard src/drivers/adc/*.c)
SRCS += $(wildcard src/drivers/canfd/*.c)
SRCS += $(wildcard src/drivers/cpu/*.c)
SRCS += $(wildcard src/drivers/crypto/*.c)
SRCS += $(wildcard src/drivers/dma/*.c)
SRCS += $(wildcard src/drivers/evtgen/*.c)
SRCS += $(wildcard src/drivers/flash/*.c)
SRCS += $(wildcard src/drivers/gpio/*.c)
SRCS += $(wildcard src/drivers/ipc/*.c)
SRCS += $(wildcard src/drivers/lin/*.c)
SRCS += $(wildcard src/drivers/lvd/*.c)
SRCS += $(wildcard src/drivers/mcwdt/*.c)
SRCS += $(wildcard src/drivers/mpu/*.c)
SRCS += $(wildcard src/drivers/prot/*.c)
SRCS += $(wildcard src/drivers/scb/*.c)
SRCS += $(wildcard src/drivers/smartio/*.c)
SRCS += $(wildcard src/drivers/srom/*.c)
SRCS += $(wildcard src/drivers/sysclk/*.c)
SRCS += $(wildcard src/drivers/sysflt/*.c)
SRCS += $(wildcard src/drivers/sysint/*.c)
SRCS += $(wildcard src/drivers/syslib/*.c)
SRCS += $(wildcard src/drivers/syspm/*.c)
SRCS += $(wildcard src/drivers/sysreset/*.c)
SRCS += $(wildcard src/drivers/sysrtc/*.c)
SRCS += $(wildcard src/drivers/systick/*.c)
SRCS += $(wildcard src/drivers/syswdt/*.c)
SRCS += $(wildcard src/drivers/tcpwm/*.c)
SRCS += $(wildcard src/drivers/trigmux/*.c)
SRCS += $(wildcard src/interrupts/rev_d/*.c)
SRCS += $(wildcard src/mw/button/*.c)
SRCS += $(wildcard src/mw/flash/*.c)
SRCS += $(wildcard src/semihosting/*.c)
SRCS += $(wildcard src/swtimer/*.c)
SRCS += $(wildcard src/startup/*.c)
SRCS += $(wildcard src/system/*.c)
# ASM sources
ASM_SOURCES = "C:/data/traveo/TVII_Sample_Driver_Library_7.1.0/tviibe1m/src/startup_cm0plus.s"
#startup_cm0plus.s
#######################################
# binaries
#######################################
PREFIX = arm-none-eabi-
# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx)
# either it can be added to the PATH environment variable.
ifdef GCC_PATH
CC = $(GCC_PATH)/$(PREFIX)gcc
AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp
CP = $(GCC_PATH)/$(PREFIX)objcopy
SZ = $(GCC_PATH)/$(PREFIX)size
else
CC = $(PREFIX)gcc
AS = $(PREFIX)gcc -x assembler-with-cpp
CP = $(PREFIX)objcopy
SZ = $(PREFIX)size
endif
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S
#######################################
# CFLAGS
#######################################
# cpu
CPU = -mcpu=cortex-m0plus
# fpu
FPU = -mfpu=fpv4-sp-d16
# float-abi
FLOAT-ABI = -mfloat-abi=soft
# mcu
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
# macros for gcc
# AS defines
AS_DEFS =
# C defines
#C_DEFS = ../../
# AS includes
AS_INCLUDES =
# C includes
INCDIRS = ../../common/hdr
INCDIRS += ../../common/hdr/cmsis/include
INCDIRS += ../../common/src/drivers
INCDIRS += ../../common/src/drivers/sysclk
INCDIRS += ../../common/src/drivers/flash
INCDIRS += ../../common/src/drivers/syslib
INCDIRS += ../../common/src/drivers/mcwdt
INCDIRS += ../../tviibe1m/hdr/rev_d
INCDIRS += ../../tviibe1m/hdr/rev_d/ip
INCDIRS += ../../tviibe1m/src/system/rev_d
INCDIRS += ../../tviibe1m/hdr/rev_d/mcureg
INCDIRS += ../../tviibe1m/src/drivers/
INCDIRS += ../../common/src/drivers/syswdt
INCDIRS += ../../common/src/mw
INCLUDE = $(addprefix -I,$(INCDIRS))
# compile gcc flags
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2
endif
# My C flags:
CFLAGS += -Wno-unused-variable
# Generate dependency information
CFLAGS += -MMD -MP -MF"$(#:%.o=%.d)"
#######################################
# LDFLAGS
#######################################
# link script
LDSCRIPT = "c:/data/traveo/TVII_Sample_Driver_Library_7.1.0/tviibe1m/src/linker.ld"
# libraries
LIBS = -lc -lm -lnosys
LIBDIR =
LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
# default action: build all
all: $(TARGET)
blinkingled: main_cm0plus.o system_tviibe1m_cm0plus.o startup.o
$(CC) $^ -o $#
main_cm0plus.o: main_cm0plus.c
$(CC) $(CFLAGS) main_cm0plus.c
system_tviibe1m_cm0plus.o: system_tviibe1m_cm0plus.c cy_project.h cy_device_headers.h
$(CC) $(CFLAGS) system_tviibe1m_cm0plus.c
startup.o: startup.c startup_customize.h
$(CC) $(CFLAGS) startup.c
BIN_NAME = $(addprefix $(BUILD_DIR), $(TARGET))
.PHONY: all
all: $(BIN_NAME).elf
all: $(BIN_NAME).bin
all: $(BIN_NAME).s19
all: $(BIN_NAME).hex
all: $(BIN_NAME).lst
all: print_size
%.bin: %.elf
$(CP) -O binary -S $< $#
%.s19: %.elf
$(CP) -O srec -S $< $#
%.hex: %.elf
$(OBJCOPY) -O ihex -S $< $#
%.lst: %.elf
$(CP) -d $< > $#
.PHONY: print_size
print_size: $(BIN_NAME).elf
$(SIZE) $<
#######################################
# build the application
#######################################
# list of objects
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
vpath %.c $(sort $(dir $(C_SOURCES)))
# list of ASM program objects
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
vpath %.s $(sort $(dir $(ASM_SOURCES)))
$(BUILD_DIR)/%.o: %.c makefile | $(BUILD_DIR)
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $#
$(BUILD_DIR)/%.o: %.s makefile | $(BUILD_DIR)
$(AS) -c $(CFLAGS) $< -o $#
$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) makefile
$(CC) $(OBJECTS) $(LDFLAGS) -o $#
$(SZ) $#
$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(HEX) $< $#
$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(BIN) $< $#
$(BUILD_DIR):
mkdir $#
#######################################
# clean up
#######################################
clean:
-rm -fR $(BUILD_DIR)
#######################################
# dependencies
#######################################
-include $(wildcard $(BUILD_DIR)/*.d)
# *** EOF ***
error:
c:/tools/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: c:/tools/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-no
ne-eabi/10.2.1/../../../../arm-none-eabi/lib/thumb/v6-m/nofp\libc.a(lib_a-exit.o): in function `exit':
exit.c:(.text.exit+0x18): undefined reference to `_exit'
c:/tools/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: C:\cygwin64\tmp\ccHNkyd5.o: in function `main':
main_cm0plus.c:(.text.main+0x2): undefined reference to `SystemInit'
c:/tools/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: main_cm0plus.c:(.text.main+0xa): undefined reference to `Cy_SysEn
ableApplCore'
c:/tools/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: main_cm0plus.c:(.text.main+0x14): undefined reference to `Cy_GPIO
_Pin_Init'
c:/tools/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: main_cm0plus.c:(.text.main+0x1a): undefined reference to `Cy_SysT
ick_DelayInUs'
c:/tools/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: main_cm0plus.c:(.text.main+0x28): undefined reference to `__cm4_v
ector_base_linker_symbol'
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:173: main_cm0plus.o] Error 1
Does anyone knows how to solve this problem?
I am trying to generate a hex and elf from this makefile.
Also, I would appreciate any tips/corrections on my makefile. I am trying to blink a led but im very new to arm development with makefiles
thanks
Consider this:
all: blinkingled
blink: main_cm0plus.o system_tviibe1m_cm0plus.o startup.o
$(CC) main_cm0plus.o system_tviibe1m_cm0plus.o startup.o -o blinkingled
Here you have two rules that define two targets: the all target depends on a prerequisite blinkingled and the blink target which depends on a bunch of object files.
When make invokes the blink target, it actually creates a file named blinkingled. This is wrong. Make only knows what you told it in the makefile, it has no way to know that you lied to it about what your recipe will do. If you define rule with a target named blink, then make believes you that the recipe you provided it will create a target named blink.
You need to change your recipe so that you are telling the truth to make and make the target match the file that is built:
blinkingled: main_cm0plus.o system_tviibe1m_cm0plus.o startup.o
$(CC) main_cm0plus.o system_tviibe1m_cm0plus.o startup.o -o blinkingled
Now everything will work.
Even better is to use make's automatic variables in your recipe, so you KNOW that you're creating the targets make expects (plus, DRY is a great principle for programming):
blinkingled: main_cm0plus.o system_tviibe1m_cm0plus.o startup.o
$(CC) $^ -o $#
I have a makefile that gives me the source files in a hierarchy.
SRCS := $(wildcard $(SRC_DIR)/*.c $(SRC_DIR)/*/*.c)
gives me
./src/main.c ./src/add/add.c ./src/sub/sub.c
I want to flatten the object files into a single "obj" directory.
Of course
OBJS := $(SRCS:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.obj)
gives me
./obj/main.obj ./obj/add/add.obj ./obj/sub/sub.obj
instead of desired
./obj/main.obj ./obj/add.obj ./obj/sub.obj
Question: How do I get rid of additional source directory levels?
Never had to use complex substitution so far. My intuitive try with additional "/%" in pattern
# won't work as expected:
OBJS := $(SRCS:$(SRC_DIR)/%/%.c=$(OBJ_DIR)/%.obj)
produces no meaningful result (${OBJS} becomes same as ${SRCS}).
All examples I found so far only have single occurance of "%" in match pattern.
MAK_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
SRC_DIR = $(MAK_DIR)./src
OBJ_DIR = $(MAK_DIR)./obj
# gives: ./src/main.c ./src/add/add.c ./src/sub/sub.c
SRCS := $(wildcard $(SRC_DIR)/*.c $(SRC_DIR)/*/*.c)
# gives: ./obj/main.obj ./obj/add/add.obj ./obj/sub/sub.obj
OBJS := $(SRCS:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.obj)
.PHONY : all
all :
#echo $(SRCS)
#echo $(OBJS)
Just use the notdir function, and also patsubst, more powerful (and that I find easier to understand than the shorthand):
OBJS := $(patsubst %.c,$(OBJ_DIR)/%.obj,$(notdir $(SRCS)))
But it is not the whole story because later on you will probably want to do something like:
$(OBJ_DIR)/%.obj: $(SRC_DIR)/%.c
which will not work any more. Not mentioning the fact that you could have several source files with the same name in different directories. Assuming you do not have such names conflicts you can generate all your dependencies using foreach-eval-call:
MAK_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
SRC_DIR := $(MAK_DIR)./src
OBJ_DIR := $(MAK_DIR)./obj
SRCS := $(shell find $(MAK_DIR) -type f -name '*.c')
OBJS := $(patsubst %.c,$(OBJ_DIR)/%.obj,$(notdir $(SRCS)))
.PHONY: objs
objs: $(OBJS)
# $(1): source file
define DEP_rule
$(1)-obj := $$(patsubst %.c,$$(OBJ_DIR)/%.obj,$$(notdir $(1)))
$(1)-dep := $$(patsubst %.c,$$(OBJ_DIR)/%.d,$$(notdir $(1)))
$$($(1)-obj): $(1) $$($(1)-dep)
endef
$(foreach src,$(SRCS),$(eval $(call DEP_rule,$(src))))
Just remember that the DEP_rule macro gets expanded twice, thus the $$.
I have, in the main repository some subdirectories called assignment_1, assignment_2, ..., assignment_n.
I'm tring to write a Makefile that compiles the all TeX files inside those subdirectories.
This is what I have so far, but it doesn't work:
.PHONY: papers clean
PUBLISH_DIR := publish
TEX_DIR := .tex
SRC_DIR := assignment_$(wildcard *)
SRC_FILES := $(wildcard $(SRC_DIR)/*.tex)
CC := xelatex
FLAGS := -shell-escape -output-directory=$(TEX_DIR)
all: $(patsubst $(SRC_DIR)/%.tex, $(PUBLISH_DIR)/%.pdf, $(SRC_FILES))
$(PUBLISH_DIR)/%.pdf: $(SRC_DIR)/%.tex
mkdir -p $(TEX_DIR)
$(CC) $(FLAGS) $<
$(CC) $(FLAGS) $<
mkdir -p $(PUBLISH_DIR)
mv $(TEX_DIR)/*.pdf $(PUBLISH_DIR)/
clean:
rm -rf $(PUBLISH_DIR) $(TEX_DIR)
If I change this line
SRC_DIR := assignment_$(wildcard *)
with
SRC_DIR := assignment_1
it works beautifully but (obviously) only with the TeX file inside assignment_1.
Beside traversing the subdirectories, is there anything else I can improove in this Makefile?
I think you should modify your wildcard:
SRC_DIR := assignment_$(wildcard *)
to
SRC_DIR := $(wildcard assignment_*)
If $(wildcard *) expands to 1 2 3 then assignment_$(wildcard *) will expand to assignment_1 2 3 which is clearly not what you want.
Try this:
SRC_DIR := $(addprefix assignment_,$(wildcard *))
to add the assignment_ prefix to the start of each word.
I have 2 folders with their subfolders 04-Software Components / 03-Specific_sources and 08-Ext_Proj / SWC_ADC, SWC_PWM / 03-SRC
There are some .c and .h files in 03-Specific_sources and there is one .c file and their .h
files in both SWC_ADC / 03-SRC (which is ADC.c) and
SWC_PWM / 03-SRC (which is PWM.c)
And I want to compile them and link them all to get the output file.
so what I did is this:
EXEDIR_RELEASE := ../01-EXE\02-Release
OBJDIR_RELEASE := ../05-Obj\02-Release
SRCDIR := ../../../03-Specific_sources (This is the path from my make folder)
EXT_DIR := ../../08-Ext_Proj (This is the path from my make folder)
FIND_SRCS := $(wildcard $(EXT_DIR)/SWC_*/03-SRC/*.c)
INCLUDES := -I $(SRCDIR) $(foreach ext, $(wildcard $(EXT_DIR)/SWC*), -I $(ext)/03-SRC)
CSRCS := $(wildcard $(SRCDIR)/*.c) $(FIND_SRCS)
CSRCS := $(notdir $(CSRCS))
CROBJS := $(patsubst %.c, %.r34, $(CSRCS))
CROBJS := $(addprefix $(OBJDIR_RELEASE)/, $(CROBJS))
.PHONY: all
all: $(EXEDIR_RELEASE)/$(TARGET_RELEASE)
# Compiling
$(OBJDIR_RELEASE)/%.r34: $(FIND_SRCS)
#echo '$^ $#'
$(CC) $(CFLAGS) $(INCLUDES) -o $# $<
# Linking
$(EXEDIR_RELEASE)/Target.mot: $(CROBJS)
$(LD) $(MFLAGS) # These are the linker and its flags
The problem is that the compilation is not working. So when I do the echo I get this:
ADC_prg.c PWM_prg.c DDF_prg.r34
ADC_prg.c PWM_prg.c DFAN_prg.r34
ADC_prg.c PWM_prg.c DFN_prg.r34
ADC_prg.c PWM_prg.c DIO_prg.r34
ADC_prg.c PWM_prg.c DMIO_prg.r34
So I think that the mathing pattern %.r34 is not working and when I use
($(OBJDIR_RELEASE)/%.r34: $(FIND_SRCS)/%.c) it also not working because I can't use %
with a variable that has wildcard function performed on it.
I also used the foreach function but with no use.
So please I need your help guys, I have a delivery today... please respond asap.
Thanks in advance
SAM
This makefile has a lot of problems. Notably:
$(OBJDIR_RELEASE)/%.r34: $(FIND_SRCS)
#echo '$^ $#'
$(CC) $(CFLAGS) $(INCLUDES) -o $# $<
This pattern rule has no wildcard ("%") in the prerequisite list. Any r34 target depends on all sources in $(FIND_SRCS). If that isn't bad enough, look at where these variables come from:
SRCDIR := ../../../03-Specific_sources (This is the path from my make folder)
EXT_DIR := ../../08-Ext_Proj (This is the path from my make folder)
FIND_SRCS := $(wildcard $(EXT_DIR)/SWC_*/03-SRC/*.c)
...
CSRCS := $(wildcard $(SRCDIR)/*.c) $(FIND_SRCS)
CSRCS := $(notdir $(CSRCS))
CROBJS := $(patsubst %.c, %.r34, $(CSRCS))
CROBJS := $(addprefix $(OBJDIR_RELEASE)/, $(CROBJS))
In other words, you seem to expect that for every source file in one directory there will be a file of the same name in the other directory. According to your echo statements, there are no such matches.
There are other problems, but this is a good place to start. Try this:
CSRCS := $(wildcard $(SRCDIR)/*.c) $(EXT_DIR)/SWC_ADC/03-SRC/ADC.c $(EXT_DIR)/SWC_PWM/03-SRC/PWM.c
CSRCS := $(notdir $(CSRCS))
CROBJS := $(patsubst %.c, $(OBJDIR_RELEASE)/%.r34, $(CSRCS))
vpath %.c $(SRCDIR) $(EXT_DIR)/SWC_ADC/03-SRC $(EXT_DIR)/SWC_PWM/03-SRC
$(OBJDIR_RELEASE)/%.r34: %.c
$(CC) $(CFLAGS) $(INCLUDES) -o $# $<
Go down the list of object files you want to build, and try building each one:
make DDF_prg.r34
make DFAN_prg.r34
...
If that works, try linking them by hand, and if that works, take a look at the linking rule -- which looks completely wrong but which I can't really diagnose because I don't know what linker you're using.
Hi I wrote this Makefile by modifying this example: https://sites.google.com/site/michaelsafyan/software-engineering/how-to-write-a-makefile
program_NAME := bin/myprogram
SRC_DIR := src
#
#srces
#
program_C_SRCS := $(wildcard $(SRC_DIR)/*.c)
program_CXX_SRCS := $(wildcard $(SRC_DIR)/*.cpp)
#
#obj files
#
program_C_OBJS := ${program_C_SRCS:.c=.o}
program_CXX_OBJS := ${program_CXX_SRCS:.cpp=.o}
program_OBJS := $(program_C_OBJS) $(program_CXX_OBJS)
#
# include and library dirs; also libraries
#
program_INCLUDE_DIRS := inc
program_LIBRARY_DIRS :=
program_LIBRARIES :=
# flags
CPPFLAGS += $(foreach includedir,$(program_INCLUDE_DIRS),-I$(includedir))
LDFLAGS += $(foreach librarydir,$(program_LIBRARY_DIRS),-L$(librarydir))
LDFLAGS += $(foreach library,$(program_LIBRARIES),-l$(library))
#
# targets
#
.PHONY: all clean distclean
all: $(program_NAME)
$(program_NAME): $(program_OBJS)
$(LINK.cc) $(program_OBJS) -o $(program_NAME)
clean:
#- $(RM) $(program_NAME)
#- $(RM) $(program_OBJS)
distclean: clean
It works in the following way. The classes below are compiled into an executable "myprogram" which is output in the bin directory. The only issue is the object files are created inside the src folder, instead of the obj folder. How can I modify this makefile such that obj files are created in the obj folder? Thank you.
/project
Makefile
/src
Class1.cpp
Class2.cpp
main.cpp
/obj
/bin
myProgram
/inc
Class1.h
Class2.h
To start with, you could use e.g. the subst function to replace the source-file directory with the object-file directory:
program_OBJS = $(subst $(SRC_DIR),$(OBJ_DIR),$(program_C_OBJS))
program_OBJS += $(subst $(SRC_DIR),$(OBJ_DIR),$(program_CXX_OBJS))
Of course you now need to add a target for object-file creation, as these will not be put in the correct place otherwise:
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
$(CC) $(CFLAGS) -c -o $# $<
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
$(CXX) $(CXXFLAGS) -c -o $# $<
Try with something like:
OUT_DIR=obj
program_bare_OBJS := $(program_C_OBJS) $(program_CXX_OBJS)
program_OBJS=$(addprefix $(OUT_DIR)/,$(program_bare_OBJS))