Preprocessing with Clang

I’m currently trying to package a project (ELPA) which is using the C preprocessor for its Fortran source code with:

${CPP:-cpp} -P -traditional

Now I’m building for a platform (OSX) where I don’t have GCC’s cpp but only clang (I can’t install or use GCC’s C compilers, but I have GFortran). I tried with

${CC:-clang} -E -P --traditional-cpp

But didn’t get it to work with the actual Fortran source in the project. Since I’m packaging this project I don’t have much control over their build system (autoconf) or their tool chain support, but I can slightly patch around things (which I’m already doing).

Does anyone here have experience with using clang for preprocessing Fortran source? Also, any hack to get around the preprocessing issue would be appreciated as well ;).

In case anyone is interested, here is my attempt to build ELPA on OSX: Support build for OSX by awvwgk · Pull Request #1 · conda-forge/elpa-feedstock · GitHub

I have used gfortran -E -cpp to preprocess on a Mac. It seems to work. Is that an option for you?

That seems to do the trick, I went with:

${FC:-gfortran} -E -P -cpp

I wonder why this doesn’t work with clang at all? For a potential future Windows build I would have to go with a clang/flang combination and can’t reuse this trick.

At least the preprocessing works now, of course the C source fails to compile with clang…

Sigh, seems to be a futile undertaking anyway. The project wasn’t developed with other systems than Linux in mind and they use a bunch of system function which are not portable, like sched_getcpu(3).