xref: /aosp_15_r20/external/rappor/client/cpp/Makefile (revision 2abb31345f6c95944768b5222a9a5ed3fc68cc00)
1# Build RAPPOR C++ code.
2
3default : \
4	_tmp/rappor_sim \
5	_tmp/encoder_demo \
6	_tmp/protobuf_encoder_demo \
7	_tmp/openssl_hash_impl_test
8
9# All intermediate files live in _tmp/
10clean :
11	rm -f --verbose _tmp/*
12
13# Use protobuf compiler to generate .cc and .h files.  The .o and the .d depend
14# on .cc, so that is the target of this rule.
15
16_tmp/%.pb.cc : ../proto/%.proto
17	protoc --cpp_out _tmp --proto_path=../proto $<
18
19#
20# Generate .d Makefile fragments.
21#
22
23# CXX flags:
24#   -MM: exclude system headers
25#   -I _tmp: So that protobuf files found
26#
27# Makefile stuff:
28#   $*: the part that matched the wildcard, e.g. 'rappor_sim' for '%.cc'
29#   matching 'rappor_sim.cc'
30#
31#   We use $< (first prereq) to generate .d and and .o files from .cc, because
32#   it only needs the .cc file.  We used $^ (all prereqs) to pass ALL the .o
33#   files to the link step.
34
35_tmp/%.d : %.cc
36	./dotd.sh $* $@ \
37		$(CXX) -I _tmp/ -MM $(CPPFLAGS) $<
38
39# Special case for .d file of generated source.
40_tmp/%.pb.d : _tmp/%.pb.cc
41	./dotd.sh $*.pb $@ \
42		$(CXX) -I _tmp/ -MM $(CPPFLAGS) $<
43
44#
45# Include the Makefile fragments we generated, so that changes to headers will
46# rebuild both .d files and .o files.  ('-include' suppresses the error if they
47# don't exist.)
48#
49# NOTE: We have to list them explicitly.  Every time you add a source file, add
50# the corresponding .d file here.
51#
52
53-include \
54	_tmp/encoder.d \
55	_tmp/libc_rand_impl.d \
56	_tmp/openssl_hash_impl.d \
57	_tmp/openssl_hash_impl_test.d \
58	_tmp/protobuf_encoder.d \
59	_tmp/protobuf_encoder_demo.d \
60	_tmp/rappor_sim.d \
61	_tmp/unix_kernel_rand_impl.d \
62	_tmp/rappor.pb.d \
63  _tmp/example_app.pb.d
64
65# For example, -Wextra warns about unused params, but -Wall doesn't.
66CXXFLAGS = -Wall -Wextra #-Wpedantic
67
68#
69# Build object files (-c: compile only)
70#
71
72# NOTE: More prerequisites to _tmp/%.o (header files) are added by the .d
73# files, so we need $<.
74_tmp/%.o : %.cc
75	$(CXX) $(CXXFLAGS) -I _tmp/ -c -o $@ $<
76
77_tmp/%.pb.o : _tmp/%.pb.cc
78	$(CXX) $(CXXFLAGS) -I _tmp/ -c -o $@ $<
79
80#
81# Build executables
82#
83
84# CXX flag notes:
85# -lcrypto from openssl
86# -g for debug info
87#
88# You can add -std=c++0x for std::array, etc.
89
90# $^ : all prerequisites
91_tmp/rappor_sim : \
92	_tmp/encoder.o \
93	_tmp/libc_rand_impl.o \
94	_tmp/unix_kernel_rand_impl.o \
95	_tmp/openssl_hash_impl.o \
96	_tmp/rappor_sim.o
97	$(CXX) \
98		$(CXXFLAGS) \
99		-o $@ \
100		$^ \
101		-lcrypto \
102		-g
103
104# $^ : all prerequisites
105_tmp/encoder_demo: \
106	_tmp/encoder.o \
107	_tmp/unix_kernel_rand_impl.o \
108	_tmp/openssl_hash_impl.o \
109	_tmp/encoder_demo.o
110	$(CXX) \
111		$(CXXFLAGS) \
112		-o $@ \
113		$^ \
114		-lcrypto \
115		-g
116
117# -I _tmp for protobuf headers
118_tmp/protobuf_encoder_demo : \
119	_tmp/encoder.o \
120	_tmp/libc_rand_impl.o \
121	_tmp/unix_kernel_rand_impl.o \
122	_tmp/openssl_hash_impl.o \
123	_tmp/protobuf_encoder.o \
124	_tmp/protobuf_encoder_demo.o \
125	_tmp/example_app.pb.o \
126	_tmp/rappor.pb.o
127	$(CXX) \
128		$(CXXFLAGS) \
129		-I _tmp \
130		-o $@ \
131		$^ \
132		-lprotobuf \
133		-lcrypto \
134		-g
135
136_tmp/openssl_hash_impl_test : \
137 	_tmp/openssl_hash_impl.o \
138	_tmp/openssl_hash_impl_test.o
139	$(CXX) \
140		$(CXXFLAGS) \
141		-o $@ \
142		$^ \
143		-lcrypto \
144		-g
145
146# Unittests are currently run manually, and require the Google gtest
147# framework version 1.7.0 or greater, found at
148#   https://github.com/google/googletest/releases
149# TODO(mdeshon-google): Installer script
150unittest: _tmp/openssl_hash_impl_unittest _tmp/encoder_unittest
151	_tmp/openssl_hash_impl_unittest
152	_tmp/encoder_unittest
153
154_tmp/openssl_hash_impl_unittest: openssl_hash_impl_unittest.cc openssl_hash_impl.cc
155	$(CXX) -g -o $@  $^ -lssl -lcrypto -lgtest
156
157_tmp/encoder_unittest: encoder_unittest.cc encoder.cc unix_kernel_rand_impl.cc openssl_hash_impl.cc
158	$(CXX) -g -o $@  $^ -lssl -lcrypto -lgtest
159