blob: 3d405a1b90178121317618b8b81adbfdde2ace3b [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
Mark Slee7628fd72007-01-18 01:16:51 +000068obj_dirs: $(BIN_DIR) $(OBJ_DIR)parse $(OBJ_DIR)generate
69$(BIN_DIR):
70 $(MKDIR) -p $(BIN_DIR)
Mark Sleeb15a68b2006-06-07 06:46:24 +000071$(OBJ_DIR)parse:
72 $(MKDIR) -p $(OBJ_DIR)parse
73$(OBJ_DIR)generate:
74 $(MKDIR) -p $(OBJ_DIR)generate
75
Mark Slee31985722006-05-24 21:45:31 +000076# Scanner generation
77$(GEN_DIR)lex.yy.cc: $(SRC_DIR)thrift.l
Mark Sleee8540632006-05-30 09:24:40 +000078 $(LEX) -o$@ $(SRC_DIR)thrift.l
Mark Sleee8540632006-05-30 09:24:40 +000079$(OBJ_DIR)lex.yy.o: $(GEN_DIR)lex.yy.cc
80 $(CC) $(CFL) -c -o $@ $(GEN_DIR)lex.yy.cc
81
Mark Sleeb15a68b2006-06-07 06:46:24 +000082# Parser generation
83$(GEN_DIR)thrift.tab.hh: $(GEN_DIR)thrift.tab.cc
84$(GEN_DIR)thrift.tab.cc: $(SRC_DIR)thrift.y
85 $(YACC) -d -o$(GEN_DIR)thrift.tab.cc $(SRC_DIR)thrift.y
Mark Sleee8540632006-05-30 09:24:40 +000086$(OBJ_DIR)thrift.tab.o: $(GEN_DIR)thrift.tab.cc
87 $(CC) $(CFL) -c -o $@ $(GEN_DIR)thrift.tab.cc
88
89# C++ compilation
90$(OBJS): $(SRCS)
Mark Slee31985722006-05-24 21:45:31 +000091 $(CC) $(CFL) -c -o $@ ${subst $(OBJ_DIR),$(SRC_DIR),$*.cc}
92
Mark Slee31985722006-05-24 21:45:31 +000093# Main build rule
Mark Sleeb15a68b2006-06-07 06:46:24 +000094thrift: obj_dirs $(OBJS) $(GOBS)
Mark Sleee8540632006-05-30 09:24:40 +000095 $(LD) $(CFL) -o $(BIN_DIR)thrift $(OBJS) $(GOBS) $(LIBS)
Mark Slee31985722006-05-24 21:45:31 +000096
Mark Sleeb15a68b2006-06-07 06:46:24 +000097# Install
Mark Sleee8540632006-05-30 09:24:40 +000098install: thrift
99 sudo install bin/thrift /usr/local/bin/thrift
Mark Slee31985722006-05-24 21:45:31 +0000100
101# Remove auto-gen'd files and binaries
102clean:
Mark Sleed1734072006-06-07 06:57:01 +0000103 rm -fr \
104 $(OBJ_DIR) \
Mark Slee31985722006-05-24 21:45:31 +0000105 $(GENS) \
106 $(BIN_DIR)thrift.exe \
107 $(BIN_DIR)thrift
Mark Slee31985722006-05-24 21:45:31 +0000108