How to install Calculix on an M1 Mac

Calculix consists of ccx and cgx. ccx can be installed through homebrew cgx can be installed following the 2015 Mac installation manual (opens in a new tab) with some additions First I was getting this error:

parser.c:91:3: error: implicit declaration of function 'DrawCommandLine' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
  DrawCommandLine(keystroke, strlen(keystroke) + *curshft);

The solution to this was to change the first line of parser.c:

#include <cgx.h>
/*#include <extUtil.h>

As well as to correct the pickfunktions.c file on line 4597:

return;

This still gave me the following error:

ld: library not found for -lSystem
collect2: error: ld returned 1 exit status
make: *** [cgx] Error 1

Which was resolved by adding the following to the LFLAGS section in the Makefile:

-L /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib \```