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