Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github Action MacOSX revamp #343

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
415 changes: 415 additions & 0 deletions .github/workflows/main-macos.yml

Large diffs are not rendered by default.

14 changes: 0 additions & 14 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,3 @@ jobs:
name: magic-wasm-bundle
path: |
${{ github.workspace }}/magic/magic.wasm
# simple_build_mac:
# runs-on: macos-11
# steps:
# - uses: actions/checkout@v4
# - name: Get Dependencies
# run: |
# brew install --cask xquartz
# brew install cairo tcl-tk tcsh
# - name: Build
# run: |
# export PATH="/opt/X11/bin:$PATH"
# ./scripts/configure_mac
# make database/database.h
# make -j$(sysctl -n hw.ncpu)
4 changes: 2 additions & 2 deletions calma/CalmaRdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ calmaReadStringRecord(type, str)

nbytes -= CALMAHEADERLENGTH;
*str = (char *) mallocMagic(nbytes + 1);
if (FREAD(*str, sizeof (char), nbytes, calmaInputFile) != nbytes)
if (magicFREAD(*str, sizeof (char), nbytes, calmaInputFile) != nbytes)
goto eof;

*(*str + nbytes) = '\0';
Expand Down Expand Up @@ -428,7 +428,7 @@ calmaReadR8(pd)
double mantissa, d;
bool isneg;

if (FREAD((char *) dchars, sizeof (char), sizeof dchars,
if (magicFREAD((char *) dchars, sizeof (char), sizeof dchars,
calmaInputFile) != sizeof dchars)
return (FALSE);

Expand Down
4 changes: 2 additions & 2 deletions calma/CalmaWrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ calmaProcessDef(def, outf, do_library)
/* Read the structure name and check against the CellDef name */
defsize = (size_t)(cellstart - structstart);
buffer = (char *)mallocMagic(defsize + 1);
numbytes = FREAD(buffer, sizeof(char), (size_t)defsize, fi);
numbytes = magicFREAD(buffer, sizeof(char), (size_t)defsize, fi);
if (numbytes == defsize)
{
buffer[defsize] = '\0';
Expand Down Expand Up @@ -1153,7 +1153,7 @@ calmaProcessDef(def, outf, do_library)
defsize = (size_t)(cellend - cellstart);
buffer = (char *)mallocMagic(defsize);

numbytes = FREAD(buffer, sizeof(char), (size_t)defsize, fi);
numbytes = magicFREAD(buffer, sizeof(char), (size_t)defsize, fi);

if (numbytes == defsize)
{
Expand Down
4 changes: 3 additions & 1 deletion scripts/configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -1806,8 +1806,10 @@ AC_SUBST(gr_srcs)
AC_SUBST(gr_hsrcs)
AC_SUBST(gr_hprog)

AC_SUBST(X_LIBS)
AC_SUBST(X_CFLAGS)
AC_SUBST(X_EXTRA_LIBS)
AC_SUBST(X_LIBS)
AC_SUBST(X_PRE_LIBS)
AC_SUBST(CPPFLAGS)
AC_SUBST(CFLAGS)
AC_SUBST(DEPEND_FLAG)
Expand Down
61 changes: 61 additions & 0 deletions scripts/configure_mac
Original file line number Diff line number Diff line change
@@ -1,7 +1,68 @@
#!/bin/sh
set -x

echo "uname_a=$(uname -a)"
echo "uname_m=$(uname -m)" # x86_64 arm64

xcodebuild -showsdks

# GHA ~202410
# x86_64-apple-darwin21.6.0 lacks needed -I/usr/X11/include
# aarch64-apple-darwin23.6.0 has needed -I/usr/X11/include

for d in /usr/X11/include /opt/X11/include /opt/local/include /usr/local/include
do
if [ -d "$d" ]
then
echo "Directory Exists: $d"
if [ -z "$x11_include_dir" ] && [ -f "${d}/X11/Xlib.h" ]
then
echo "Found Xlib.h: ${d}/X11/Xlib.h"
x11_include_dir="${d}"
fi
fi
done

for d in /usr/X11/lib /opt/X11/lib /opt/local/lib /usr/local/lib
do
if [ -d "$d" ]
then
echo "Directory Exists: $d"
if [ -z "$x11_library_dir" ] && [ -e "${d}/libX11.dylib" ]
then
echo "Found libX11.dylib: ${d}/libX11.dylib"
x11_library_dir="${d}"
fi
fi
done

if [ -n "$x11_include_dir" ]
then
# On some versions of MacOSX (example macosx12 / XCode 14.2) the tcl-tk
# also installs a set of X11 headers that seem incomplete. At a location
# like /usr/local/Cellar/tcl-tk/8.6.15/include/X11/X.h
#
# When XQuartz is installed it has a full set of correct X11 headers but
# it doesn't provide any explicit -I directory itself, and tcl-tk does
# provide -I value, so the incomplete headers end up having priority.
#CFLAGS="-I/opt/local/include"
#CFLAGS="-I/opt/X11/include"
CONFARGS="$CONFARGS --x-includes=$x11_include_dir"
fi

if [ -n "$x11_library_dir" ]
then
# Example system view from xquartz 2.8.5 and tcl-tk 8.6.15
# /opt/X11/lib/libX11.6.dylib (3496912 bytes 2023-01-26)
# /opt/homebrew/Cellar/libx11/1.8.10/lib/libX11.6.dylib (1025536 bytes 2024-10-07)
# Note the size difference, the question is ... if the tcl-tk expects to run against
# their copy of libX11, is the ABI equivalent and substitutable without crashing ?
CONFARGS="$CONFARGS --x-libraries=$x11_library_dir"
fi

./configure\
--with-tcl=$(brew --prefix tcl-tk)\
--with-tk=$(brew --prefix tcl-tk)\
--with-cairo=$(brew --prefix cairo)/include\
$CONFARGS\
"LDFLAGS=-L$(brew --prefix cairo)/lib"
2 changes: 1 addition & 1 deletion scripts/defs.mak.in
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ EXEEXT = @EXEEXT@

GR_CFLAGS = @X_CFLAGS@ @gr_cflags@
GR_DFLAGS = @gr_dflags@ -DNDEBUG
GR_LIBS = @gr_libs@ @X_LIBS@
GR_LIBS = @X_LIBS@ @X_PRE_LIBS@ @gr_libs@ @X_EXTRA_LIBS@
GR_SRCS = @gr_srcs@
GR_HELPER_SRCS = @gr_hsrcs@
GR_HELPER_PROG = @gr_hprog@
Expand Down
4 changes: 2 additions & 2 deletions utils/magic.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ extern char AbortMessage[];
#define FOPEN gzopen
#define FCLOSE gzclose
#define FGETC gzgetc
#define FREAD(a,b,c,d) gzread(d,a,b*c)
#define magicFREAD(a,b,c,d) gzread(d,a,b*c)
#define FEOF gzeof
#define FSEEK gzseek
#define FTELL gztell
Expand All @@ -157,7 +157,7 @@ extern char AbortMessage[];
#define FOPEN fopen
#define FCLOSE fclose
#define FGETC getc
#define FREAD fread
#define magicFREAD fread
#define FEOF feof
#define FSEEK fseek
#define FTELL ftello
Expand Down
Loading