1#!/bin/sh -eux 2 3# Copyright (c) 2022-2023 Yubico AB. All rights reserved. 4# Use of this source code is governed by a BSD-style 5# license that can be found in the LICENSE file. 6# SPDX-License-Identifier: BSD-2-Clause 7 8# XXX defining CC and cross-compiling confuses OpenSSL's build. 9unset CC 10 11sudo mkdir /fakeroot 12sudo chmod 755 /fakeroot 13 14cat << EOF > /tmp/mingw.cmake 15SET(CMAKE_SYSTEM_NAME Windows) 16SET(CMAKE_C_COMPILER i686-w64-mingw32-gcc) 17SET(CMAKE_CXX_COMPILER i686-w64-mingw32-g++) 18SET(CMAKE_RC_COMPILER i686-w64-mingw32-windres) 19SET(CMAKE_FIND_ROOT_PATH /fakeroot) 20SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 21SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 22SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 23EOF 24 25# Build and install libcbor. 26git clone --depth=1 https://github.com/pjk/libcbor -b v0.10.1 27cd libcbor 28mkdir build 29(cd build && cmake -DCMAKE_TOOLCHAIN_FILE=/tmp/mingw.cmake \ 30 -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=/fakeroot ..) 31make -j"$(nproc)" -C build 32sudo make -C build install 33cd .. 34 35# Build and install OpenSSL 3.0.11. 36git clone --branch openssl-3.0.12 \ 37 --depth=1 https://github.com/openssl/openssl 38cd openssl 39./Configure mingw --prefix=/fakeroot --openssldir=/fakeroot/openssl \ 40 --cross-compile-prefix=i686-w64-mingw32- --libdir=lib 41make -j"$(nproc)" 42sudo make install_sw 43cd .. 44 45# Build and install zlib. 46git clone --depth=1 https://github.com/madler/zlib -b v1.3 47cd zlib 48make -fwin32/Makefile.gcc PREFIX=i686-w64-mingw32- 49sudo make -fwin32/Makefile.gcc PREFIX=i686-w64-mingw32- DESTDIR=/fakeroot \ 50 INCLUDE_PATH=/include LIBRARY_PATH=/lib BINARY_PATH=/bin install 51cd .. 52 53# Build and install libfido2. 54export PKG_CONFIG_PATH=/fakeroot/lib/pkgconfig 55mkdir build 56(cd build && cmake -DCMAKE_TOOLCHAIN_FILE=/tmp/mingw.cmake \ 57 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/fakeroot ..) 58make -C build 2>&1 59sudo make -C build install 60