From b90552dfb1a3c4b36ec8028b3dba8103925c1203 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Thu, 23 Jun 2022 16:23:46 -0500 Subject: [PATCH] fix Termux build --- CMakeLists.txt | 18 ++++++++++++++++++ src/engine/platform/pcspkr.cpp | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 82094ce00..4c00b62fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -537,6 +537,24 @@ endif() if (NOT WIN32 AND NOT APPLE) list(APPEND GUI_SOURCES src/gui/icon.c) + + include(CheckIncludeFile) + + CHECK_INCLUDE_FILE(sys/io.h SYS_IO_FOUND) + CHECK_INCLUDE_FILE(linux/input.h LINUX_INPUT_FOUND) + CHECK_INCLUDE_FILE(linux/kd.h LINUX_KD_FOUND) + if (SYS_IO_FOUND) + list(APPEND DEPENDENCIES_DEFINES HAVE_SYS_IO) + message(STATUS "PC speaker output: outb()") + endif() + if (LINUX_INPUT_FOUND) + list(APPEND DEPENDENCIES_DEFINES HAVE_LINUX_INPUT) + message(STATUS "PC speaker output: evdev") + endif() + if (LINUX_KD_FOUND) + list(APPEND DEPENDENCIES_DEFINES HAVE_LINUX_KD) + message(STATUS "PC speaker output: KIOCSOUND") + endif() endif() set(USED_SOURCES ${ENGINE_SOURCES} ${AUDIO_SOURCES} src/main.cpp) diff --git a/src/engine/platform/pcspkr.cpp b/src/engine/platform/pcspkr.cpp index d977690f5..57c72b677 100644 --- a/src/engine/platform/pcspkr.cpp +++ b/src/engine/platform/pcspkr.cpp @@ -27,11 +27,17 @@ #include #include #include +#ifdef HAVE_LINUX_INPUT #include +#endif +#ifdef HAVE_LINUX_KD #include +#endif #include +#ifdef HAVE_SYS_IO #include #endif +#endif #define PCSPKR_DIVIDER 4 #define CHIP_DIVIDER 1 @@ -80,6 +86,7 @@ void DivPlatformPCSpeaker::pcSpeakerThread() { } if (beepFD>=0) { switch (realOutMethod) { +#ifdef HAVE_LINUX_INPUT case 0: { // evdev static struct input_event ie; ie.time.tv_sec=r.tv_sec; @@ -98,11 +105,14 @@ void DivPlatformPCSpeaker::pcSpeakerThread() { } break; } +#endif +#ifdef HAVE_LINUX_KD case 1: // KIOCSOUND (on tty) if (ioctl(beepFD,KIOCSOUND,r.val)<0) { logW("ioctl error! %s",strerror(errno)); } break; +#endif case 2: { // /dev/port unsigned char bOut; bOut=0; @@ -144,11 +154,14 @@ void DivPlatformPCSpeaker::pcSpeakerThread() { } break; } +#ifdef HAVE_LINUX_KD case 3: // KIOCSOUND (on stdout) if (ioctl(beepFD,KIOCSOUND,r.val)<0) { logW("ioctl error! %s",strerror(errno)); } break; +#endif +#ifdef HAVE_SYS_IO case 4: // outb() if (r.val==0) { outb(inb(0x61)&(~3),0x61); @@ -163,6 +176,7 @@ void DivPlatformPCSpeaker::pcSpeakerThread() { } } break; +#endif } } else { //logV("not writing because fd is less than 0"); @@ -544,6 +558,7 @@ void DivPlatformPCSpeaker::reset() { break; case 4: // outb() beepFD=-1; +#ifdef HAVE_SYS_IO if (ioperm(0x61,8,1)<0) { logW("ioperm 0x61: %s",strerror(errno)); break; @@ -557,6 +572,9 @@ void DivPlatformPCSpeaker::reset() { break; } beepFD=STDOUT_FILENO; +#else + errno=ENOSYS; +#endif break; } if (beepFD<0) {