欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

记录第一次写Makefile文件

程序员文章站 2022-06-20 08:40:00
...

先将文件记录在此,以后再来总结 Makefile 的写法

楼主目前正在将 ravel 的java版本改写为C++ 版本,每次需要写很长的 gcc 命令,想到用 make 来代替GCC 的命令行。

  1. 公共部分的Makefile
CXXFLAGS = -g -I /home/san/eclipse-workspace/ratel/landlords-common -pthread -L/home/san/apps/build/debug-install-cpp11/lib
LDFLAGS = -lboost_serialization -lprotobuf -lz -lmuduo_base -lpthread -lmuduo_net -L/home/san/apps/build/debug-install-cpp11/lib -L. -lravel -lz
landlord_root = /home/san/eclipse-workspace/ratel/landlords-common
BASE_SRC = $(landlord_root)/protobuf/codec.cc $(landlord_root)/protobuf/query.pb.cc $(landlord_root)/helper/PokerHelper.cc $(landlord_root)/entity/PokerSell.cc $(landlord_root)/robot/RobotDecisionMakers.cc
MUDUO_SRC = $(notdir $(LIB_SRC) $(BASE_SRC))
OBJS = $(patsubst %.cc,%.o,$(MUDUO_SRC))

libravel.a: $(BASE_SRC) $(LIB_SRC)
	g++ $(CXXFLAGS) -c $^
	ar rcs [email protected] $(OBJS)

$(BINARIES): libravel.a
	g++ $(CXXFLAGS) -o [email protected] $(filter %.cc,$^) $(LDFLAGS)

clean:
	rm -f $(BINARIES) *.o *.a core

  1. 服务端的 Makefile
LIB_SRC =                          \
    event/EventFuncs.cc            \
	event/ServerEventListener.cc   \
	event/ServerContains.cc        \
	robot/RobotEventListener.cc    \
	robot/RobotEventFuncs.cc       \

BINARIES = server

all: $(BINARIES)

include ../landlords-common/common.mk

server: server.cc
  1. 客户端的Makefile
LIB_SRC =                              \
        event/eventFuncs.cc            \

BINARIES = client

all: $(BINARIES)

include ../landlords-common/common.mk

client: client.cc
相关标签: C++ linux