blob: 49833cb6713fbad5fd94a2bb84752f1f910e2e97 [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 \
39 generate/t_java_generator.cc
Mark Slee31985722006-05-24 21:45:31 +000040
41# Autogenerated files
42GEN_FILES = thrift.tab.hh \
43 thrift.tab.cc \
44 lex.yy.cc
45
46# Object files
Mark Sleee8540632006-05-30 09:24:40 +000047OBJ_FILES = ${SRC_FILES:.cc=.o}
48
49# Generated object files
50GOB_FILES = thrift.tab.o \
51 lex.yy.o
Mark Slee31985722006-05-24 21:45:31 +000052
53# Apply directory prefixes
54SRCS = ${addprefix $(SRC_DIR), $(SRC_FILES)}
55GENS = ${addprefix $(GEN_DIR), $(GEN_FILES)}
56OBJS = ${addprefix $(OBJ_DIR), $(OBJ_FILES)}
Mark Sleee8540632006-05-30 09:24:40 +000057GOBS = ${addprefix $(OBJ_DIR), $(GOB_FILES)}
Mark Slee31985722006-05-24 21:45:31 +000058
59# Compile with strict warnings
60CFL = -g -Wall -I$(SRC_DIR) -I$(OBJ_DIR)
61
62# Flex library
63LIBS = -lfl
64
Mark Sleeb15a68b2006-06-07 06:46:24 +000065# Build directories
66obj_dirs: $(OBJ_DIR)parse $(OBJ_DIR)generate
67$(OBJ_DIR)parse:
68 $(MKDIR) -p $(OBJ_DIR)parse
69$(OBJ_DIR)generate:
70 $(MKDIR) -p $(OBJ_DIR)generate
71
Mark Slee31985722006-05-24 21:45:31 +000072# Scanner generation
73$(GEN_DIR)lex.yy.cc: $(SRC_DIR)thrift.l
Mark Sleee8540632006-05-30 09:24:40 +000074 $(LEX) -o$@ $(SRC_DIR)thrift.l
Mark Sleee8540632006-05-30 09:24:40 +000075$(OBJ_DIR)lex.yy.o: $(GEN_DIR)lex.yy.cc
76 $(CC) $(CFL) -c -o $@ $(GEN_DIR)lex.yy.cc
77
Mark Sleeb15a68b2006-06-07 06:46:24 +000078# Parser generation
79$(GEN_DIR)thrift.tab.hh: $(GEN_DIR)thrift.tab.cc
80$(GEN_DIR)thrift.tab.cc: $(SRC_DIR)thrift.y
81 $(YACC) -d -o$(GEN_DIR)thrift.tab.cc $(SRC_DIR)thrift.y
Mark Sleee8540632006-05-30 09:24:40 +000082$(OBJ_DIR)thrift.tab.o: $(GEN_DIR)thrift.tab.cc
83 $(CC) $(CFL) -c -o $@ $(GEN_DIR)thrift.tab.cc
84
85# C++ compilation
86$(OBJS): $(SRCS)
Mark Slee31985722006-05-24 21:45:31 +000087 $(CC) $(CFL) -c -o $@ ${subst $(OBJ_DIR),$(SRC_DIR),$*.cc}
88
Mark Slee31985722006-05-24 21:45:31 +000089# Main build rule
Mark Sleeb15a68b2006-06-07 06:46:24 +000090thrift: obj_dirs $(OBJS) $(GOBS)
Mark Sleee8540632006-05-30 09:24:40 +000091 $(LD) $(CFL) -o $(BIN_DIR)thrift $(OBJS) $(GOBS) $(LIBS)
Mark Slee31985722006-05-24 21:45:31 +000092
Mark Sleeb15a68b2006-06-07 06:46:24 +000093# Install
Mark Sleee8540632006-05-30 09:24:40 +000094install: thrift
95 sudo install bin/thrift /usr/local/bin/thrift
Mark Slee31985722006-05-24 21:45:31 +000096
97# Remove auto-gen'd files and binaries
98clean:
99 rm -f \
100 $(OBJS) \
Mark Sleee8540632006-05-30 09:24:40 +0000101 $(GOBS) \
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