From 58afb03f7082b355f2c317c9acb60e48a86d6eec Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 8 Oct 2026 19:22:16 +0000 Subject: Start working on support for compiling on windows using msys2. FossilOrigin-Name: d0b8a592f04b7c438aff01694ef262cef67b71da7625bf7415c1e61ff22d8a63 --- src/Makefile.am | 1 + src/bin/Makefile.am | 2 +- src/bin/aplwc_repl.h | 3 +++ src/bin/main.c | 2 +- src/include/Makefile.am | 8 ++++++- src/include/os.h | 54 +++++++++++++++++++++++++++++++++++++++++++ src/include/os/windows.h | 25 ++++++++++++++++++++ src/include/os/windows_main.h | 20 ++++++++++++++++ src/include/os_main.h | 31 +++++++++++++++++++++++++ src/lib/Makefile.am | 2 ++ src/os/Makefile.am | 11 +++++++++ src/os/os.c | 24 +++++++++++++++++++ src/os/os_main.c | 24 +++++++++++++++++++ src/os/windows.c | 25 ++++++++++++++++++++ src/os/windows_main.c | 26 +++++++++++++++++++++ src/tools/Makefile.am | 8 +++---- src/tools/genboot.c | 5 ++-- src/tools/genunicode.c | 8 ++----- 18 files changed, 263 insertions(+), 16 deletions(-) create mode 100644 src/include/os.h create mode 100644 src/include/os/windows.h create mode 100644 src/include/os/windows_main.h create mode 100644 src/include/os_main.h create mode 100644 src/os/Makefile.am create mode 100644 src/os/os.c create mode 100644 src/os/os_main.c create mode 100644 src/os/windows.c create mode 100644 src/os/windows_main.c (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index b4cd291..92b080f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,6 @@ include src/bin/Makefile.am include src/include/Makefile.am include src/lib/Makefile.am +include src/os/Makefile.am include src/tools/Makefile.am include src/unicode/Makefile.am diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index e4d2204..4ae24a6 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -5,4 +5,4 @@ aplwc_SOURCES = \ src/bin/main.c \ src/bin/util.c -aplwc_LDADD = libaplwc.la +aplwc_LDADD = libaplwc.la libos.la libosmain.la diff --git a/src/bin/aplwc_repl.h b/src/bin/aplwc_repl.h index 6fb4415..6d01de1 100644 --- a/src/bin/aplwc_repl.h +++ b/src/bin/aplwc_repl.h @@ -20,6 +20,9 @@ #ifndef APLWC_REPL_H #define APLWC_REPL_H +#include +#include + #include #include #include diff --git a/src/bin/main.c b/src/bin/main.c index 5242cd5..04bb13a 100644 --- a/src/bin/main.c +++ b/src/bin/main.c @@ -79,7 +79,7 @@ my_setup_failsim(enum aplwc_failsim_parameter p, unsigned long def) } int -main(int argc, char *argv[]) +portable_main(int argc, char *argv[]) { struct aplwc_fns fns; struct aplwc *aplwc; diff --git a/src/include/Makefile.am b/src/include/Makefile.am index 3f082fb..99326ea 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am @@ -1,2 +1,8 @@ +OS_HS = \ + src/include/os/windows.h + include_HEADERS += src/include/aplwc.h -noinst_HEADERS += src/include/aplwc_macros.h +noinst_HEADERS += src/include/aplwc_macros.h src/include/os.h $(OS_HS) + +src/include/os.h: $(OS_HS) + diff --git a/src/include/os.h b/src/include/os.h new file mode 100644 index 0000000..a56b79d --- /dev/null +++ b/src/include/os.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2026 Peter Mikkelsen + * + * This file is part of aplwc. + * + * Aplwc is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Aplwc is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with aplwc. If not, see . + */ + +#ifndef OS_H +#define OS_H + +#include + +enum OS { + OS_Windows, + OS_Unknown +}; + +#if BUILD_TARGET + +#ifdef BUILD_OS_WINDOWS +#define OS OS_Windows +#else +#error "Unexpected build os" +#endif + +#else + +#ifdef HOST_OS_WINDOWS +#define OS OS_Windows +#else +#error "Unexpected host os" +#endif + +#endif + +#if OS == OS_Windows +#include +#endif + +int getline(char **, size_t *, void *); + +#endif /* OS_H */ diff --git a/src/include/os/windows.h b/src/include/os/windows.h new file mode 100644 index 0000000..7d12e12 --- /dev/null +++ b/src/include/os/windows.h @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2026 Peter Mikkelsen + * + * This file is part of aplwc. + * + * Aplwc is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Aplwc is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with aplwc. If not, see . + */ + +#include +#include +#include +#include +#include +#include diff --git a/src/include/os/windows_main.h b/src/include/os/windows_main.h new file mode 100644 index 0000000..fad4151 --- /dev/null +++ b/src/include/os/windows_main.h @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2026 Peter Mikkelsen + * + * This file is part of aplwc. + * + * Aplwc is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Aplwc is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with aplwc. If not, see . + */ + +int main(int, char **); diff --git a/src/include/os_main.h b/src/include/os_main.h new file mode 100644 index 0000000..1aa3d55 --- /dev/null +++ b/src/include/os_main.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2026 Peter Mikkelsen + * + * This file is part of aplwc. + * + * Aplwc is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Aplwc is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with aplwc. If not, see . + */ + +#ifndef OS_MAIN_H +#define OS_MAIN_H + +#if OS == OS_Windows +#include +#else +#error "Did you include before including ?" /* There may also be a missing case */ +#endif + +int portable_main(int, char **); + +#endif /* OS_MAIN_H */ diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index b0f60f8..6a526e3 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -1,6 +1,7 @@ lib_LTLIBRARIES += libaplwc.la libaplwc_la_SOURCES = \ + src/os/os.c \ src/lib/aplwc_internal.h \ src/lib/eval.c \ src/lib/main.c \ @@ -11,6 +12,7 @@ libaplwc_la_SOURCES = \ src/lib/syntax.c \ src/lib/unicode.c +libaplwc_la_LIBADD = libos.la libaplwc_la_LDFLAGS = -version-info 0:0:0 EXTRA_DIST += src/lib/boot.aplwc diff --git a/src/os/Makefile.am b/src/os/Makefile.am new file mode 100644 index 0000000..46d9edf --- /dev/null +++ b/src/os/Makefile.am @@ -0,0 +1,11 @@ +noinst_LTLIBRARIES = libos.la libosmain.la + +libos_la_SOURCES = src/os/os.c +libos_la_LDFLAGS = -static + +libosmain_la_SOURCES = src/os/os_main.c +libosmain_la_LDFLAGS = -static + +src/os/os.c: src/os/windows.c + +src/os/os_main.c: src/os/windows_main.c diff --git a/src/os/os.c b/src/os/os.c new file mode 100644 index 0000000..2c4fcc6 --- /dev/null +++ b/src/os/os.c @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2026 Peter Mikkelsen + * + * This file is part of aplwc. + * + * Aplwc is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Aplwc is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with aplwc. If not, see . + */ + +#include + +#if OS == OS_Windows +#include "windows.c" +#endif diff --git a/src/os/os_main.c b/src/os/os_main.c new file mode 100644 index 0000000..1d35a78 --- /dev/null +++ b/src/os/os_main.c @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2026 Peter Mikkelsen + * + * This file is part of aplwc. + * + * Aplwc is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Aplwc is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with aplwc. If not, see . + */ + +#include + +#if OS == OS_Windows +#include "windows_main.c" +#endif diff --git a/src/os/windows.c b/src/os/windows.c new file mode 100644 index 0000000..88d8b27 --- /dev/null +++ b/src/os/windows.c @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2026 Peter Mikkelsen + * + * This file is part of aplwc. + * + * Aplwc is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Aplwc is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with aplwc. If not, see . + */ + +#include + +int getline(char **, size_t *, void *) +{ + return -1; +} diff --git a/src/os/windows_main.c b/src/os/windows_main.c new file mode 100644 index 0000000..dc30750 --- /dev/null +++ b/src/os/windows_main.c @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2026 Peter Mikkelsen + * + * This file is part of aplwc. + * + * Aplwc is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Aplwc is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with aplwc. If not, see . + */ + +#include + +int +main(int argc, char **argv) +{ + return portable_main(argc, argv); +} diff --git a/src/tools/Makefile.am b/src/tools/Makefile.am index 9f1d00a..8e995db 100644 --- a/src/tools/Makefile.am +++ b/src/tools/Makefile.am @@ -1,10 +1,10 @@ -genboot$(EXEEXT): src/tools/genboot.c +genboot$(EXEEXT): src/tools/genboot.c src/os/os.c src/os/os_main.c src/include/os.h src/include/os_main.h $(AM_V_CC) - $(AM_V_at)$(CC_FOR_BUILD) -o $@ $(top_srcdir)/src/tools/genboot.c + $(AM_V_at)$(CC_FOR_BUILD) -DBUILD_TARGET -I$(top_srcdir)/src/include/ -I. -o $@ $(top_srcdir)/src/tools/genboot.c $(top_srcdir)/src/os/os.c $(top_srcdir)/src/os/os_main.c -genunicode$(EXEEXT): src/tools/genunicode.c +genunicode$(EXEEXT): src/tools/genunicode.c src/os/os.c src/os/os_main.c src/include/os.h src/include/os_main.h $(AM_V_CC) - $(AM_V_at)$(CC_FOR_BUILD) -o $@ $(top_srcdir)/src/tools/genunicode.c + $(AM_V_at)$(CC_FOR_BUILD) -DBUILD_TARGET -I$(top_srcdir)/src/include/ -I. -o $@ $(top_srcdir)/src/tools/genunicode.c $(top_srcdir)/src/os/os.c $(top_srcdir)/src/os/os_main.c EXTRA_DIST += src/tools/genboot.c src/tools/genunicode.c CLEANFILES += genboot$(EXEEXT) genunicode$(EXEEXT) diff --git a/src/tools/genboot.c b/src/tools/genboot.c index 9d0a7e4..6433bf7 100644 --- a/src/tools/genboot.c +++ b/src/tools/genboot.c @@ -17,11 +17,10 @@ * along with aplwc. If not, see . */ -#include -#include +#include int -main(int argc, char *argv[]) +portable_main(int argc, char *argv[]) { FILE *f; int c, s; diff --git a/src/tools/genunicode.c b/src/tools/genunicode.c index 76f2c60..209984f 100644 --- a/src/tools/genunicode.c +++ b/src/tools/genunicode.c @@ -17,11 +17,7 @@ * along with aplwc. If not, see . */ -#include -#include -#include -#include -#include +#include static char *files[] = { "DerivedCoreProperties.txt", @@ -51,7 +47,7 @@ static void parse_sep(FILE *); static jmp_buf env; int -main(int argc, char *argv[]) +portable_main(int argc, char *argv[]) { FILE *f; char *dir, *buf; -- cgit v1.2.3