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.
 
 
 

279 lines
9.1 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 NativeClient?
  74. ac_cv_my_have_nacl="no"
  75. AC_LANG_PUSH(C++)
  76. AC_CHECK_HEADERS(ppapi/cpp/instance.h,
  77. [ac_cv_my_have_nacl="yes"
  78. LOL_LIBS="${LOL_LIBS} -lnosys"
  79. if test "${ac_cv_my_build_mode}" = "xrelease"; then
  80. LOL_TRY_CXXFLAGS(-s, [AM_CXXFLAGS="${AM_CXXFLAGS} -s"])
  81. fi])
  82. AC_LANG_POP(C++)
  83. AM_CONDITIONAL(LOL_USE_NACL, test "${ac_cv_my_have_nacl}" != "no")
  84. dnl Use Android? FIXME: super hacks!
  85. ac_cv_my_have_android="no"
  86. AC_CHECK_LIB(log, __android_log_vprint,
  87. [ac_cv_my_have_android="yes"
  88. LOL_LIBS="${LOL_LIBS} -llog -landroid -module -lEGL -lGLESv2"])
  89. AM_CONDITIONAL(LOL_USE_ANDROID, test "${ac_cv_my_have_android}" != "no")
  90. dnl Use EGL? (autodetect unless GL is disabled)
  91. ac_cv_my_have_egl="no"
  92. if test "${enable_gl}" != "no"; then
  93. PKG_CHECK_MODULES(EGL, egl, [ac_cv_my_have_egl="yes"], [:])
  94. if test "${ac_cv_my_have_egl}" != "no"; then
  95. AC_DEFINE(LOL_USE_EGL, 1, Define to 1 to use libegl)
  96. EGL_LIBS="${EGL_LIBS} -lX11"
  97. fi
  98. AC_CHECK_LIB(EGL, main,
  99. [ac_cv_my_have_egl="yes"
  100. AC_DEFINE(LOL_USE_EGL, 1, Define to 1 to use libegl)
  101. EGL_LIBS="-lEGL"])
  102. dnl Raspberry Pi is different, check for it with extra libs; also we
  103. dnl look for a different function to bypass autoconf caching
  104. AC_CHECK_LIB(EGL, eglGetDisplay,
  105. [ac_cv_my_have_egl="yes"
  106. AC_DEFINE(LOL_USE_EGL, 1, Define to 1 to use libegl)
  107. EGL_LIBS="-lEGL -lvcos -lvchiq_arm -lbcm_host -lGLESv2"],
  108. [:],
  109. [-lvcos -lvchiq_arm -lbcm_host -lGLESv2])
  110. fi
  111. AM_CONDITIONAL(LOL_USE_EGL, test "${ac_cv_my_have_egl}" != "no")
  112. dnl Use libpng? (replacement for SDL_image)
  113. ac_cv_my_have_libpng="no"
  114. if test "${enable_png}" != "no"; then
  115. PKG_CHECK_MODULES(LIBPNG, libpng, [ac_cv_my_have_libpng="yes"], [:])
  116. if test "${ac_cv_my_have_libpng}" != "no"; then
  117. AC_DEFINE(LOL_USE_LIBPNG, 1, Define to 1 to use libpng)
  118. fi
  119. fi
  120. AM_CONDITIONAL(LOL_USE_LIBPNG, test "${ac_cv_my_have_libpng}" != "no")
  121. dnl Use Imlib2?
  122. ac_cv_my_have_imlib2="no"
  123. if test "${enable_imlib2}" != "no"; then
  124. PKG_CHECK_MODULES(IMLIB2, imlib2, [ac_cv_my_have_imlib2="yes"], [:])
  125. if test "${ac_cv_my_have_imlib2}" != "no"; then
  126. AC_DEFINE(LOL_USE_IMLIB2, 1, Define to 1 to use Imlib2)
  127. LOL_CFLAGS="${LOL_CFLAGS} ${IMLIB2_CFLAGS}"
  128. LOL_LIBS="${LOL_LIBS} ${IMLIB2_LIBS}"
  129. fi
  130. fi
  131. AM_CONDITIONAL(LOL_USE_IMLIB2, test "${ac_cv_my_have_imlib2}" = "yes")
  132. dnl Use Windows GDI+?
  133. ac_cv_my_have_gdiplus="no"
  134. AC_LANG_PUSH(C++)
  135. AC_CHECK_HEADERS(gdiplus.h,
  136. [ac_cv_my_have_gdiplus="yes"
  137. LOL_LIBS="${LOL_LIBS} -lgdiplus"],
  138. [ac_cv_my_have_gdiplus="no"],
  139. [#include <algorithm>
  140. using std::min;
  141. using std::max;
  142. #include <windows.h>])
  143. AC_LANG_POP(C++)
  144. if test "${ac_cv_my_have_gdiplus}" != "no"; then
  145. AC_DEFINE(LOL_USE_GDIPLUS, 1, Define to 1 to use GDI+)
  146. fi
  147. AM_CONDITIONAL(LOL_USE_GDIPLUS, test "${ac_cv_my_have_gdiplus}" = "yes")
  148. dnl Are we building using MinGW?
  149. LOL_TRY_CXXFLAGS(-mwindows -mwin32,
  150. [AM_CXXFLAGS="${AM_CXXFLAGS} -mwindows -mwin32"
  151. LOL_LIBS="${LOL_LIBS} -uWinMain -u_WinMain@16"])
  152. dnl Are we building using Emscripten?
  153. ac_cv_my_have_emscripten="no"
  154. AC_CHECK_HEADERS(emscripten.h,
  155. [ac_cv_my_have_emscripten="yes"
  156. dnl XXX: activate this if memory heap is too small
  157. #AM_CXXFLAGS="${AM_CXXFLAGS} -s ALLOW_MEMORY_GROWTH=1"
  158. dnl HACK: until emcc properly adds these to EMSDK_OPTS
  159. CPPFLAGS="${CPPFLAGS} -U__i386__ -U__x86_64__ -U__i386 -U__x86_64 -Ui386 -Ux86_64"
  160. CPPFLAGS="${CPPFLAGS} -U__SSE__ -U__SSE2__ -U__MMX__ -UX87_DOUBLE_ROUNDING"
  161. CPPFLAGS="${CPPFLAGS} -UHAVE_GCC_ASM_FOR_X87 -DEMSCRIPTEN -U__STRICT_ANSI__"
  162. CPPFLAGS="${CPPFLAGS} -U__CYGWIN__"])
  163. AM_CONDITIONAL(LOL_USE_EMSCRIPTEN, test "${ac_cv_my_have_emscripten}" != "no")
  164. dnl Are we on an OS X or iOS platform?
  165. LOL_TRY_LDFLAGS(-framework Foundation,
  166. [LOL_LIBS="${LOL_LIBS} -framework Foundation"])
  167. LOL_TRY_LDFLAGS(-framework CoreGraphics,
  168. [LOL_LIBS="${LOL_LIBS} -framework CoreGraphics"])
  169. LOL_TRY_LDFLAGS(-framework CoreData,
  170. [LOL_LIBS="${LOL_LIBS} -framework CoreData"])
  171. LOL_TRY_LDFLAGS(-framework UIKit,
  172. [LOL_LIBS="${LOL_LIBS} -framework UIKit"])
  173. dnl Other complex checks
  174. LOL_AC_CHECK_OPENGL()
  175. LOL_AC_CHECK_SDL()
  176. LOL_AC_CHECK_FFMPEG()
  177. dnl Debug symbols
  178. LOL_TRY_LDFLAGS(-rdynamic, [AM_LDFLAGS="${AM_LDFLAGS} -rdynamic"])
  179. dnl Code qui fait des warnings == code de porc == deux baffes dans ta gueule
  180. LOL_TRY_CXXFLAGS(-Wall, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wall"])
  181. LOL_TRY_CXXFLAGS(-Wextra, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wextra"])
  182. LOL_TRY_CXXFLAGS(-Wpointer-arith, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wpointer-arith"])
  183. LOL_TRY_CXXFLAGS(-Wcast-align, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wcast-align"])
  184. LOL_TRY_CXXFLAGS(-Wcast-qual, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wcast-qual"])
  185. LOL_TRY_CXXFLAGS(-Wshadow, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wshadow"])
  186. LOL_TRY_CXXFLAGS(-Wsign-compare, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wsign-compare"])
  187. LOL_TRY_CXXFLAGS(-Wstrict-overflow=1, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wstrict-overflow=1"])
  188. dnl Add these even though they're implicitly set, so that we can safely
  189. dnl remove them from within a Makefile.
  190. LOL_TRY_CXXFLAGS(-Wuninitialized, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wuninitialized"])
  191. LOL_TRY_CXXFLAGS(-Wnarrowing, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wnarrowing"])
  192. LOL_TRY_CXXFLAGS(-Wunused, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wunused"])
  193. LOL_TRY_CXXFLAGS(-Wcast-align, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wcast-align"])
  194. LOL_TRY_CXXFLAGS(-Wunused-parameter, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wunused-parameter"])
  195. LOL_TRY_CXXFLAGS(-Wstrict-aliasing, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wstrict-aliasing"])
  196. LOL_TRY_CXXFLAGS(-Wparentheses, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wparentheses"])
  197. LOL_TRY_CXXFLAGS(-Wreorder, [AM_CXXFLAGS="${AM_CXXFLAGS} -Wreorder"])
  198. dnl Disable these warnings because they're annoyingly verbose
  199. LOL_TRY_CXXFLAGS(-Wno-psabi, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wno-psabi"])
  200. ]) # LOL_AC_CHECK
  201. # LOL_AC_FINI()
  202. # ---------------------
  203. AC_DEFUN([LOL_AC_FINI], [
  204. dnl How to use the Lol Engine outside this tree
  205. LOL_CFLAGS="$LOL_CFLAGS $SDL_CFLAGS $GL_CFLAGS $EGL_CFLAGS $LIBPNG_CFLAGS"
  206. LOL_LIBS="$LOL_LIBS $SDL_LIBS $GL_LIBS $EGL_LIBS $LIBPNG_LIBS $D3D_LIBS"
  207. LOL_DEPS="${LOL_DEPS} \$(lol_builddir)/src/liblol-core.a"
  208. LOL_BULLET_DEPS="${LOL_BULLET_DEPS} \$(lol_builddir)/src/3rdparty/liblol-bullet.a"
  209. LOL_LUA_DEPS="${LOL_LUA_DEPS} \$(lol_builddir)/src/3rdparty/liblol-lua.a"
  210. dnl How to use the Lol Engine inside this tree
  211. AM_CPPFLAGS="${AM_CPPFLAGS} -I\$(lol_srcdir)/src"
  212. AM_CPPFLAGS="${AM_CPPFLAGS} -DLOL_CONFIG_SOURCESUBDIR=\\\"\$(subdir)\\\""
  213. AM_CPPFLAGS="${AM_CPPFLAGS} ${LOL_CFLAGS}"
  214. AM_LDFLAGS="${AM_LDFLAGS} ${LOL_DEPS}"
  215. AM_LDFLAGS="${AM_LDFLAGS} ${LOL_LIBS}"
  216. dnl Extra flags
  217. AC_SUBST(LOL_CFLAGS)
  218. AC_SUBST(LOL_LIBS)
  219. AC_SUBST(LOL_DEPS)
  220. AC_SUBST(LOL_BULLET_DEPS)
  221. AC_SUBST(LOL_LUA_DEPS)
  222. AC_SUBST(AM_CFLAGS)
  223. AC_SUBST(AM_CPPFLAGS)
  224. AC_SUBST(AM_CXXFLAGS)
  225. AC_SUBST(AM_LDFLAGS)
  226. ]) # LOL_AC_FINI