Auto-detect platform in makefiles and test runner

Use uname -s to select Linux vs macOS build flags instead of
hardcoding. Add -undefined dynamic_lookup for test shared libs
on macOS. Set _port=true automatically on non-Linux in ./all.
This commit is contained in:
Cormac Shannon
2026-02-28 19:27:14 +00:00
parent 27f16b126d
commit 84b9aeb7e9
3 changed files with 21 additions and 3 deletions

6
all
View File

@@ -2,7 +2,11 @@ make -s -j
cd testes/libs; make -s cd testes/libs; make -s
cd .. # back to directory 'testes' cd .. # back to directory 'testes'
ulimit -S -s 1100 ulimit -S -s 1100
if { ../lua -W all.lua; } then LUA_FLAGS="-W"
if [ "$(uname)" != "Linux" ]; then
LUA_FLAGS="$LUA_FLAGS -e_port=true"
fi
if { ../lua $LUA_FLAGS all.lua; } then
echo -e "\n\n final OK!!!!\n\n" echo -e "\n\n final OK!!!!\n\n"
else else
echo -e "\n\n >>>> BUG!!!!\n\n" echo -e "\n\n >>>> BUG!!!!\n\n"

View File

@@ -71,9 +71,18 @@ LOCAL = $(TESTS) $(CWARNS)
# To enable Linux goodies, -DLUA_USE_LINUX # To enable Linux goodies, -DLUA_USE_LINUX
# For C89, "-std=c89 -DLUA_USE_C89" # For C89, "-std=c89 -DLUA_USE_C89"
# Note that Linux/Posix options are not compatible with C89 # Note that Linux/Posix options are not compatible with C89
#
# Platform detection
UNAME= $(shell uname -s)
ifeq ($(UNAME),Darwin)
MYCFLAGS= $(LOCAL) -std=c99 -DLUA_USE_MACOSX
MYLDFLAGS=
MYLIBS=
else
MYCFLAGS= $(LOCAL) -std=c99 -DLUA_USE_LINUX MYCFLAGS= $(LOCAL) -std=c99 -DLUA_USE_LINUX
MYLDFLAGS= -Wl,-E MYLDFLAGS= -Wl,-E
MYLIBS= -ldl MYLIBS= -ldl
endif
CC= gcc CC= gcc
@@ -95,7 +104,7 @@ CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \
ltm.o lundump.o lvm.o lzio.o ltests.o ltm.o lundump.o lvm.o lzio.o ltests.o
AUX_O= lauxlib.o AUX_O= lauxlib.o
LIB_O= lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o lstrlib.o \ LIB_O= lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o lstrlib.o \
lutf8lib.o loadlib.o lcorolib.o linit.o lutf8lib.o loadlib.o lcorolib.o lcmd.o linit.o
LUA_T= lua LUA_T= lua
LUA_O= lua.o LUA_O= lua.o
@@ -148,6 +157,7 @@ lapi.o: lapi.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \
lauxlib.o: lauxlib.c lprefix.h lua.h luaconf.h lauxlib.h llimits.h lauxlib.o: lauxlib.c lprefix.h lua.h luaconf.h lauxlib.h llimits.h
lbaselib.o: lbaselib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h \ lbaselib.o: lbaselib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h \
llimits.h llimits.h
lcmd.o: lcmd.c lprefix.h lua.h luaconf.h lauxlib.h lcmd.h
lcode.o: lcode.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \ lcode.o: lcode.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \
llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \ llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \
ldo.h lgc.h lstring.h ltable.h lvm.h lopnames.h ldo.h lgc.h lstring.h ltable.h lvm.h lopnames.h
@@ -167,7 +177,7 @@ lfunc.o: lfunc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \
llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h
lgc.o: lgc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ lgc.o: lgc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \
llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h
linit.o: linit.c lprefix.h lua.h luaconf.h lualib.h lauxlib.h llimits.h linit.o: linit.c lprefix.h lua.h luaconf.h lualib.h lauxlib.h llimits.h lcmd.h
liolib.o: liolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h llimits.h liolib.o: liolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h llimits.h
llex.o: llex.c lprefix.h lua.h luaconf.h lctype.h llimits.h ldebug.h \ llex.o: llex.c lprefix.h lua.h luaconf.h lctype.h llimits.h ldebug.h \
lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lgc.h llex.h lparser.h \ lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lgc.h llex.h lparser.h \

View File

@@ -6,6 +6,10 @@ CC = gcc
# compilation should generate Dynamic-Link Libraries # compilation should generate Dynamic-Link Libraries
CFLAGS = -Wall -O2 -I$(LUA_DIR) -fPIC -shared CFLAGS = -Wall -O2 -I$(LUA_DIR) -fPIC -shared
UNAME = $(shell uname -s)
ifeq ($(UNAME),Darwin)
CFLAGS += -undefined dynamic_lookup
endif
# libraries used by the tests # libraries used by the tests
all: lib1.so lib11.so lib2.so lib21.so lib2-v2.so all: lib1.so lib11.so lib2.so lib21.so lib2-v2.so