| 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 \ | 
| Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 38 | generate/t_java_generator.cc \ | 
| Mark Slee | 52f643d | 2006-08-09 00:03:43 +0000 | [diff] [blame] | 39 | generate/t_php_generator.cc \ | 
| Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 40 | generate/t_cpp_generator.cc | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 41 |  | 
|  | 42 | # Autogenerated files | 
|  | 43 | GEN_FILES = thrift.tab.hh \ | 
|  | 44 | thrift.tab.cc \ | 
|  | 45 | lex.yy.cc | 
|  | 46 |  | 
|  | 47 | # Object files | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 48 | OBJ_FILES = ${SRC_FILES:.cc=.o} | 
|  | 49 |  | 
|  | 50 | # Generated object files | 
|  | 51 | GOB_FILES = thrift.tab.o \ | 
|  | 52 | lex.yy.o | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 53 |  | 
|  | 54 | # Apply directory prefixes | 
|  | 55 | SRCS = ${addprefix $(SRC_DIR), $(SRC_FILES)} | 
|  | 56 | GENS = ${addprefix $(GEN_DIR), $(GEN_FILES)} | 
|  | 57 | OBJS = ${addprefix $(OBJ_DIR), $(OBJ_FILES)} | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 58 | GOBS = ${addprefix $(OBJ_DIR), $(GOB_FILES)} | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 59 |  | 
|  | 60 | # Compile with strict warnings | 
|  | 61 | CFL = -g -Wall -I$(SRC_DIR) -I$(OBJ_DIR) | 
|  | 62 |  | 
|  | 63 | # Flex library | 
|  | 64 | LIBS = -lfl | 
|  | 65 |  | 
| Mark Slee | b15a68b | 2006-06-07 06:46:24 +0000 | [diff] [blame] | 66 | # Build directories | 
|  | 67 | obj_dirs: $(OBJ_DIR)parse $(OBJ_DIR)generate | 
|  | 68 | $(OBJ_DIR)parse: | 
|  | 69 | $(MKDIR) -p $(OBJ_DIR)parse | 
|  | 70 | $(OBJ_DIR)generate: | 
|  | 71 | $(MKDIR) -p $(OBJ_DIR)generate | 
|  | 72 |  | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 73 | # Scanner generation | 
|  | 74 | $(GEN_DIR)lex.yy.cc: $(SRC_DIR)thrift.l | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 75 | $(LEX) -o$@ $(SRC_DIR)thrift.l | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 76 | $(OBJ_DIR)lex.yy.o: $(GEN_DIR)lex.yy.cc | 
|  | 77 | $(CC) $(CFL) -c -o $@ $(GEN_DIR)lex.yy.cc | 
|  | 78 |  | 
| Mark Slee | b15a68b | 2006-06-07 06:46:24 +0000 | [diff] [blame] | 79 | # Parser generation | 
|  | 80 | $(GEN_DIR)thrift.tab.hh: $(GEN_DIR)thrift.tab.cc | 
|  | 81 | $(GEN_DIR)thrift.tab.cc: $(SRC_DIR)thrift.y | 
|  | 82 | $(YACC) -d -o$(GEN_DIR)thrift.tab.cc $(SRC_DIR)thrift.y | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 83 | $(OBJ_DIR)thrift.tab.o: $(GEN_DIR)thrift.tab.cc | 
|  | 84 | $(CC) $(CFL) -c -o $@ $(GEN_DIR)thrift.tab.cc | 
|  | 85 |  | 
|  | 86 | # C++ compilation | 
|  | 87 | $(OBJS): $(SRCS) | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 88 | $(CC) $(CFL) -c -o $@ ${subst $(OBJ_DIR),$(SRC_DIR),$*.cc} | 
|  | 89 |  | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 90 | # Main build rule | 
| Mark Slee | b15a68b | 2006-06-07 06:46:24 +0000 | [diff] [blame] | 91 | thrift:	obj_dirs $(OBJS) $(GOBS) | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 92 | $(LD) $(CFL) -o $(BIN_DIR)thrift $(OBJS) $(GOBS) $(LIBS) | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 93 |  | 
| Mark Slee | b15a68b | 2006-06-07 06:46:24 +0000 | [diff] [blame] | 94 | # Install | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 95 | install: thrift | 
|  | 96 | sudo install bin/thrift /usr/local/bin/thrift | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 97 |  | 
|  | 98 | # Remove auto-gen'd files and binaries | 
|  | 99 | clean: | 
| Mark Slee | d173407 | 2006-06-07 06:57:01 +0000 | [diff] [blame] | 100 | rm -fr \ | 
|  | 101 | $(OBJ_DIR) \ | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 102 | $(GENS) \ | 
|  | 103 | $(BIN_DIR)thrift.exe \ | 
|  | 104 | $(BIN_DIR)thrift | 
| Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 105 |  |