blob: 62ce2752311d135128350877bb679a664fc75461 [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 \
38 generate/t_cpp_generator.cc
39
40# Autogenerated files
41GEN_FILES = thrift.tab.hh \
42 thrift.tab.cc \
43 lex.yy.cc
44
45# Object files
Mark Sleee8540632006-05-30 09:24:40 +000046OBJ_FILES = ${SRC_FILES:.cc=.o}
47
48# Generated object files
49GOB_FILES = thrift.tab.o \
50 lex.yy.o
Mark Slee31985722006-05-24 21:45:31 +000051
52# Apply directory prefixes
53SRCS = ${addprefix $(SRC_DIR), $(SRC_FILES)}
54GENS = ${addprefix $(GEN_DIR), $(GEN_FILES)}
55OBJS = ${addprefix $(OBJ_DIR), $(OBJ_FILES)}
Mark Sleee8540632006-05-30 09:24:40 +000056GOBS = ${addprefix $(OBJ_DIR), $(GOB_FILES)}
Mark Slee31985722006-05-24 21:45:31 +000057
58# Compile with strict warnings
59CFL = -g -Wall -I$(SRC_DIR) -I$(OBJ_DIR)
60
61# Flex library
62LIBS = -lfl
63
64# Scanner generation
65$(GEN_DIR)lex.yy.cc: $(SRC_DIR)thrift.l
Mark Sleee8540632006-05-30 09:24:40 +000066 $(LEX) -o$@ $(SRC_DIR)thrift.l
Mark Slee31985722006-05-24 21:45:31 +000067
68# Parser generation
69$(GEN_DIR)thrift.tab.hh: $(GEN_DIR)thrift.tab.cc
70
71$(GEN_DIR)thrift.tab.cc: $(SRC_DIR)thrift.y
72 $(YACC) -d -o$(GEN_DIR)thrift.tab.cc $(SRC_DIR)thrift.y
73
74# C++ compilation
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
78# C++ compilation
79$(OBJ_DIR)thrift.tab.o: $(GEN_DIR)thrift.tab.cc
80 $(CC) $(CFL) -c -o $@ $(GEN_DIR)thrift.tab.cc
81
82# C++ compilation
83$(OBJS): $(SRCS)
Mark Slee31985722006-05-24 21:45:31 +000084 $(CC) $(CFL) -c -o $@ ${subst $(OBJ_DIR),$(SRC_DIR),$*.cc}
85
Mark Slee31985722006-05-24 21:45:31 +000086# Main build rule
Mark Sleee8540632006-05-30 09:24:40 +000087thrift: $(OBJS) $(GOBS)
88 $(LD) $(CFL) -o $(BIN_DIR)thrift $(OBJS) $(GOBS) $(LIBS)
Mark Slee31985722006-05-24 21:45:31 +000089
90# Build directory
Mark Sleee8540632006-05-30 09:24:40 +000091obj_dirs:
Mark Slee31985722006-05-24 21:45:31 +000092 $(MKDIR) -p $(OBJ_DIR)parse
93 $(MKDIR) -p $(OBJ_DIR)generate
94
Mark Sleee8540632006-05-30 09:24:40 +000095# Install it
96install: 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:
101 rm -f \
102 $(OBJS) \
Mark Sleee8540632006-05-30 09:24:40 +0000103 $(GOBS) \
Mark Slee31985722006-05-24 21:45:31 +0000104 $(GENS) \
105 $(BIN_DIR)thrift.exe \
106 $(BIN_DIR)thrift
Mark Slee31985722006-05-24 21:45:31 +0000107