我想要創建對象創建所需的所有目錄。這裏是我的項目結構:爲子目錄創建Makefile目錄
Project/
src/
main.cc
graphics/
window.h
window.cc
math/
vec3.h
vec3.cc
Makefile
這裏是我的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 [email protected] $(OBJECTS) $(LDLIBS)
$(OBJ_DIR)/%.o: %.cc
$(CXX) $(INC_DIR) -c $< -o [email protected]
init:
@echo $(SRC_DIR)
@echo $(OBJ_DIR)
mkdir -p "$(addprefix $(OBJ_DIR)/,$(SRC_DIR))"
clean:
rm -rf $(OBJ_DIR) $(EXECUTABLE)
我想創建bin
,bin/src/
,bin/src/graphics
和bin/src/math
目錄。
在目標init
我已經完成mkdir -p "$(OBJ_DIR)/$(SRC_DIR)"
但只創建bin/src src/graphics src/math
而不是bin/src bin/src/graphics/ bin/src/math
。如何將bin
前綴添加到我要創建的文件夾中?
林還學習如何編寫makefile文件。也許你可以看看我的Q和[這個答案](http://stackoverflow.com/a/25086511/3087952)。這是[我目前的makefile](http://stackoverflow.com/questions/31329581/error-flood-when-compiling-simple-hello-world-program)。 – nonsensation