blob: 26a8b3194f19bbd99ba80940cbb55e5b2308af33 [file] [log] [blame]
Mark Slee31985722006-05-24 21:45:31 +00001# Makefile for Thrift compiler. This Makefile assumes that you are running on
2# some form of *NIX operating system with the following tools and packages
3# installed:
4#
5# g++
6# flex
7# bison
8# libfl
9#
10# Author:
11# Mark Slee <mcslee@facebook.com>
12
13# Default build rule
14target: thrift
15
16# Tools
17CC = g++
18LD = g++
19LEX = flex
20YACC = bison
21MKDIR = mkdir
22
23# Source directory
24SRC_DIR = src/
25
26# Object file directory
27OBJ_DIR = obj/
28
29# Generated source dir
30GEN_DIR = $(SRC_DIR)
31
32# Output directory
33BIN_DIR = bin/
34
35# Source files
36SRC_FILES = main.cc \
37 generate/t_generator.cc \
Mark Sleeb15a68b2006-06-07 06:46:24 +000038 generate/t_cpp_generator.cc \
Mark Slee6e536442006-06-30 18:28:50 +000039 generate/t_java_generator.cc \
40 generate/t_php_generator.cc
Mark Slee31985722006-05-24 21:45:31 +000041
42# Autogenerated files
43GEN_FILES = thrift.tab.hh \
44 thrift.tab.cc \
45 lex.yy.cc
46
47# Object files
Mark Sleee8540632006-05-30 09:24:40 +000048OBJ_FILES = ${SRC_FILES:.cc=.o}
49
50# Generated object files
51GOB_FILES = thrift.tab.o \
52 lex.yy.o
Mark Slee31985722006-05-24 21:45:31 +000053
54# Apply directory prefixes
55SRCS = ${addprefix $(SRC_DIR), $(SRC_FILES)}
56GENS = ${addprefix $(GEN_DIR), $(GEN_FILES)}
57OBJS = ${addprefix $(OBJ_DIR), $(OBJ_FILES)}
Mark Sleee8540632006-05-30 09:24:40 +000058GOBS = ${addprefix $(OBJ_DIR), $(GOB_FILES)}
Mark Slee31985722006-05-24 21:45:31 +000059
60# Compile with strict warnings
61CFL = -g -Wall -I$(SRC_DIR) -I$(OBJ_DIR)
62
63# Flex library
64LIBS = -lfl
65
Mark Sleeb15a68b2006-06-07 06:46:24 +000066# Build directories
67obj_dirs: $(OBJ_DIR)parse $(OBJ_DIR)generate
68$(OBJ_DIR)parse:
69 $(MKDIR) -p $(OBJ_DIR)parse
70$(OBJ_DIR)generate:
71 $(MKDIR) -p $(OBJ_DIR)generate
72
Mark Slee31985722006-05-24 21:45:31 +000073# Scanner generation
74$(GEN_DIR)lex.yy.cc: $(SRC_DIR)thrift.l
Mark Sleee8540632006-05-30 09:24:40 +000075 $(LEX) -o$@ $(SRC_DIR)thrift.l
Mark Sleee8540632006-05-30 09:24:40 +000076$(OBJ_DIR)lex.yy.o: $(GEN_DIR)lex.yy.cc
77 $(CC) $(CFL) -c -o $@ $(GEN_DIR)lex.yy.cc
78
Mark Sleeb15a68b2006-06-07 06:46:24 +000079# Parser generation
80$(GEN_DIR)thrift.tab.hh: $(GEN_DIR)thrift.tab.cc
81$(GEN_DIR)thrift.tab.cc: $(SRC_DIR)thrift.y
82 $(YACC) -d -o$(GEN_DIR)thrift.tab.cc $(SRC_DIR)thrift.y
Mark Sleee8540632006-05-30 09:24:40 +000083$(OBJ_DIR)thrift.tab.o: $(GEN_DIR)thrift.tab.cc
84 $(CC) $(CFL) -c -o $@ $(GEN_DIR)thrift.tab.cc
85
86# C++ compilation
87$(OBJS): $(SRCS)
Mark Slee31985722006-05-24 21:45:31 +000088 $(CC) $(CFL) -c -o $@ ${subst $(OBJ_DIR),$(SRC_DIR),$*.cc}
89
Mark Slee31985722006-05-24 21:45:31 +000090# Main build rule
Mark Sleeb15a68b2006-06-07 06:46:24 +000091thrift: obj_dirs $(OBJS) $(GOBS)
Mark Sleee8540632006-05-30 09:24:40 +000092 $(LD) $(CFL) -o $(BIN_DIR)thrift $(OBJS) $(GOBS) $(LIBS)
Mark Slee31985722006-05-24 21:45:31 +000093
Mark Sleeb15a68b2006-06-07 06:46:24 +000094# Install
Mark Sleee8540632006-05-30 09:24:40 +000095install: thrift
96 sudo install bin/thrift /usr/local/bin/thrift
Mark Slee31985722006-05-24 21:45:31 +000097
98# Remove auto-gen'd files and binaries
99clean:
Mark Sleed1734072006-06-07 06:57:01 +0000100 rm -fr \
101 $(OBJ_DIR) \
Mark Slee31985722006-05-24 21:45:31 +0000102 $(GENS) \
103 $(BIN_DIR)thrift.exe \
104 $(BIN_DIR)thrift
Mark Slee31985722006-05-24 21:45:31 +0000105