zenorogue / hyperrogue

A SDL roguelike in a non-euclidean world
GNU General Public License v2.0
580 stars 72 forks source link

SDL_gfxPrimitives.h compilation fails as /usr/include/SDL is not in include path #135

Open akien-mga opened 4 years ago

akien-mga commented 4 years ago

Compiling the latest master branch (as well as 11.3o on Mageia Cauldron), I get the following error:

[akien@cauldron hyperrogue (master)]$ autoreconf -vif
autoreconf: Entering directory '.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force 
autoreconf: configure.ac: tracing
autoreconf: configure.ac: not using Libtool
autoreconf: configure.ac: not using Intltool
autoreconf: configure.ac: not using Gtkdoc
autoreconf: running: /usr/bin/autoconf --force
autoreconf: configure.ac: not using Autoheader
autoreconf: running: automake --add-missing --copy --force-missing
configure.ac:7: installing './compile'
configure.ac:9: installing './config.guess'
configure.ac:9: installing './config.sub'
configure.ac:4: installing './install-sh'
configure.ac:4: installing './missing'
Makefile.am: installing './depcomp'
autoreconf: Leaving directory '.'
[akien@cauldron hyperrogue (master)]$ ./conf
config.guess  config.sub    configure     
[akien@cauldron hyperrogue (master)]$ ./configure 
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a race-free mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for g++... g++
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C++... yes
checking whether g++ accepts -g... yes
checking for g++ option to enable C++11 features... none needed
checking whether make supports the include directive... yes (GNU style)
checking dependency style of g++... gcc3
checking for gcc... gcc
checking whether the compiler supports GNU C... yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for GL/gl.h... yes
checking for GL/glew.h... yes
checking for png.h... yes
checking for SDL/SDL.h... yes
checking for SDL/SDL_gfxPrimitives.h... no
SDL/SDL_gfxPrimitives.h header was not found
checking for SDL/SDL_mixer.h... yes
checking for SDL/SDL_ttf.h... yes
checking for library containing glBegin... -lGL
checking for library containing glewInit... -lGLEW
checking for library containing png_create_info_struct... -lpng
checking for library containing SDL_SetVideoMode... -lSDL
checking for library containing aacircleColor... -lSDL_gfx
checking for library containing Mix_LoadMUS... -lSDL_mixer
checking for library containing TTF_OpenFont... -lSDL_ttf
checking for library containing pthread_create... -lpthread
checking for library containing deflate... -lz
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: executing depfiles commands

Note that it says SDL/SDL_gfxPrimitives.h header was not found, yet the configure does not fail (that's the first bug).

Then calling make eventually leads to the same issue in hyperrogue's code:

g++ -DPACKAGE_NAME=\"hyperrogue\" -DPACKAGE_TARNAME=\"hyperrogue\" -DPACKAGE_VERSION=\"10.4i\" -DPACKAGE_STRING=\"hyperrogue\ 10.4i\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"hyperrogue\" -DVERSION=\"10.4i\" -DLINUX=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DSTDC_HEADERS=1 -DHAVE_GL_GL_H=1 -DHAVE_GL_GLEW_H=1 -DHAVE_PNG_H=1 -DHAVE_SDL_SDL_H=1 -DHAVE_SDL_SDL_MIXER_H=1 -DHAVE_SDL_SDL_TTF_H=1 -I.  -DFONTDESTDIR=\"/usr/local/share/hyperrogue/DejaVuSans-Bold.ttf\" -DMUSICDESTDIR=\"/usr/local/share/hyperrogue/hyperrogue-music.txt\" -DSOUNDDESTDIR=\"/usr/local/share/hyperrogue/sounds/\" -DRESOURCEDESTDIR=\"/usr/local/share/hyperrogue/\"   -O2 -std=c++11  -g -O2 -MT hyperrogue-hyper.o -MD -MP -MF .deps/hyperrogue-hyper.Tpo -c -o hyperrogue-hyper.o `test -f 'hyper.cpp' || echo './'`hyper.cpp
In file included from sysconfig.h:348,
                 from hyper.h:19,
                 from hyper.cpp:23:
/usr/include/SDL/SDL_gfxPrimitives.h:38:10: fatal error: SDL.h: No such file or directory
   38 | #include <SDL.h>
      |          ^~~~~~~

Exporting CXXFLAGS = -I/usr/include/SDL fixes it, but this should be done by the autotools buildsystem.

Notably, the recommended approach would be to rely on sdl-config --cflags or pkg-config sdl --cflags to retrieve the relevant information:

$ sdl-config --cflags
-I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT
$ pkg-config --cflags sdl
-I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT 

More specifically, pkg-config should likely be queried for all dependencies with both --cflags and --libs to get the necessary compile and linking flags. E.g.:

$ pkg-config --cflags --libs SDL_gfx
-I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -lSDL_gfx -lSDL
Quuxplusone commented 4 years ago

Does make -f Makefile.simple work for you? (I'd guess "no", but if it did, that'd confirm my bias against autotools.)

I do think it would be reasonable to use pkg-config --cflags sdl and pkg-config --ldflags sdl in Makefile.simple, instead of hardcoding the flags as I originally did. I think I just wasn't confident that the pkg-config utility would exist everywhere.

iacore commented 1 year ago

Fixed in #333