Marcel Hlopko | 74b9432 | 2016-10-11 15:30:49 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright 2016 The Bazel Authors. All rights reserved. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | # This script handles interface library generation for dynamic library |
| 18 | # link action. |
| 19 | # |
| 20 | # Bazel can be configured to generate external interface library script |
| 21 | # to generate interface libraries in CppLinkAction for dynamic libraries. |
| 22 | # This is not needed on Windows (as the "interface" libraries are |
| 23 | # generated by default). This script therefore handles the cases when |
| 24 | # external script is provided, or when no script should be used. |
| 25 | |
| 26 | set -eu |
| 27 | |
| 28 | E_LINKER_COMMAND_NOT_FOUND=12 |
| 29 | E_INTERFACE_BUILDER_NOT_FOUND=13 |
| 30 | |
| 31 | # Should generate interface library switch (<yes|no>); if the value is "no", |
| 32 | # following 3 args are ignored (but must be present) |
| 33 | GENERATE_INTERFACE_LIBRARY="$1" |
| 34 | # Tool which can generate interface library from dynamic library file |
| 35 | INTERFACE_LIBRARY_BUILDER="$2" |
| 36 | # Dynamic library from which we want to generate interface library |
| 37 | DYNAMIC_LIBRARY="$3" |
| 38 | # Resulting interface library |
| 39 | INTERFACE_LIBRARY="$4" |
| 40 | # The command used to generate the dynamic library |
| 41 | LINKER_COMMAND="$5" |
| 42 | |
| 43 | shift 5 |
| 44 | |
| 45 | if [ ! -e "$LINKER_COMMAND" ]; then |
| 46 | echo "Linker command ($LINKER_COMMAND) not found." 1>&2; |
| 47 | exit "$E_LINKER_COMMAND_NOT_FOUND" |
| 48 | fi |
| 49 | |
| 50 | if [ "no" == "$GENERATE_INTERFACE_LIBRARY" ]; then |
| 51 | INTERFACE_GENERATION=: |
| 52 | else |
| 53 | if [ ! -e "$INTERFACE_LIBRARY_BUILDER" ]; then |
| 54 | echo "Interface library builder ($INTERFACE_LIBRARY_BUILDER) not found." 1>&2; |
| 55 | exit "$E_INTERFACE_BUILDER_NOT_FOUND" |
| 56 | fi |
| 57 | INTERFACE_GENERATION="${INTERFACE_LIBRARY_BUILDER} ${DYNAMIC_LIBRARY} ${INTERFACE_LIBRARY}" |
| 58 | fi |
| 59 | |
| 60 | ${LINKER_COMMAND} "$@" && ${INTERFACE_GENERATION} |