OLD | NEW |
---|---|
(Empty) | |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 # This is a simplistic sample Makefile for building a Mojo application. It | |
6 # produces output in the out subdirectory (which it creates if necessary), and | |
7 # produces "debug" builds. It assumes that the mojom tool and clang have been | |
8 # obtained by running mojo_sdk_setup/setup.sh. | |
9 # | |
10 # Note: It is very primitive, and doesn't try to correctly handle dependencies. | |
11 # | |
12 # TODO(vtl): Even so, it could use a lot of improvements. | |
13 # TODO(vtl): Should probably support other toolchains, when appropriate. | |
14 | |
15 # Default target --------------------------------------------------------------- | |
16 | |
17 all: default | |
18 | |
19 # Build directories ------------------------------------------------------------ | |
20 | |
21 OUT_DIR := out | |
22 GEN_DIR := $(OUT_DIR)/gen | |
23 OBJ_DIR := $(OUT_DIR)/obj | |
24 | |
25 $(OUT_DIR): | |
26 mkdir -p $(OUT_DIR) | |
27 | |
28 $(GEN_DIR): | $(OUT_DIR) | |
29 mkdir -p $(GEN_DIR) | |
30 | |
31 $(OBJ_DIR): | $(OUT_DIR) | |
32 mkdir -p $(OBJ_DIR) | |
33 | |
34 # Tools ------------------------------------------------------------------------ | |
35 | |
36 MOJOM_BINDINGS_GENERATOR := \ | |
37 mojo/public/tools/bindings/mojom_bindings_generator.py | |
38 | |
39 CC := toolchain/clang/bin/clang | |
40 CFLAGS := -m64 -march=x86-64 -fPIC -fvisibility=hidden -fno-strict-aliasing \ | |
41 -pthread -O0 -g2 -Wall -Werror -I. -I$(GEN_DIR) | |
42 | |
43 CXX := toolchain/clang/bin/clang++ | |
44 CXXFLAGS := $(CFLAGS) -std=c++11 -fno-rtti -fno-exceptions | |
45 | |
46 CXX_MAKE_SO_FLAGS := $(CXXFLAGS) -shared -ldl -Wl,--fatal-warnings \ | |
47 -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro -Wl,-z,defs | |
48 | |
49 # Build patterns --------------------------------------------------------------- | |
50 | |
51 $(GEN_DIR)/%.mojom.cc $(GEN_DIR)/%.mojom.h $(GEN_DIR)/%.mojom-internal.h: \ | |
52 %.mojom | $(GEN_DIR) | |
53 $(MOJOM_BINDINGS_GENERATOR) --use_bundled_pylibs -d . -I . -o $(GEN_DIR) \ | |
54 --no-gen-imports --no-generate-type-info $< | |
55 | |
56 $(OBJ_DIR)/%.o: %.c | |
57 mkdir -p $(@D) | |
58 $(CC) $(CFLAGS) -o $@ -c $< | |
59 | |
60 $(OBJ_DIR)/%.o: %.cc | |
61 mkdir -p $(@D) | |
62 $(CXX) $(CXXFLAGS) -o $@ -c $< | |
63 | |
64 # "Functions" (to use with $(call function_name,...)) -------------------------- | |
65 | |
66 # Function to get a list of generated .cc files from a list of .mojom files. | |
67 cc_files_from_mojom_files = $(patsubst %.mojom,$(GEN_DIR)/%.mojom.cc,$(1)) | |
68 | |
69 # Function to get a list of generated .o files from a list of .c files. | |
70 o_files_from_c_files = $(patsubst %.c,$(OBJ_DIR)/%.o,$(1)) | |
71 | |
72 # Function to get a list of generated .o files from a list of .cc files. | |
73 o_files_from_cc_files = $(patsubst %.cc,$(OBJ_DIR)/%.o,$(1)) | |
74 | |
75 # Target: mojo_public.a -------------------------------------------------------- | |
76 | |
77 MOJO_PUBLIC_MOJOM_FILES := \ | |
78 $(wildcard mojo/public/interfaces/application/*.mojom) \ | |
79 $(wildcard mojo/public/interfaces/bindings/*.mojom) \ | |
80 $(wildcard mojo/public/interfaces/network/*.mojom) | |
81 MOJO_PUBLIC_MOJOM_CC_FILES := \ | |
82 $(call cc_files_from_mojom_files,$(MOJO_PUBLIC_MOJOM_FILES)) | |
83 MOJO_PUBLIC_C_FILES := \ | |
84 $(wildcard mojo/public/c/bindings/lib/*.c) | |
85 MOJO_PUBLIC_CC_FILES := \ | |
86 $(wildcard mojo/public/cpp/application/lib/*.cc) \ | |
87 $(wildcard mojo/public/cpp/bindings/lib/*.cc) \ | |
88 $(wildcard mojo/public/cpp/environment/lib/*.cc) \ | |
89 $(wildcard mojo/public/cpp/system/lib/*.cc) \ | |
90 $(wildcard mojo/public/cpp/utility/lib/*.cc) | |
91 # We have to choose *one* implementation of |Environment|, so remove the | |
92 # logging-only environment. | |
93 MOJO_PUBLIC_CC_FILES := \ | |
94 $(filter-out mojo/public/cpp/environment/lib/logging_only_enviro nment.cc, \ | |
95 $(MOJO_PUBLIC_CC_FILES)) | |
96 | |
97 $(MOJO_PUBLIC_CC_FILES): $(MOJO_PUBLIC_MOJOM_CC_FILES) | |
vardhan
2016/02/29 20:56:37
what about header file dependencies, since a lot o
viettrungluu
2016/02/29 21:02:54
Blah blah blah. Apparently, you can't read -- see
vardhan
2016/02/29 21:11:54
that's uncalled for -- please practice courtesy wh
| |
98 | |
99 # TODO(vtl): We could really update the archive instead of re-creating it each | |
100 # time. | |
101 $(OUT_DIR)/mojo_public.a: \ | |
102 $(MOJO_PUBLIC_MOJOM_CC_FILES) \ | |
103 $(call o_files_from_cc_files,$(MOJO_PUBLIC_MOJOM_CC_FILES)) \ | |
104 $(call o_files_from_c_files,$(MOJO_PUBLIC_C_FILES)) \ | |
105 $(call o_files_from_cc_files,$(MOJO_PUBLIC_CC_FILES)) \ | |
106 | $(OUT_DIR) | |
107 rm -f $@ | |
108 ar rc $@ $(filter %.o,$^) | |
109 | |
110 # Target: mojo_system_thunks.o ------------------------------------------------- | |
111 | |
112 # TODO(vtl): Support other thunk libraries. | |
113 | |
114 $(OBJ_DIR)/mojo_system_thunks.o: \ | |
115 $(OBJ_DIR)/mojo/public/platform/native/system_thunks.o | |
116 cp $^ $@ | |
117 | |
118 # Targets: hello_mojo_client.mojo and hello_mojo_server.mojo ------------------- | |
119 | |
120 EXAMPLES_HELLO_MOJO_MOJOM_FILES := \ | |
121 $(wildcard examples/hello_mojo/*.mojom) | |
122 EXAMPLES_HELLO_MOJO_MOJOM_CC_FILES := \ | |
123 $(call cc_files_from_mojom_files,$(EXAMPLES_HELLO_MOJO_MOJOM_FIL ES)) | |
124 | |
125 EXAMPLES_HELLO_MOJO_CLIENT_CC_FILES := \ | |
126 examples/hello_mojo/hello_mojo_client.cc | |
127 $(EXAMPLES_HELLO_MOJO_CLIENT_CC_FILES): $(EXAMPLES_HELLO_MOJO_MOJOM_CC_FILES) | |
128 $(OUT_DIR)/hello_mojo_client.mojo: \ | |
129 $(OUT_DIR)/mojo_public.a \ | |
130 $(OBJ_DIR)/mojo_system_thunks.o \ | |
131 $(call o_files_from_cc_files,$(EXAMPLES_HELLO_MOJO_MOJOM_CC_FILE S)) \ | |
132 $(call o_files_from_cc_files,$(EXAMPLES_HELLO_MOJO_CLIENT_CC_FIL ES)) | |
133 $(CXX) $(CXX_MAKE_SO_FLAGS) \ | |
134 -Wl,--whole-archive $(filter %.o,$^) -Wl,-no-whole-archi ve \ | |
135 $(filter %.a,$^) -o $@ | |
136 | |
137 EXAMPLES_HELLO_MOJO_SERVER_CC_FILES := \ | |
138 examples/hello_mojo/hello_mojo_server.cc | |
139 $(EXAMPLES_HELLO_MOJO_SERVER_CC_FILES): $(EXAMPLES_HELLO_MOJO_MOJOM_CC_FILES) | |
140 $(OUT_DIR)/hello_mojo_server.mojo: \ | |
141 $(OUT_DIR)/mojo_public.a \ | |
142 $(OBJ_DIR)/mojo_system_thunks.o \ | |
143 $(call o_files_from_cc_files,$(EXAMPLES_HELLO_MOJO_MOJOM_CC_FILE S)) \ | |
144 $(call o_files_from_cc_files,$(EXAMPLES_HELLO_MOJO_SERVER_CC_FIL ES)) | |
145 $(CXX) $(CXX_MAKE_SO_FLAGS) \ | |
146 -Wl,--whole-archive $(filter %.o,$^) -Wl,-no-whole-archi ve \ | |
147 $(filter %.a,$^) -o $@ | |
148 | |
149 # Default targets -------------------------------------------------------------- | |
150 | |
151 default: $(OUT_DIR)/hello_mojo_client.mojo $(OUT_DIR)/hello_mojo_server.mojo | |
OLD | NEW |