Sergiusz Bazanski | 0037eda | 2020-06-13 22:43:06 +0200 | [diff] [blame] | 1 | # Copyright 2019 Google LLC |
| 2 | # Copyright 2020 Sergiusz 'q3k' Bazanski |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | # The jq binary. |
| 17 | cc_binary( |
| 18 | name = "jq", |
| 19 | srcs = [ |
| 20 | ":source_files", |
| 21 | ], |
| 22 | copts = [ |
| 23 | "-Iexternal/com_github_kkos_oniguruma/src", |
| 24 | "-Wno-cpp", |
| 25 | "-Wno-unused-function", |
| 26 | "-Wno-unused-variable", |
| 27 | ], |
| 28 | visibility = ["//visibility:public"], |
| 29 | deps = [ |
| 30 | "@com_github_kkos_oniguruma//:oniguruma", |
| 31 | ], |
| 32 | ) |
| 33 | |
| 34 | # Generate the source files. |
| 35 | # This will run ./configure and extract a host-dependent confdefs.h file, then |
| 36 | # prefix each .h acd .c file with '#include "confdefs.h"'. |
| 37 | genrule( |
| 38 | name = "source_files", |
| 39 | srcs = glob(["**"]), |
| 40 | outs = ["build/" + f for f in glob( |
| 41 | [ |
| 42 | "src/*.h", |
| 43 | "src/*.c", |
| 44 | ], |
| 45 | exclude = [ |
| 46 | "src/inject_errors.c", |
| 47 | ], |
| 48 | )] + [ |
| 49 | # The extracted confdefs.h. |
| 50 | "build/src/confdefs.h", |
| 51 | # The generated builtin.inc. |
| 52 | "build/src/builtin.inc", |
| 53 | ], |
| 54 | cmd = |
| 55 | # Run ./configure && make src/builtin.inc. |
| 56 | "( " + |
| 57 | " cd external/com_github_stedolan_jq; " + |
| 58 | " ./configure > /dev/null 2> /dev/null; " + |
| 59 | " make src/builtin.inc > /dev/null; " + |
| 60 | "); " + |
| 61 | # Extract confdefs.h from config.log. |
| 62 | "grep '^/\\* confdefs.h \\*/$$' external/com_github_stedolan_jq/config.log -A1000 " + |
| 63 | " | head -n -1 > \"$(@D)\"/build/src/confdefs.h; " + |
| 64 | # Prefix each output file with an include of confdefs.h. |
| 65 | "OUTS=\"$(OUTS)\"; for FILE in $$OUTS; do " + |
| 66 | " touch \"$$FILE\"; " + |
| 67 | " BASENAME=\"$$(basename $$FILE)\"; " + |
| 68 | " if [ \"$$BASENAME\" != \"confdefs.h\" ]; then " + |
| 69 | " echo '#include \"confdefs.h\"' > \"$$FILE\"; " + |
| 70 | " cat external/com_github_stedolan_jq/src/\"$$BASENAME\" >> \"$$FILE\"; " + |
| 71 | " fi; " + |
| 72 | # Replace non-relative references. |
| 73 | " sed -e 's|^#include \"src/|#include \"|g' -i \"$$FILE\"; " + |
| 74 | "done; " + |
| 75 | # Copy builtin.inc and version.h without modificaitons. |
| 76 | "cp external/com_github_stedolan_jq/src/builtin.inc \"$(@D)\"/build/src/builtin.inc; ", |
| 77 | ) |
| 78 | |