Can build with Bazel now
[platform/upstream/glog.git] / BUILD
1 licenses(['notice'])
2
3 namespace = 'google'
4 with_gflags = 1
5 with_libunwind = 1
6
7 cc_library(
8     name = 'glog',
9     visibility = [ '//visibility:public' ],
10     srcs = glob([
11         'src/base/commandlineflags.h',
12         'src/base/googleinit.h',
13         'src/demangle.cc',
14         'src/logging.cc',
15         'src/raw_logging.cc',
16         'src/signalhandler.cc',
17         'src/stacktrace_*-inl.h',
18         'src/symbolize.cc',
19         'src/utilities.cc',
20         'src/vlog_is_on.cc',
21     ]),
22     hdrs = [
23         'src/base/mutex.h',
24         'src/demangle.h',
25         'src/stacktrace.h',
26         'src/symbolize.h',
27         'src/utilities.h',
28         'src/glog/log_severity.h',
29     ],
30     includes = [
31         'src',
32     ],
33     copts = [
34         # Disable warnings that exists in glog.
35         '-Wno-invalid-noreturn',
36         '-Wno-sign-compare',
37         '-Wno-unused-const-variable',
38         '-Wno-unused-function',
39         '-Wno-unused-local-typedefs',
40         '-Wno-unused-variable',
41         # Inject a C++ namespace.
42         "-D_START_GOOGLE_NAMESPACE_='namespace %s {'" % namespace,
43         "-D_END_GOOGLE_NAMESPACE_='}'",
44         "-DGOOGLE_NAMESPACE='%s'" % namespace,
45         # Allows src/base/mutex.h to include pthread.h.
46         '-DHAVE_PTHREAD',
47         # Allows src/logging.cc to determine the host name.
48         '-DHAVE_SYS_UTSNAME_H',
49         # For src/utilities.cc.
50         '-DHAVE_SYS_SYSCALL_H',
51         '-DHAVE_SYS_TIME_H',
52         '-DHAVE_STDINT_H',
53         '-DHAVE_STRING_H',
54         # Enable dumping stacktrace upon sigaction.
55         '-DHAVE_SIGACTION',
56         # For logging.cc.
57         '-DHAVE_PREAD',
58     ] + ([
59         # Use gflags to parse CLI arguments.
60         # NOTE: These parenthesis are necessary.
61         '-DHAVE_LIB_GFLAGS',
62     ] if with_gflags else []) + ([
63         # Use linunwind to get stacktrace.
64         '-DHAVE_LIB_UNWIND',
65     ] if with_libunwind else []),
66     deps = [
67         ':internal_headers',
68     ] + ([
69         '//third_party/gflags',
70     ] if with_gflags else []) + ([
71         '//third_party/libunwind',
72     ] if with_libunwind else []),
73 )
74
75
76 cc_library(
77     name = 'internal_headers',
78     hdrs = [
79         ':config_h',
80         ':logging_h',
81         ':raw_logging_h',
82         ':stl_logging_h',
83         ':vlog_is_on_h',
84     ],
85     includes = [
86                 PACKAGE_NAME,
87     ] if PACKAGE_NAME else [],
88 )
89
90
91 genrule(
92     name = 'gen_sh',
93     outs = [
94         'gen.sh',
95     ],
96     cmd = r'''\
97 #!/bin/sh
98 cat > $@ <<"EOF"
99 sed -e 's/@ac_cv_have_unistd_h@/1/g' \
100     -e 's/@ac_cv_have_stdint_h@/1/g' \
101     -e 's/@ac_cv_have_systypes_h@/1/g' \
102     -e 's/@ac_cv_have_libgflags_h@/1/g' \
103     -e 's/@ac_cv_have_uint16_t@/1/g' \
104     -e 's/@ac_cv_have___builtin_expect@/1/g' \
105     -e 's/@ac_cv_have_.*@/0/g' \
106     -e 's/@ac_google_start_namespace@/namespace google {/g' \
107     -e 's/@ac_google_end_namespace@/}/g' \
108     -e 's/@ac_google_namespace@/google/g' \
109     -e 's/@ac_cv___attribute___noinline@/__attribute__((noinline))/g' \
110     -e 's/@ac_cv___attribute___noreturn@/__attribute__((noreturn))/g' \
111     -e 's/@ac_cv___attribute___printf_4_5@/__attribute__((__format__ (__printf__, 4, 5)))/g'
112 EOF
113 ''',
114 )
115
116
117 genrule(
118     name = 'config_h',
119     srcs = [
120         'src/config.h.cmake.in',
121     ],
122     outs = [
123         '/'.join([PACKAGE_NAME, 'config.h']) if PACKAGE_NAME else 'config.h',
124     ],
125     cmd = "awk '{ gsub(/^#cmakedefine/, \"//cmakedefine\"); print; }' $(<) > $(@)",
126 )
127
128
129 [genrule(
130     name = '%s_h' % f,
131     srcs = [
132         'src/glog/%s.h.in' % f,
133     ],
134     outs = [
135         '/'.join([PACKAGE_NAME, 'glog/%s.h' % f]) \
136                 if PACKAGE_NAME else 'glog/%s.h' % f,
137     ],
138     cmd = '$(location :gen_sh) < $(<) > $(@)',
139     tools = [':gen_sh'],
140 ) for f in [
141         'vlog_is_on',
142         'stl_logging',
143         'raw_logging',
144         'logging',
145     ]
146 ]