June 07, 2010 posted by Iain Hibbert
After reading about progress with the Portable C Compiler (PCC) last year, I was inspired to try building it on NetBSD. Gregory McGarry had done some work integrating it into the toolchain though it is not yet useable to build a full release, but the native build framework in external/bsd/pcc was incomplete.
I updated this a while ago so that it is possible to build a distribution or release containing pcc(1), pcpp(1) and ccom(1) binaries for the target architecture by setting the following two variables in your /etc/mk.conf or passing them to build.sh on the commandline
There had been many bug fixes and features added since previous import in September 2009, but the major addition was that GCC compatibility is now enabled by default, and many commonly used attributes and builtin functions are now supported. I had heard of people trying to use pcc to build a kernel without success and went for an alternative approach, building userland programs, as my feeling was that testing smaller code units would be a lot easier. I wrote a script (src/external/bsd/pcc/prepare-import.sh) to configure the PCC sources for import to NetBSD in a consistent manner, and have been using it to follow development for a few months, reporting problems along the way where I could.
The latest pcc can build all of bin/ and sbin/, most of games/ (except for dab(6) which is C++), and only a few issues remain in usr.bin/ and usr.sbin/. There are still issues outstanding with PIC support on i386 at least, which prevents building shared libraries within the NetBSD framework at this time, though this can be worked around by setting MKPIC=no.
The in-tree version has been updated and is now at "pcc 0.9.9 " which I've been using successfully on i386 though there is support included for amd64, arm, hppa, mips, powerpc, sparc64 & vax CPUs which may also work.
All the credit and many thanks go to Anders Magnusson who has been working on pcc for many years, he is very responsive to problem reports, sometimes with fixes posted the same day.