How to build SDL2 for mac m1?

How to build SDL2 for mac m1?

I execute these commands on Mac M1:

  1. I get stable SDL2 source from SDL site
  2. I enter the dir of SDL2 source, and run autoconf.sh
  3. run ./configure --prefix=xxxxxxx
  4. make -j 4

but, I get some errors when I run make -j 4:

/Users/lichao/Downloads/SDL2-2.0.20/src/video/x11/SDL_x11events.c:721:27: error: use of undeclared identifier 'XkbEvent'
    XkbEvent* xkbEvent = (XkbEvent*) xevent;
                          ^
/Users/lichao/Downloads/SDL2-2.0.20/src/video/x11/SDL_x11events.c:721:5: error: use of undeclared identifier 'XkbEvent'
    XkbEvent* xkbEvent = (XkbEvent*) xevent;
    ^
/Users/lichao/Downloads/SDL2-2.0.20/src/video/x11/SDL_x11events.c:721:15: error: use of undeclared identifier 'xkbEvent'
    XkbEvent* xkbEvent = (XkbEvent*) xevent;
              ^
/Users/lichao/Downloads/SDL2-2.0.20/src/video/x11/SDL_x11events.c:812:61: error: use of undeclared identifier 'xkbEvent'
                   (xevent->type == videodata->xkb_event && xkbEvent->any.xkb_type == XkbStateNotify)) {
                                                            ^
/Users/lichao/Downloads/SDL2-2.0.20/src/video/x11/SDL_x11events.c:812:87: error: use of undeclared identifier 'XkbStateNotify'
                   (xevent->type == videodata->xkb_event && xkbEvent->any.xkb_type == XkbStateNotify)) {

Why will it report these error? How should I do?

The configure script thinks you have X11 support, which isn’t needed on macOS (more accurately, it thinks you have X11 support, but apparently you don’t have support for the Xkb extension. That this fails in this case is a bug in SDL, apparently).

You can try running ./configure --prefix=xxxxxxx --disable-video-x11 which will just not build the (unneeded!) X11 support.

Thank you very much, It has worked!