Support static linking when compiling shared libraries
Sometimes, it's useful to have a statically linked shared library (when building foreign libraries for use with C/etc code). I've hacked together a way to do it, but it needs some cleanup.
- GHC needs to compile every library with
-fPIC -fexternal-dynamic-refsThis solves the myriad of linker errors that occur when attempting to statically link a dynamic library, but I don't know if it has any negative implications. If this is harmless, this should be the default way. Otherwise add another Way flag (like profiling/etc).
- Cabal needs to be updated to not force
-dynamicwhen compiling dynlibs. GHC gets confused when you pass -dynamic and -static and decides to link against
-lHSrts-ghc<version>, which is the name for the .so (but we want to link against the .a)
So far, the foreign library I've built has been running well as a static build, but this needs more testing.
Incidentally, this also solves the issue where you can't profile foreign libraries (as profiling builds are static).