blob: 3b9be48cedf812478127f23ded4e4d5be35d3c97 [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 Slee0e0ff7e2007-01-18 22:59:59 +000038 generate/t_xsd_generator.cc \
Mark Sleefc89d392006-09-04 00:04:39 +000039 generate/t_py_generator.cc \
Mark Slee78f58e22006-09-02 04:17:07 +000040 generate/t_java_generator.cc \
Mark Slee52f643d2006-08-09 00:03:43 +000041 generate/t_php_generator.cc \
Mark Slee78f58e22006-09-02 04:17:07 +000042 generate/t_cpp_generator.cc
Mark Slee31985722006-05-24 21:45:31 +000043
44# Autogenerated files
45GEN_FILES = thrift.tab.hh \
46 thrift.tab.cc \
47 lex.yy.cc
48
49# Object files
Mark Sleee8540632006-05-30 09:24:40 +000050OBJ_FILES = ${SRC_FILES:.cc=.o}
51
52# Generated object files
53GOB_FILES = thrift.tab.o \
54 lex.yy.o
Mark Slee31985722006-05-24 21:45:31 +000055
56# Apply directory prefixes
57SRCS = ${addprefix $(SRC_DIR), $(SRC_FILES)}
58GENS = ${addprefix $(GEN_DIR), $(GEN_FILES)}
59OBJS = ${addprefix $(OBJ_DIR), $(OBJ_FILES)}
Mark Sleee8540632006-05-30 09:24:40 +000060GOBS = ${addprefix $(OBJ_DIR), $(GOB_FILES)}
Mark Slee31985722006-05-24 21:45:31 +000061
62# Compile with strict warnings
63CFL = -g -Wall -I$(SRC_DIR) -I$(OBJ_DIR)
64
65# Flex library
66LIBS = -lfl
67
Mark Sleeb15a68b2006-06-07 06:46:24 +000068# Build directories
Mark Slee7628fd72007-01-18 01:16:51 +000069obj_dirs: $(BIN_DIR) $(OBJ_DIR)parse $(OBJ_DIR)generate
70$(BIN_DIR):
71 $(MKDIR) -p $(BIN_DIR)
Mark Sleeb15a68b2006-06-07 06:46:24 +000072$(OBJ_DIR)parse:
73 $(MKDIR) -p $(OBJ_DIR)parse
74$(OBJ_DIR)generate:
75 $(MKDIR) -p $(OBJ_DIR)generate
76
Mark Slee31985722006-05-24 21:45:31 +000077# Scanner generation
78$(GEN_DIR)lex.yy.cc: $(SRC_DIR)thrift.l
Mark Sleee8540632006-05-30 09:24:40 +000079 $(LEX) -o$@ $(SRC_DIR)thrift.l
Mark Sleee8540632006-05-30 09:24:40 +000080$(OBJ_DIR)lex.yy.o: $(GEN_DIR)lex.yy.cc
81 $(CC) $(CFL) -c -o $@ $(GEN_DIR)lex.yy.cc
82
Mark Sleeb15a68b2006-06-07 06:46:24 +000083# Parser generation
84$(GEN_DIR)thrift.tab.hh: $(GEN_DIR)thrift.tab.cc
85$(GEN_DIR)thrift.tab.cc: $(SRC_DIR)thrift.y
86 $(YACC) -d -o$(GEN_DIR)thrift.tab.cc $(SRC_DIR)thrift.y
Mark Sleee8540632006-05-30 09:24:40 +000087$(OBJ_DIR)thrift.tab.o: $(GEN_DIR)thrift.tab.cc
88 $(CC) $(CFL) -c -o $@ $(GEN_DIR)thrift.tab.cc
89
90# C++ compilation
91$(OBJS): $(SRCS)
Mark Slee31985722006-05-24 21:45:31 +000092 $(CC) $(CFL) -c -o $@ ${subst $(OBJ_DIR),$(SRC_DIR),$*.cc}
93
Mark Slee31985722006-05-24 21:45:31 +000094# Main build rule
Mark Sleeb15a68b2006-06-07 06:46:24 +000095thrift: obj_dirs $(OBJS) $(GOBS)
Mark Sleee8540632006-05-30 09:24:40 +000096 $(LD) $(CFL) -o $(BIN_DIR)thrift $(OBJS) $(GOBS) $(LIBS)
Mark Slee31985722006-05-24 21:45:31 +000097
Mark Sleeb15a68b2006-06-07 06:46:24 +000098# Install
Mark Sleee8540632006-05-30 09:24:40 +000099install: thrift
100 sudo install bin/thrift /usr/local/bin/thrift
Mark Slee31985722006-05-24 21:45:31 +0000101
102# Remove auto-gen'd files and binaries
103clean:
Mark Sleed1734072006-06-07 06:57:01 +0000104 rm -fr \
105 $(OBJ_DIR) \
Mark Slee31985722006-05-24 21:45:31 +0000106 $(GENS) \
107 $(BIN_DIR)thrift.exe \
108 $(BIN_DIR)thrift
Mark Slee31985722006-05-24 21:45:31 +0000109