Search code examples
cgcc4netbsd

How to build a cross compile NetBSD toolchain using NetBSD


I have a NetBSD VM that I created using qemu, and I am trying to compile a simple Hello World.c program with the cross compiled toolchain that I built using the build.sh script that comes with the NetBSD source. However, I can not get the program to compile.

I built the toolchain with the following commands,

./build.sh -m evbarm tools

./build.sh -m evbarm -U distribution

And the output from the above commands yields,

===> Tools built to /opt/cross/evbarm/usr/src/tooldir.NetBSD-4.0.1-i386
===> build.sh ended:   Sat Nov 28 12:52:34 CST 2015
===> Summary of results:
         build.sh command: ./build.sh -m evbarm tools
         build.sh started: Sat Nov 28 12:48:47 CST 2015
         NetBSD version:   4.0
         MACHINE:          evbarm
         MACHINE_ARCH:     arm
         Build platform:   NetBSD 4.0.1 i386
         HOST_SH:          /bin/sh
         No nonexistent/bin/nbmake, needs building.
         Bootstrapping nbmake
         TOOLDIR path:     /opt/cross/evbarm/usr/src/tooldir.NetBSD-4.0.1-i386
         DESTDIR path:     /opt/cross/evbarm/usr/src/destdir.evbarm
         RELEASEDIR path:  /opt/cross/evbarm/usr/src/releasedir
         Created /opt/cross/evbarm/usr/src/tooldir.NetBSD-4.0.1-i386/bin/nbmake
         makewrapper:      /opt/cross/evbarm/usr/src/tooldir.NetBSD-4.0.1-i386/bin/nbmake-evbarm
         Updated /opt/cross/evbarm/usr/src/tooldir.NetBSD-4.0.1-i386/bin/nbmake-evbarm
         Tools built to /opt/cross/evbarm/usr/src/tooldir.NetBSD-4.0.1-i386
         build.sh ended:   Sat Nov 28 12:52:34 CST 2015
===> .


make distribution started at:  Sat Nov 28 14:31:23 CST 2015
make distribution finished at: Sat Nov 28 15:04:34 CST 2015
===> Successful make distribution
===> build.sh ended:   Sat Nov 28 15:04:34 CST 2015
===> Summary of results:
         build.sh command: ./build.sh -m evbarm -U distribution
         build.sh started: Sat Nov 28 14:31:20 CST 2015
         NetBSD version:   4.0
         MACHINE:          evbarm
         MACHINE_ARCH:     arm
         Build platform:   NetBSD 4.0.1 i386
         HOST_SH:          /bin/sh
         No nonexistent/bin/nbmake, needs building.
         Bootstrapping nbmake
         TOOLDIR path:     /opt/cross/evbarm/usr/src/tooldir.NetBSD-4.0.1-i386
         DESTDIR path:     /opt/cross/evbarm/usr/src/destdir.evbarm
         RELEASEDIR path:  /opt/cross/evbarm/usr/src/releasedir
         Created /opt/cross/evbarm/usr/src/tooldir.NetBSD-4.0.1-i386/bin/nbmake
         makewrapper:      /opt/cross/evbarm/usr/src/tooldir.NetBSD-4.0.1-i386/bin/nbmake-evbarm
         Updated /opt/cross/evbarm/usr/src/tooldir.NetBSD-4.0.1-i386/bin/nbmake-evbarm
         Successful make distribution
         build.sh ended:   Sat Nov 28 15:04:34 CST 2015
===> .

However, when I try to compile helloARM.c using the nbmake-evbarm wrapper I get the following output,

$ nbmake-evbarm ./helloARM
/opt/cross/evbarm/usr/src/tooldir.NetBSD-4.0.1-i386/bin/arm--netbsdelf-gcc -O2   -Werror    -nostdinc -isystem /opt/cross/evbarm/usr/src/destdir.evbarm/usr/include    -o ./helloARM ./helloARM.c 
/opt/cross/evbarm/usr/src/tooldir.NetBSD-4.0.1-i386/lib/gcc/arm--netbsdelf/4.1.2/../../../../arm--netbsdelf/bin/ld: crt0.o: No such file: No such file or directory
collect2: ld returned 1 exit status

*** Failed target:  ./helloARM
*** Failed command: /opt/cross/evbarm/usr/src/tooldir.NetBSD-4.0.1-i386/bin/arm--netbsdelf-gcc -O2 -Werror -nostdinc -isystem /opt/cross/evbarm/usr/src/destdir.evbarm/usr/include -o ./helloARM ./helloARM.c 
*** Error code 1

Stop.
nbmake: stopped in /home/capin/apps

Solution

  • Don't put the ./ path prefix on the target name.

    I.e. just run:

    nbmake-evbarm helloARM
    

    I'm assuming of course that you have a Makefile in the same directory which looks a bit like this, at minimum:

    PROG = helloARM
    
    .include <bsd.prog.mk>
    

    You must have such a local Makefile which uses the standard NetBSD macros because when there is no makefile (or when the makefile does not use the proper NetBSD macros, i.e. <bsd.prog.mk>) the default sys.mk macros are used and they do not include all the ${DESTDIR} magic needed to access the target system's headers and libraries and such.