From 8fec8a09152e21eac1e89a225a130bfa9be0a674 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 23 Apr 2022 01:35:02 +0200 Subject: [PATCH] [ mingw ] build script and doc --- build.sh | 212 ++++++++++++++++++++++++++++++++++++++++++++ build_win64.sh | 50 ----------- doc/cross_mingw.txt | 121 ++++++++++++++++++++----- test/hello.html | 5 ++ 4 files changed, 316 insertions(+), 72 deletions(-) create mode 100755 build.sh delete mode 100755 build_win64.sh create mode 100644 test/hello.html diff --git a/build.sh b/build.sh new file mode 100755 index 00000000..da97847e --- /dev/null +++ b/build.sh @@ -0,0 +1,212 @@ +#!/bin/bash +# +# shell script to build static elinks +# for differenct architectures with +# the same configuration +# + +clear + +echo ' --/ \--' +echo ' --[ Welcome to the elinks build helper ]--' +echo ' --[ ]--' +echo ' --[ [*] select the architecture 1-4 ]--' +echo ' --[ [*] use option 5 for config ]--' +echo ' --[ [*] use option 6 for make ]--' +echo ' --[ [*] use option 7 for test ]--' +echo ' --[ [*] use option 8 for publishing ]--' +echo ' --\ /--' +echo ' ' + +gen_conf() { + ./autogen.sh +} + +configure() { + echo "--[ Configure starts in 2 seconds ]--" + echo "--[ Compiler: " $1 "]--" + echo "--[ Host : " $2 "]--" + sleep 2 + rm -f config.cache + time \ + CC=$1 \ + LD=$2 \ + LIBS=$5 \ + CFLAGS="-g -no-pie -std=c99" \ + LDFLAGS=$4 \ + PKG_CONFIG="./pkg-config.sh" \ + ./configure -C \ + --host=$3 \ + --prefix=/usr \ + --enable-256-colors \ + --enable-fastmem \ + --with-static \ + --enable-utf-8 \ + --without-openssl \ + --without-quickjs \ + --disable-88-colors \ + --disable-backtrace \ + --disable-bittorrent \ + --disable-debug \ + --disable-cgi \ + --disable-combining \ + --disable-gopher \ + --disable-nls \ + --disable-ipv6 \ + --disable-sm-scripting \ + --disable-true-color \ + --without-bzlib \ + --without-brotli \ + --without-gnutls \ + --without-libev \ + --without-libevent \ + --without-lzma \ + --without-perl \ + --without-python \ + --without-ruby \ + --without-terminfo \ + --without-zlib \ + --without-zstd \ + --without-x + if [ $? -eq 0 ]; then + echo "--[ Configuration Sucessfull ]--" + # turn off warnings + sed -i 's/-Wall/-w/g' Makefile.config + #sed -i 's/-lpthread/-pthread/g' Makefile.config + build + else + echo "--[ Configuration failed... ]--" + fi +} + +# BUILD FUNCTION +build() { + echo "--[ Build starts in 2 seconds ]--" + sleep 2 + time make # --trace + if [ $? -eq 0 ]; then + echo "--[ ................ ]--" + echo "--[ Build Sucessfull ]--" + echo "--[ All Done. ]--" + echo "--[ ................ ]--" + else + echo "--[ Build failed... ]--" + fi +} + +test() { + # + # very basic to test binary + # won't core dump + # + # for arm32: qemu-arm-static + # for win64: wine + # + ./src/elinks$1 \ + --no-connect \ + --dump \ + ./test/hello.html +} + +pub() { + ls -l ./src/elinks$1 + file ./src/elinks$1 + if [ ! -d ../bin ]; then + mkdir ../bin + fi + cp ./src/elinks$1 ../bin/elinks_$2$1 + echo "--[ File Published to ../bin ]--" +} + +info() { + echo "--[ binary info ]--" + file ./src/elinks$1 + ls -lh ./src/elinks$1 + ls -l ./src/elinks$1 +} + +set_arch() { + if [ "$1" = "lin64" ]; then + ARCHIT="$1" + CC="x86_64-linux-gnu-gcc" + LD="x86_64-linux-gnu-ld" + MAKE_HOST="x86_64-linux-gnu" + BIN_SUFFIX="" + LDFLAGS="" + LIBS="" + elif [ "$1" = "win64" ]; then + ARCHIT="$1" + CC="x86_64-w64-mingw32-gcc" + LD="x86_64-w64-mingw32-ld" + MAKE_HOST="x86_64-w64-mingw32" + BIN_SUFFIX=".exe" + LDFLAGS="" + LIBS="" + elif [ "$1" = "arm32" ]; then + ARCHIT="$1" + CC="arm-linux-gnueabihf-gcc" + LD="arm-linux-gnueabihf-ld" + MAKE_HOST="arm-linux-gnu" + BIN_SUFFIX="" + LDFLAGS="" + LIBS="-L../../lib/$ARCHIT" + elif [ "$1" = "native" ]; then + ARCHIT="$1" + CC="gcc" + LD="ld" + MAKE_HOST="" + BIN_SUFFIX="" + LDFLAGS="" + LIBS="" + fi +} + +# MAIN LOOP +ARCHIT="" +BIN_SUFFIX="" +ARCHS="lin64 win64 arm32" +CC_SEL="lin64 win64 arm32 native \ +config make test \ +pub debug \ +info \ +build_all \ +exit" +set_arch native +select SEL in $CC_SEL; do + if [ "$SEL" = "lin64" ]; then + set_arch lin64 + elif [ "$SEL" = "win64" ]; then + set_arch win64 + elif [ "$SEL" = "arm32" ]; then + set_arch arm32 + elif [ "$SEL" = "native" ]; then + set_arch native + elif [ "$SEL" = "make" ]; then + build + elif [ "$SEL" = "config" ]; then + configure "$CC" "$LD" "$MAKE_HOST" "$LDFLAGS" "$LIBS" + elif [ "$SEL" = "test" ]; then + test $BIN_SUFFIX + elif [ "$SEL" = "pub" ]; then + pub "$BIN_SUFFIX" "$ARCHIT" + elif [ "$SEL" = "debug" ]; then + gdb ./src/elinks$BIN_SUFFIX + elif [ "$SEL" = "info" ]; then + info "$BIN_SUFFIX" + elif [ "$SEL" = "build_all" ]; then + #set -f # avoid globbing (expansion of *). + arch_arr=($ARCHS) + for arch in "${arch_arr[@]}"; do + echo "--[ Building: $arch ]--" + set_arch "$arch" + configure "$CC" "$LD" "$MAKE_HOST" "$LDFLAGS" "$LIBS" + build + info "$BIN_SUFFIX" + pub "$BIN_SUFFIX" "$ARCHIT" + done + elif [ "$SEL" = "exit" ]; then + exit + fi + echo "--[ Compiler: " $CC " ]--" + echo "--[ Host : " $MAKE_HOST " ]--" +done diff --git a/build_win64.sh b/build_win64.sh deleted file mode 100755 index 2c3bf1c5..00000000 --- a/build_win64.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/sh -# -# WIndows x64 elinks cross-compilation -# - -./autogen.sh - -CC=x86_64-w64-mingw32-gcc \ -LD=x86_64-w64-mingw32-ld \ -CFLAGS="-g -static -no-pie" \ -PKG_CONFIG="./pkg-config.sh" \ -./configure -C \ ---host=x86_64-w64-mingw32 \ ---enable-static \ ---without-brotli \ ---enable-utf-8 \ ---enable-256-colors \ ---without-quickjs \ ---without-lzma \ ---disable-gopher \ ---without-bzlib \ ---without-zlib \ ---disable-backtrace \ ---without-openssl \ ---disable-debug \ ---enable-fastmem \ ---without-perl \ ---disable-88-colors \ ---disable-true-color \ ---prefix=/usr \ ---disable-combining \ ---disable-bittorrent \ ---without-gnutls \ ---without-libev \ ---without-libevent \ ---without-terminfo \ ---disable-cgi \ ---without-ruby \ ---disable-sm-scripting \ ---without-python \ ---without-zstd \ ---without-x \ ---disable-nls -if [ $? = 0 ]; then - sed -i 's/-Wall/-w/g' Makefile.config - make -else - print config failed -fi - diff --git a/doc/cross_mingw.txt b/doc/cross_mingw.txt index 55861eca..55c7e58d 100644 --- a/doc/cross_mingw.txt +++ b/doc/cross_mingw.txt @@ -1,24 +1,28 @@ - --[ HOWTO CROSS-COMPILE ELINKS FOR WIN64 ]-- - + --| |-- + --[ HOWTO CROSS-COMPILE ELINKS ]-- + --| |-- + --[ FOR LIN64, WIN64 AND ARM32 ]-- + --| |-- + --= 2022 04 22 =-- + --| |-- + Hello All, -so it could be annoying to get elinks compiled -on Windows. Or Arm or just different architecture -than Linux. +so it could be annoying to get elinks compiled on Windows. +Or Arm or just different architecture than Linux. -if You'd like to do that there is a solution. And -that's mingw. You can cross-compile on Linux for -Windows etc. +if You'd like to do that there is a solution. And that's +mingw. You can cross-compile on Linux for Windows or Arm +CPU. -Now I'll assume You'd want to compile Windows x64 -binary on Linux. There is a script I provide. it's -build_win64.sh. It would create static binary for -Windows. +Now I'll assume You'd want to compile Windows x64 binary on +Linux. There is a script I provide. it's build.sh. It would +create static binary for arm, win or lin. -On Debian You'd use x86_64-w64-mingw32-gcc or rather -the mingw toolchain. It's usage it's quite straight -forward just use it as environment variable: +On Debian You'd use x86_64-w64-mingw32-gcc or rather the +mingw toolchain. It's usage it's quite straight forward just +use it as environment variable: CC=x86_64-w64-mingw32-gcc @@ -26,16 +30,89 @@ and to prepare the compilation configuration add: --host=x86_64-w64-mingw32 -parameter to configure.. +parameter to configure. -And that's it. With the script You'll get the very -basic binary for Windows. It could be run, it would -open simple http pages. The support for the terminal -is not very good. So I would advise You to use -environment variable TERM and set it to dumb. Like this: +And that's it. With the script You'll get the very basic +binary for Windows. It could be run, it would open simple +http pages. The support for the terminal is not very good. +So I would advise You to use environment variable TERM and +set it to dumb. Like this: set TERM=dumb -And that's it for today. +Some note on the testing environment. You of course obtain +several machines and test it. But Linux handles all the +emulation by itself. As I said here we assume You have +Debian 10 at hand. And it can provide several machines at +once as testing environment. +[*] Windows + +For Windows You can run it in qemu. There is plenty of +tutorials on the Net on HOWTO run Windows on it. Once You +have the Windows x64 system it's not really necessary to +open the graphical user interface. In the time of the +writting there is possibility to run openssh server on +it. To prepare the OpenSSH server just execute in admin +powershell: + + Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0 + + Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0 + + Start-Service sshd + + Set-Service -Name sshd -StartupType 'Automatic' + +You have to tune the firewall. And forward the port to the +localhost of the host machine from gues. After that You get +the command prompt. I'm using sshfs to mount the host +directory with the elinks sources so there is nothing +necessary to copy and You can compile on the Linux host and +execute binary on the Windows guest. + +Using GNU screen enables me to have 0-9 console screens. +Some of it are dedicated to the binaries building on the +Linux host and some one is ssh to the Windows guest and it's +prepared in the mounted sources directory via sshfs to +execute when compilation succeed. + +Other option is to use Wine but currently that doesn't +provide the natural feeling of dumb terminal (see above). + +[*] ARM CPU + +The other architecture is from different category. In time +of writting there is Raspberry Pi, Mobile Phones, NAS etc. +Shortly You can get ARM processor in many devices. And +sometimes it's handy to browse without much stress for the +CPU that makes the common Graphical Interface unusable. + +To compile the binary for ARM You can use MinGW analogically +to the Win architecture. I'd suggest following: + + CC=arm-linux-gnueabihf-gcc + LD=arm-linux-gnueabihf-ld + --build=arm-linux-gnu + +There are differences in the processors and currently the +64-bit ARM CPU's are out [ aarch64 ]. + +To test the binary You can emulate the raspberry pi in qemu +in the same manner as windows. In my case I've got qemu +running with the Raspbery Pi 2B emulation. I'm using sshfs +in the same manner and have it open on one of the GNU +screens. That makes the same efficiency in the terms of not +needing to have any other device at hand and still make the +basic tests of binaries correctness. + +There is one more option to run the arm binary. And that's +qemu's command qemu-arm-static: + + qemu-arm-static ./src/elinks + +Finally the qemu provides runtime emulation for static +binary without any need for additional disk space etc. + +Till Next Time diff --git a/test/hello.html b/test/hello.html new file mode 100644 index 00000000..7d8ba297 --- /dev/null +++ b/test/hello.html @@ -0,0 +1,5 @@ + + +Hello World! + +