1# Copyright (C) 2018 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import("//common-mk/pkg_config.gni")
16
17group("all") {
18  deps = [
19    ":bsdiff",
20    ":bspatch",
21    ":libbsdiff",
22    ":libbspatch",
23  ]
24  if (use.test) {
25    deps += [ ":bsdiff_test" ]
26  }
27  if (use.fuzzer) {
28    deps += [ ":bspatch_fuzzer" ]
29  }
30}
31
32config("target_defaults") {
33  cflags = [
34    "-Wextra",
35    "-Wno-unused-parameter",
36  ]
37  cflags_cc = [ "-Wnon-virtual-dtor" ]
38  defines = [ "_FILE_OFFSET_BITS=64" ]
39  include_dirs = [
40      "include",
41      # We need this include dir because we include all the local code as
42      # "bsdiff/...".
43      "${platform2_root}/../aosp/external",
44  ]
45  libs = [ "bz2" ]
46}
47
48pkg_config("libbspatch_config") {
49  pkg_deps = [ "libbrotlidec" ]
50}
51
52static_library("libbspatch") {
53  configs += [
54   "//common-mk:nouse_thin_archive",
55   ":target_defaults",
56   ":libbspatch_config"
57  ]
58  configs -= [ "//common-mk:use_thin_archive" ]
59  sources = [
60    "brotli_decompressor.cc",
61    "bspatch.cc",
62    "buffer_file.cc",
63    "bz2_decompressor.cc",
64    "decompressor_interface.cc",
65    "extents.cc",
66    "extents_file.cc",
67    "file.cc",
68    "logging.cc",
69    "memory_file.cc",
70    "patch_reader.cc",
71    "sink_file.cc",
72    "utils.cc",
73  ]
74}
75
76executable("bspatch") {
77  configs += [ ":target_defaults" ]
78  deps = [ ":libbspatch" ]
79  sources = [
80    "bspatch_main.cc",
81  ]
82}
83
84pkg_config("libbsdiff_config") {
85  pkg_deps = [
86    "libbrotlienc",
87    "libdivsufsort",
88    "libdivsufsort64",
89  ]
90}
91
92static_library("libbsdiff") {
93  configs += [
94    "//common-mk:nouse_thin_archive",
95    ":target_defaults",
96    ":libbsdiff_config",
97  ]
98  configs -= [ "//common-mk:use_thin_archive" ]
99  sources = [
100    "brotli_compressor.cc",
101    "bsdiff.cc",
102    "bz2_compressor.cc",
103    "compressor_buffer.cc",
104    "diff_encoder.cc",
105    "endsley_patch_writer.cc",
106    "logging.cc",
107    "patch_writer.cc",
108    "patch_writer_factory.cc",
109    "split_patch_writer.cc",
110    "suffix_array_index.cc",
111  ]
112}
113
114executable("bsdiff") {
115  configs += [ ":target_defaults" ]
116  deps = [ ":libbsdiff" ]
117  sources = [
118    "bsdiff_arguments.cc",
119    "bsdiff_main.cc",
120  ]
121}
122
123if (use.test) {
124  executable("bsdiff_test") {
125    configs += [
126      "//common-mk:test",
127      ":target_defaults",
128    ]
129    deps = [
130      "//common-mk/testrunner",
131      ":libbspatch",
132      ":libbsdiff",
133    ]
134    sources = [
135      "brotli_compressor_unittest.cc",
136      "brotli_decompressor_unittest.cc",
137      "bsdiff_arguments.cc",
138      "bsdiff_arguments_unittest.cc",
139      "bsdiff_unittest.cc",
140      "bspatch_unittest.cc",
141      "bz2_decompressor_unittest.cc",
142      "diff_encoder_unittest.cc",
143      "endsley_patch_writer_unittest.cc",
144      "extents_file_unittest.cc",
145      "extents_unittest.cc",
146      "patch_reader_unittest.cc",
147      "patch_writer_unittest.cc",
148      "split_patch_writer_unittest.cc",
149      "suffix_array_index_unittest.cc",
150      "test_utils.cc",
151    ]
152  }
153}
154
155if (use.fuzzer) {
156  executable("bspatch_fuzzer") {
157    configs += [
158      "//common-mk/common_fuzzer",
159      ":target_defaults",
160    ]
161    deps = [ ":libbspatch" ]
162    sources = [
163      "bspatch_fuzzer.cc",
164    ]
165  }
166}
167