autotools project libssh2 porting with libmbedtls

Post Reply
dza
Posts: 3
Joined: Sat Aug 08, 2020 5:40 am

autotools project libssh2 porting with libmbedtls

Post by dza » Sun Aug 09, 2020 2:58 am

I've been searching everywhere for this and recognize I must be doing something wrong, possibly related to LDFLAGS missing a "-Wl" parameter or so trying the autotools route? I've tried searching for clues in all other projects. The modules included `-lmbedtls -lmbedx509 -lmbedcrypto` and the order before `-lnx` doesn't make much difference.

Trying to build libssh2 https://github.com/libssh2/libssh2

Error(make):

Code: Select all

  CC       ssh2.o
  CCLD     ssh2
/opt/devkitpro/devkitA64/bin/../lib/gcc/aarch64-none-elf/10.2.0/../../../../aarch64-none-elf/bin/ld: /opt/devkitpro/portlibs/switch/lib/libmbedcrypto.a(entropy.c.obj): in function `mbedtls_hardware_poll':
entropy.c:(.text.mbedtls_hardware_poll+0x1c): undefined reference to `csrngGetRandomBytes'
switchvars.sh: modified with 2 lines in the bottom

Code: Select all

export PORTLIBS_PREFIX=${DEVKITPRO}/portlibs/switch
export PATH=$PORTLIBS_PREFIX/bin:$PATH

export ARCH="-march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIC -ftls-model=local-exec"
export CFLAGS="${ARCH} -O2 -ffunction-sections -fdata-sections"
export CXXFLAGS="${CFLAGS}"
export CPPFLAGS="-D__SWITCH__ -I${PORTLIBS_PREFIX}/include -isystem${DEVKITPRO}/libnx/include"
export LDFLAGS="${ARCH} -L${PORTLIBS_PREFIX}/lib -L${DEVKITPRO}/libnx/lib"

export DEVKITPRO=/opt/devkitpro
export PORTLIBS_ROOT=${DEVKITPRO}/portlibs
export PATH=${DEVKITPRO}/tools/bin:${DEVKITPRO}/devkitA64/bin:$PATH
export TOOL_PREFIX=aarch64-none-elf-
export AR=${TOOL_PREFIX}gcc-ar
export RANLIB=${TOOL_PREFIX}gcc-ranlib

# modified/added
export CC="/opt/devkitpro/devkitA64/bin/aarch64-none-elf-gcc"
export LIBS="-L/opt/devkitpro/libnx/lib -L/opt/devkitpro/portlibs/switch/lib -lmbedtls -lmbedx509 -lmbedcrypto -lnx"
./configure

Code: Select all

./configure --enable-static=no --enable-shared=no --host=arm-none-eabi --with-crypto=mbedtls --with-libmbedcrypto-prefix=/opt/devkitpro/portlibs/switch --includedir=/opt/devkitpro/portlibs/switch/include
I appreciate you taking your time. I love the work the switch homebrew community has done! Thank you!

WinterMute
Site Admin
Posts: 1845
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: autotools project libssh2 porting with libmbedtls

Post by WinterMute » Mon Aug 10, 2020 8:08 pm

You shouldn't modify the provided helper scripts, you'll end up with a system that no longer matches the standard toolchain setup which will, unless you upstream suitable changes, make it more difficult to troubleshoot any problems you have. You should use bash or at least something closely compatible when dealing with autotools based projects since that is what the autotools machinery is written to work under. It's also good practice to create a build directory if possible but many projects are unfortunately designed to run configure directly. You should source switchvars.sh which will import the variables to your current shell. Running the script directly will pretty much do nothing useful

Your configure line is wrong. You're using the wrong switches to build a static library, using the wrong host tuplet and manually specifying paths and libraries that should be picked up by the configure script.

The correct configure parameters should be something like :-

Code: Select all

LIBS=-lnx ./configure --disable-shared --enable-static \
	--host=aarch64-none-elf \
	--with-crypto=mbedtls \
	--disable-examples-build
If you can disable building of example code in this environment then you always should. It generally assumes a host with an OS that can run the binaries directly and this is not the case when cross building binaries with newlib based tools.

This may not work properly yet. If the configure step fails then you should find out what the issue is by looking at configure.log which should show you any error messages. I don't want to do the whole thing for you at this point since running through these steps is a useful learning exercise for both of us.
Help keep devkitPro toolchains free, Donate today

Personal Blog

dza
Posts: 3
Joined: Sat Aug 08, 2020 5:40 am

Re: autotools project libssh2 porting with libmbedtls

Post by dza » Mon Aug 10, 2020 8:26 pm

I appreciate the response that cleared out some confusion!

I figured out the Makefile puts

Code: Select all

-lmbedcrypto
after anything specified with environment variables it seems, so overriding it on the make command works.

configure does not have any

Code: Select all

--disable-shared
but I corrected it as it was supposed to be enabled as you pointed out, which I read later!

These are my updated files

switchvars.sh (modified)

Code: Select all

export PORTLIBS_PREFIX=${DEVKITPRO}/portlibs/switch
export PATH=$PORTLIBS_PREFIX/bin:$PATH

export ARCH="-march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIC -ftls-model=local-exec"
export CFLAGS="${ARCH} -O2 -ffunction-sections -fdata-sections"
export CXXFLAGS="${CFLAGS}"
export CPPFLAGS="-D__SWITCH__ -I${PORTLIBS_PREFIX}/include -isystem${DEVKITPRO}/libnx/include"
export LDFLAGS="${ARCH} -L${PORTLIBS_PREFIX}/lib -L${DEVKITPRO}/libnx/lib"


#!/usr/bin/env bash
export DEVKITPRO=/opt/devkitpro
export PORTLIBS_ROOT=${DEVKITPRO}/portlibs
export PATH=${DEVKITPRO}/tools/bin:${DEVKITPRO}/devkitA64/bin:$PATH
export TOOL_PREFIX=aarch64-none-elf-
export AR=${TOOL_PREFIX}gcc-ar
export RANLIB=${TOOL_PREFIX}gcc-ranlib

# modified/added
export CC="/opt/devkitpro/devkitA64/bin/aarch64-none-elf-gcc"
./configure

Code: Select all

./configure --enable-shared=no --host=aarch64-none-elf --with-crypto=mbedtls && make LIBS="-lmbedcrypto -lnx"

And make now runs successfully. I will try to make a sample program now.

WinterMute
Site Admin
Posts: 1845
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: autotools project libssh2 porting with libmbedtls

Post by WinterMute » Mon Aug 10, 2020 10:50 pm

No. You're still doing it wrong. I just tried building the library locally and it works completely fine with the configure parameters I specified and no modifications to any other files. This is even a library that builds fine from a separate directory. See attached build log. The configure very definitely has a --disable-shared, why do you think it doesn't?

Please revert the changes you made to switchvars.sh, manual editing of toolchain files can and will cause you difficult to troubleshoot issues. You can simply run (sudo) (dkp-)pacman -S devkitpro-pkgbuild-helpers depending on your host & how pacman is provided.
Attachments
libssh2-switch-build.log
(11.12 KiB) Downloaded 358 times
Help keep devkitPro toolchains free, Donate today

Personal Blog

dza
Posts: 3
Joined: Sat Aug 08, 2020 5:40 am

Re: autotools project libssh2 porting with libmbedtls

Post by dza » Tue Aug 11, 2020 1:55 am

Image

I got it all to work!

I appreciate your help, really! This is all very new to me.

I will try your commandline now and reset switchvars.sh to see if I can do like you.

Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests