tolua++没有提供makefile,我人工写了一个提供给大家。我是linux初学者,对makefile这东西还是有点头痛的,这里希望给遇到同样问题的人带来一点帮助.
#****************************************************************************
# Makefile for tolua++# This is a GNU make (gmake) makefile
#****************************************************************************
# DEBUG can be set to YES to include debugging info, or NO otherwise
DEBUG := NO
#****************************************************************************
CC := gcc
CXX := g++
LD := g++
AR := ar rc
RANLIB := ranlib
DEBUG_CFLAGS := -Wall -Wno-format -g -DDEBUG
RELEASE_CFLAGS := -Wall -Wno-unknown-pragmas -Wno-format -O2
#
SYSLIB := -lpthread -ldl -lrt -lm
#编译设置
DEBUG_CXXFLAGS := ${DEBUG_CFLAGS}
RELEASE_CXXFLAGS := ${RELEASE_CFLAGS}
DEBUG_LDFLAGS := -g
RELEASE_LDFLAGS :=
ifeq (YES, ${DEBUG})
CFLAGS := ${DEBUG_CFLAGS}
CXXFLAGS := ${DEBUG_CXXFLAGS}
LDFLAGS := ${DEBUG_LDFLAGS}
else
CFLAGS := ${RELEASE_CFLAGS}
CXXFLAGS := ${RELEASE_CXXFLAGS}
LDFLAGS := ${RELEASE_LDFLAGS}
endif
#****************************************************************************
# Preprocessor directives
#****************************************************************************
#宏定义
DEFS :=
#****************************************************************************
# Include paths
#****************************************************************************
#INCS := -I/usr/include/g++-2 -I/usr/local/include
#附加包含路径
INCS := -I../lua-5.1.4/include\
-I./src/bin\
-I./src/lib\
-I./include
#附加库包含库路径+名称../3rdparty
LIBS1 :=../lua-5.1.4/lib/liblua.a
#附加库包含库路径+名称
LIBS2 :=../lua-5.1.4/lib/liblua.a\
./lib/libtolua.a
#****************************************************************************
# Makefile code common to all platforms
#****************************************************************************
CFLAGS := ${CFLAGS} ${DEFS}
CXXFLAGS := ${CXXFLAGS} ${DEFS}
#****************************************************************************
# Targets of the build
#****************************************************************************
#输出可执行程序
OUTPUT1 := libtolua.a
#输出库
OUTPUT2 := tolua
all: ${OUTPUT1} ${OUTPUT2}
#****************************************************************************
# Source files
#****************************************************************************
#源代码目录
DIR_SRC_LIB = ./src/lib/
DIR_SRC_BIN = ./src/bin/
#tolua++库文件需要的代码
SRCS1 := $(DIR_SRC_LIB)tolua_event.c\
$(DIR_SRC_LIB)tolua_is.c\
$(DIR_SRC_LIB)tolua_map.c\
$(DIR_SRC_LIB)tolua_push.c\
$(DIR_SRC_LIB)tolua_to.c
# Add on the sources for libraries
#SRCS1 := ${SRCS1}
OBJS1 := $(addsuffix .o,$(basename ${SRCS1}))
#tolua++可执行文件需要的代码$(DIR_SRC_BIN)toluabind_default.c
SRCS2 := $(DIR_SRC_BIN)tolua.c\
$(DIR_SRC_BIN)toluabind.c
# Add on the sources for libraries
#SRCS2 := ${SRCS2}
OBJS2 := $(addsuffix .o,$(basename ${SRCS2}))
#****************************************************************************
# Output
#****************************************************************************
DIR_BIN = ./bin/
DIR_LIB = ./lib/
#静态库
${OUTPUT1}: ${OBJS1}
${AR} $@ ${LDFLAGS} ${OBJS1} ${LIBS1} ${EXTRA_LIBS}
#将生成的文件移动到对应的文件夹
mv ${OUTPUT1} $(DIR_LIB)
${OUTPUT2}: ${OBJS2}
#动态库
#${LD}
#${CC} -o $@ ${LDFLAGS} ${OBJS2} ${LIBS2} ${EXTRA_LIBS} $(SYSLIB)
${CC} -o ${OUTPUT2} ${LDFLAGS} ${OBJS2} ${LIBS2} ${EXTRA_LIBS} $(SYSLIB)
#将生成的文件移动到对应的文件夹
mv ${OUTPUT2} $(DIR_BIN)
#****************************************************************************
# common rules
#****************************************************************************
# Rules for compiling source files to object files
%.o : %.cpp
${CXX} -c ${CXXFLAGS} ${INCS} $< -o $@
%.o : %.c
${CC} -c ${CFLAGS} ${INCS} $< -o $@
dist:
bash makedistlinux
clean:
#-rm -f core ${OBJS1} ${OUTPUT1}
-rm -f core ${OBJS2} ${OUTPUT2}
depend:
#makedepend ${INCS} ${SRCS}