blob: b20ec3b92551d439472325a537c9dc22cf500694 [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 Sleefc89d392006-09-04 00:04:39 +000038 generate/t_py_generator.cc \
Mark Slee78f58e22006-09-02 04:17:07 +000039 generate/t_java_generator.cc \
Mark Slee52f643d2006-08-09 00:03:43 +000040 generate/t_php_generator.cc \
Mark Slee78f58e22006-09-02 04:17:07 +000041 generate/t_cpp_generator.cc
Mark Slee31985722006-05-24 21:45:31 +000042
43# Autogenerated files
44GEN_FILES = thrift.tab.hh \
45 thrift.tab.cc \
46 lex.yy.cc
47
48# Object files
Mark Sleee8540632006-05-30 09:24:40 +000049OBJ_FILES = ${SRC_FILES:.cc=.o}
50
51# Generated object files
52GOB_FILES = thrift.tab.o \
53 lex.yy.o
Mark Slee31985722006-05-24 21:45:31 +000054
55# Apply directory prefixes
56SRCS = ${addprefix $(SRC_DIR), $(SRC_FILES)}
57GENS = ${addprefix $(GEN_DIR), $(GEN_FILES)}
58OBJS = ${addprefix $(OBJ_DIR), $(OBJ_FILES)}
Mark Sleee8540632006-05-30 09:24:40 +000059GOBS = ${addprefix $(OBJ_DIR), $(GOB_FILES)}
Mark Slee31985722006-05-24 21:45:31 +000060
61# Compile with strict warnings
62CFL = -g -Wall -I$(SRC_DIR) -I$(OBJ_DIR)
63
64# Flex library
65LIBS = -lfl
66
Mark Sleeb15a68b2006-06-07 06:46:24 +000067# Build directories
68obj_dirs: $(OBJ_DIR)parse $(OBJ_DIR)generate
69$(OBJ_DIR)parse:
70 $(MKDIR) -p $(OBJ_DIR)parse
71$(OBJ_DIR)generate:
72 $(MKDIR) -p $(OBJ_DIR)generate
73
Mark Slee31985722006-05-24 21:45:31 +000074# Scanner generation
75$(GEN_DIR)lex.yy.cc: $(SRC_DIR)thrift.l
Mark Sleee8540632006-05-30 09:24:40 +000076 $(LEX) -o$@ $(SRC_DIR)thrift.l
Mark Sleee8540632006-05-30 09:24:40 +000077$(OBJ_DIR)lex.yy.o: $(GEN_DIR)lex.yy.cc
78 $(CC) $(CFL) -c -o $@ $(GEN_DIR)lex.yy.cc
79
Mark Sleeb15a68b2006-06-07 06:46:24 +000080# Parser generation
81$(GEN_DIR)thrift.tab.hh: $(GEN_DIR)thrift.tab.cc
82$(GEN_DIR)thrift.tab.cc: $(SRC_DIR)thrift.y
83 $(YACC) -d -o$(GEN_DIR)thrift.tab.cc $(SRC_DIR)thrift.y
Mark Sleee8540632006-05-30 09:24:40 +000084$(OBJ_DIR)thrift.tab.o: $(GEN_DIR)thrift.tab.cc
85 $(CC) $(CFL) -c -o $@ $(GEN_DIR)thrift.tab.cc
86
87# C++ compilation
88$(OBJS): $(SRCS)
Mark Slee31985722006-05-24 21:45:31 +000089 $(CC) $(CFL) -c -o $@ ${subst $(OBJ_DIR),$(SRC_DIR),$*.cc}
90
Mark Slee31985722006-05-24 21:45:31 +000091# Main build rule
Mark Sleeb15a68b2006-06-07 06:46:24 +000092thrift: obj_dirs $(OBJS) $(GOBS)
Mark Sleee8540632006-05-30 09:24:40 +000093 $(LD) $(CFL) -o $(BIN_DIR)thrift $(OBJS) $(GOBS) $(LIBS)
Mark Slee31985722006-05-24 21:45:31 +000094
Mark Sleeb15a68b2006-06-07 06:46:24 +000095# Install
Mark Sleee8540632006-05-30 09:24:40 +000096install: thrift
97 sudo install bin/thrift /usr/local/bin/thrift
Mark Slee31985722006-05-24 21:45:31 +000098
99# Remove auto-gen'd files and binaries
100clean:
Mark Sleed1734072006-06-07 06:57:01 +0000101 rm -fr \
102 $(OBJ_DIR) \
Mark Slee31985722006-05-24 21:45:31 +0000103 $(GENS) \
104 $(BIN_DIR)thrift.exe \
105 $(BIN_DIR)thrift
Mark Slee31985722006-05-24 21:45:31 +0000106