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.
 
 
 

271 lines
9.0 KiB

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