I want to create all directories that are needed for object creation. Here is my project structure:
Project/
src/
main.cc
graphics/
window.h
window.cc
math/
vec3.h
vec3.cc
Makefile
And here is my Makefile:
CXX = g++
CXXFLAGS = -Wall -Wno-write-strings -std=c++11
LDLIBS = -lglfw3 -lGLEW -lGLU -lGL -lX11 -lXi -lXrandr -lXxf86vm -lXinerama -lXcursor -lpthread
SRC_DIR = src/ src/graphics/ src/math/
OBJ_DIR = bin
LIB_DIR = -L/usr/lib
INC_DIR = -L/usr/include
SOURCE = $(wildcard $(SRC_DIR)/*.cc)
OBJECTS = ${SOURCE:%.cc=$(OBJ_DIR)/%.o}
EXECUTABLE = application
all: init $(OBJECTS) $(EXECUTABLE)
${EXECUTABLE}: $(OBJECTS)
$(CXX) $(LDFLAGS) $(LIB_DIR) -o $@ $(OBJECTS) $(LDLIBS)
$(OBJ_DIR)/%.o: %.cc
$(CXX) $(INC_DIR) -c $< -o $@
init:
@echo $(SRC_DIR)
@echo $(OBJ_DIR)
mkdir -p "$(addprefix $(OBJ_DIR)/,$(SRC_DIR))"
clean:
rm -rf $(OBJ_DIR) $(EXECUTABLE)
I want to create bin
, bin/src/
, bin/src/graphics
and bin/src/math
directories.
At the target init
I've done mkdir -p "$(OBJ_DIR)/$(SRC_DIR)"
but that only creates bin/src src/graphics src/math
instead of bin/src bin/src/graphics/ bin/src/math
. How can I add bin
prefix to those folders that I'm creating?