Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Shell/python helpers run under MSYS bash on Windows runners too:
# keep them LF everywhere.
*.sh text eol=lf
*.py text eol=lf
tools/* text eol=lf
8 changes: 8 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ autogen.sh script as you would to the configure script.
If you want to know more about installation options refer to the INSTALL file
(not for beginners).

Windows
-------

Native MSYS2/MinGW-w64 builds and Linux cross-builds (which the CI uses
to produce Windows artifacts) are documented in doc/BUILDING-WINDOWS.md;
the sysroot/packaging helpers live in tools/. The legacy win32/Makefile
flow is described in win32/README.


Using Gpredict
--------------
Expand Down
35 changes: 34 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AC_INIT([gpredict],[m4_esyscmd(./git-version-gen .tarball-version)],[https://community.libre.space/c/gpredict])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_MACRO_DIRS([m4])
AC_CONFIG_SRCDIR(src/main.c)
AC_CONFIG_HEADERS(build-config.h)
AM_INIT_AUTOMAKE([subdir-objects dist-bzip2 no-dist-gzip 1.6])
Expand Down Expand Up @@ -65,6 +65,39 @@ else
havelibgps=false;
fi

# winsock2 (rigctld/rotctld TCP clients): on Unix the BSD socket
# functions are in libc, on MinGW/Windows they live in ws2_32.
AC_SEARCH_LIBS([htons],[ws2_32])

# Windows builds: link the GUI subsystem (no console window on
# double-click) and embed the app icon + version info from
# win32/gpredict.rc, mirroring what win32/Makefile does. Note that
# autotools running inside MSYS2 reports the host as *-*-msys, so
# *mingw* alone would miss the native build.
case "$host" in
*mingw*|*msys*|*cygwin*)
gp_cv_windows=yes
AC_CHECK_TOOL([WINDRES], [windres], [:])
;;
*)
gp_cv_windows=no
;;
esac
AM_CONDITIONAL([MINGW], [test "$gp_cv_windows" = yes])
AM_CONDITIONAL([W32RES],
[test "$gp_cv_windows" = yes && test "x$WINDRES" != "x:"])

dnl numeric pieces of $VERSION for the VERSIONINFO resource (cut/tr to
dnl keep autoconf's m4 from eating bracketed sed regexes; tag-less
dnl checkouts yield VERSION=UNKNOWN -> 0.0.0)
gp_major=`echo "x$VERSION" | cut -d. -f1 | tr -dc '0-9'`
gp_minor=`echo "x$VERSION" | cut -d. -f2 | tr -dc '0-9'`
test -n "$gp_major" || gp_major=0
test -n "$gp_minor" || gp_minor=0
AC_SUBST([VERMAJ], [$gp_major])
AC_SUBST([VERMIN], [$gp_minor])
AC_SUBST([VERBLD], [0])

AC_SUBST(PACKAGE_CFLAGS)
AC_SUBST(PACKAGE_LIBS)

Expand Down
215 changes: 215 additions & 0 deletions doc/BUILDING-WINDOWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
# Building Gpredict for Windows

There are two maintained ways to build the Windows 64-bit `gpredict.exe`
(GTK-3, Win32 backend):

1. **Cross-build on Linux** — distro MinGW-w64 toolchain plus a
dependency sysroot assembled from MSYS2 repository packages,
section 5. This is the path CI uses: the `windows-cross` job in
`.github/workflows/ci.yml` uploads the standalone zip as the
`gpredict-windows-x86_64-cross` artifact.
2. **Native build on Windows with MSYS2/MinGW-w64**, sections 1-3.
Convenient for day-to-day development on a Windows machine. CI does
not run it: a Linux runner cross-compiling to Windows removes the
need for a Windows build server, so there is no Windows CI job.

Both flows are verified with Gpredict 2.7 (`master`): the native build
with MSYS2 UCRT `mingw-w64-x86_64-gcc` 15.2 / `mingw-w64-x86_64-gtk3`
3.24.51, and the Linux cross-build on Ubuntu 24.04 with
`gcc-mingw-w64` 13 — the resulting exe and its standalone tree start
the GUI and load maps on a stock Windows install.

The older recipe in `win32/README` (cross-build against the
gtk+-bundle 3.10 zip from win32builder.gnome.org) still exists via
`win32/Makefile`, but it targets 2013-era GTK bundles. The two autotools
builds — native (sections 1-3) and Linux cross (section 5) — are the
maintained paths.

## 1. Prerequisites

1. Install [MSYS2](https://www.msys2.org/) (default location `C:\msys64`).
2. Open an **MSYS2 MinGW x64** shell (Start menu shortcut, or
`C:\msys64\msys2_shell.cmd -mingw64`) and install the toolchain and
dependencies:

```sh
pacman -Syu # update core, restart shell if asked
pacman -S --needed \
base-devel \
git \
intltool \
mingw-w64-x86_64-toolchain \
mingw-w64-x86_64-pkgconf \
mingw-w64-x86_64-glib2 \
mingw-w64-x86_64-gtk3 \
mingw-w64-x86_64-libcurl \
mingw-w64-x86_64-gettext-runtime \
mingw-w64-x86_64-gpsd # optional: GPS support via libgps
```

Notes:
- `base-devel` provides the MSYS-side autotools
(autoconf/automake/libtool/intltool/gettext/autopoint).
- `zip` (MSYS package) is only needed by `win32/Makefile`'s `dist`
target; any zip tool works as a stand-in (e.g. `tar -a -cf`).
- The MinGW packages (prefixed `mingw-w64-x86_64-`) provide the
*target* libraries the binary links against. Never link against
MSYS (`/usr/bin`) DLLs — the resulting exe would require the MSYS
runtime and would not be portable.

## 2. Configure and build

```sh
cd gpredict
./autogen.sh --prefix=/mingw64
make -j4
```

The binary is `src/gpredict.exe`.

## 3. Install and run

Install into the MinGW tree so the executable sits next to its
`share/gpredict` data (maps, TLE sources, sample QTH/modules), which is
how the Win32 build locates its data files
(`g_win32_get_package_installation_directory_of_module`):

```sh
make install # installs under C:\msys64\mingw64
gpredict.exe # from an MSYS2 MinGW x64 shell
```

The first run creates `satdata/`, `modules/`, `hwconf/`, `trsp/` under
`%APPDATA%`-based config dirs and populates them from the shipped
defaults; logs land under the user data dir.

**Gotcha:** depending on the libtool version, `make` leaves the *real*
binary at `src/.libs/gpredict.exe` while `src/gpredict.exe` is a
libtool exec-wrapper stub that may fail silently (exits instantly with
code 0 and no output) when run outside an environment matching the
stub's assumptions. If running `src/gpredict.exe` "does nothing", run
`src/.libs/gpredict.exe` instead — or just `make install` and use
`/mingw64/bin/gpredict.exe`.

## 4. Known Windows quirks handled by the build

These are fixed in-tree; listed here as documentation of why the code
looks the way it does:

| Issue | Fix |
|---|---|
| `#ifdef WIN32` guards never trigger under `-std=c11`: GCC for MinGW only predefines `WIN32` in GNU dialects, never in strict ISO mode | Socket/OS guards changed to `_WIN32` (always predefined by the compiler) in `main.c`, `gtk-rig-ctrl.c`, `gtk-rot-ctrl.c`, `sat-info.c`, `sgpsdp/sgp_time.c` |
| MinGW's `curl/curl.h` itself defines `WIN32` after inclusion, silently switching later `#ifdef WIN32` blocks to the `win32_fetch` backend even when libcurl is linked | TLE/TRSP download code now selects its backend with the build-system macro `HAVE_WIN32_FETCH` (`tle-update.c`, `trsp-update.c`); `win32/Makefile` passes `-DHAVE_WIN32_FETCH` |
| `strcasestr()` is a glibc extension, absent from the Windows CRT | Call sites in `gtk-rig-ctrl.c`/`gtk-rot-ctrl.c` use the existing portable `gpredict_strcasestr()` helper |
| `timegm()` is not declared on Windows unless included as `_mkgmtime` | `sat-info.c` `#define timegm _mkgmtime` guard now triggers on `_WIN32` |
| Winsock2 functions need `ws2_32` on Windows but not on Unix | `configure.ac` uses `AC_SEARCH_LIBS([htons],[ws2_32])` |
| Double-clicking `gpredict.exe` popped up a console window and showed no file icon | On a MinGW host the autotools build links with `-mwindows` and compiles the pre-existing `win32/gpredict.rc` (icon + version info) with `windres` into the exe (`src/Makefile.am`) |

`gmtime_r()` (`sgpsdp/sgp_time.c`) is shimmed on Windows via the same
`_WIN32` guard; the UCRT also provides it, so the shim is harmless.

Pixmaps install under `share/pixmaps/gpredict` (FHS) but the Win32 data
lookup in `compat.c` reads `share/gpredict/pixmaps`; see section 7.

## 5. Cross-building on Linux (MSYS2 sysroot)

Gpredict can be cross-compiled for Windows from any Linux box using the
system MinGW-w64 toolchain plus a Windows dependency sysroot assembled
on the fly from MSYS2 repository packages (they are plain `.pkg.tar.zst`
archives, no MSYS2 runtime involved):

```sh
sudo apt-get install mingw-w64 autoconf automake libtool intltool \
autopoint gettext pkg-config python3 zstd zip

python3 tools/msys2-sysroot.py ../sysroot # gtk3 + libcurl + gettext deps
./autogen.sh
./configure --host=x86_64-w64-mingw32 --prefix=/mingw64 \
PKG_CONFIG_LIBDIR=../sysroot/mingw64/lib/pkgconfig
make -j$(nproc)

sh tools/cross-package.sh . ../sysroot stage/gpredict-x86_64-w64-mingw32
(cd stage && zip -qr ../gpredict-win64.zip gpredict-x86_64-w64-mingw32)
```

`tools/msys2-sysroot.py` resolves the transitive dependency set from the
repo's pacman DB and rewrites the `/mingw64` prefixes in the `.pc` files;
`tools/cross-package.sh` collects the exe, the DLL closure (via
`x86_64-w64-mingw32-objdump`, walking from the exe *and* from the
staged gdk-pixbuf loader DLLs so the SVG/librsvg chain ships),
pixmaps/data in the `compat.c` layout, gdk-pixbuf loaders, themes and
gspawn helpers. Pin package names/versions
as script arguments in CI for reproducibility. This is what the
`windows-cross` job in `.github/workflows/ci.yml` does; the workflow
uploads the zip as the `gpredict-windows-x86_64-cross` build artifact.

Debian/Ubuntu mingw-w64 builds link the exe against `msvcrt` while the
sysroot libraries are UCRT-built; this works because UCRT keeps the CRT
`FILE` ABI, and stdio across that boundary (a handle opened by glib's
`g_fopen` and closed by application code) was probed. If a real CRT
clash ever surfaces, swap the distro gcc for a UCRT-native toolchain
(e.g. llvm-mingw) — the sysroot and packaging flow stay the same.

The alternative historical path, `win32/Makefile` pointed at an existing
MSYS2 (`MINGW_ROOT=/mingw64` or `../../msys64/mingw64`), also works
inside an MSYS2 shell and additionally exercises the WinHTTP-based
`win32_fetch` downloader instead of libcurl.

## 6. Optional: cross-build variant (win32/Makefile, Windows host)

`win32/Makefile` remains for the historical cross/packaging build
(`make` / `make dist` from inside `win32/`, pointed at a GTK bundle or
at `MINGW_ROOT=/mingw64` in an MSYS2 shell — the latter works as-is
against current MSYS2 packages and `make dist` yields the standalone
`gpredict-<version>.zip`). It compiles the extra `win32/win32-fetch.c`
(WinHTTP-based downloader) and defines `HAVE_WIN32_FETCH` so the
TLE/TRSP fetchers use it instead of libcurl.

## 7. Packaging a standalone zip

The fastest path is `tools/cross-package.sh`; it automates everything
described below: the exe (taken from `src/.libs/`, avoiding the libtool
stub), the full DLL closure *including* the dlopen'ed gdk-pixbuf
loaders and their librsvg/SVG chain, the data in the `compat.c`
layout, icons, locales, and gtk schemas — deliberately *without* a
`loaders.cache`, so gdk-pixbuf relocates its loaders from the DLL
location at runtime:

```sh
sh tools/cross-package.sh . / stage/gpredict-x86_64-w64-mingw32
```

The second argument is `/`: inside an MSYS2 shell the dependency tree
already lives at `/mingw64`. (On Linux, pass the sysroot produced by
`tools/msys2-sysroot.py` instead — section 5.)

Then zip the stage directory — install `zip` (`pacman -S zip`) or use
PowerShell:

```sh
PSDIR=$(cygpath -w "$PWD/stage")
powershell.exe -NoProfile -Command \
"Compress-Archive -Path '$PSDIR\\gpredict-x86_64-w64-mingw32' -DestinationPath '$(cygpath -w "$PWD")\\gpredict-x86_64-w64-mingw32.zip'"
```

The result (~30 MB, GUI-subsystem exe with embedded icon) runs from
any folder on a stock Windows install, no installer or runtime
needed.

Background — what must end up where: the autotools install follows
the Linux FHS layout (`share/pixmaps/gpredict/maps`), but the Win32
code in `compat.c` (and the `win32/Makefile` packaging) expects the
pixmaps tree under `share/gpredict/pixmaps`. When staging from the
autotools install manually, place it accordingly, e.g.:

```sh
cp -rp /mingw64/share/pixmaps/gpredict /mingw64/share/gpredict/pixmaps
```

Then ship `bin/gpredict.exe` together with the required MinGW DLLs
(`ldd /mingw64/bin/gpredict.exe` lists them) plus `share/gpredict`
(data, pixmaps, TLE templates), `share/icons/Adwaita`, `share/locale`,
the gdk-pixbuf loaders under `lib/gdk-pixbuf-2.0` (with a regenerated
`loaders.cache`) and `gspawn-win*-helper.exe` next to the exe for
hyperlinks. `win32/Makefile`'s `dist` target automates exactly this
collection; mirror it if you script your own packaging.
21 changes: 21 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,26 @@ gpredict_SOURCES = \
##gpredict_LDADD = ./sgpsdp/libsgp4sdp4.a @PACKAGE_LIBS@
gpredict_LDADD = @PACKAGE_LIBS@

if MINGW
## GUI subsystem: double-clicking gpredict.exe must not open a console
## window; diagnostics go to the log file (win32/Makefile does the same).
gpredict_LDFLAGS = -mwindows
endif

if W32RES
## App icon + version info in the PE resources (Explorer/taskbar icon).
gpredict_res = gpredict.res
gpredict_LDADD += $(gpredict_res)
CLEANFILES = $(gpredict_res)
$(gpredict_res): $(top_srcdir)/win32/gpredict.rc \
$(top_srcdir)/win32/resource.h \
$(top_srcdir)/win32/icons/gpredict-icon.ico
$(WINDRES) $(AM_RCFLAGS) \
--define VERMAJ=$(VERMAJ) --define VERMIN=$(VERMIN) \
--define VERBLD=$(VERBLD) \
--include-dir=$(top_srcdir)/win32 --output-format=coff \
--input=$(top_srcdir)/win32/gpredict.rc --output=$@
endif

## $(INTLLIBS)

8 changes: 4 additions & 4 deletions src/gtk-rig-ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#endif

#define _GNU_SOURCE
#include <string.h> /* strcasestr */
#include <string.h>

#include <gdk/gdkkeysyms.h>
#include <glib.h>
Expand All @@ -45,7 +45,7 @@
#include <math.h>

/* NETWORK */
#ifndef WIN32
#ifndef _WIN32
#include <arpa/inet.h> /* htons() */
#include <netdb.h> /* gethostbyname() */
#include <netinet/in.h> /* struct sockaddr_in */
Expand Down Expand Up @@ -1066,7 +1066,7 @@ static void filter_text_changed_cb(GtkSearchEntry *entry, gpointer data)
for (i = 0; i < n; i++)
{
sat = SAT(g_slist_nth_data(ctrl->sats, i));
if (sat && strcasestr(sat->nickname, filter))
if (sat && gpredict_strcasestr(sat->nickname, filter))
{
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(ctrl->SatSel),
sat->nickname);
Expand Down Expand Up @@ -2924,7 +2924,7 @@ static gboolean close_rigctld_socket(gint *sock)
sat_log_log(SAT_LOG_LEVEL_ERROR, _("%s:%s: Sent 2 bytes but sent %d."),
__FILE__, __func__, written);
}
#ifndef WIN32
#ifndef _WIN32
shutdown(*sock, SHUT_RDWR);
close(*sock);
#else
Expand Down
Loading