xref: /freebsd/contrib/libfido2/.actions/build-linux-i686-w64-mingw32-gcc (revision a0ca4af9455b844c5e094fc1b09b1390ffa979fc)
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 1.1.1w.
36git clone --depth=1 https://github.com/openssl/openssl -b OpenSSL_1_1_1w
37cd openssl
38./Configure mingw --prefix=/fakeroot --openssldir=/fakeroot/openssl \
39	--cross-compile-prefix=i686-w64-mingw32-
40make -j"$(nproc)"
41sudo make install_sw
42cd ..
43
44# Build and install zlib.
45git clone --depth=1 https://github.com/madler/zlib -b v1.3
46cd zlib
47make -fwin32/Makefile.gcc PREFIX=i686-w64-mingw32-
48sudo make -fwin32/Makefile.gcc PREFIX=i686-w64-mingw32- DESTDIR=/fakeroot \
49	INCLUDE_PATH=/include LIBRARY_PATH=/lib BINARY_PATH=/bin install
50cd ..
51
52# Build and install libfido2.
53export PKG_CONFIG_PATH=/fakeroot/lib/pkgconfig
54mkdir build
55(cd build && cmake -DCMAKE_TOOLCHAIN_FILE=/tmp/mingw.cmake \
56	-DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/fakeroot ..)
57make -j"$(nproc)" -C build
58sudo make -C build install
59