Search code examples
yoctobitbakeopenembedded

native package refuses to place libraries in the sysroot folder


I have a package (openssl) that must be built for the host and the target. It creates some .so and .a libraries that some other packages need for runtime and compilation time respectively.

When I compile this package for the target everything works fine and every file ends up in the place I tell it to go, but when I compile for the host (${PN}-native target) it just doesn't put the libraries in the host sysroot directory (./build/tmp/sysroot/x86_64-linux).

This is the recipe:

SUMMARY = "Secure Socket Layer"
SECTION = "libs/network"
LICENSE = "openssl"
LIC_FILES_CHKSUM = "file://LICENSE;md5=4004583eb8fb7f89"

branch = "yocto"
SRC_URI = "git://www.myserver.com/openssl.git;protocol=ssh;branch=${branch}"
SRCREV = "${AUTOREV}"
S = "${WORKDIR}/git"

BBCLASSEXTEND += "native nativesdk"

# This is because I am porting this package from other project and I can't modify it.
FILES_${PN} += "${libdir}/libssl.so ${base_libdir}/libcrypto.so"
FILES_SOLIBSDEV = ""

do_compile() {
    ${MAKE}
}

do_install() {
    DESTDIR=${D} ${MAKE} install
}

Could anyone let me know what I am doing wrong? Thanks in advance


Solution

  • Ok, I know what the problem is:

    It seems like for native recipes, you have to install it using the full path to your host sysroot inside the image folder. This means that when compiling for the target, the image folder looks like this:

    $ tree -d
    /openssl/1.0.0-r0/image
    ├── lib
    └── usr
        ├── include
        │   └── openssl
        └── lib
    

    but for the host, it looks like this in my case:

    $ tree -d
    openssl-native/1.0.0-r0/image
    └── home
        └── xnor
            └── yocto
                └── build
                    └── tmp
                        └── sysroots
                            └── x86_64-linux
                                ├── lib
                                └── usr
                                    ├── include
                                    │   └── openssl
                                    └── lib
    

    EDIT The right solution is to modify the Makefile to take ${prefix}, ${bindir}, ${libdir}, etc. from the environment instead of hardcoding those paths in the Makefile. In my case this is not possible because of the project requirements, so I have to do this:

    SUMMARY = "Secure Socket Layer"
    SECTION = "libs/network"
    LICENSE = "openssl"
    LIC_FILES_CHKSUM = "file://LICENSE;md5=4004583eb8fb7f89"
    
    branch = "yocto"
    SRC_URI = "git://www.myserver.com/openssl.git;protocol=ssh;branch=${branch}"
    SRCREV = "${AUTOREV}"
    S = "${WORKDIR}/git"
    
    BBCLASSEXTEND += "native nativesdk"
    
    # This is because I am porting this package from other project and I can't modify it.
    FILES_${PN} += "${libdir}/libssl.so ${base_libdir}/libcrypto.so"
    FILES_SOLIBSDEV = ""
    
    do_compile() {
        ${MAKE}
    }
    
    do_install() {
        # The change is here!
        DESTDIR=${D}${base_prefix} ${MAKE} install
    }
    

    and as you can imagine, ${base_prefix} expands to "/home/xnor/yocto/build/tmp/sysroots/x86_64-linux/" for the host (openssl-native) recipe and to "" for the target (openssl).