blob: c35e92913b6523389b36abe48a1ee0ca9a0efb21 [file] [log] [blame]
Austin Schuh906616c2019-01-21 20:25:11 -08001#!/bin/sh
2
3# Copyright (c) 2008, 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# Copied from google-perftools and modified by Shinichiro Hamaji
35#
36# This script is meant to be run at distribution-generation time, for
37# instance by autogen.sh. It does some of the work configure would
38# normally do, for windows systems. In particular, it expands all the
39# @...@ variables found in .in files, and puts them here, in the windows
40# directory.
41#
42# This script should be run before any new release.
43
44if [ -z "$1" ]; then
45 echo "USAGE: $0 <src/ directory>"
46 exit 1
47fi
48
49DLLDEF_MACRO_NAME="GLOG_DLL_DECL"
50
51# The text we put in every .h files we create. As a courtesy, we'll
52# include a helpful comment for windows users as to how to use
53# GLOG_DLL_DECL. Apparently sed expands \n into a newline. Good!
54DLLDEF_DEFINES="\
55// NOTE: if you are statically linking the template library into your binary\n\
56// (rather than using the template .dll), set '/D $DLLDEF_MACRO_NAME='\n\
57// as a compiler flag in your project file to turn off the dllimports.\n\
58#ifndef $DLLDEF_MACRO_NAME\n\
59# define $DLLDEF_MACRO_NAME __declspec(dllimport)\n\
60#endif"
61
62# Read all the windows config info into variables
63# In order for the 'set' to take, this requires putting all in a subshell.
64(
65 while read define varname value; do
66 [ "$define" != "#define" ] && continue
67 eval "$varname='$value'"
68 done
69
70 # Process all the .in files in the "glog" subdirectory
71 mkdir -p "$1/windows/glog"
72 for file in `echo "$1"/glog/*.in`; do
73 echo "Processing $file"
74 outfile="$1/windows/glog/`basename $file .in`"
75
76 echo "\
77// This file is automatically generated from $file
78// using src/windows/preprocess.sh.
79// DO NOT EDIT!
80" > "$outfile"
81 # Besides replacing @...@, we also need to turn on dllimport
82 # We also need to replace hash by hash_compare (annoying we hard-code :-( )
83 sed -e "s!@ac_windows_dllexport@!$DLLDEF_MACRO_NAME!g" \
84 -e "s!@ac_windows_dllexport_defines@!$DLLDEF_DEFINES!g" \
85 -e "s!@ac_cv_cxx_hash_map@!$HASH_MAP_H!g" \
86 -e "s!@ac_cv_cxx_hash_namespace@!$HASH_NAMESPACE!g" \
87 -e "s!@ac_cv_cxx_hash_set@!$HASH_SET_H!g" \
88 -e "s!@ac_cv_have_stdint_h@!0!g" \
89 -e "s!@ac_cv_have_systypes_h@!0!g" \
90 -e "s!@ac_cv_have_inttypes_h@!0!g" \
91 -e "s!@ac_cv_have_unistd_h@!0!g" \
92 -e "s!@ac_cv_have_uint16_t@!0!g" \
93 -e "s!@ac_cv_have_u_int16_t@!0!g" \
94 -e "s!@ac_cv_have___uint16@!1!g" \
95 -e "s!@ac_cv_have_libgflags@!0!g" \
96 -e "s!@ac_cv_have___builtin_expect@!0!g" \
97 -e "s!@ac_cv_cxx_using_operator@!1!g" \
98 -e "s!@ac_cv___attribute___noreturn@!__declspec(noreturn)!g" \
99 -e "s!@ac_cv___attribute___noinline@!!g" \
100 -e "s!@ac_cv___attribute___printf_4_5@!!g" \
101 -e "s!@ac_google_attribute@!${HAVE___ATTRIBUTE__:-0}!g" \
102 -e "s!@ac_google_end_namespace@!$_END_GOOGLE_NAMESPACE_!g" \
103 -e "s!@ac_google_namespace@!$GOOGLE_NAMESPACE!g" \
104 -e "s!@ac_google_start_namespace@!$_START_GOOGLE_NAMESPACE_!g" \
105 -e "s!@ac_htmlparser_namespace@!$HTMLPARSER_NAMESPACE!g" \
106 -e "s!\\bhash\\b!hash_compare!g" \
107 "$file" >> "$outfile"
108 done
109) < "$1/windows/config.h"
110
111# log_severity.h isn't a .in file.
112echo "\
113// This file is automatically generated from $1/glog/log_severity.h
114// using src/windows/preprocess.sh.
115// DO NOT EDIT!
116" > "$1/windows/glog/log_severity.h"
117cat "$1/glog/log_severity.h" >> "$1/windows/glog/log_severity.h"
118
119echo "DONE"