| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 1 | # 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 | 
|  | 14 | target:	thrift | 
|  | 15 |  | 
|  | 16 | # Tools | 
|  | 17 | CC    = g++ | 
|  | 18 | LD    = g++ | 
|  | 19 | LEX   = flex | 
|  | 20 | YACC  = bison | 
|  | 21 | MKDIR = mkdir | 
|  | 22 |  | 
|  | 23 | # Source directory | 
|  | 24 | SRC_DIR = src/ | 
|  | 25 |  | 
|  | 26 | # Object file directory | 
|  | 27 | OBJ_DIR = obj/ | 
|  | 28 |  | 
|  | 29 | # Generated source dir | 
|  | 30 | GEN_DIR = $(SRC_DIR) | 
|  | 31 |  | 
|  | 32 | # Output directory | 
|  | 33 | BIN_DIR = bin/ | 
|  | 34 |  | 
|  | 35 | # Source files | 
|  | 36 | SRC_FILES = main.cc \ | 
|  | 37 | generate/t_generator.cc \ | 
|  | 38 | generate/t_cpp_generator.cc | 
|  | 39 |  | 
|  | 40 | # Autogenerated files | 
|  | 41 | GEN_FILES = thrift.tab.hh \ | 
|  | 42 | thrift.tab.cc \ | 
|  | 43 | lex.yy.cc | 
|  | 44 |  | 
|  | 45 | # Object files | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame^] | 46 | OBJ_FILES = ${SRC_FILES:.cc=.o} | 
|  | 47 |  | 
|  | 48 | # Generated object files | 
|  | 49 | GOB_FILES = thrift.tab.o \ | 
|  | 50 | lex.yy.o | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 51 |  | 
|  | 52 | # Apply directory prefixes | 
|  | 53 | SRCS = ${addprefix $(SRC_DIR), $(SRC_FILES)} | 
|  | 54 | GENS = ${addprefix $(GEN_DIR), $(GEN_FILES)} | 
|  | 55 | OBJS = ${addprefix $(OBJ_DIR), $(OBJ_FILES)} | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame^] | 56 | GOBS = ${addprefix $(OBJ_DIR), $(GOB_FILES)} | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 57 |  | 
|  | 58 | # Compile with strict warnings | 
|  | 59 | CFL = -g -Wall -I$(SRC_DIR) -I$(OBJ_DIR) | 
|  | 60 |  | 
|  | 61 | # Flex library | 
|  | 62 | LIBS = -lfl | 
|  | 63 |  | 
|  | 64 | # Scanner generation | 
|  | 65 | $(GEN_DIR)lex.yy.cc: $(SRC_DIR)thrift.l | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame^] | 66 | $(LEX) -o$@ $(SRC_DIR)thrift.l | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 67 |  | 
|  | 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 Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame^] | 75 | $(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 Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 84 | $(CC) $(CFL) -c -o $@ ${subst $(OBJ_DIR),$(SRC_DIR),$*.cc} | 
|  | 85 |  | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 86 | # Main build rule | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame^] | 87 | thrift:	$(OBJS)	$(GOBS) | 
|  | 88 | $(LD) $(CFL) -o $(BIN_DIR)thrift $(OBJS) $(GOBS) $(LIBS) | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 89 |  | 
|  | 90 | # Build directory | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame^] | 91 | obj_dirs: | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 92 | $(MKDIR) -p $(OBJ_DIR)parse | 
|  | 93 | $(MKDIR) -p $(OBJ_DIR)generate | 
|  | 94 |  | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame^] | 95 | # Install it | 
|  | 96 | install: thrift | 
|  | 97 | sudo install bin/thrift /usr/local/bin/thrift | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 98 |  | 
|  | 99 | # Remove auto-gen'd files and binaries | 
|  | 100 | clean: | 
|  | 101 | rm -f \ | 
|  | 102 | $(OBJS) \ | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame^] | 103 | $(GOBS) \ | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 104 | $(GENS) \ | 
|  | 105 | $(BIN_DIR)thrift.exe \ | 
|  | 106 | $(BIN_DIR)thrift | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 107 |  |