David Reiss | 16f5cd1 | 2009-03-30 22:52:51 +0000 | [diff] [blame] | 1 | dnl Copyright (C) 2009 Facebook |
| 2 | dnl Copying and distribution of this file, with or without modification, |
| 3 | dnl are permitted in any medium without royalty provided the copyright |
| 4 | dnl notice and this notice are preserved. |
| 5 | |
pwyckoff | 99b000b | 2008-04-03 19:30:55 +0000 | [diff] [blame] | 6 | AC_DEFUN([FB_INITIALIZE], |
| 7 | [ |
| 8 | AM_INIT_AUTOMAKE([ foreign 1.9.5 no-define ]) |
| 9 | if test "x$1" = "xlocalinstall"; then |
| 10 | wdir=`pwd` |
| 11 | # To use $wdir undef quote. |
| 12 | # |
| 13 | ########## |
| 14 | AC_PREFIX_DEFAULT([`pwd`/install]) |
| 15 | echo |
| 16 | fi |
| 17 | AC_PROG_CC |
| 18 | AC_PROG_CXX |
| 19 | AC_PROG_RANLIB(RANLIB, ranlib) |
| 20 | AC_PATH_PROGS(BASH, bash) |
| 21 | AC_PATH_PROGS(PERL, perl) |
| 22 | AC_PATH_PROGS(PYTHON, python) |
| 23 | AC_PATH_PROGS(AR, ar) |
| 24 | AC_PATH_PROGS(ANT, ant) |
| 25 | PRODUCT_MK="" |
| 26 | ]) |
| 27 | |
| 28 | AC_DEFUN([FB_WITH_EXTERNAL_PATH], |
| 29 | [ |
| 30 | cdir=`pwd` |
| 31 | AC_MSG_CHECKING([Checking EXTERNAL_PATH set to]) |
| 32 | AC_ARG_WITH([externalpath], |
| 33 | [ --with-externalpath=DIR User specified path to external facebook components.], |
| 34 | [ |
| 35 | if test "x${EXTERNAL_PATH}" != "x"; then |
| 36 | echo "" |
| 37 | echo "ERROR: You have already set EXTERNAL_PATH in your environment" |
| 38 | echo "Cannot override it using --with-externalpath. Unset EXTERNAL_PATH to use this option" |
| 39 | exit 1 |
| 40 | fi |
| 41 | EXTERNAL_PATH=$withval |
| 42 | ], |
| 43 | [ |
| 44 | if test "x${EXTERNAL_PATH}" = "x"; then |
| 45 | EXTERNAL_PATH=$1 |
| 46 | fi |
| 47 | ] |
| 48 | ) |
| 49 | if test "x${EXTERNAL_PATH}" = "x"; then |
| 50 | export EXTERNAL_PATH="$cdir/external" |
| 51 | GLOBAL_HEADER_MK="include ${EXTERNAL_PATH}/global_header.mk" |
| 52 | GLOBAL_FOOTER_MK="include ${EXTERNAL_PATH}/global_footer.mk" |
| 53 | else |
| 54 | export EXTERNAL_PATH |
| 55 | GLOBAL_HEADER_MK="include ${EXTERNAL_PATH}/global_header.mk" |
| 56 | GLOBAL_FOOTER_MK="include ${EXTERNAL_PATH}/global_footer.mk" |
| 57 | fi |
| 58 | AC_MSG_RESULT($EXTERNAL_PATH) |
| 59 | if test ! -d ${EXTERNAL_PATH}; then |
| 60 | echo "" |
| 61 | echo "ERROR: EXTERNAL_PATH set to an nonexistent directory ${EXTERNAL_PATH}" |
| 62 | exit 1 |
| 63 | fi |
| 64 | AC_SUBST(EXTERNAL_PATH) |
| 65 | AC_SUBST(GLOBAL_HEADER_MK) |
| 66 | AC_SUBST(GLOBAL_FOOTER_MK) |
| 67 | ]) |
| 68 | |
| 69 | # Set option to enable shared mode. Set DEBUG and OPT for use in Makefile.am. |
| 70 | AC_DEFUN([FB_ENABLE_DEFAULT_OPT_BUILD], |
| 71 | [ |
| 72 | AC_MSG_CHECKING([whether to enable optimized build]) |
| 73 | AC_ARG_ENABLE([opt], |
| 74 | [ --disable-opt Set up debug mode.], |
| 75 | [ |
| 76 | ENABLED_OPT=$enableval |
| 77 | ], |
| 78 | [ |
| 79 | ENABLED_OPT="yes" |
| 80 | ] |
| 81 | ) |
| 82 | if test "$ENABLED_OPT" = "yes" |
| 83 | then |
| 84 | CFLAGS="-Wall -O3" |
| 85 | CXXFLAGS="-Wall -O3" |
| 86 | else |
| 87 | CFLAGS="-Wall -g" |
| 88 | CXXFLAGS="-Wall -g" |
| 89 | fi |
| 90 | AC_MSG_RESULT($ENABLED_OPT) |
| 91 | AM_CONDITIONAL([OPT], [test "$ENABLED_OPT" = yes]) |
| 92 | AM_CONDITIONAL([DEBUG], [test "$ENABLED_OPT" = no]) |
| 93 | ]) |
| 94 | |
| 95 | # Set option to enable debug mode. Set DEBUG and OPT for use in Makefile.am. |
| 96 | AC_DEFUN([FB_ENABLE_DEFAULT_DEBUG_BUILD], |
| 97 | [ |
| 98 | AC_MSG_CHECKING([whether to enable debug build]) |
| 99 | AC_ARG_ENABLE([debug], |
| 100 | [ --disable-debug Set up opt mode.], |
| 101 | [ |
| 102 | ENABLED_DEBUG=$enableval |
| 103 | ], |
| 104 | [ |
| 105 | ENABLED_DEBUG="yes" |
| 106 | ] |
| 107 | ) |
| 108 | if test "$ENABLED_DEBUG" = "yes" |
| 109 | then |
| 110 | CFLAGS="-Wall -g" |
| 111 | CXXFLAGS="-Wall -g" |
| 112 | else |
| 113 | CFLAGS="-Wall -O3" |
| 114 | CXXFLAGS="-Wall -O3" |
| 115 | fi |
| 116 | AC_MSG_RESULT($ENABLED_DEBUG) |
| 117 | AM_CONDITIONAL([DEBUG], [test "$ENABLED_DEBUG" = yes]) |
| 118 | AM_CONDITIONAL([OPT], [test "$ENABLED_DEBUG" = no]) |
| 119 | ]) |
| 120 | |
| 121 | # Set option to enable static libs. |
| 122 | AC_DEFUN([FB_ENABLE_DEFAULT_STATIC], |
| 123 | [ |
| 124 | SHARED="" |
| 125 | STATIC="" |
| 126 | AC_MSG_CHECKING([whether to enable static mode]) |
| 127 | AC_ARG_ENABLE([static], |
| 128 | [ --disable-static Set up shared mode.], |
| 129 | [ |
| 130 | ENABLED_STATIC=$enableval |
| 131 | ], |
| 132 | [ |
| 133 | ENABLED_STATIC="yes" |
| 134 | ] |
| 135 | ) |
| 136 | if test "$ENABLED_STATIC" = "yes" |
| 137 | then |
| 138 | LTYPE=".a" |
| 139 | else |
| 140 | LTYPE=".so" |
| 141 | SHARED_CXXFLAGS="-fPIC" |
| 142 | SHARED_CFLAGS="-fPIC" |
| 143 | SHARED_LDFLAGS="-shared -fPIC" |
| 144 | AC_SUBST(SHARED_CXXFLAGS) |
| 145 | AC_SUBST(SHARED_CFLAGS) |
| 146 | AC_SUBST(SHARED_LDFLAGS) |
| 147 | fi |
| 148 | AC_MSG_RESULT($ENABLED_STATIC) |
| 149 | AC_SUBST(LTYPE) |
| 150 | AM_CONDITIONAL([STATIC], [test "$ENABLED_STATIC" = yes]) |
| 151 | AM_CONDITIONAL([SHARED], [test "$ENABLED_STATIC" = no]) |
| 152 | ]) |
| 153 | |
| 154 | # Set option to enable shared libs. |
| 155 | AC_DEFUN([FB_ENABLE_DEFAULT_SHARED], |
| 156 | [ |
| 157 | SHARED="" |
| 158 | STATIC="" |
| 159 | AC_MSG_CHECKING([whether to enable shared mode]) |
| 160 | AC_ARG_ENABLE([shared], |
| 161 | [ --disable-shared Set up static mode.], |
| 162 | [ |
| 163 | ENABLED_SHARED=$enableval |
| 164 | ], |
| 165 | [ |
| 166 | ENABLED_SHARED="yes" |
| 167 | ] |
| 168 | ) |
| 169 | if test "$ENABLED_SHARED" = "yes" |
| 170 | then |
| 171 | LTYPE=".so" |
| 172 | SHARED_CXXFLAGS="-fPIC" |
| 173 | SHARED_CFLAGS="-fPIC" |
| 174 | SHARED_LDFLAGS="-shared -fPIC" |
| 175 | AC_SUBST(SHARED_CXXFLAGS) |
| 176 | AC_SUBST(SHARED_CFLAGS) |
| 177 | AC_SUBST(SHARED_LDFLAGS) |
| 178 | else |
| 179 | LTYPE=".a" |
| 180 | fi |
| 181 | AC_MSG_RESULT($ENABLED_SHARED) |
| 182 | AC_SUBST(LTYPE) |
| 183 | AM_CONDITIONAL([SHARED], [test "$ENABLED_SHARED" = yes]) |
| 184 | AM_CONDITIONAL([STATIC], [test "$ENABLED_SHARED" = no]) |
| 185 | ]) |
| 186 | |
| 187 | # Generates define flags and conditionals as specified by user. |
| 188 | # This gets enabled *only* if user selects --enable-<FEATURE> otion. |
| 189 | AC_DEFUN([FB_ENABLE_FEATURE], |
| 190 | [ |
| 191 | ENABLE="" |
| 192 | flag="$1" |
| 193 | value="$3" |
| 194 | AC_MSG_CHECKING([whether to enable $1]) |
| 195 | AC_ARG_ENABLE([$2], |
| 196 | [ --enable-$2 Enable $2.], |
| 197 | [ |
| 198 | ENABLE=$enableval |
| 199 | ], |
| 200 | [ |
| 201 | ENABLE="no" |
| 202 | ] |
| 203 | ) |
| 204 | AM_CONDITIONAL([$1], [test "$ENABLE" = yes]) |
| 205 | if test "$ENABLE" = "yes" |
| 206 | then |
| 207 | if test "x${value}" = "x" |
| 208 | then |
| 209 | AC_DEFINE([$1]) |
| 210 | else |
| 211 | AC_DEFINE_UNQUOTED([$1], [$value]) |
| 212 | fi |
| 213 | fi |
| 214 | AC_MSG_RESULT($ENABLE) |
| 215 | ]) |
| 216 | |
| 217 | |
| 218 | # can also use eval $2=$withval;AC_SUBST($2) |
| 219 | AC_DEFUN([FB_WITH_PATH], |
| 220 | [ |
| 221 | USRFLAG="" |
| 222 | USRFLAG=$1 |
| 223 | AC_MSG_CHECKING([Checking $1 set to]) |
| 224 | AC_ARG_WITH([$2], |
| 225 | [ --with-$2=DIR User specified path.], |
| 226 | [ |
| 227 | LOC=$withval |
| 228 | eval $USRFLAG=$withval |
| 229 | ], |
| 230 | [ |
| 231 | LOC=$3 |
| 232 | eval $USRFLAG=$3 |
| 233 | ] |
| 234 | ) |
| 235 | AC_SUBST([$1]) |
| 236 | AC_MSG_RESULT($LOC) |
| 237 | ]) |
| 238 | |
| 239 | AC_DEFUN([FB_SET_FLAG_VALUE], |
| 240 | [ |
| 241 | SETFLAG="" |
| 242 | AC_MSG_CHECKING([Checking $1 set to]) |
| 243 | SETFLAG=$1 |
| 244 | eval $SETFLAG=\"$2\" |
| 245 | AC_SUBST([$SETFLAG]) |
| 246 | AC_MSG_RESULT($2) |
| 247 | ]) |
| 248 | |
| 249 | # NOTES |
| 250 | # if using if else bourne stmt you must have more than a macro in it. |
| 251 | # EX1 is not correct. EX2 is correct |
| 252 | # EX1: if test "$XX" = "yes"; then |
| 253 | # AC_SUBST(xx) |
| 254 | # fi |
| 255 | # EX2: if test "$XX" = "yes"; then |
| 256 | # xx="foo" |
| 257 | # AC_SUBST(xx) |
| 258 | # fi |