You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

268 lines
8.9 KiB

  1. dnl
  2. dnl Lol Engine
  3. dnl
  4. dnl Copyright © 2010—2017 Sam Hocevar <sam@hocevar.net>
  5. dnl
  6. dnl Lol Engine is free software. It comes without any warranty, to
  7. dnl the extent permitted by applicable law. You can redistribute it
  8. dnl and/or modify it under the terms of the Do What the Fuck You Want
  9. dnl to Public License, Version 2, as published by the WTFPL Task Force.
  10. dnl See http://www.wtfpl.net/ for more details.
  11. dnl
  12. # LOL_AC_INIT()
  13. # ---------------------
  14. AC_DEFUN([LOL_AC_INIT], [
  15. dnl C++11 and later mode. Checked early so that we don't run into surprises.
  16. version_flag=''
  17. LOL_TRY_CXXFLAGS(-std=c++0x, [version_flag='-std=c++0x'])
  18. LOL_TRY_CXXFLAGS(-std=c++11, [version_flag='-std=c++11'])
  19. LOL_TRY_CXXFLAGS(-std=c++14, [version_flag='-std=c++14'])
  20. LOL_TRY_CXXFLAGS(-std=c++17, [version_flag='-std=c++17'])
  21. AM_CXXFLAGS="${AM_CXXFLAGS} ${version_flag}"
  22. CXXFLAGS="${CXXFLAGS} ${version_flag}"
  23. AC_LANG_PUSH(C++)
  24. AC_MSG_CHECKING(for C++11 enum class support)
  25. AC_TRY_LINK([], [enum class Foo : int { Bar, Baz };],
  26. [AC_MSG_RESULT(yes)],
  27. [AC_MSG_RESULT(no)
  28. AC_MSG_ERROR([[C++ compiler does not support C++11 enum classes]])])
  29. AC_LANG_POP(C++)
  30. ]) # LOL_AC_INIT
  31. # LOL_AC_CHECK()
  32. # ---------------------
  33. AC_DEFUN([LOL_AC_CHECK], [
  34. dnl Check that the C++ compiler really works
  35. AC_LANG_PUSH(C++)
  36. AC_MSG_CHECKING(for a fully working C++ compiler)
  37. AC_TRY_LINK([], [],
  38. [AC_MSG_RESULT(yes)],
  39. [AC_MSG_RESULT(no)
  40. AC_MSG_ERROR([[C++ compiler cannot link executables]])])
  41. AC_LANG_POP(C++)
  42. AC_C_CONST
  43. AC_C_INLINE
  44. dnl
  45. dnl Common libraries
  46. dnl
  47. AC_CHECK_LIB(m, sin, LIBS="${LIBS} -lm")
  48. AC_CHECK_LIB(pthread, main, LIBS="${LIBS} -lpthread")
  49. dnl
  50. dnl Activate some header-only libraries
  51. dnl
  52. LOL_CFLAGS="$LOL_CFLAGS -I\$(lol_srcdir)/src/3rdparty/mingw-std-threads"
  53. LOL_CFLAGS="$LOL_CFLAGS -I\$(lol_srcdir)/src/3rdparty/pegtl/include"
  54. LOL_CFLAGS="$LOL_CFLAGS -I\$(lol_srcdir)/src/3rdparty/imgui"
  55. dnl Use system-provided getopt_long?
  56. ac_cv_have_getopt_long="no"
  57. AC_CHECK_HEADERS(getopt.h unistd.h)
  58. AC_CHECK_FUNCS(getopt_long,
  59. [ac_cv_have_getopt_long="yes"],
  60. [AC_CHECK_LIB(gnugetopt, getopt_long,
  61. [ac_cv_have_getopt_long="yes"
  62. LIBS="${LIBS} -lgnugetopt"])])
  63. if test "$ac_cv_have_getopt_long" != "no"; then
  64. AC_DEFINE(HAVE_GETOPT_LONG, 1, Define to 1 if you have the ‘getopt_long’ function.)
  65. fi
  66. dnl Use Bullet Physics?
  67. ac_cv_my_have_bullet="no"
  68. if test "${enable_bullet}" != "no"; then
  69. ac_cv_my_have_bullet="yes"
  70. AC_DEFINE(LOL_USE_BULLET, 1, Define to 1 to use Bullet Physics)
  71. fi
  72. AM_CONDITIONAL(LOL_USE_BULLET, test "${ac_cv_my_have_bullet}" = "yes")
  73. dnl Use Android? FIXME: super hacks!
  74. ac_cv_my_have_android="no"
  75. AC_CHECK_LIB(log, __android_log_vprint,
  76. [ac_cv_my_have_android="yes"
  77. LOL_LIBS="${LOL_LIBS} -llog -landroid -module -lEGL -lGLESv2"])
  78. AM_CONDITIONAL(LOL_USE_ANDROID, test "${ac_cv_my_have_android}" != "no")
  79. dnl Use EGL? (autodetect unless GL is disabled)
  80. ac_cv_my_have_egl="no"
  81. if test "${enable_gl}" != "no"; then
  82. PKG_CHECK_MODULES(EGL, egl, [ac_cv_my_have_egl="yes"], [:])
  83. if test "${ac_cv_my_have_egl}" != "no"; then
  84. AC_DEFINE(LOL_USE_EGL, 1, Define to 1 to use libegl)
  85. EGL_LIBS="${EGL_LIBS} -lX11"
  86. fi
  87. AC_CHECK_HEADERS(EGL/egl.h,
  88. [AC_CHECK_LIB(EGL, eglInitialize,
  89. [ac_cv_my_have_egl="yes"
  90. AC_DEFINE(LOL_USE_EGL, 1, Define to 1 to use libegl)
  91. EGL_LIBS="-lEGL"])
  92. dnl Raspberry Pi is different, check for it with extra libs; also we
  93. dnl look for a different function to bypass autoconf caching
  94. AC_CHECK_LIB(EGL, eglGetDisplay,
  95. [ac_cv_my_have_egl="yes"
  96. AC_DEFINE(LOL_USE_EGL, 1, Define to 1 to use libegl)
  97. EGL_LIBS="-lEGL -lvcos -lvchiq_arm -lbcm_host -lGLESv2"],
  98. [:],
  99. [-lvcos -lvchiq_arm -lbcm_host -lGLESv2])])
  100. fi
  101. AM_CONDITIONAL(LOL_USE_EGL, test "${ac_cv_my_have_egl}" != "no")
  102. dnl Use libpng? (replacement for SDL_image)
  103. ac_cv_my_have_libpng="no"
  104. if test "${enable_png}" != "no"; then
  105. PKG_CHECK_MODULES(LIBPNG, libpng, [ac_cv_my_have_libpng="yes"], [:])
  106. if test "${ac_cv_my_have_libpng}" != "no"; then
  107. AC_DEFINE(LOL_USE_LIBPNG, 1, Define to 1 to use libpng)
  108. fi
  109. fi
  110. AM_CONDITIONAL(LOL_USE_LIBPNG, test "${ac_cv_my_have_libpng}" != "no")
  111. dnl Use Imlib2?
  112. ac_cv_my_have_imlib2="no"
  113. if test "${enable_imlib2}" != "no"; then
  114. PKG_CHECK_MODULES(IMLIB2, imlib2, [ac_cv_my_have_imlib2="yes"], [:])
  115. if test "${ac_cv_my_have_imlib2}" != "no"; then
  116. AC_DEFINE(LOL_USE_IMLIB2, 1, Define to 1 to use Imlib2)
  117. LOL_CFLAGS="${LOL_CFLAGS} ${IMLIB2_CFLAGS}"
  118. LOL_LIBS="${LOL_LIBS} ${IMLIB2_LIBS}"
  119. fi
  120. fi
  121. AM_CONDITIONAL(LOL_USE_IMLIB2, test "${ac_cv_my_have_imlib2}" = "yes")
  122. dnl Use Windows GDI+?
  123. ac_cv_my_have_gdiplus="no"
  124. AC_LANG_PUSH(C++)
  125. AC_CHECK_HEADERS(gdiplus.h,
  126. [ac_cv_my_have_gdiplus="yes"
  127. LOL_LIBS="${LOL_LIBS} -lgdiplus"],
  128. [ac_cv_my_have_gdiplus="no"],
  129. [#include <algorithm>
  130. using std::min;
  131. using std::max;
  132. #include <windows.h>])
  133. AC_LANG_POP(C++)
  134. if test "${ac_cv_my_have_gdiplus}" != "no"; then
  135. AC_DEFINE(LOL_USE_GDIPLUS, 1, Define to 1 to use GDI+)
  136. fi
  137. AM_CONDITIONAL(LOL_USE_GDIPLUS, test "${ac_cv_my_have_gdiplus}" = "yes")
  138. dnl Are we building using MinGW?
  139. LOL_TRY_CXXFLAGS(-mwindows -mwin32,
  140. [AM_CXXFLAGS="${AM_CXXFLAGS} -mwindows -mwin32"
  141. LOL_LIBS="${LOL_LIBS} -uWinMain -u_WinMain@16"])
  142. dnl Are we building using Emscripten?
  143. ac_cv_my_have_emscripten="no"
  144. AC_CHECK_HEADERS(emscripten.h,
  145. [ac_cv_my_have_emscripten="yes"
  146. AC_CHECK_HEADERS(emscripten/html5.h)
  147. dnl XXX: activate this if memory heap is too small
  148. #AM_CXXFLAGS="${AM_CXXFLAGS} -s ALLOW_MEMORY_GROWTH=1"
  149. dnl HACK: until emcc properly adds these to EMSDK_OPTS
  150. CPPFLAGS="${CPPFLAGS} -U__i386__ -U__x86_64__ -U__i386 -U__x86_64 -Ui386 -Ux86_64"
  151. CPPFLAGS="${CPPFLAGS} -U__SSE__ -U__SSE2__ -U__MMX__ -UX87_DOUBLE_ROUNDING"
  152. CPPFLAGS="${CPPFLAGS} -UHAVE_GCC_ASM_FOR_X87 -DEMSCRIPTEN -U__STRICT_ANSI__"
  153. CPPFLAGS="${CPPFLAGS} -U__CYGWIN__"])
  154. AM_CONDITIONAL(LOL_USE_EMSCRIPTEN, test "${ac_cv_my_have_emscripten}" != "no")
  155. dnl Are we on an OS X or iOS platform?
  156. LOL_TRY_LDFLAGS(-framework Foundation,
  157. [LOL_LIBS="${LOL_LIBS} -framework Foundation"])
  158. LOL_TRY_LDFLAGS(-framework CoreGraphics,
  159. [LOL_LIBS="${LOL_LIBS} -framework CoreGraphics"])
  160. LOL_TRY_LDFLAGS(-framework CoreData,
  161. [LOL_LIBS="${LOL_LIBS} -framework CoreData"])
  162. LOL_TRY_LDFLAGS(-framework UIKit,
  163. [LOL_LIBS="${LOL_LIBS} -framework UIKit"])
  164. dnl Other complex checks
  165. LOL_AC_CHECK_OPENGL()
  166. LOL_AC_CHECK_SDL()
  167. LOL_AC_CHECK_FFMPEG()
  168. dnl Debug symbols
  169. LOL_TRY_LDFLAGS(-rdynamic, [AM_LDFLAGS="${AM_LDFLAGS} -rdynamic"])
  170. dnl Code qui fait des warnings == code de porc == deux baffes dans ta gueule
  171. LOL_TRY_CXXFLAGS(-Wall, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wall"])
  172. LOL_TRY_CXXFLAGS(-Wextra, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wextra"])
  173. LOL_TRY_CXXFLAGS(-Wpointer-arith, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wpointer-arith"])
  174. LOL_TRY_CXXFLAGS(-Wcast-align, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wcast-align"])
  175. LOL_TRY_CXXFLAGS(-Wcast-qual, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wcast-qual"])
  176. LOL_TRY_CXXFLAGS(-Wshadow, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wshadow"])
  177. LOL_TRY_CXXFLAGS(-Wsign-compare, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wsign-compare"])
  178. LOL_TRY_CXXFLAGS(-Wstrict-overflow=1, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wstrict-overflow=1"])
  179. dnl Add these even though they're implicitly set, so that we can safely
  180. dnl remove them from within a Makefile.
  181. LOL_TRY_CXXFLAGS(-Wuninitialized, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wuninitialized"])
  182. LOL_TRY_CXXFLAGS(-Wnarrowing, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wnarrowing"])
  183. LOL_TRY_CXXFLAGS(-Wunused, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wunused"])
  184. LOL_TRY_CXXFLAGS(-Wcast-align, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wcast-align"])
  185. LOL_TRY_CXXFLAGS(-Wunused-parameter, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wunused-parameter"])
  186. LOL_TRY_CXXFLAGS(-Wstrict-aliasing, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wstrict-aliasing"])
  187. LOL_TRY_CXXFLAGS(-Wparentheses, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wparentheses"])
  188. LOL_TRY_CXXFLAGS(-Wreorder, [AM_CXXFLAGS="${AM_CXXFLAGS} -Wreorder"])
  189. dnl Disable these warnings because they're annoyingly verbose
  190. LOL_TRY_CXXFLAGS(-Wno-psabi, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wno-psabi"])
  191. ]) # LOL_AC_CHECK
  192. # LOL_AC_FINI()
  193. # ---------------------
  194. AC_DEFUN([LOL_AC_FINI], [
  195. dnl How to use the Lol Engine outside this tree
  196. LOL_CFLAGS="$LOL_CFLAGS $SDL_CFLAGS $GL_CFLAGS $EGL_CFLAGS $LIBPNG_CFLAGS"
  197. LOL_LIBS="$LOL_LIBS $SDL_LIBS $GL_LIBS $EGL_LIBS $LIBPNG_LIBS $D3D_LIBS"
  198. LOL_DEPS="${LOL_DEPS} \$(lol_builddir)/src/liblol-core.a"
  199. LOL_BULLET_DEPS="${LOL_BULLET_DEPS} \$(lol_builddir)/src/3rdparty/liblol-bullet.a"
  200. LOL_LUA_DEPS="${LOL_LUA_DEPS} \$(lol_builddir)/src/3rdparty/liblol-lua.a"
  201. dnl How to use the Lol Engine inside this tree
  202. AM_CPPFLAGS="${AM_CPPFLAGS} -I\$(lol_srcdir)/src"
  203. AM_CPPFLAGS="${AM_CPPFLAGS} -DLOL_CONFIG_SOURCESUBDIR=\\\"\$(subdir)\\\""
  204. AM_CPPFLAGS="${AM_CPPFLAGS} ${LOL_CFLAGS}"
  205. AM_LDFLAGS="${AM_LDFLAGS} ${LOL_DEPS}"
  206. AM_LDFLAGS="${AM_LDFLAGS} ${LOL_LIBS}"
  207. dnl Extra flags
  208. AC_SUBST(LOL_CFLAGS)
  209. AC_SUBST(LOL_LIBS)
  210. AC_SUBST(LOL_DEPS)
  211. AC_SUBST(LOL_BULLET_DEPS)
  212. AC_SUBST(LOL_LUA_DEPS)
  213. AC_SUBST(AM_CFLAGS)
  214. AC_SUBST(AM_CPPFLAGS)
  215. AC_SUBST(AM_CXXFLAGS)
  216. AC_SUBST(AM_LDFLAGS)
  217. ]) # LOL_AC_FINI