【发布时间】:2023-01-17 21:08:18
【问题描述】:
我正在尝试为基于 Windows 的应用程序编写 makefile。想法很简单,我必须在构建目录中生成类似 .o、.exe 文件的构建输出。我编写了 makefile,它是编译器源目录,但无法生成构建目录,编译过程运行良好。
请查看生成文件。看起来我无法使用 mkdir 命令生成构建目录。
CC= gcc
CFLAG= -g -Wall
TARGET_EXEC ?= test.exe
RELEASE= Release
RELEASE_BIN= bin
RELEASE_CNFG= config
RELEASE_LOG= log
RELEASE_DATA=data
BUILD_DIR ?= build
SRC_DIRS ?= src
#OS dependent cleaning command
ifdef OS
RM = rd /s /q
else
ifeq ($(shell uname), Linux)
RM = rm -f
endif
endif
SRCS := $(wildcard $(SRC_DIRS)/*.c)
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
INC_DIRS := $(wildcard $(SRC_DIRS) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
#find the directory for the include file
#this is best otpion to search curl directory
USR_INC := /usr/include
FILES :=
INCLUDES = -Iinclude
LIBS= -lm
CPPFLAGS ?= $(INC_FLAGS) -MMD -MP
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
$(CC) $(OBJS) -o $@ $(LIBS) $(LLFLAGS)
# c source
$(BUILD_DIR)/%.c.o: %.c
@echo Compiling $<
# here I am trying to generate the file into the build/src/xxxc.o
@ $(MKDIR_P) $@
$(CC) $(CFLAG) -c $< -o $@ $(INCLUDES)
.PHONY: install
install:
@ echo "Installing..........."
@ echo "Creating $(RELEASE) Directory..."
@ $(MKDIR_P) $(RELEASE)
@ echo "Creating $(RELEASE)/$(RELEASE_BIN) Directory.."
@ $(MKDIR_P) $(RELEASE)/$(RELEASE_BIN)
@ echo "Creating $(RELEASE)/$(RELEASE_CNFG) Directory..."
@ $(MKDIR_P) $(RELEASE)/$(RELEASE_CNFG)
@ echo "Creating $(RELEASE)/$(RELEASE_LOG) Directory..."
@ $(MKDIR_P) $(RELEASE)/$(RELEASE_LOG)
@ echo "Creating $(RELEASE)/$(RELEASE_DATA) Directory..."
@ $(MKDIR_P) $(RELEASE)/$(RELEASE_DATA)
@ echo "Makking Release folder ready.."
@cp $(BUILD_DIR)/$(TARGET_EXEC) $(RELEASE)/$(RELEASE_BIN)
@ echo "copy certificate file to Release"
@cp -r cert $(RELEASE)
@ echo "copy .ini file to Release"
@cp -r config/*.ini $(RELEASE)/$(RELEASE_CNFG)
.PHONY: clean
clean:
$(RM) $(BUILD_DIR) $(RELEASE)
-include $(DEPS)
MKDIR_P ?= mkdir
【问题讨论】:
-
没有人在 Windows 中使用它。使用 cmake 或 visual studio。
-
嗨,是的,你是对的,但尝试使用 makefile,因为稍后必须为 linux 制作相同的源代码,所以这就是为什么要为两个系统使用通用的构建过程
-
Make 文件用于构建二进制可执行文件针对特定目标.所以拥有可移植的 make 文件没有任何意义。通常,您只需使用一些声称具有跨平台可移植性的 IDE,并让 IDE 为链接操心。