|
| 1 | +# Makefile for building FuseX third-party libraries on Windows (MSYS2 MinGW-w64). |
| 2 | +# Run from MSYS2 "MinGW 64-bit" shell: cd 3rdparty && make |
| 3 | + |
| 4 | +SCRIPT_DIR := $(CURDIR) |
| 5 | +DIST_PREFIX := $(SCRIPT_DIR)/dist |
| 6 | + |
| 7 | +export PKG_CONFIG_PATH := $(DIST_PREFIX)/lib/pkgconfig:$(PKG_CONFIG_PATH) |
| 8 | + |
| 9 | +RED := \033[0;31m |
| 10 | +GREEN := \033[0;32m |
| 11 | +YELLOW := \033[1;33m |
| 12 | +NC := \033[0m |
| 13 | + |
| 14 | +# Optional audiofile: only the legacy `audiofile-patched/` tree (from zip), not the |
| 15 | +# submodule path, so default Windows deps stay minimal and build with current GCC. |
| 16 | +AUDIOFILE_SRC := $(shell if [ -d "audiofile-patched" ]; then echo "audiofile-patched"; else echo ""; fi) |
| 17 | + |
| 18 | +.PHONY: all clean distclean libspectrum audiofile libxml2 mbedtls check-tools check-libspectrum extract-audiofile extract-libxml2 libspectrum-with-audiofile |
| 19 | + |
| 20 | +# Default: libspectrum (+ optional libxml2 / mbedtls if present). |
| 21 | +all: check-tools check-libspectrum dist-dirs libspectrum |
| 22 | + @if [ -d "libxml2-2.9.12" ] || [ -f "libxml2-2.9.12.tar.gz" ]; then \ |
| 23 | + $(MAKE) libxml2; \ |
| 24 | + fi |
| 25 | + @if [ -d "mbedtls/src" ] && [ -f "mbedtls/src/Makefile" ]; then \ |
| 26 | + $(MAKE) mbedtls; \ |
| 27 | + fi |
| 28 | + @echo "" |
| 29 | + @echo "$(GREEN)=== Library build complete! ===$(NC)" |
| 30 | + @echo "" |
| 31 | + @echo "Libraries installed to: $(DIST_PREFIX)" |
| 32 | + @echo " - DLLs: $(DIST_PREFIX)/bin/" |
| 33 | + @echo " - Headers: $(DIST_PREFIX)/include/" |
| 34 | + @echo " - pkg-config: $(DIST_PREFIX)/lib/pkgconfig/" |
| 35 | + @echo "" |
| 36 | + @echo "Built libraries:" |
| 37 | + @echo " ✓ libspectrum" |
| 38 | + @if [ -n "$(AUDIOFILE_SRC)" ]; then echo " ✓ audiofile"; fi |
| 39 | + @if [ -d "libxml2-2.9.12" ]; then echo " ✓ libxml2"; fi |
| 40 | + @if [ -d "mbedtls/src" ] && [ -f "mbedtls/src/Makefile" ]; then echo " ✓ mbedtls"; fi |
| 41 | + @echo "" |
| 42 | + @echo "You can now run ./build_win32.sh from the repository root." |
| 43 | + |
| 44 | +dist-dirs: |
| 45 | + @mkdir -p $(DIST_PREFIX)/bin |
| 46 | + @mkdir -p $(DIST_PREFIX)/lib/pkgconfig |
| 47 | + @mkdir -p $(DIST_PREFIX)/include |
| 48 | + @echo "$(GREEN)Using local dist prefix: $(DIST_PREFIX)$(NC)" |
| 49 | + |
| 50 | +check-tools: |
| 51 | + @echo "$(GREEN)Checking for required tools...$(NC)" |
| 52 | + @for tool in gcc make pkg-config; do \ |
| 53 | + if ! command -v $$tool >/dev/null 2>&1; then \ |
| 54 | + echo "$(RED)Error: $$tool is not installed$(NC)"; \ |
| 55 | + echo "Install with: pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-make mingw-w64-x86_64-pkg-config"; \ |
| 56 | + exit 1; \ |
| 57 | + fi; \ |
| 58 | + echo " ✓ $$tool found"; \ |
| 59 | + done |
| 60 | + |
| 61 | +check-libspectrum: |
| 62 | + @echo "" |
| 63 | + @echo "$(GREEN)Checking for libspectrum...$(NC)" |
| 64 | + @if [ ! -d "libspectrum" ]; then \ |
| 65 | + echo "$(YELLOW)libspectrum submodule missing; initializing from repo root...$(NC)"; \ |
| 66 | + cd .. && git submodule update --init --recursive 3rdparty/libspectrum && cd 3rdparty; \ |
| 67 | + fi |
| 68 | + |
| 69 | +extract-audiofile: |
| 70 | + @if [ -f "audiofile-patched.zip" ] && [ ! -d "audiofile-patched" ]; then \ |
| 71 | + echo "$(GREEN)Extracting audiofile-patched.zip...$(NC)"; \ |
| 72 | + unzip -q audiofile-patched.zip; \ |
| 73 | + fi |
| 74 | + |
| 75 | +extract-libxml2: |
| 76 | + @if [ -f "libxml2-2.9.12.tar.gz" ] && [ ! -d "libxml2-2.9.12" ]; then \ |
| 77 | + echo "$(GREEN)Extracting libxml2...$(NC)"; \ |
| 78 | + tar -xzf libxml2-2.9.12.tar.gz; \ |
| 79 | + fi |
| 80 | + |
| 81 | +libspectrum: dist-dirs check-libspectrum |
| 82 | + @echo "" |
| 83 | + @echo "$(GREEN)Building libspectrum (required)...$(NC)" |
| 84 | + @cd libspectrum && \ |
| 85 | + if [ -f Makefile ]; then \ |
| 86 | + $(MAKE) distclean || true; \ |
| 87 | + fi && \ |
| 88 | + if [ ! -f configure ]; then \ |
| 89 | + ./autogen.sh; \ |
| 90 | + fi && \ |
| 91 | + ./configure --with-fake-glib --without-libaudiofile --without-libgcrypt \ |
| 92 | + --without-zlib --without-bzip2 --prefix="$(DIST_PREFIX)" && \ |
| 93 | + $(MAKE) && \ |
| 94 | + $(MAKE) install |
| 95 | + |
| 96 | +audiofile: extract-audiofile |
| 97 | + @afdir="$(AUDIOFILE_SRC)"; \ |
| 98 | + if test -z "$$afdir" && test -d audiofile-patched; then afdir=audiofile-patched; fi; \ |
| 99 | + if test -n "$$afdir"; then \ |
| 100 | + echo ""; \ |
| 101 | + echo "$(GREEN)Building audiofile (optional)...$(NC)"; \ |
| 102 | + cd "$$afdir" && \ |
| 103 | + if [ -f Makefile ]; then \ |
| 104 | + $(MAKE) distclean || true; \ |
| 105 | + fi && \ |
| 106 | + if [ ! -f configure ]; then \ |
| 107 | + ./autogen.sh --disable-static --disable-flac --disable-docs --disable-examples; \ |
| 108 | + fi && \ |
| 109 | + ./configure --disable-static --disable-flac --disable-docs --disable-examples --prefix="$(DIST_PREFIX)" && \ |
| 110 | + $(MAKE) && \ |
| 111 | + $(MAKE) install-strip; \ |
| 112 | + fi |
| 113 | + |
| 114 | +libspectrum-with-audiofile: audiofile |
| 115 | + @echo "" |
| 116 | + @echo "$(GREEN)Rebuilding libspectrum with audiofile...$(NC)" |
| 117 | + @cd libspectrum && \ |
| 118 | + $(MAKE) distclean || true && \ |
| 119 | + ./autogen.sh && \ |
| 120 | + ./configure --with-fake-glib --with-libaudiofile --without-libgcrypt \ |
| 121 | + --without-zlib --without-bzip2 --prefix="$(DIST_PREFIX)" && \ |
| 122 | + $(MAKE) && \ |
| 123 | + $(MAKE) install |
| 124 | + |
| 125 | +libxml2: extract-libxml2 |
| 126 | + @if [ -d "libxml2-2.9.12" ]; then \ |
| 127 | + echo ""; \ |
| 128 | + echo "$(GREEN)Building libxml2 (optional)...$(NC)"; \ |
| 129 | + cd libxml2-2.9.12 && \ |
| 130 | + if [ -f Makefile ]; then \ |
| 131 | + $(MAKE) distclean || true; \ |
| 132 | + fi && \ |
| 133 | + ./configure --disable-static --without-iconv --without-python --without-lzma --prefix="$(DIST_PREFIX)" && \ |
| 134 | + $(MAKE) && \ |
| 135 | + $(MAKE) install-strip; \ |
| 136 | + fi |
| 137 | + |
| 138 | +mbedtls: |
| 139 | + @if [ -d "mbedtls/src" ] && [ -f "mbedtls/src/Makefile" ]; then \ |
| 140 | + echo ""; \ |
| 141 | + echo "$(GREEN)Building mbedtls (optional)...$(NC)"; \ |
| 142 | + cd mbedtls/src && \ |
| 143 | + if [ -f library/Makefile ]; then \ |
| 144 | + $(MAKE) clean || true; \ |
| 145 | + fi && \ |
| 146 | + $(MAKE) WINDOWS=1 SHARED=1 no_test && \ |
| 147 | + mkdir -p "$(DIST_PREFIX)/include/mbedtls" && \ |
| 148 | + cp -rp include/mbedtls/* "$(DIST_PREFIX)/include/mbedtls/" && \ |
| 149 | + mkdir -p "$(DIST_PREFIX)/lib" && \ |
| 150 | + mkdir -p "$(DIST_PREFIX)/bin" && \ |
| 151 | + cd library && \ |
| 152 | + for lib in libmbedtls libmbedx509 libmbedcrypto; do \ |
| 153 | + if [ -f "$$lib.a" ]; then cp -f "$$lib.a" "$(DIST_PREFIX)/lib/" || true; fi; \ |
| 154 | + if [ -f "$$lib.dll.a" ]; then cp -f "$$lib.dll.a" "$(DIST_PREFIX)/lib/" || true; fi; \ |
| 155 | + if [ -f "$$lib.dll" ]; then cp -f "$$lib.dll" "$(DIST_PREFIX)/bin/" || true; fi; \ |
| 156 | + done; \ |
| 157 | + fi |
| 158 | + |
| 159 | +clean: |
| 160 | + @echo "$(YELLOW)Cleaning build artifacts...$(NC)" |
| 161 | + @if [ -d "libspectrum" ] && [ -f "libspectrum/Makefile" ]; then \ |
| 162 | + cd libspectrum && $(MAKE) distclean || true; \ |
| 163 | + fi |
| 164 | + @if [ -n "$(AUDIOFILE_SRC)" ] && [ -f "$(AUDIOFILE_SRC)/Makefile" ]; then \ |
| 165 | + cd "$(AUDIOFILE_SRC)" && $(MAKE) distclean || true; \ |
| 166 | + fi |
| 167 | + @if [ -d "audiofile-patched" ] && [ -f "audiofile-patched/Makefile" ]; then \ |
| 168 | + cd audiofile-patched && $(MAKE) distclean || true; \ |
| 169 | + fi |
| 170 | + @if [ -d "libxml2-2.9.12" ] && [ -f "libxml2-2.9.12/Makefile" ]; then \ |
| 171 | + cd libxml2-2.9.12 && $(MAKE) distclean || true; \ |
| 172 | + fi |
| 173 | + @if [ -d "mbedtls/src" ] && [ -f "mbedtls/src/library/Makefile" ]; then \ |
| 174 | + cd mbedtls/src && $(MAKE) clean || true; \ |
| 175 | + fi |
| 176 | + |
| 177 | +distclean: clean |
| 178 | + @echo "$(YELLOW)Removing dist directory...$(NC)" |
| 179 | + @rm -rf $(DIST_PREFIX) |
0 commit comments