This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
justhomework/OpenGL/lab4/Makefile

67 lines
1.9 KiB
Makefile
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#源文件目录
SRC_DIR := ./
#头文件目录
INC_DIR := ./
#输出文件目录
OUT_DIR := ./build
#目标文件(中间文件)目录
OBJ_DIR :=./build
#链接选项
LDFLAGS := $(shell pkg-config --static --libs glfw3)
LDFLAGS += $(shell pkg-config --static --libs assimp)
LDFLAGS += $(shell pkg-config --static -libs openscenegraph)
# 调试符号
LDFLAGS += -g
#编译工具链
CC := g++
#输出文件命名
OUT := $(OUT_DIR)/hello
#增加所有头文件所在的目录
# INC_DIR += ./include/glad
# INC_DIR += ./include/KHR
#获取头文件目录
CPP_FLAGS := $(foreach dir, $(INC_DIR), -I$(wildcard $(dir)))
#方法一: 将所有源文件的文件目录添加进来就不用每增加一个文件都修改一下makefile文件
#SRC_DIR += ./src/
#获取所有cpp文件名
CPP_SRCS := $(foreach dir, $(SRC_DIR), $(wildcard $(dir)/*.cpp))
#方法二:将增加的文件(带目录)增加到源文件数组中,此操作不用增加源文件目录
# CPP_SRCS += ./src/sub_path1/*.cpp
# CPP_SRCS += ./src/sub_path2/*.cpp
# CPP_SRCS += ./src/sub_path....../*.cpp
# CPP_SRCS += ./src/sub_pathn/*.cpp
#生成所有的目标文件名
OBJ := $(addprefix $(OBJ_DIR)/, $(notdir $(CPP_SRCS:.cpp=.o)))
# 最终目标文件的生成makefile 会将第一个target设为最终生成的目标文件
# 【当然这里可以不是可执行文件,它也可以是.o文件】链接过程
# 这条语句的完全写法应该是:
# ./OUT/xxx.OUT: prerequisites1.o prerequisites2.o prerequisites3.o ...
# g++ prerequisites1.o prerequisites2.o prerequisites3.o ... -o ./OUT/xxx.OUT
$(OUT):$(OBJ)
$(CC) $^ -o $@ $(LDFLAGS)
#将所有的.cpp文件加载到当前的路径中
vpath %.cpp $(sort $(dir $(CPP_SRCS)))
#将所有的源文件编译生成响应的目标文件
$(OBJ_DIR)/%.o:%.cpp
$(CC) $(CPP_FLAGS) -c $< -o $@
nv:$(OUT)
prime-run ./$(OUT)
run:$(OUT)
./$(OUT)
all:$(OUT)
.PHONY:clean
clean:
rm -rf ./${OUT_DIR}/*
rm -rf ./${OBJ_DIR}/*