mirror of
https://github.com/kichikuou/xsystem35-sdl2.git
synced 2026-10-01 19:28:00 +03:00
Windows MSYS2 build support
- Add feature detection and fallback implementation for some functions - Use binary mode for fopen() - CMake: Add workaround for MSYS link error
This commit is contained in:
+18
-5
@@ -7,6 +7,12 @@ include(CheckIncludeFile)
|
||||
include(CheckLibraryExists)
|
||||
include(CheckSymbolExists)
|
||||
|
||||
# In msys, `pkg-config --libs` returns `-lmingw32` but find_library() cannot
|
||||
# find it in default search paths.
|
||||
if (MSYS)
|
||||
list(APPEND CMAKE_LIBRARY_PATH $ENV{MINGW_PREFIX}/$ENV{MINGW_CHOST}/lib)
|
||||
endif ()
|
||||
|
||||
# A wrapper around find_package() that skips the check if ENABLE_<package> is false
|
||||
macro (optional_find_package package)
|
||||
option(ENABLE_${package} "Use ${package} if available" ON)
|
||||
@@ -23,6 +29,11 @@ macro (optional_pkg_check_modules prefix)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
check_symbol_exists(getlogin "unistd.h" HAVE_GETLOGIN)
|
||||
check_symbol_exists(mmap "sys/mman.h" HAVE_MMAP)
|
||||
check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION)
|
||||
check_symbol_exists(uname "sys/utsname.h" HAVE_UNAME)
|
||||
|
||||
if (EMSCRIPTEN)
|
||||
set(SDL2_FOUND 1)
|
||||
set(FREETYPE_FOUND 1)
|
||||
@@ -141,11 +152,13 @@ if (EMSCRIPTEN)
|
||||
list(APPEND SRC_MIDI midi.emscripten.c)
|
||||
list(APPEND SUMMARY_MIDI "Emscripten")
|
||||
else()
|
||||
list(APPEND SRC_MIDI midi.rawmidi.c midifile.c)
|
||||
list(APPEND SUMMARY_MIDI "raw")
|
||||
set(MIDI_DEVICE "/dev/midi" CACHE STRING "midi device")
|
||||
set(ENABLE_MIDI_RAWMIDI 1)
|
||||
option(QUIET_MIDI "No display midi stdout" OFF)
|
||||
if (HAVE_SIGACTION)
|
||||
list(APPEND SRC_MIDI midi.rawmidi.c midifile.c)
|
||||
list(APPEND SUMMARY_MIDI "raw")
|
||||
set(MIDI_DEVICE "/dev/midi" CACHE STRING "midi device")
|
||||
set(ENABLE_MIDI_RAWMIDI 1)
|
||||
option(QUIET_MIDI "No display midi stdout" OFF)
|
||||
endif()
|
||||
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
|
||||
check_symbol_exists(SNDCTL_SEQ_NRSYNTHS "machine/soundcard.h" ENABLE_MIDI_SEQMIDI)
|
||||
|
||||
@@ -26,6 +26,16 @@ cmake の実行でエラーになる場合は必要なライブラリをイン
|
||||
$ cmake -DCMAKE_BUILD_TYPE=Debug ../../
|
||||
$ make && make install
|
||||
|
||||
### Windows
|
||||
|
||||
[MSYS2](https://www.msys2.org) が必要です。
|
||||
|
||||
$ pacman -S cmake mingw-w64-x86_64-cmake mingw-w64-x86_64-SDL2 mingw-w64-x86_64-SDL2_ttf mingw-w64-x86_64-SDL2_mixer
|
||||
$ mkdir -p out/debug
|
||||
$ cd out/debug
|
||||
$ cmake -G"MSYS Makefiles" -DCMAKE_BUILD_TYPE=Debug ../../
|
||||
$ make
|
||||
|
||||
### Emscripten
|
||||
|
||||
$ mkdir -p out/wasm
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#cmakedefine PACKAGE "@PACKAGE@"
|
||||
#define VERSION "1.7.3sdl2"
|
||||
|
||||
#cmakedefine CMAKE_SYSTEM_NAME "@CMAKE_SYSTEM_NAME@"
|
||||
|
||||
#define RGB_ORDER 1
|
||||
#cmakedefine WORDS_BIGENDIAN @WORDS_BIGENDIAN@
|
||||
|
||||
@@ -29,7 +31,11 @@
|
||||
|
||||
#cmakedefine QUIET_MIDI @QUIET_MIDI@
|
||||
|
||||
#cmakedefine HAVE_GETLOGIN @HAVE_GETLOGIN@
|
||||
#cmakedefine HAVE_MMAP @HAVE_MMAP@
|
||||
#cmakedefine HAVE_SDLJOY @HAVE_SDLJOY@
|
||||
#cmakedefine HAVE_SIGACTION @HAVE_SIGACTION@
|
||||
#cmakedefine HAVE_UNAME @HAVE_UNAME@
|
||||
#cmakedefine HAVE_XF86VMODE @HAVE_XF86VMODE@
|
||||
|
||||
#define DEFAULT_GOTHIC_TTF "@DEFAULT_FONT_PATH@/MTLc3m.ttf"
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ static void bgi_read() {
|
||||
if (nact->files.bgi == NULL)
|
||||
return;
|
||||
|
||||
FILE *fp = fopen(nact->files.bgi, "r");
|
||||
FILE *fp = fopen(nact->files.bgi, "rb");
|
||||
if (!fp) {
|
||||
WARNING("Could not open %s\n", nact->files.bgi);
|
||||
return;
|
||||
|
||||
+10
-4
@@ -25,7 +25,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/utsname.h>
|
||||
#include "portab.h"
|
||||
#include "xsystem35.h"
|
||||
#include "savedata.h"
|
||||
@@ -38,6 +37,9 @@
|
||||
#include "graphicsdevice.h"
|
||||
#include "ald_manager.h"
|
||||
#include "LittleEndian.h"
|
||||
#if HAVE_UNAME
|
||||
#include <sys/utsname.h>
|
||||
#endif
|
||||
|
||||
/* defined by cmdm.c */
|
||||
extern boolean have_eng_mp_patch;
|
||||
@@ -868,17 +870,21 @@ void commands2F51() {
|
||||
|
||||
void commands2F52() {
|
||||
int eNum = getCaliValue();
|
||||
if (eNum <= 0) return;
|
||||
|
||||
#if HAVE_UNAME
|
||||
struct utsname un;
|
||||
char s[256];
|
||||
|
||||
if (eNum <= 0) return;
|
||||
if (uname(&un) < 0) return;
|
||||
NOTICE("sysname %s nodename %s release %s version %s machine %s\n",
|
||||
un.sysname, un.nodename, un.release, un.version, un.machine);
|
||||
sprintf(s,"%s %s %s",
|
||||
un.sysname, un.release, un.machine);
|
||||
#else
|
||||
const char *s = CMAKE_SYSTEM_NAME;
|
||||
#endif
|
||||
|
||||
v_strcpy(eNum -1, s);
|
||||
|
||||
DEBUG_COMMAND("sysGetOsName %d: %s\n", eNum, s);
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -449,16 +449,16 @@ void commandZZ13() {
|
||||
|
||||
void commandZZ14() {
|
||||
int no = getCaliValue();
|
||||
char *s = "xsys35_user";
|
||||
|
||||
#ifdef HAVE_GETLOGIN
|
||||
char *lname=getlogin();
|
||||
if (lname)
|
||||
s = lname;
|
||||
#endif
|
||||
|
||||
if (no <= 0) return;
|
||||
if (lname) {
|
||||
v_strcpy(no -1, lname);
|
||||
} else {
|
||||
char s[256];
|
||||
sprintf(s, "%d", getuid());
|
||||
v_strcpy(no -1, s);
|
||||
}
|
||||
v_strcpy(no -1, s);
|
||||
|
||||
DEBUG_COMMAND("ZZ14 %d:\n", no);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
@@ -34,6 +33,9 @@
|
||||
#include "system.h"
|
||||
#include "LittleEndian.h"
|
||||
#include "dri.h"
|
||||
#ifdef HAVE_MMAP
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* static maethods
|
||||
@@ -184,7 +186,7 @@ drifiles *dri_init(char **file, int cnt, boolean mmapping) {
|
||||
for (i = 0; i < cnt; i++) {
|
||||
if (*(file + i) == NULL) continue;
|
||||
/* open check */
|
||||
if (NULL == (fp = fopen(*(file + i), "r"))) {
|
||||
if (NULL == (fp = fopen(*(file + i), "rb"))) {
|
||||
SYSERROR("File %s is not found\n", *(file + i));
|
||||
}
|
||||
/* check is drifile or noe */
|
||||
@@ -204,6 +206,7 @@ drifiles *dri_init(char **file, int cnt, boolean mmapping) {
|
||||
d->fnames[i] = strdup(*(file + i));
|
||||
/* close */
|
||||
fclose(fp);
|
||||
#ifdef HAVE_MMAP
|
||||
/* mmap */
|
||||
if (mmapping) {
|
||||
int fd;
|
||||
@@ -219,6 +222,7 @@ drifiles *dri_init(char **file, int cnt, boolean mmapping) {
|
||||
}
|
||||
d->mmapped = TRUE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return d;
|
||||
}
|
||||
@@ -257,7 +261,7 @@ dridata *dri_getdata(drifiles *d, int no) {
|
||||
int readsize = dataptr2 - dataptr;
|
||||
FILE *fp;
|
||||
data = malloc(sizeof(char) * readsize);
|
||||
fp = fopen(d->fnames[disk], "r");
|
||||
fp = fopen(d->fnames[disk], "rb");
|
||||
fseek(fp, dataptr, SEEK_SET);
|
||||
fread(data, 1, readsize, fp);
|
||||
fclose(fp);
|
||||
|
||||
+2
-2
@@ -98,9 +98,9 @@ FILE *fc_open(char *filename, char type) {
|
||||
FILE *fp;
|
||||
if (type == 'w') {
|
||||
fc_backup_oldfile(fullpath);
|
||||
fp = fopen(fullpath, "w");
|
||||
fp = fopen(fullpath, "wb");
|
||||
} else {
|
||||
fp = fopen(fullpath, "r");
|
||||
fp = fopen(fullpath, "rb");
|
||||
}
|
||||
free(fullpath);
|
||||
return fp;
|
||||
|
||||
+27
-1
@@ -28,7 +28,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
@@ -44,6 +43,9 @@
|
||||
#include "counter.h"
|
||||
#include "nact.h"
|
||||
#include "LittleEndian.h"
|
||||
#ifdef HAVE_MMAP
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
#define DEFAULT_AUDIO_BUFFER_SIZE 2048
|
||||
|
||||
@@ -359,15 +361,39 @@ static int load_wai() {
|
||||
goto endwai;
|
||||
}
|
||||
|
||||
#ifdef HAVE_MMAP
|
||||
if (MAP_FAILED == (adr = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, fd, 0))) {
|
||||
WARNING("mmap: %s\n", strerror(errno));
|
||||
close(fd);
|
||||
goto endwai;
|
||||
}
|
||||
#else
|
||||
adr = malloc(sbuf.st_size);
|
||||
if (!adr) {
|
||||
WARNING("load_wai: out of memory\n");
|
||||
close(fd);
|
||||
goto endwai;
|
||||
}
|
||||
size_t bytes = 0;
|
||||
while (bytes < sbuf.st_size) {
|
||||
ssize_t ret = read(fd, adr, sbuf.st_size);
|
||||
if (ret <= 0) {
|
||||
WARNING("load_wai: failed to read\n");
|
||||
close(fd);
|
||||
free(adr);
|
||||
goto endwai;
|
||||
}
|
||||
bytes += ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (*adr != 'X' || *(adr+1) != 'I' || *(adr+2) != '2') {
|
||||
WARNING("not WAI file\n");
|
||||
#ifdef HAVE_MMAP
|
||||
munmap(adr, sbuf.st_size);
|
||||
#else
|
||||
free(adr);
|
||||
#endif
|
||||
close(fd);
|
||||
goto endwai;
|
||||
}
|
||||
|
||||
+2
-2
@@ -73,7 +73,7 @@ int s39ini_init(void) {
|
||||
|
||||
// Volume.sav があればそれを読み込む
|
||||
snprintf(fn, sizeof(fn) -1, "%s/Volume.sav", nact->files.savedir);
|
||||
if (NULL == (fp = fopen(fn, "r"))) {
|
||||
if (NULL == (fp = fopen(fn, "rb"))) {
|
||||
// とりあえず、初期ボリュームは 100
|
||||
for (i = 0; i < MAXVOLCH; i++) {
|
||||
vol[i] = vval[i].vol = 100;
|
||||
@@ -143,7 +143,7 @@ int s39ini_remove() {
|
||||
}
|
||||
|
||||
snprintf(fn, sizeof(fn) -1, "%s/Volume.sav", nact->files.savedir);
|
||||
if (NULL == (fp = fopen(fn, "w"))) {
|
||||
if (NULL == (fp = fopen(fn, "wb"))) {
|
||||
WARNING("Fail to save Volume.save\n");
|
||||
return NG;
|
||||
}
|
||||
|
||||
+22
-16
@@ -28,11 +28,14 @@
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef HAVE_SIGACTION
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_GTK
|
||||
# define GTK_RC_NAME ".gtk/gtkrc"
|
||||
# include <gtk/gtk.h>
|
||||
@@ -72,10 +75,7 @@ static void sys35_init();
|
||||
static void sys35_remove();
|
||||
static boolean sys35_initGameDataResorce();
|
||||
static void sys35_ParseOption(int *argc, char **argv);
|
||||
static void signal_handler(int sig_num);
|
||||
static void signal_handler_segv(int sig_num);
|
||||
static void check_profile();
|
||||
static void init_signalhandler();
|
||||
|
||||
/* for debugging */
|
||||
static FILE *fpdebuglog;
|
||||
@@ -543,17 +543,6 @@ void sys_reset() {
|
||||
sys_error("exec fail");
|
||||
}
|
||||
|
||||
static void signal_handler(int sig_num) {
|
||||
sys35_remove();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void signal_handler_segv(int sig_num) {
|
||||
fprintf(stderr, "PID(%d), sigsegv caught @ %03d, %05x\n", (int)getpid(), sl_getPage(), sl_getIndex());
|
||||
sys35_remove();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void sys35_ParseOption(int *argc, char **argv) {
|
||||
int i;
|
||||
FILE *fp;
|
||||
@@ -746,6 +735,18 @@ static void check_profile() {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_SIGACTION
|
||||
static void signal_handler(int sig_num) {
|
||||
sys35_remove();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void signal_handler_segv(int sig_num) {
|
||||
fprintf(stderr, "PID(%d), sigsegv caught @ %03d, %05x\n", (int)getpid(), sl_getPage(), sl_getIndex());
|
||||
sys35_remove();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void sys_set_signalhandler(int SIG, void (*handler)(int)) {
|
||||
struct sigaction act;
|
||||
sigset_t smask;
|
||||
@@ -760,17 +761,20 @@ void sys_set_signalhandler(int SIG, void (*handler)(int)) {
|
||||
sigaction(SIG, &act, NULL);
|
||||
}
|
||||
|
||||
void init_signalhandler() {
|
||||
static void init_signalhandler() {
|
||||
sys_set_signalhandler(SIGINT, signal_handler);
|
||||
sys_set_signalhandler(SIGTERM, signal_handler);
|
||||
sys_set_signalhandler(SIGPIPE, SIG_IGN);
|
||||
sys_set_signalhandler(SIGABRT, signal_handler);
|
||||
sys_set_signalhandler(SIGSEGV, signal_handler_segv);
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
char *homedir = getenv("HOME"), *rc_name, *rc_path;
|
||||
#ifdef HAVE_SIGACTION
|
||||
sys_set_signalhandler(SIGINT, SIG_IGN);
|
||||
#endif
|
||||
|
||||
saved_argc = argc;
|
||||
saved_argv = argv;
|
||||
@@ -788,7 +792,9 @@ int main(int argc, char **argv) {
|
||||
#endif
|
||||
sys35_initGameDataResorce();
|
||||
|
||||
#ifdef HAVE_SIGACTION
|
||||
init_signalhandler();
|
||||
#endif
|
||||
|
||||
mus_init(audio_buffer_size);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user