代码拉取完成,页面将自动刷新
#directory structure
INCLUDE_DIR := ./include
SERVER_DIR := ./server
CLIENT_DIR := ./client
BIN_DIR := ./bin
OBJ_DIR := ./obj
#phony target
.PHONY: all clean-obj clean-main clean-file rebuild debug
.DEFAULT_GOAL := all
# CC is compiler and compiler options
CC := gcc
CFLAGS := -Wall -g -O1 -I$(INCLUDE_DIR) -pthread -lmysqlclient
# Conditional logic to set FINAL and SRC_DIR
ifeq ($(FINAL),server)
SRC_DIR := $(SERVER_DIR)
TARGET := $(BIN_DIR)/server
else ifeq ($(FINAL),client)
SRC_DIR := $(CLIENT_DIR)
TARGET := $(BIN_DIR)/client
else
# This target will be the default if FINAL is not set
default:
$(error "FINAL must be 'server' or 'client'")
endif
# file preparation
SRCS := $(wildcard $(SRC_DIR)/*.c)
OBJS := $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRCS))
DEPS := $(OBJS)
# final target
MESSAGE := "Build Succeed!"
all: $(TARGET)
@echo $(MESSAGE)
#linking .o files
$(TARGET):$(DEPS)
$(CC) $(CFLAGS) $^ -o $@
#compiling to generate .o files
$(OBJ_DIR)/%.o : $(SRC_DIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@
#cleaning options
clean:
rm -f ./obj/*.o
rm -f ./bin/server
rm -f ./bin/client
clean-server:
rm -f ./bin/server
clean-client:
rm -f ./bin/client
clean-file:
rm -f $(BIN_DIR)/$(FN) $(OBJ_DIR)/$(FileName)
rebuild:
clean-$(FINAL) all
#debugging information
debug:
@echo "TARGET: $(TARGET)"
@echo "DEPS: $(DEPS)"
@echo "CFLAGS: $(CFLAGS)"
help:
@echo "Available targets:"
@echo " clean - clean all the build files"
@echo " clean-obj - clean object files"
@echo " clean-server - clean the server executable"
@echo " clean-client - clean the client executable"
@echo " clean-file - clean a specific file (specify FN=<filename>)"
@echo " rebuild - clean and rebuild the project"
@echo " debug - print Makefile variables for debugging"
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。