Brian Silverman | 70325d6 | 2015-09-20 17:00:43 -0400 | [diff] [blame^] | 1 | #!/bin/sh |
| 2 | |
| 3 | # Copyright (c) 2007, Google Inc. |
| 4 | # All rights reserved. |
| 5 | # |
| 6 | # Redistribution and use in source and binary forms, with or without |
| 7 | # modification, are permitted provided that the following conditions are |
| 8 | # met: |
| 9 | # |
| 10 | # * Redistributions of source code must retain the above copyright |
| 11 | # notice, this list of conditions and the following disclaimer. |
| 12 | # * Redistributions in binary form must reproduce the above |
| 13 | # copyright notice, this list of conditions and the following disclaimer |
| 14 | # in the documentation and/or other materials provided with the |
| 15 | # distribution. |
| 16 | # * Neither the name of Google Inc. nor the names of its |
| 17 | # contributors may be used to endorse or promote products derived from |
| 18 | # this software without specific prior written permission. |
| 19 | # |
| 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | |
| 32 | # --- |
| 33 | # Author: Craig Silverstein |
| 34 | # |
| 35 | # This script is meant to be run at distribution-generation time, for |
| 36 | # instance by autogen.sh. It does some of the work configure would |
| 37 | # normally do, for windows systems. In particular, it expands all the |
| 38 | # @...@ variables found in .in files, and puts them here, in the windows |
| 39 | # directory. |
| 40 | # |
| 41 | # This script should be run before any new release. |
| 42 | |
| 43 | if [ -z "$1" ]; then |
| 44 | echo "USAGE: $0 <src/ directory>" |
| 45 | exit 1 |
| 46 | fi |
| 47 | |
| 48 | DLLDEF_MACRO_NAME="CTEMPLATE_DLL_DECL" |
| 49 | |
| 50 | # The text we put in every .h files we create. As a courtesy, we'll |
| 51 | # include a helpful comment for windows users as to how to use |
| 52 | # CTEMPLATE_DLL_DECL. Apparently sed expands \n into a newline. Good! |
| 53 | DLLDEF_DEFINES="\ |
| 54 | // NOTE: if you are statically linking the template library into your binary\n\ |
| 55 | // (rather than using the template .dll), set '/D $DLLDEF_MACRO_NAME='\n\ |
| 56 | // as a compiler flag in your project file to turn off the dllimports.\n\ |
| 57 | #ifndef $DLLDEF_MACRO_NAME\n\ |
| 58 | # define $DLLDEF_MACRO_NAME __declspec(dllimport)\n\ |
| 59 | #endif" |
| 60 | |
| 61 | # template_cache.h gets a special DEFINE to work around the |
| 62 | # difficulties in dll-exporting stl containers. Ugh. |
| 63 | TEMPLATE_CACHE_DLLDEF_DEFINES="\ |
| 64 | // NOTE: if you are statically linking the template library into your binary\n\ |
| 65 | // (rather than using the template .dll), set '/D $DLLDEF_MACRO_NAME='\n\ |
| 66 | // as a compiler flag in your project file to turn off the dllimports.\n\ |
| 67 | #ifndef $DLLDEF_MACRO_NAME\n\ |
| 68 | # define $DLLDEF_MACRO_NAME __declspec(dllimport)\n\ |
| 69 | extern template class __declspec(dllimport) std::allocator<std::string>;\n\ |
| 70 | extern template class __declspec(dllimport) std::vector<std::string>;\n\ |
| 71 | #else\n\ |
| 72 | template class __declspec(dllexport) std::allocator<std::string>;\n\ |
| 73 | template class __declspec(dllexport) std::vector<std::string>;\n\ |
| 74 | #endif" |
| 75 | |
| 76 | # Read all the windows config info into variables |
| 77 | # In order for the 'set' to take, this requires putting all in a subshell. |
| 78 | ( |
| 79 | while read define varname value; do |
| 80 | [ "$define" != "#define" ] && continue |
| 81 | eval "$varname='$value'" |
| 82 | done |
| 83 | |
| 84 | # Process all the .in files in the "ctemplate" subdirectory |
| 85 | mkdir -p "$1/windows/ctemplate" |
| 86 | for file in "$1"/ctemplate/*.in; do |
| 87 | echo "Processing $file" |
| 88 | outfile="$1/windows/ctemplate/`basename $file .in`" |
| 89 | |
| 90 | if test "`basename $file`" = template_cache.h.in; then |
| 91 | MY_DLLDEF_DEFINES=$TEMPLATE_CACHE_DLLDEF_DEFINES |
| 92 | else |
| 93 | MY_DLLDEF_DEFINES=$DLLDEF_DEFINES |
| 94 | fi |
| 95 | |
| 96 | # Besides replacing @...@, we also need to turn on dllimport |
| 97 | # We also need to replace hash by hash_compare (annoying we hard-code :-( ) |
| 98 | sed -e "s!@ac_windows_dllexport@!$DLLDEF_MACRO_NAME!g" \ |
| 99 | -e "s!@ac_windows_dllexport_defines@!$MY_DLLDEF_DEFINES!g" \ |
| 100 | -e "s!@ac_cv_cxx_hash_map@!$HASH_MAP_H!g" \ |
| 101 | -e "s!@ac_cv_cxx_hash_set@!$HASH_SET_H!g" \ |
| 102 | -e "s!@ac_cv_cxx_hash_map_class@!$HASH_NAMESPACE::hash_map!g" \ |
| 103 | -e "s!@ac_cv_cxx_hash_set_class@!$HASH_NAMESPACE::hash_set!g" \ |
| 104 | -e "s!@ac_google_attribute@!${HAVE___ATTRIBUTE__:-0}!g" \ |
| 105 | -e "s!@ac_google_end_namespace@!$_END_GOOGLE_NAMESPACE_!g" \ |
| 106 | -e "s!@ac_google_namespace@!$GOOGLE_NAMESPACE!g" \ |
| 107 | -e "s!@ac_google_start_namespace@!$_START_GOOGLE_NAMESPACE_!g" \ |
| 108 | -e "s!@ac_htmlparser_namespace@!$HTMLPARSER_NAMESPACE!g" \ |
| 109 | -e "s!@ac_cv_uint64@!unsigned __int64!g" \ |
| 110 | -e "s!@ac_cv_have_stdint_h@!0!g" \ |
| 111 | -e "s!@ac_cv_have_inttypes_h@!0!g" \ |
| 112 | -e "s!@ac_have_attribute_weak@!0!g" \ |
| 113 | -e "s!\\bhash\\b!hash_compare!g" \ |
| 114 | "$file" > "$outfile" |
| 115 | done |
| 116 | ) < "$1/windows/config.h" |
| 117 | |
| 118 | echo "DONE" |