From 0c9c39612b43bd982e218ac092997ae12e5c9ece Mon Sep 17 00:00:00 2001 From: Fernando Rijo Cedeno <37381190+zFernand0@users.noreply.github.com> Date: Tue, 31 Mar 2026 09:09:59 -0400 Subject: [PATCH 01/17] refactor: examples Signed-off-by: Fernando Rijo Cedeno <37381190+zFernand0@users.noreply.github.com> --- native/c/examples/enq/makefile | 97 ++-------------------- native/c/examples/examples_toolchain.mk | 55 +++++++++++++ native/c/examples/jsoncpp/makefile | 103 +++--------------------- native/c/examples/jsonm/makefile | 90 +-------------------- native/c/examples/metal/makefile | 95 ++-------------------- 5 files changed, 82 insertions(+), 358 deletions(-) create mode 100644 native/c/examples/examples_toolchain.mk diff --git a/native/c/examples/enq/makefile b/native/c/examples/enq/makefile index 2961d1dcd..238567ce7 100644 --- a/native/c/examples/enq/makefile +++ b/native/c/examples/enq/makefile @@ -10,96 +10,14 @@ # OUT_DIR=build-out -OUT_DIRS=$(OUT_DIR_CXXLANG) -XLC_FLAGS=_CC_ACCEPTABLE_RC=0 _C89_ACCEPTABLE_RC=0 _CXX_ACCEPTABLE_RC=0 -CXX=$(XLC_FLAGS) xlc++ -CC=$(XLC_FLAGS) xlc -ASM=as -BIND=ld +.INCLUDE: ../examples_toolchain.mk -MTL_OPTS=metal,\ - langlvl(extended),\ - sscom,\ - nolongname,\ - inline,\ - genasm,\ - inlrpt,\ - csect,\ - nose,\ - list,\ - warn64,\ - optimize(2),\ - aggregate +all: build-out run -MTL_OPTS64=$(MTL_OPTS),lp64 -MTL_FLAGS=-S -W "c,$(MTL_OPTS)" -MTL_FLAGS64=-S -W "c,$(MTL_OPTS64)" - -MACLIBS= -I../../../asmmac \ - -ISYS1.MACLIB \ - -ISYS1.MODGEN \ - -ICBC.SCCNSAM - -MTL_HEADERS=-I/usr/include/metal \ - -I../../chdsect \ - -I../../../c - -CPP_BND_FLAGS=-W "l,lp64,xplink,map,list" - -CPP_BND_FLAGS_AUTH=-W "l,lp64,xplink,map,list,ac=1" - -C_FLAGS=-W "c,lp64,langlvl(extended),xplink,exportall"\ - -c \ - -I../../chdsect \ - -I../../../c - -DLL_CPP_FLAGS=-W "c,lp64,langlvl(extended0x),dll,xplink,exportall"\ - -c \ - -I./chdsect - -DLL_BND_FLAGS=-W "l,lp64,dll,dynam=dll,xplink,map,list" - -CPP_FLAGS=-W "c,lp64,langlvl(extended0x),dll,xplink"\ - -c \ - -I../../chdsect \ - -I../../../c - -ASM_FLAGS=-mRENT - -# make -DBuildType=DEBUG -.IF $(BuildType) == DEBUG -# -g generates debugging information -DEBUGGER_FLAGS=-qSOURCE -g9 -OTHER_C_FLAGS=-qSHOWINC -qSHOWMACROS - -CPP_BND_FLAGS+=$(DEBUGGER_FLAGS) -CPP_BND_FLAGS_AUTH+=$(DEBUGGER_FLAGS) -C_FLAGS+=$(DEBUGGER_FLAGS) -DLL_BND_FLAGS+=$(DEBUGGER_FLAGS) -DLL_CPP_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -CPP_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -MTL_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -MTL_FLAGS64+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -ASM_FLAGS+=--verbose - -.ELSE -C_FLAGS+=-g0 -CPP_FLAGS+=-g0 -CPP_BND_FLAGS+=-g0 -CPP_BND_FLAGS_AUTH+=-g0 -DLL_BND_FLAGS+=-g0 -DLL_CPP_FLAGS+=-g0 -ASM_FLAGS+=--noverbose - -# Still investigating why we need `-g1` for the MetalC flags :'( -MTL_FLAGS+=-g1 -MTL_FLAGS64+=-g1 -.END - -all: build-out build-out/runenq - -runenq: build-out/runenq +run: build-out/runenq + @echo 'Running ./build-out/runenq' + ./build-out/runenq build-out: @echo 'Creating build-out' @@ -110,11 +28,12 @@ build-out/runenq.s: runenq.c $(CC) $(MTL_FLAGS64) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ build-out/runenq.o: build-out/runenq.s - @echo 'Building build-out/runenq.s' + @echo 'Building build-out/runenq.o' $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ build-out/runenq: build-out/runenq.o - $(BIND) $(BIND_FLAGS_64) -V -eMAIN -o $@ $^ > $*.bind.lst + @echo 'Building build-out/runenq' + $(CXX) $(CPP_BND_FLAGS) -Wl,-eMAIN -o $@ $^ clean: rm -f *.o diff --git a/native/c/examples/examples_toolchain.mk b/native/c/examples/examples_toolchain.mk new file mode 100644 index 000000000..b1c328d0e --- /dev/null +++ b/native/c/examples/examples_toolchain.mk @@ -0,0 +1,55 @@ +# +# This program and the accompanying materials are +# made available under the terms of the Eclipse Public License v2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-v20.html +# +# SPDX-License-Identifier: EPL-2.0 +# +# Copyright Contributors to the Zowe Project. +# + +# Common toolchain definitions for examples +.INCLUDE: ../../toolchain.mk +# WARNING: Since this file is meant to be included by other files, we need to use the relative path to the toolchain.mk file. + +# Common directories for examples +MACLIBS= -I../../../asmmac $(MACLIBS_BASE) +MTL_HEADERS=$(MTL_HEADERS_BASE) -I../../chdsect -I../../../c + +# Common flags for examples +C_FLAGS_COMMON=-I../../chdsect -I../../../c +CPP_FLAGS_COMMON=-I../../chdsect -I../../../c + +# Build type handling for examples +.IF $(BuildType) == DEBUG +CPP_BND_FLAGS=$(CPP_BND_DEBUG_FLAGS) $(DEBUGGER_FLAGS) +C_FLAGS=$(C_FLAGS_BASE) $(C_FLAGS_COMMON) $(DEBUGGER_FLAGS) +CPP_FLAGS=$(CPP_FLAGS_BASE) $(CPP_FLAGS_COMMON) $(DEBUGGER_FLAGS) +MTL_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) +MTL_FLAGS64+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) +ASM_FLAGS+=--verbose +.ELIF $(BuildType) == RELEASE +CPP_BND_FLAGS=$(CPP_BND_BASE_FLAGS) +C_FLAGS=$(C_FLAGS_BASE) $(C_FLAGS_COMMON) $(RELEASE_FLAGS) +CPP_FLAGS=$(CPP_FLAGS_BASE) $(CPP_FLAGS_COMMON) $(RELEASE_FLAGS) +ASM_FLAGS+=--noverbose +MTL_FLAGS+=-g1 +MTL_FLAGS64+=-g1 +.ELSE +CPP_BND_FLAGS=$(CPP_BND_BASE_FLAGS) +C_FLAGS=$(C_FLAGS_BASE) $(C_FLAGS_COMMON) -g1 +CPP_FLAGS=$(CPP_FLAGS_BASE) $(CPP_FLAGS_COMMON) -g1 +ASM_FLAGS+=--noverbose +# Still investigating why we need `-g1` for the MetalC flags :'( +MTL_FLAGS+=-g1 +MTL_FLAGS64+=-g1 +.END + +# Apply LOG_FLAGS if enabled +.IF DEFINED(LOG_FLAGS) +C_FLAGS+=$(LOG_FLAGS) +CPP_FLAGS+=$(LOG_FLAGS) +MTL_FLAGS+=$(LOG_FLAGS) +MTL_FLAGS64+=$(LOG_FLAGS) +.END diff --git a/native/c/examples/jsoncpp/makefile b/native/c/examples/jsoncpp/makefile index a55c8f001..76033fedb 100644 --- a/native/c/examples/jsoncpp/makefile +++ b/native/c/examples/jsoncpp/makefile @@ -10,97 +10,10 @@ # OUT_DIR=build-out -OUT_DIRS=$(OUT_DIR_CXXLANG) -XLC_FLAGS=_CC_ACCEPTABLE_RC=0 _C89_ACCEPTABLE_RC=0 _CXX_ACCEPTABLE_RC=0 -CXX=$(XLC_FLAGS) xlc++ -CXXLANG=xlclang++ -CC=$(XLC_FLAGS) xlc -ASM=as +.INCLUDE: ../examples_toolchain.mk -MTL_OPTS=metal,\ - langlvl(extended),\ - sscom,\ - nolongname,\ - inline,\ - genasm,\ - inlrpt,\ - csect,\ - nose,\ - list,\ - warn64,\ - optimize(2),\ - aggregate - -MTL_OPTS64=$(MTL_OPTS),lp64 -MTL_FLAGS=-S -W "c,$(MTL_OPTS)" -MTL_FLAGS64=-S -W "c,$(MTL_OPTS64)" - -MACLIBS= -I../../../asmmac \ - -ISYS1.MACLIB \ - -ISYS1.MODGEN \ - -ICBC.SCCNSAM - -MTL_HEADERS=-I/usr/include/metal \ - -I/usr/include \ - -I../../chdsect \ - -I../../../c - -CPP_BND_FLAGS=-W "l,lp64,xplink,map,list" - -CPP_BND_FLAGS_AUTH=-W "l,lp64,xplink,map,list,ac=1" - -C_FLAGS=-W "c,lp64,langlvl(extended),xplink,exportall"\ - -c \ - -I../../chdsect \ - -I../../../c - -DLL_CPP_FLAGS=-W "c,lp64,langlvl(extended0x),dll,xplink,exportall"\ - -c \ - -I./chdsect - -DLL_BND_FLAGS=-W "l,lp64,dll,dynam=dll,xplink,map,list" - -CPP_FLAGS=-W "c,lp64,langlvl(extended0x),dll,xplink"\ - -c \ - -I../../chdsect \ - -I../../../c - -ASM_FLAGS=-mRENT - -# make -DBuildType=DEBUG -.IF $(BuildType) == DEBUG -# -g generates debugging information -DEBUGGER_FLAGS=-qSOURCE -g9 -OTHER_C_FLAGS=-qSHOWINC -qSHOWMACROS - -CPP_BND_FLAGS+=$(DEBUGGER_FLAGS) -CPP_BND_FLAGS_AUTH+=$(DEBUGGER_FLAGS) -C_FLAGS+=$(DEBUGGER_FLAGS) -DLL_BND_FLAGS+=$(DEBUGGER_FLAGS) -DLL_CPP_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -CPP_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -MTL_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -MTL_FLAGS64+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -ASM_FLAGS+=--verbose - -.ELSE -C_FLAGS+=-g0 -CPP_FLAGS+=-g0 -# CPP_FLAGS+=-qasm -# CPP_FLAGS+=-qasmlib\('CEE.SCEEMAC','SYS1.MACLIB','SYS1.MODGEN'\) -CPP_BND_FLAGS+=-g0 -CPP_BND_FLAGS_AUTH+=-g0 -DLL_BND_FLAGS+=-g0 -DLL_CPP_FLAGS+=-g0 -ASM_FLAGS+=--noverbose - -# Still investigating why we need `-g1` for the MetalC flags :'( -MTL_FLAGS+=-g1 -MTL_FLAGS64+=-g1 -.END - -all: copy-mtl build-out json +all: copy-mtl build-out run # # Output directories @@ -109,6 +22,10 @@ build-out: @echo 'Creating build-out' mkdir -p build-out +run: build-out/json + @echo 'Running ./build-out/json' + ./build-out/json + copy-mtl: cp ../../zjsonm.c zjsonm.c @@ -122,13 +39,11 @@ build-out/zjsonm.o: build-out/zjsonm.s build-out/json.o: json.cpp @echo 'Building $(OUT_DIR)/json.o' - $(CXXLANG) $(CPP_FLAGS) -qlist=$*.cpp.lst -c $^ -o $@ + $(CXX) $(CPP_FLAGS) -c $^ -o $@ build-out/json: build-out/json.o build-out/zjsonm.o @echo 'Building json' - $(CXXLANG) $(CPP_BND_FLAGS) -o $@ $^ > $*.bind.lst - -json: build-out/json + $(CXX) $(CPP_BND_FLAGS) -o $@ $^ > $*.bind.lst clean: rm -f *.o @@ -139,4 +54,4 @@ clean: rm -f *.x rm -f *.lst rm -f CEEDUMP.* - rm -rf $(OUT_DIR) \ No newline at end of file + rm -rf $(OUT_DIR) diff --git a/native/c/examples/jsonm/makefile b/native/c/examples/jsonm/makefile index 4646d8d74..5546d921e 100644 --- a/native/c/examples/jsonm/makefile +++ b/native/c/examples/jsonm/makefile @@ -10,93 +10,8 @@ # OUT_DIR=build-out -OUT_DIRS=$(OUT_DIR_CXXLANG) -XLC_FLAGS=_CC_ACCEPTABLE_RC=0 _C89_ACCEPTABLE_RC=0 _CXX_ACCEPTABLE_RC=0 -CXX=$(XLC_FLAGS) xlc++ -CC=$(XLC_FLAGS) xlc -ASM=as -BIND=ld - -MTL_OPTS=metal,\ - langlvl(extended),\ - sscom,\ - nolongname,\ - inline,\ - genasm,\ - inlrpt,\ - csect,\ - nose,\ - list,\ - warn64,\ - optimize(2),\ - aggregate - -MTL_OPTS64=$(MTL_OPTS),lp64 -MTL_FLAGS=-S -W "c,$(MTL_OPTS)" -MTL_FLAGS64=-S -W "c,$(MTL_OPTS64)" - -MACLIBS= -I../../../asmmac \ - -ISYS1.MACLIB \ - -ISYS1.MODGEN \ - -ICBC.SCCNSAM - -MTL_HEADERS=-I/usr/include/metal \ - -I/usr/include \ - -I../../chdsect \ - -I../../../c - -CPP_BND_FLAGS=-W "l,lp64,xplink,map,list" - -CPP_BND_FLAGS_AUTH=-W "l,lp64,xplink,map,list,ac=1" - -C_FLAGS=-W "c,lp64,langlvl(extended),xplink,exportall"\ - -c \ - -I../../chdsect \ - -I../../../c - -DLL_CPP_FLAGS=-W "c,lp64,langlvl(extended0x),dll,xplink,exportall"\ - -c \ - -I./chdsect - -DLL_BND_FLAGS=-W "l,lp64,dll,dynam=dll,xplink,map,list" - -CPP_FLAGS=-W "c,lp64,langlvl(extended0x),dll,xplink"\ - -c \ - -I../../chdsect \ - -I../../../c - -ASM_FLAGS=-mRENT - -# make -DBuildType=DEBUG -.IF $(BuildType) == DEBUG -# -g generates debugging information -DEBUGGER_FLAGS=-qSOURCE -g9 -OTHER_C_FLAGS=-qSHOWINC -qSHOWMACROS - -CPP_BND_FLAGS+=$(DEBUGGER_FLAGS) -CPP_BND_FLAGS_AUTH+=$(DEBUGGER_FLAGS) -C_FLAGS+=$(DEBUGGER_FLAGS) -DLL_BND_FLAGS+=$(DEBUGGER_FLAGS) -DLL_CPP_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -CPP_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -MTL_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -MTL_FLAGS64+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -ASM_FLAGS+=--verbose - -.ELSE -C_FLAGS+=-g0 -CPP_FLAGS+=-g0 -CPP_BND_FLAGS+=-g0 -CPP_BND_FLAGS_AUTH+=-g0 -DLL_BND_FLAGS+=-g0 -DLL_CPP_FLAGS+=-g0 -ASM_FLAGS+=--noverbose - -# Still investigating why we need `-g1` for the MetalC flags :'( -MTL_FLAGS+=-g1 -MTL_FLAGS64+=-g1 -.END +.INCLUDE: ../toolchain.mk all: build-out build-out/json @@ -115,7 +30,8 @@ build-out/json.o: build-out/json.s $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ build-out/json: build-out/json.o - $(BIND) $(BIND_FLAGS_64) -V -eMAIN -o $@ $^ > $*.bind.lst + @echo 'Building build-out/json' + $(CXX) $(CPP_BND_FLAGS) -Wl,-eMAIN -o $@ $^ clean: rm -f *.o diff --git a/native/c/examples/metal/makefile b/native/c/examples/metal/makefile index baeb1cb8a..38a1d12f0 100644 --- a/native/c/examples/metal/makefile +++ b/native/c/examples/metal/makefile @@ -10,96 +10,14 @@ # OUT_DIR=build-out -OUT_DIRS=$(OUT_DIR_CXXLANG) -XLC_FLAGS=_CC_ACCEPTABLE_RC=0 _C89_ACCEPTABLE_RC=0 _CXX_ACCEPTABLE_RC=0 -CXX=$(XLC_FLAGS) xlc++ -CC=$(XLC_FLAGS) xlc -ASM=as -BIND=ld +.INCLUDE: ../examples_toolchain.mk -MTL_OPTS=metal,\ - langlvl(extended),\ - sscom,\ - nolongname,\ - inline,\ - genasm,\ - inlrpt,\ - csect,\ - nose,\ - list,\ - warn64,\ - optimize(2),\ - aggregate +all: build-out run -MTL_OPTS64=$(MTL_OPTS),lp64 -MTL_FLAGS=-S -W "c,$(MTL_OPTS)" -MTL_FLAGS64=-S -W "c,$(MTL_OPTS64)" - -MACLIBS= -I../../../asmmac \ - -ISYS1.MACLIB \ - -ISYS1.MODGEN \ - -ICBC.SCCNSAM - -MTL_HEADERS=-I/usr/include/metal \ - -I../../chdsect \ - -I../../../c - -CPP_BND_FLAGS=-W "l,lp64,xplink,map,list" - -CPP_BND_FLAGS_AUTH=-W "l,lp64,xplink,map,list,ac=1" - -C_FLAGS=-W "c,lp64,langlvl(extended),xplink,exportall"\ - -c \ - -I../../chdsect \ - -I../../../c - -DLL_CPP_FLAGS=-W "c,lp64,langlvl(extended0x),dll,xplink,exportall"\ - -c \ - -I./chdsect - -DLL_BND_FLAGS=-W "l,lp64,dll,dynam=dll,xplink,map,list" - -CPP_FLAGS=-W "c,lp64,langlvl(extended0x),dll,xplink"\ - -c \ - -I../../chdsect \ - -I../../../c - -ASM_FLAGS=-mRENT - -# make -DBuildType=DEBUG -.IF $(BuildType) == DEBUG -# -g generates debugging information -DEBUGGER_FLAGS=-qSOURCE -g9 -OTHER_C_FLAGS=-qSHOWINC -qSHOWMACROS - -CPP_BND_FLAGS+=$(DEBUGGER_FLAGS) -CPP_BND_FLAGS_AUTH+=$(DEBUGGER_FLAGS) -C_FLAGS+=$(DEBUGGER_FLAGS) -DLL_BND_FLAGS+=$(DEBUGGER_FLAGS) -DLL_CPP_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -CPP_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -MTL_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -MTL_FLAGS64+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -ASM_FLAGS+=--verbose - -.ELSE -C_FLAGS+=-g0 -CPP_FLAGS+=-g0 -CPP_BND_FLAGS+=-g0 -CPP_BND_FLAGS_AUTH+=-g0 -DLL_BND_FLAGS+=-g0 -DLL_CPP_FLAGS+=-g0 -ASM_FLAGS+=--noverbose - -# Still investigating why we need `-g1` for the MetalC flags :'( -MTL_FLAGS+=-g1 -MTL_FLAGS64+=-g1 -.END - -all: build-out build-out/demometal - -demometal: build-out/demometal +run: build-out/demometal + @echo 'Running ./build-out/demometal' + ./build-out/demometal build-out: @echo 'Creating build-out' @@ -114,7 +32,8 @@ build-out/demometal.o: build-out/demometal.s $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ build-out/demometal: build-out/demometal.o - $(BIND) $(BIND_FLAGS_64) -V -eMAIN -o $@ $^ > $*.bind.lst + @echo 'Building build-out/demometal' + $(CXX) $(CPP_BND_FLAGS) -Wl,-eMAIN -o $@ $^ clean: rm -f *.o From 77af043af98dc71a7628cc1c48d6ffd884772c72 Mon Sep 17 00:00:00 2001 From: Fernando Rijo Cedeno <37381190+zFernand0@users.noreply.github.com> Date: Wed, 1 Apr 2026 09:38:37 -0400 Subject: [PATCH 02/17] fix elif syntax in makefiles Signed-off-by: Fernando Rijo Cedeno <37381190+zFernand0@users.noreply.github.com> --- native/c/examples/examples_toolchain.mk | 4 +-- native/c/examples/jsonm/makefile | 15 +++++--- native/c/examples/metal/demometal.c | 47 +++---------------------- native/c/examples/metal/makefile | 14 +++++++- 4 files changed, 30 insertions(+), 50 deletions(-) diff --git a/native/c/examples/examples_toolchain.mk b/native/c/examples/examples_toolchain.mk index b1c328d0e..7b7b2da3e 100644 --- a/native/c/examples/examples_toolchain.mk +++ b/native/c/examples/examples_toolchain.mk @@ -14,7 +14,7 @@ # WARNING: Since this file is meant to be included by other files, we need to use the relative path to the toolchain.mk file. # Common directories for examples -MACLIBS= -I../../../asmmac $(MACLIBS_BASE) +MACLIBS= -I../../../asmmac -I../../../asmchdr $(MACLIBS_BASE) MTL_HEADERS=$(MTL_HEADERS_BASE) -I../../chdsect -I../../../c # Common flags for examples @@ -29,7 +29,7 @@ CPP_FLAGS=$(CPP_FLAGS_BASE) $(CPP_FLAGS_COMMON) $(DEBUGGER_FLAGS) MTL_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) MTL_FLAGS64+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) ASM_FLAGS+=--verbose -.ELIF $(BuildType) == RELEASE +.ELSIF $(BuildType) == RELEASE CPP_BND_FLAGS=$(CPP_BND_BASE_FLAGS) C_FLAGS=$(C_FLAGS_BASE) $(C_FLAGS_COMMON) $(RELEASE_FLAGS) CPP_FLAGS=$(CPP_FLAGS_BASE) $(CPP_FLAGS_COMMON) $(RELEASE_FLAGS) diff --git a/native/c/examples/jsonm/makefile b/native/c/examples/jsonm/makefile index 5546d921e..81ce8cf00 100644 --- a/native/c/examples/jsonm/makefile +++ b/native/c/examples/jsonm/makefile @@ -11,16 +11,23 @@ OUT_DIR=build-out -.INCLUDE: ../toolchain.mk +.INCLUDE: ../examples_toolchain.mk -all: build-out build-out/json +all: build-out run -json: build-out/json +run: build-out/json + @echo 'Running ./build-out/json' + ./build-out/json build-out: @echo 'Creating build-out' mkdir -p build-out +copy-mtl: + cp ../../zmetal.h zmetal.h + cp ../../zwto.h zwto.h + cp ../../zjsonm31.h zjsonm31.h + build-out/json.s: json.c @echo 'Building build-out/json.s' $(CC) $(MTL_FLAGS64) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ @@ -31,7 +38,7 @@ build-out/json.o: build-out/json.s build-out/json: build-out/json.o @echo 'Building build-out/json' - $(CXX) $(CPP_BND_FLAGS) -Wl,-eMAIN -o $@ $^ + $(CXX) $(CPP_BND_FLAGS) -o $@ $^ clean: rm -f *.o diff --git a/native/c/examples/metal/demometal.c b/native/c/examples/metal/demometal.c index 144926266..1cb4c1672 100644 --- a/native/c/examples/metal/demometal.c +++ b/native/c/examples/metal/demometal.c @@ -9,9 +9,7 @@ * */ -#include "zwto.h" #include "zmetal.h" -#include "zsetjmp.h" #include "ztime.h" #include "zwto.h" #include "zdbg.h" @@ -27,57 +25,20 @@ int main() int rc = 0; // get stck - zut_dump_storage_wto("tod before STCK", &tod, sizeof(tod)); + zut_dump_storage("tod before STCK", &tod, sizeof(tod)); __asm(" STCK %0" : "=m"(tod)); - zut_dump_storage_wto("tod after STCK", &tod, sizeof(tod)); + zut_dump_storage("tod after STCK", &tod, sizeof(tod)); // convert to YYYYDDD rc = stckconv(&tod, &time_struct); zwto_debug("stckconv returned %d", rc); - zut_dump_storage_wto("time_struct", &time_struct, sizeof(time_struct)); + zut_dump_storage("time_struct", &time_struct, sizeof(time_struct)); // convert back to stck rc = convtod(&time_struct, &tod); zwto_debug("convdod returned %d", rc); - zut_dump_storage_wto("tod after CONVTOD", &tod, sizeof(tod)); + zut_dump_storage("tod after CONVTOD", &tod, sizeof(tod)); // demo_setjmp(); return 0; -} - -void test(ZSETJMP_ENV *zenv) -{ - zwto_debug("test called"); - zlongjmp(zenv); -} - -int demo_time() -{ - unsigned long long tod = 0; - time(&tod); - zwto_debug("time: %llx", tod); - return 0; -} - -int demo_setjmp() -{ - PSW psw = {0}; - get_psw(&psw); - int mode_switch = psw.data.bits.p ? 0 : 1; - - ZSETJMP_ENV zenv = {0}; - - int rc = zsetjmp(&zenv); - if (rc == 0) - { - zwto_debug("zsetjmp returned 0"); - test(&zenv); - ZLONGJMP(&zenv); - } - else - { - zwto_debug("zsetjmp returned %d", rc); - } - - return rc; } \ No newline at end of file diff --git a/native/c/examples/metal/makefile b/native/c/examples/metal/makefile index 38a1d12f0..1ad932cc4 100644 --- a/native/c/examples/metal/makefile +++ b/native/c/examples/metal/makefile @@ -13,7 +13,7 @@ OUT_DIR=build-out .INCLUDE: ../examples_toolchain.mk -all: build-out run +all: copy-mtl build-out run run: build-out/demometal @echo 'Running ./build-out/demometal' @@ -23,6 +23,18 @@ build-out: @echo 'Creating build-out' mkdir -p build-out +copy-mtl: + cp ../../zutm.c zutm.c + cp ../../ztime.h ztime.h + +build-out/zutm.s: zutm.c + @echo 'Building $(OUT_DIR)/zutm.s' + $(CC) $(MTL_FLAGS64) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ + +build-out/zutm.o: build-out/zutm.s + @echo 'Building $(OUT_DIR)/zutm.o' + $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ + build-out/demometal.s: demometal.c @echo 'Building build-out/demometal.s' $(CC) $(MTL_FLAGS64) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ From 12330aac725b2ada3bc772de2f761c8531c79bb8 Mon Sep 17 00:00:00 2001 From: Fernando Rijo Cedeno <37381190+zFernand0@users.noreply.github.com> Date: Thu, 9 Apr 2026 09:45:34 -0400 Subject: [PATCH 03/17] refactor two more examples (during meetings) :yum: Signed-off-by: Fernando Rijo Cedeno <37381190+zFernand0@users.noreply.github.com> --- native/c/examples/examples_toolchain.mk | 6 +- native/c/examples/timer/makefile | 94 +------- native/c/examples/zcn/makefile | 302 +----------------------- 3 files changed, 18 insertions(+), 384 deletions(-) diff --git a/native/c/examples/examples_toolchain.mk b/native/c/examples/examples_toolchain.mk index 7b7b2da3e..b06c55967 100644 --- a/native/c/examples/examples_toolchain.mk +++ b/native/c/examples/examples_toolchain.mk @@ -11,7 +11,8 @@ # Common toolchain definitions for examples .INCLUDE: ../../toolchain.mk -# WARNING: Since this file is meant to be included by other files, we need to use the relative path to the toolchain.mk file. +# WARNING: Since this file is meant to be included by other files, +# we need to use the relative path to the toolchain.mk file. # Common directories for examples MACLIBS= -I../../../asmmac -I../../../asmchdr $(MACLIBS_BASE) @@ -24,6 +25,7 @@ CPP_FLAGS_COMMON=-I../../chdsect -I../../../c # Build type handling for examples .IF $(BuildType) == DEBUG CPP_BND_FLAGS=$(CPP_BND_DEBUG_FLAGS) $(DEBUGGER_FLAGS) +CPP_BND_FLAGS_AUTH=$(CPP_BND_DEBUG_FLAGS_AUTH) $(DEBUGGER_FLAGS) C_FLAGS=$(C_FLAGS_BASE) $(C_FLAGS_COMMON) $(DEBUGGER_FLAGS) CPP_FLAGS=$(CPP_FLAGS_BASE) $(CPP_FLAGS_COMMON) $(DEBUGGER_FLAGS) MTL_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) @@ -31,6 +33,7 @@ MTL_FLAGS64+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) ASM_FLAGS+=--verbose .ELSIF $(BuildType) == RELEASE CPP_BND_FLAGS=$(CPP_BND_BASE_FLAGS) +CPP_BND_FLAGS_AUTH=$(CPP_BND_BASE_FLAGS_AUTH) C_FLAGS=$(C_FLAGS_BASE) $(C_FLAGS_COMMON) $(RELEASE_FLAGS) CPP_FLAGS=$(CPP_FLAGS_BASE) $(CPP_FLAGS_COMMON) $(RELEASE_FLAGS) ASM_FLAGS+=--noverbose @@ -38,6 +41,7 @@ MTL_FLAGS+=-g1 MTL_FLAGS64+=-g1 .ELSE CPP_BND_FLAGS=$(CPP_BND_BASE_FLAGS) +CPP_BND_FLAGS_AUTH=$(CPP_BND_BASE_FLAGS_AUTH) C_FLAGS=$(C_FLAGS_BASE) $(C_FLAGS_COMMON) -g1 CPP_FLAGS=$(CPP_FLAGS_BASE) $(CPP_FLAGS_COMMON) -g1 ASM_FLAGS+=--noverbose diff --git a/native/c/examples/timer/makefile b/native/c/examples/timer/makefile index b4effafee..deca6861b 100644 --- a/native/c/examples/timer/makefile +++ b/native/c/examples/timer/makefile @@ -10,101 +10,21 @@ # OUT_DIR=build-out -OUT_DIRS=$(OUT_DIR_CXXLANG) -XLC_FLAGS=_CC_ACCEPTABLE_RC=0 _C89_ACCEPTABLE_RC=0 _CXX_ACCEPTABLE_RC=0 -CXX=$(XLC_FLAGS) xlc++ -CC=$(XLC_FLAGS) xlc -ASM=as -BIND=ld - -MTL_OPTS=metal,\ - langlvl(extended),\ - sscom,\ - nolongname,\ - inline,\ - genasm,\ - inlrpt,\ - csect,\ - nose,\ - list,\ - warn64,\ - optimize(2),\ - aggregate - -MTL_OPTS64=$(MTL_OPTS),lp64 -MTL_FLAGS=-S -W "c,$(MTL_OPTS)" -MTL_FLAGS64=-S -W "c,$(MTL_OPTS64)" - -MACLIBS= -I../../../asmmac \ - -ISYS1.MACLIB \ - -ISYS1.MODGEN \ - -ICBC.SCCNSAM - -MTL_HEADERS=-I/usr/include/metal \ - -I../../chdsect \ - -I../../../c - -CPP_BND_FLAGS=-W "l,lp64,xplink,map,list" - -CPP_BND_FLAGS_AUTH=-W "l,lp64,xplink,map,list,ac=1" - -C_FLAGS=-W "c,lp64,langlvl(extended),xplink,exportall"\ - -c \ - -I../../chdsect \ - -I../../../c - -DLL_CPP_FLAGS=-W "c,lp64,langlvl(extended0x),dll,xplink,exportall"\ - -c \ - -I./chdsect +.INCLUDE: ../examples_toolchain.mk -DLL_BND_FLAGS=-W "l,lp64,dll,dynam=dll,xplink,map,list" - -CPP_FLAGS=-W "c,lp64,langlvl(extended0x),dll,xplink"\ - -c \ - -I../../chdsect \ - -I../../../c - -ASM_FLAGS=-mRENT - -# make -DBuildType=DEBUG -.IF $(BuildType) == DEBUG -# -g generates debugging information -DEBUGGER_FLAGS=-qSOURCE -g9 -OTHER_C_FLAGS=-qSHOWINC -qSHOWMACROS - -CPP_BND_FLAGS+=$(DEBUGGER_FLAGS) -CPP_BND_FLAGS_AUTH+=$(DEBUGGER_FLAGS) -C_FLAGS+=$(DEBUGGER_FLAGS) -DLL_BND_FLAGS+=$(DEBUGGER_FLAGS) -DLL_CPP_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -CPP_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -MTL_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -MTL_FLAGS64+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -ASM_FLAGS+=--verbose - -.ELSE -C_FLAGS+=-g0 -CPP_FLAGS+=-g0 -CPP_BND_FLAGS+=-g0 -CPP_BND_FLAGS_AUTH+=-g0 -DLL_BND_FLAGS+=-g0 -DLL_CPP_FLAGS+=-g0 -ASM_FLAGS+=--noverbose - -# Still investigating why we need `-g1` for the MetalC flags :'( -MTL_FLAGS+=-g1 -MTL_FLAGS64+=-g1 -.END - -all: build-out build-out/testtime +BIND=ld -testtime: build-out/testtime +all: build-out run build-out: @echo 'Creating build-out' mkdir -p build-out +run: build-out/testtime + @echo 'Running ./build-out/testtime' + export _BPXK_JOBLOG=STDERR && ./build-out/testtime + build-out/testtime.s: testtime.c @echo 'Building build-out/testtime.s' $(CC) $(MTL_FLAGS64) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ diff --git a/native/c/examples/zcn/makefile b/native/c/examples/zcn/makefile index c9cb067d2..794d7802d 100644 --- a/native/c/examples/zcn/makefile +++ b/native/c/examples/zcn/makefile @@ -10,93 +10,10 @@ # OUT_DIR=build-out -OUT_DIRS=$(OUT_DIR_CXXLANG) -XLC_FLAGS=_CC_ACCEPTABLE_RC=0 _C89_ACCEPTABLE_RC=0 _CXX_ACCEPTABLE_RC=0 -CXX=$(XLC_FLAGS) xlc++ -CC=$(XLC_FLAGS) xlc -ASM=as +.INCLUDE: ../examples_toolchain.mk -MTL_OPTS=metal,\ - langlvl(extended),\ - sscom,\ - nolongname,\ - inline,\ - genasm,\ - inlrpt,\ - csect,\ - nose,\ - list,\ - warn64,\ - optimize(2),\ - aggregate - -MTL_OPTS64=$(MTL_OPTS),lp64 -MTL_FLAGS=-S -W "c,$(MTL_OPTS)" -MTL_FLAGS64=-S -W "c,$(MTL_OPTS64)" - -MACLIBS= -I../asmmac \ - -ISYS1.MACLIB \ - -ISYS1.MODGEN \ - -ICBC.SCCNSAM - -MTL_HEADERS=-I/usr/include/metal \ - -I../../chdsect \ - -I../../../c - -CPP_BND_FLAGS=-W "l,lp64,xplink,map,list" - -CPP_BND_FLAGS_AUTH=-W "l,lp64,xplink,map,list,ac=1" - -C_FLAGS=-W "c,lp64,langlvl(extended),xplink,exportall"\ - -c \ - -I../../chdsect \ - -I../../../c - -DLL_CPP_FLAGS=-W "c,lp64,langlvl(extended0x),dll,xplink,exportall"\ - -c \ - -I./chdsect - -DLL_BND_FLAGS=-W "l,lp64,dll,dynam=dll,xplink,map,list" - -CPP_FLAGS=-W "c,lp64,langlvl(extended0x),dll,xplink"\ - -c \ - -I../../chdsect \ - -I../../../c - -ASM_FLAGS=-mRENT - -# make -DBuildType=DEBUG -.IF $(BuildType) == DEBUG -# -g generates debugging information -DEBUGGER_FLAGS=-qSOURCE -g9 -OTHER_C_FLAGS=-qSHOWINC -qSHOWMACROS - -CPP_BND_FLAGS+=$(DEBUGGER_FLAGS) -CPP_BND_FLAGS_AUTH+=$(DEBUGGER_FLAGS) -C_FLAGS+=$(DEBUGGER_FLAGS) -DLL_BND_FLAGS+=$(DEBUGGER_FLAGS) -DLL_CPP_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -CPP_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -MTL_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -MTL_FLAGS64+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -ASM_FLAGS+=--verbose - -.ELSE -C_FLAGS+=-g0 -CPP_FLAGS+=-g0 -CPP_BND_FLAGS+=-g0 -CPP_BND_FLAGS_AUTH+=-g0 -DLL_BND_FLAGS+=-g0 -DLL_CPP_FLAGS+=-g0 -ASM_FLAGS+=--noverbose - -# Still investigating why we need `-g1` for the MetalC flags :'( -MTL_FLAGS+=-g1 -MTL_FLAGS64+=-g1 -.END - -all: build-out demozcnx extattr +all: build-out extattr run # # Output directories @@ -105,226 +22,19 @@ build-out: @echo 'Creating build-out' mkdir -p build-out -# # -# # Utilities -# # -# $(OUT_DIR)/zut.o: zut.cpp -# @echo 'Building $(OUT_DIR)/zut.o' -# $(CXX) $(DLL_CPP_FLAGS) -qlist=$*.cpp.lst -o $@ $^ - -# $(OUT_DIR_CXXLANG)/zut.o: $(OUT_DIRS) zut.cpp -# @echo '$(OUT_DIR_CXXLANG)/zut.o' -# $(CXXLANG) $(CXXLANG_FLAGS) -qlist=$*.cpp.lst -o $@ $^ - -# $(OUT_DIR)/zutm.s: zutm.c -# @echo 'Building $(OUT_DIR)/zutm.s' -# $(CC) $(MTL_FLAGS64) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ - -# $(OUT_DIR)/zutm.o: $(OUT_DIR)/zutm.s -# @echo 'Building $(OUT_DIR)/zutm.s' -# $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ - -# $(OUT_DIR)/zutm31.s: zutm31.c -# @echo 'Building $(OUT_DIR)/zutm31.s' -# $(CC) $(MTL_FLAGS) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ - -# $(OUT_DIR)/zutm31.o: $(OUT_DIR)/zutm31.s -# @echo 'Building $(OUT_DIR)/zutm31.o' -# $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ - -# $(OUT_DIR)/libzut.so: $(OUT_DIR)/zut.o $(OUT_DIR)/zutm.o $(OUT_DIR)/zam.o $(OUT_DIR)/zutm31.o -# @echo 'Building $(OUT_DIR)/libzut.so' -# $(CXX) $(DLL_BND_FLAGS) -o $@ $^ > $*.bind.lst - -# libzut.so: $(OUT_DIRS) $(OUT_DIR)/libzut.so - -# $(OUT_DIR)/libzut.a: $(OUT_DIR)/zut.o $(OUT_DIR)/zutm.o $(OUT_DIR)/zam.o $(OUT_DIR)/zutm31.o -# @echo 'Building $(OUT_DIR)/libzut.a' -# ar -rv $@ $^ - -# libzut.a: $(OUT_DIRS) $(OUT_DIR)/libzut.a - -# # -# # Data sets -# # -# $(OUT_DIR)/zam.s: zam.c -# @echo 'Building $(OUT_DIR)/zam.s' -# $(CC) $(MTL_FLAGS) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ - -# $(OUT_DIR)/zam.o: $(OUT_DIR)/zam.s -# @echo 'Building $(OUT_DIR)/zdsm.o' -# $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ - -# $(OUT_DIR)/zdsm.s: zdsm.c -# @echo 'Building $(OUT_DIR)/zdsm.s' -# $(CC) $(MTL_FLAGS64) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ - -# $(OUT_DIR)/zdsm.o: $(OUT_DIR)/zdsm.s -# @echo 'Building $(OUT_DIR)/zdsm.o' -# $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ - -# $(OUT_DIR)/zds.o: zds.cpp -# @echo 'Building $(OUT_DIR)/zds.o' -# $(CXX) $(DLL_CPP_FLAGS) -qlist=$*.cpp.lst -o $@ $^ - -# $(OUT_DIR_CXXLANG)/zds.o: $(OUT_DIRS) zds.cpp -# @echo '$(OUT_DIR_CXXLANG)/zds.o' -# $(CXXLANG) $(CXXLANG_FLAGS) -qlist=$*.cpp.lst -o $@ $^ - -# $(OUT_DIR)/libzds.so: $(OUT_DIR)/zds.o $(OUT_DIR)/zdsm.o $(OUT_DIR)/zam.o $(OUT_DIR)/libzut.a -# $(CXX) $(DLL_BND_FLAGS) -o $@ $^ > $*.bind.lst -# @echo 'Building $(OUT_DIR)/libzds.so' - -# libzds.so: $(OUT_DIRS) $(OUT_DIR)/libzds.so - -# $(OUT_DIR)/libzds.a: $(OUT_DIR)/zds.o $(OUT_DIR)/zdsm.o $(OUT_DIR)/zam.o $(OUT_DIR)/libzut.a -# @echo 'Building $(OUT_DIR)/libzds.a' -# ar -rv $@ $^ - -# libzds.a: $(OUT_DIRS) $(OUT_DIR)/libzds.a - -# # -# # Jobs -# # -# $(OUT_DIR)/zjbm.s: zjbm.c -# @echo 'Building $(OUT_DIR)/zjbm.s' -# $(CC) $(MTL_FLAGS64) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ - -# $(OUT_DIR)/zjbm.o: $(OUT_DIR)/zjbm.s -# @echo 'Building $(OUT_DIR)/zjbm.o' -# $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ - -# $(OUT_DIR)/zjb.o: zjb.cpp -# @echo 'Building $(OUT_DIR)/zjb.o' -# $(CXX) $(DLL_CPP_FLAGS) -qlist=$*.cpp.lst -o $@ $^ - -# $(OUT_DIR_CXXLANG)/zjb.o: $(OUT_DIRS) zjb.cpp -# @echo '$(OUT_DIR_CXXLANG)/zjb.o' -# $(CXXLANG) $(CXXLANG_FLAGS) -qlist=$*.cpp.lst -o $@ $^ - -# $(OUT_DIR)/zjbm31.s: zjbm31.c -# @echo 'Building $(OUT_DIR)/zjbm31.s' -# $(CC) $(MTL_FLAGS) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ - -# $(OUT_DIR)/zjbm31.o: $(OUT_DIR)/zjbm31.s -# @echo 'Building $(OUT_DIR)/zjbm31.o' -# $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ - -# $(OUT_DIR)/zssi31.s: zssi31.c -# @echo 'Building $(OUT_DIR)/zssi31.s' -# $(CC) $(MTL_FLAGS) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ - -# $(OUT_DIR)/zssi31.o: $(OUT_DIR)/zssi31.s -# @echo 'Building $(OUT_DIR)/zssi31.o' -# $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ - -# $(OUT_DIR)/libzjb.so: $(OUT_DIR)/zjb.o $(OUT_DIR)/zjbm.o $(OUT_DIR)/zssi31.o $(OUT_DIR)/zjbm31.o $(OUT_DIR)/libzds.a $(OUT_DIR)/libzut.a -# @echo 'Building $(OUT_DIR)/libzjb.so' -# $(CXX) $(DLL_BND_FLAGS) -o $@ $^ > $*.bind.lst - -# libzjb.so: $(OUT_DIRS) $(OUT_DIR)/libzjb.so - -# $(OUT_DIR)/libzjb.a: $(OUT_DIR)/zjb.o $(OUT_DIR)/zjbm.o $(OUT_DIR)/zssi31.o $(OUT_DIR)/zjbm31.o $(OUT_DIR)/libzds.a $(OUT_DIR)/libzut.a -# @echo 'Building $(OUT_DIR)/libzjb.a' -# ar -rv $@ $^ - -# libzjb.a: $(OUT_DIRS) $(OUT_DIR)/libzjb.a - -# # -# # Console -# # -# $(OUT_DIR)/zcn.o: zcn.cpp -# $(CXX) $(DLL_CPP_FLAGS) -qlist=$*.cpp.lst -o $@ $^ - -# $(OUT_DIR_CXXLANG)/zcn.o: $(OUT_DIRS) zcn.cpp -# @echo '$(OUT_DIR_CXXLANG)/zcn.o' -# $(CXXLANG) $(CXXLANG_FLAGS) -qlist=$*.cpp.lst -o $@ $^ - -# $(OUT_DIR)/zcnm.s: zcnm.c -# $(CC) $(MTL_FLAGS64) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ - -# $(OUT_DIR)/zcnm.o: $(OUT_DIR)/zcnm.s -# $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ - -# $(OUT_DIR)/zcnm31.s: zcnm31.c -# $(CC) $(MTL_FLAGS) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ - -# $(OUT_DIR)/zcnm31.o: $(OUT_DIR)/zcnm31.s -# $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ - -# $(OUT_DIR)/libzcn.so: $(OUT_DIR)/zcn.o $(OUT_DIR)/zcnm.o $(OUT_DIR)/zcnm31.o $(OUT_DIR)/libzut.a -# @echo 'Building $(OUT_DIR)/libzcn.so' -# $(CXX) $(DLL_BND_FLAGS) -o $@ $^ > $*.bind.lst - -# libzcn.so: $(OUT_DIRS) $(OUT_DIR)/libzcn.so - -# $(OUT_DIR)/libzcn.a: $(OUT_DIR)/zcn.o $(OUT_DIR)/zcnm.o $(OUT_DIR)/zcnm31.o $(OUT_DIR)/libzut.a -# @echo 'Building libzcn.a' -# ar -rv $@ $^ - -# libzcn.a: $(OUT_DIRS) $(OUT_DIR)/libzcn.a - -# # -# # USS data -# # -# $(OUT_DIR)/zusf.o: zusf.cpp -# @echo 'Building $(OUT_DIR)/zusf.o' -# $(CXX) $(DLL_CPP_FLAGS) -qlist=$*.cpp.lst -o $@ $^ - -# $(OUT_DIR)/libzusf.so: $(OUT_DIR)/zusf.o $(OUT_DIR)/libzut.a -# @echo 'Building $(OUT_DIR)/libzusf.so' -# $(CXX) $(DLL_BND_FLAGS) -o $@ $^ > $*.bind.lst - -# libzusf.so: $(OUT_DIRS) $(OUT_DIR)/libzusf.so - -# $(OUT_DIR)/libzusf.a: $(OUT_DIR)/zusf.o $(OUT_DIR)/libzut.a -# @echo 'Building $(OUT_DIR)/libzusf.a' -# ar -rv $@ $^ - -# libzusf.a: $(OUT_DIRS) $(OUT_DIR)/libzusf.a - -# -# TSO -# # -# $(OUT_DIR)/ztso.o: ztso.cpp -# @echo 'Building $(OUT_DIR)/ztso.o' -# $(CXX) $(DLL_CPP_FLAGS) -qlist=$*.cpp.lst -o $@ $^ - -# $(OUT_DIR)/libztso.so: ztso -# @echo 'Building $(OUT_DIR)/libztso.so' -# $(CXX) $(DLL_BND_FLAGS) -o $@ $^ > $*.bind.lst - -# libztso.so: $(OUT_DIRS) $(OUT_DIR)/libztso.so - -# $(OUT_DIR)/libztso.a: $(OUT_DIR)/ztso.o -# @echo 'Building $(OUT_DIR)/libztso.a' -# ar -rv $@ $^ - -# libztso.a: $(OUT_DIRS) $(OUT_DIR)/libztso.a - -# -# Test CLI -# -# zowex: zowex.o zcn.o zcnm.o zcnm31.o zut.o zutm.o zutm31.o zjb.o zjbm.o zssi31.o zjbm31.o zds.o -# $(OUT_DIR)/zowex: $(OUT_DIR)/zowex.o $(OUT_DIR)/libzcn.a $(OUT_DIR)/libzut.a $(OUT_DIR)/libzjb.a $(OUT_DIR)/libzds.a $(OUT_DIR)/libzusf.a $(OUT_DIR)/libztso.a -# @echo 'Building zowex' -# $(CXX) $(CPP_BND_FLAGS) -o $@ $^ > $*.bind.lst -# ln -sf ../c/$@ ../golang/zowex -# @echo 'Copied zowex to golang/' - -# zcnx: $(OUT_DIRS) $(OUT_DIR)/zcnx +run: build-out/demozcnx + @echo 'Running ./build-out/demozcnx' + export _BPXK_JOBLOG=STDERR && ./build-out/demozcnx build-out/demozcn.o: demozcn.cpp @echo 'Building $(OUT_DIR)/demozcn.o' cp ../../build-out/*.a build-out - $(CXX) $(CPP_FLAGS) -qlist=$*.cpp.lst -c $^ -o $@ + $(CXX) $(CPP_FLAGS) -c $^ -o $@ build-out/demozcnx: build-out/demozcn.o build-out/libzcn.a build-out/libzut.a @echo 'Building demozcnx' $(CXX) $(CPP_BND_FLAGS_AUTH) -o $@ $^ > $*.bind.lst -demozcnx: build-out/demozcnx - extattr: extattr +ap build-out/demozcnx From a6aaed5182a07894e08e59a49164dee5585dfa80 Mon Sep 17 00:00:00 2001 From: Fernando Rijo Cedeno <37381190+zFernand0@users.noreply.github.com> Date: Thu, 9 Apr 2026 10:27:38 -0400 Subject: [PATCH 04/17] chore: and another one during meetings Signed-off-by: Fernando Rijo Cedeno <37381190+zFernand0@users.noreply.github.com> --- native/c/examples/ams/ams_driver.cpp | 17 ++- native/c/examples/ams/makefile | 178 +++++++++------------------ 2 files changed, 74 insertions(+), 121 deletions(-) diff --git a/native/c/examples/ams/ams_driver.cpp b/native/c/examples/ams/ams_driver.cpp index 6da382797..89f26b9fe 100644 --- a/native/c/examples/ams/ams_driver.cpp +++ b/native/c/examples/ams/ams_driver.cpp @@ -45,12 +45,12 @@ int main() // data.push_back("012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789abcdefghijkl"); // data.push_back(" 0123456789012345678901234567890123456789012345678901234567890123456789"); // data.push_back("0123456789 012345678901234567890123456789012345678901234567890123456789"); - data.push_back(" hey workld"); + data.push_back(" hey world"); data.push_back(" one more"); ZDS zds = {0}; IO_CTRL *ioc = nullptr; - rc = zds_open_output_bpam(&zds, "DKELOSKY.IO.O.FB80(data)", ioc); + rc = zds_open_output_bpam(&zds, "ZOWETEST.IO.O.FB80(data)", ioc); // rc = zds_open_output_bpam(&zds, "DKELOSKY.IO.O.V25(OMGNESS)", ioc); // rc = zds_open_output_bpam(&zds, "DKELOSKY.IO.O.V256(OMGNESS)", ioc); // rc = zds_open_output_bpam(&zds, "DKELOSKY.IO.O.VB256(OMGNESS)", ioc); @@ -62,7 +62,7 @@ int main() return -1; } - for (const auto &line : data) + for (std::string &line : data) { rc = zds_write_output_bpam(&zds, ioc, line); if (0 != rc) @@ -81,5 +81,16 @@ int main() return -1; } + std::cout << "zds_close_output_bpam success" << std::endl; + std::cout << " Data set: ZOWETEST.IO.O.FB80(data)" << std::endl; + // Run command to view data set + std::string command = "../../build-out/zowex ds view 'ZOWETEST.IO.O.FB80(data)'"; + std::cout << " Run: " << command << std::endl; + rc = system(command.c_str()); + if (0 != rc) + { + std::cout << "Failed to run command: " << command << std::endl; + return -1; + } return 0; } diff --git a/native/c/examples/ams/makefile b/native/c/examples/ams/makefile index e04b7c91d..a77a5c09a 100644 --- a/native/c/examples/ams/makefile +++ b/native/c/examples/ams/makefile @@ -10,115 +10,73 @@ # OUT_DIR=build-out -OUT_DIRS=$(OUT_DIR_CXXLANG) - -XLC_FLAGS=_CC_ACCEPTABLE_RC=0 _C89_ACCEPTABLE_RC=0 _CXX_ACCEPTABLE_RC=0 -CXX=$(XLC_FLAGS) xlc++ -CC=$(XLC_FLAGS) xlc -ASM=as -BIND=ld - -MTL_OPTS=metal,\ - langlvl(extended),\ - sscom,\ - nolongname,\ - inline,\ - genasm,\ - inlrpt,\ - csect,\ - nose,\ - list,\ - warn64,\ - optimize(2),\ - aggregate - -MTL_OPTS64=$(MTL_OPTS),lp64 -MTL_FLAGS=-S -W "c,$(MTL_OPTS)" -MTL_FLAGS64=-S -W "c,$(MTL_OPTS64)" - -MACLIBS= -I../../../asmmac \ - -ISYS1.MACLIB \ - -ISYS1.MODGEN \ - -ICBC.SCCNSAM - -MTL_HEADERS=-I/usr/include/metal \ - -I../../chdsect \ - -I../../../c - -CPP_BND_FLAGS=-W "l,lp64,xplink,map,list" - -CPP_BND_FLAGS_AUTH=-W "l,lp64,xplink,map,list,ac=1" - -C_FLAGS=-W "c,lp64,langlvl(extended),xplink,exportall"\ - -c \ - -I../../chdsect \ - -I../../../c - -DLL_CPP_FLAGS=-W "c,lp64,langlvl(extended0x),dll,xplink,exportall"\ - -c \ - -I./chdsect - -DLL_BND_FLAGS=-W "l,lp64,dll,dynam=dll,xplink,map,list" - -CPP_FLAGS=-W "c,lp64,langlvl(extended0x),dll,xplink"\ - -c \ - -I../../chdsect \ - -I../../../c - -ASM_FLAGS=-mRENT - -# make -DBuildType=DEBUG -.IF $(BuildType) == DEBUG -# -g generates debugging information -DEBUGGER_FLAGS=-qSOURCE -g9 -OTHER_C_FLAGS=-qSHOWINC -qSHOWMACROS - -CPP_BND_FLAGS+=$(DEBUGGER_FLAGS) -CPP_BND_FLAGS_AUTH+=$(DEBUGGER_FLAGS) -C_FLAGS+=$(DEBUGGER_FLAGS) -DLL_BND_FLAGS+=$(DEBUGGER_FLAGS) -DLL_CPP_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -CPP_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -MTL_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -MTL_FLAGS64+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -ASM_FLAGS+=--verbose - -.ELSE -C_FLAGS+=-g0 -CPP_FLAGS+=-g0 -CPP_BND_FLAGS+=-g0 -CPP_BND_FLAGS_AUTH+=-g0 -DLL_BND_FLAGS+=-g0 -DLL_CPP_FLAGS+=-g0 -ASM_FLAGS+=--noverbose - -# Still investigating why we need `-g1` for the MetalC flags :'( -MTL_FLAGS+=-g1 -MTL_FLAGS64+=-g1 -.END - -all: build-out build-out/ams_driver - -ams: build-out/ams +.INCLUDE: ../examples_toolchain.mk + +all: copy-mtl build-out run + +# +# Output directories +# build-out: @echo 'Creating build-out' mkdir -p build-out -# zam.c: ../../zam.c -# cp ../../zam.c . +run: build-out/ams_driver + @echo 'Running ./build-out/ams_driver' + ./build-out/ams_driver + +copy-mtl: + cp ../../zdsm.c zdsm.c + cp ../../zam.c zam.c + cp ../../zutm.c zutm.c + cp ../../zutm31.c zutm31.c build-out/ams_driver.o: ams_driver.cpp @echo 'Building $(OUT_DIR)/ams_driver.o' - $(CXX) $(CPP_FLAGS) -qlist=$*.cpp.lst -c $^ -o $@ + $(CXX) $(CPP_FLAGS) -c $^ -o $@ -# build-out/zam.s: zam.c -# @echo 'Building build-out/zam.s' -# $(CC) $(MTL_FLAGS) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ +build-out/zds.o: ../../zds.cpp + @echo 'Building $(OUT_DIR)/zds.o' + $(CXX) $(CPP_FLAGS) -c $^ -o $@ -# build-out/zam.o: build-out/zam.s -# @echo 'Building build-out/zam.s' -# $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ +build-out/zut.o: ../../zut.cpp + @echo 'Building $(OUT_DIR)/zut.o' + $(CXX) $(CPP_FLAGS) -c $^ -o $@ + +build-out/zdsm.s: zdsm.c + @echo 'Building $(OUT_DIR)/zdsm.s' + $(CC) $(MTL_FLAGS64) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ + +build-out/zdsm.o: build-out/zdsm.s + @echo 'Building $(OUT_DIR)/zdsm.o' + $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ + +build-out/zam.s: zam.c + @echo 'Building $(OUT_DIR)/zam.s' + $(CC) $(MTL_FLAGS) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ + +build-out/zam.o: build-out/zam.s + @echo 'Building $(OUT_DIR)/zam.o' + $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ + +build-out/zutm.s: zutm.c + @echo 'Building $(OUT_DIR)/zutm.s' + $(CC) $(MTL_FLAGS64) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ + +build-out/zutm.o: build-out/zutm.s + @echo 'Building $(OUT_DIR)/zutm.o' + $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ + +build-out/zutm31.s: zutm31.c + @echo 'Building $(OUT_DIR)/zutm31.s' + $(CC) $(MTL_FLAGS) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ + +build-out/zutm31.o: build-out/zutm31.s + @echo 'Building $(OUT_DIR)/zutm31.o' + $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ + +# ams: build-out/ams # build-out/ams.s: ams.c # @echo 'Building build-out/ams.s' @@ -129,32 +87,16 @@ build-out/ams_driver.o: ams_driver.cpp # $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ build-out/ams_driver: build-out/zds.o build-out/zdsm.o build-out/zut.o build-out/zam.o build-out/zutm.o build-out/zutm31.o build-out/ams_driver.o + @echo 'Building ams_driver' $(CXX) $(CPP_BND_FLAGS) -o $@ $^ > $*.bind.lst -build-out/zds.o: - cp ../../build-out/zds.o build-out - -build-out/zdsm.o: - cp ../../build-out/zdsm.o build-out - -build-out/zut.o: - cp ../../build-out/zut.o build-out - -build-out/zam.o: - cp ../../build-out/zam.o build-out - -build-out/zutm.o: - cp ../../build-out/zutm.o build-out - -build-out/zutm31.o: - cp ../../build-out/zutm31.o build-out - clean: rm -f *.o rm -f *.dbg rm -f *.so rm -f *.a + rm -f *.u rm -f *.x rm -f *.lst rm -f CEEDUMP.* - rm -rf build-out + rm -rf $(OUT_DIR) From a7dd05bfed24cdcc582f1b4d3bdb7e4f4c7f6aac Mon Sep 17 00:00:00 2001 From: Fernando Rijo Cedeno <37381190+zFernand0@users.noreply.github.com> Date: Fri, 10 Apr 2026 19:06:28 -0400 Subject: [PATCH 05/17] chore: fix debug flags and add required files for zlogger.hpp Signed-off-by: Fernando Rijo Cedeno <37381190+zFernand0@users.noreply.github.com> --- native/c/examples/ams/makefile | 63 +++++++------ native/c/examples/enq/makefile | 28 +++--- native/c/examples/examples_toolchain.mk | 15 +++ native/c/examples/jsoncpp/makefile | 67 +++++++++++--- native/c/examples/jsonm/makefile | 28 +++--- native/c/examples/metal/makefile | 32 +++---- native/c/examples/prolog/makefile | 117 ++++-------------------- native/c/examples/rcvy/makefile | 22 ++--- native/c/examples/timer/makefile | 24 ++--- native/c/examples/zcn/makefile | 26 +++--- 10 files changed, 206 insertions(+), 216 deletions(-) diff --git a/native/c/examples/ams/makefile b/native/c/examples/ams/makefile index a77a5c09a..ce2bbd5b7 100644 --- a/native/c/examples/ams/makefile +++ b/native/c/examples/ams/makefile @@ -13,80 +13,87 @@ OUT_DIR=build-out .INCLUDE: ../examples_toolchain.mk -all: copy-mtl build-out run +all: copy-mtl $(OUT_DIR) run # # Output directories # -build-out: - @echo 'Creating build-out' - mkdir -p build-out +$(OUT_DIR): + @echo 'Creating $(OUT_DIR)' + mkdir -p $(OUT_DIR) -run: build-out/ams_driver - @echo 'Running ./build-out/ams_driver' - ./build-out/ams_driver +run: $(OUT_DIR)/ams_driver + @echo 'Running ./$(OUT_DIR)/ams_driver' + ./$(OUT_DIR)/ams_driver copy-mtl: cp ../../zdsm.c zdsm.c cp ../../zam.c zam.c cp ../../zutm.c zutm.c cp ../../zutm31.c zutm31.c + cp ../../zlogger_metal.c zlogger_metal.c + +$(OUT_DIR)/zam24.s: ../../zam24.s + @echo 'Building $(OUT_DIR)/zam24.s' + cp ../../zam24.s $(OUT_DIR)/zam24.s + +$(OUT_DIR)/zam24.o: $(OUT_DIR)/zam24.s + @echo 'Building $(OUT_DIR)/zam24.o' + $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ -build-out/ams_driver.o: ams_driver.cpp +$(OUT_DIR)/ams_driver.o: ams_driver.cpp @echo 'Building $(OUT_DIR)/ams_driver.o' $(CXX) $(CPP_FLAGS) -c $^ -o $@ -build-out/zds.o: ../../zds.cpp +$(OUT_DIR)/zds.o: ../../zds.cpp @echo 'Building $(OUT_DIR)/zds.o' $(CXX) $(CPP_FLAGS) -c $^ -o $@ -build-out/zut.o: ../../zut.cpp +$(OUT_DIR)/zut.o: ../../zut.cpp @echo 'Building $(OUT_DIR)/zut.o' $(CXX) $(CPP_FLAGS) -c $^ -o $@ -build-out/zdsm.s: zdsm.c +$(OUT_DIR)/zdsm.s: zdsm.c @echo 'Building $(OUT_DIR)/zdsm.s' $(CC) $(MTL_FLAGS64) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ -build-out/zdsm.o: build-out/zdsm.s +$(OUT_DIR)/zdsm.o: $(OUT_DIR)/zdsm.s @echo 'Building $(OUT_DIR)/zdsm.o' $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ -build-out/zam.s: zam.c +$(OUT_DIR)/zam.s: zam.c @echo 'Building $(OUT_DIR)/zam.s' - $(CC) $(MTL_FLAGS) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ + $(CC) $(MTL_FLAGS) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ -build-out/zam.o: build-out/zam.s +$(OUT_DIR)/zam.o: $(OUT_DIR)/zam.s @echo 'Building $(OUT_DIR)/zam.o' $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ -build-out/zutm.s: zutm.c +$(OUT_DIR)/zutm.s: zutm.c @echo 'Building $(OUT_DIR)/zutm.s' $(CC) $(MTL_FLAGS64) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ -build-out/zutm.o: build-out/zutm.s +$(OUT_DIR)/zutm.o: $(OUT_DIR)/zutm.s @echo 'Building $(OUT_DIR)/zutm.o' $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ -build-out/zutm31.s: zutm31.c +$(OUT_DIR)/zutm31.s: zutm31.c @echo 'Building $(OUT_DIR)/zutm31.s' $(CC) $(MTL_FLAGS) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ -build-out/zutm31.o: build-out/zutm31.s +$(OUT_DIR)/zutm31.o: $(OUT_DIR)/zutm31.s @echo 'Building $(OUT_DIR)/zutm31.o' $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ -# ams: build-out/ams - -# build-out/ams.s: ams.c -# @echo 'Building build-out/ams.s' -# $(CC) $(MTL_FLAGS64) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ +$(OUT_DIR)/zlogger_metal.s: zlogger_metal.c + @echo 'Building $(OUT_DIR)/zlogger_metal.s' + $(CC) $(MTL_FLAGS64) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ -# build-out/ams.o: build-out/ams.s -# @echo 'Building build-out/ams.s' -# $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ +$(OUT_DIR)/zlogger_metal.o: $(OUT_DIR)/zlogger_metal.s + @echo 'Building $(OUT_DIR)/zlogger_metal.o' + $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ -build-out/ams_driver: build-out/zds.o build-out/zdsm.o build-out/zut.o build-out/zam.o build-out/zutm.o build-out/zutm31.o build-out/ams_driver.o +$(OUT_DIR)/ams_driver: $(OUT_DIR)/zds.o $(OUT_DIR)/zdsm.o $(OUT_DIR)/zut.o $(OUT_DIR)/zam.o $(OUT_DIR)/zam24.o $(OUT_DIR)/zutm.o $(OUT_DIR)/zutm31.o $(OUT_DIR)/zlogger_metal.o $(OUT_DIR)/ams_driver.o @echo 'Building ams_driver' $(CXX) $(CPP_BND_FLAGS) -o $@ $^ > $*.bind.lst diff --git a/native/c/examples/enq/makefile b/native/c/examples/enq/makefile index 238567ce7..d3854221f 100644 --- a/native/c/examples/enq/makefile +++ b/native/c/examples/enq/makefile @@ -13,26 +13,26 @@ OUT_DIR=build-out .INCLUDE: ../examples_toolchain.mk -all: build-out run +all: $(OUT_DIR) run -run: build-out/runenq - @echo 'Running ./build-out/runenq' - ./build-out/runenq +run: $(OUT_DIR)/runenq + @echo 'Running ./$(OUT_DIR)/runenq' + ./$(OUT_DIR)/runenq -build-out: - @echo 'Creating build-out' - mkdir -p build-out +$(OUT_DIR): + @echo 'Creating $(OUT_DIR)' + mkdir -p $(OUT_DIR) -build-out/runenq.s: runenq.c - @echo 'Building build-out/runenq.s' +$(OUT_DIR)/runenq.s: runenq.c + @echo 'Building $(OUT_DIR)/runenq.s' $(CC) $(MTL_FLAGS64) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ -build-out/runenq.o: build-out/runenq.s - @echo 'Building build-out/runenq.o' +$(OUT_DIR)/runenq.o: $(OUT_DIR)/runenq.s + @echo 'Building $(OUT_DIR)/runenq.o' $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ -build-out/runenq: build-out/runenq.o - @echo 'Building build-out/runenq' +$(OUT_DIR)/runenq: $(OUT_DIR)/runenq.o + @echo 'Building $(OUT_DIR)/runenq' $(CXX) $(CPP_BND_FLAGS) -Wl,-eMAIN -o $@ $^ clean: @@ -43,4 +43,4 @@ clean: rm -f *.x rm -f *.lst rm -f CEEDUMP.* - rm -rf build-out + rm -rf $(OUT_DIR) diff --git a/native/c/examples/examples_toolchain.mk b/native/c/examples/examples_toolchain.mk index b06c55967..6c519d9c7 100644 --- a/native/c/examples/examples_toolchain.mk +++ b/native/c/examples/examples_toolchain.mk @@ -22,6 +22,21 @@ MTL_HEADERS=$(MTL_HEADERS_BASE) -I../../chdsect -I../../../c C_FLAGS_COMMON=-I../../chdsect -I../../../c CPP_FLAGS_COMMON=-I../../chdsect -I../../../c +MTL_BASE_OPTS=metal,\ + langlvl(extended),\ + sscom,\ + nolongname,\ + genasm,\ + csect,\ + nose,\ + warn64,\ + optimize(2) + +# WARNING CCN3396 - Option INLINE is incompatible with option TEST/DEBUG and is ignored. + # inline,\ +# WARNING CCN0833 - "GONUMBER" is not compatible with "METAL". "NOGONUMBER" is being set. +DEBUGGER_FLAGS=-g0 # This value was previously set to `-g` in the toolchain.mk file. + # Build type handling for examples .IF $(BuildType) == DEBUG CPP_BND_FLAGS=$(CPP_BND_DEBUG_FLAGS) $(DEBUGGER_FLAGS) diff --git a/native/c/examples/jsoncpp/makefile b/native/c/examples/jsoncpp/makefile index 76033fedb..89a6315ec 100644 --- a/native/c/examples/jsoncpp/makefile +++ b/native/c/examples/jsoncpp/makefile @@ -13,35 +13,80 @@ OUT_DIR=build-out .INCLUDE: ../examples_toolchain.mk -all: copy-mtl build-out run +all: copy-mtl $(OUT_DIR) run # # Output directories # -build-out: - @echo 'Creating build-out' - mkdir -p build-out +$(OUT_DIR): + @echo 'Creating $(OUT_DIR)' + mkdir -p $(OUT_DIR) -run: build-out/json - @echo 'Running ./build-out/json' - ./build-out/json +run: $(OUT_DIR)/json + @echo 'Running ./$(OUT_DIR)/json' + ./$(OUT_DIR)/json copy-mtl: cp ../../zjsonm.c zjsonm.c + cp ../../zam.c zam.c + cp ../../zam24.s zam24.s + cp ../../zutm.c zutm.c + cp ../../zutm31.c zutm31.c + cp ../../zlogger_metal.c zlogger_metal.c -build-out/zjsonm.s: zjsonm.c +$(OUT_DIR)/zjsonm.s: zjsonm.c @echo 'Building $(OUT_DIR)/zjsonm.s' $(CC) $(MTL_FLAGS64) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ -build-out/zjsonm.o: build-out/zjsonm.s +$(OUT_DIR)/zjsonm.o: $(OUT_DIR)/zjsonm.s @echo 'Building $(OUT_DIR)/zjsonm.o' $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ -build-out/json.o: json.cpp +$(OUT_DIR)/zam.s: zam.c + @echo 'Building $(OUT_DIR)/zam.s' + $(CC) $(MTL_FLAGS) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ + +$(OUT_DIR)/zam.o: $(OUT_DIR)/zam.s + @echo 'Building $(OUT_DIR)/zam.o' + $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ + +$(OUT_DIR)/zam24.s: zam24.s + @echo 'Copying $(OUT_DIR)/zam24.s' + cp ../../zam24.s $(OUT_DIR)/zam24.s + +$(OUT_DIR)/zam24.o: $(OUT_DIR)/zam24.s + @echo 'Building $(OUT_DIR)/zam24.o' + $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ + +$(OUT_DIR)/zutm.s: zutm.c + @echo 'Building $(OUT_DIR)/zutm.s' + $(CC) $(MTL_FLAGS64) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ + +$(OUT_DIR)/zutm.o: $(OUT_DIR)/zutm.s + @echo 'Building $(OUT_DIR)/zutm.o' + $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ + +$(OUT_DIR)/zutm31.s: zutm31.c + @echo 'Building $(OUT_DIR)/zutm31.s' + $(CC) $(MTL_FLAGS) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ + +$(OUT_DIR)/zutm31.o: $(OUT_DIR)/zutm31.s + @echo 'Building $(OUT_DIR)/zutm31.o' + $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ + +$(OUT_DIR)/zlogger_metal.s: zlogger_metal.c + @echo 'Building $(OUT_DIR)/zlogger_metal.s' + $(CC) $(MTL_FLAGS64) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ + +$(OUT_DIR)/zlogger_metal.o: $(OUT_DIR)/zlogger_metal.s + @echo 'Building $(OUT_DIR)/zlogger_metal.o' + $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ + +$(OUT_DIR)/json.o: json.cpp @echo 'Building $(OUT_DIR)/json.o' $(CXX) $(CPP_FLAGS) -c $^ -o $@ -build-out/json: build-out/json.o build-out/zjsonm.o +$(OUT_DIR)/json: $(OUT_DIR)/zjsonm.o $(OUT_DIR)/zam.o $(OUT_DIR)/zam24.o $(OUT_DIR)/zutm.o $(OUT_DIR)/zutm31.o $(OUT_DIR)/zlogger_metal.o $(OUT_DIR)/json.o @echo 'Building json' $(CXX) $(CPP_BND_FLAGS) -o $@ $^ > $*.bind.lst diff --git a/native/c/examples/jsonm/makefile b/native/c/examples/jsonm/makefile index 81ce8cf00..39f351924 100644 --- a/native/c/examples/jsonm/makefile +++ b/native/c/examples/jsonm/makefile @@ -13,31 +13,31 @@ OUT_DIR=build-out .INCLUDE: ../examples_toolchain.mk -all: build-out run +all: $(OUT_DIR) run -run: build-out/json - @echo 'Running ./build-out/json' - ./build-out/json +run: $(OUT_DIR)/json + @echo 'Running ./$(OUT_DIR)/json' + ./$(OUT_DIR)/json -build-out: - @echo 'Creating build-out' - mkdir -p build-out +$(OUT_DIR): + @echo 'Creating $(OUT_DIR)' + mkdir -p $(OUT_DIR) copy-mtl: cp ../../zmetal.h zmetal.h cp ../../zwto.h zwto.h cp ../../zjsonm31.h zjsonm31.h -build-out/json.s: json.c - @echo 'Building build-out/json.s' +$(OUT_DIR)/json.s: json.c + @echo 'Building $(OUT_DIR)/json.s' $(CC) $(MTL_FLAGS64) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ -build-out/json.o: build-out/json.s - @echo 'Building build-out/json.s' +$(OUT_DIR)/json.o: $(OUT_DIR)/json.s + @echo 'Building $(OUT_DIR)/json.s' $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ -build-out/json: build-out/json.o - @echo 'Building build-out/json' +$(OUT_DIR)/json: $(OUT_DIR)/json.o + @echo 'Building $(OUT_DIR)/json' $(CXX) $(CPP_BND_FLAGS) -o $@ $^ clean: @@ -48,4 +48,4 @@ clean: rm -f *.x rm -f *.lst rm -f CEEDUMP.* - rm -rf build-out + rm -rf $(OUT_DIR) diff --git a/native/c/examples/metal/makefile b/native/c/examples/metal/makefile index 1ad932cc4..1dc8229aa 100644 --- a/native/c/examples/metal/makefile +++ b/native/c/examples/metal/makefile @@ -13,38 +13,38 @@ OUT_DIR=build-out .INCLUDE: ../examples_toolchain.mk -all: copy-mtl build-out run +all: copy-mtl $(OUT_DIR) run -run: build-out/demometal - @echo 'Running ./build-out/demometal' - ./build-out/demometal +run: $(OUT_DIR)/demometal + @echo 'Running ./$(OUT_DIR)/demometal' + ./$(OUT_DIR)/demometal -build-out: - @echo 'Creating build-out' - mkdir -p build-out +$(OUT_DIR): + @echo 'Creating $(OUT_DIR)' + mkdir -p $(OUT_DIR) copy-mtl: cp ../../zutm.c zutm.c cp ../../ztime.h ztime.h -build-out/zutm.s: zutm.c +$(OUT_DIR)/zutm.s: zutm.c @echo 'Building $(OUT_DIR)/zutm.s' $(CC) $(MTL_FLAGS64) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ -build-out/zutm.o: build-out/zutm.s +$(OUT_DIR)/zutm.o: $(OUT_DIR)/zutm.s @echo 'Building $(OUT_DIR)/zutm.o' $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ -build-out/demometal.s: demometal.c - @echo 'Building build-out/demometal.s' +$(OUT_DIR)/demometal.s: demometal.c + @echo 'Building $(OUT_DIR)/demometal.s' $(CC) $(MTL_FLAGS64) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ -build-out/demometal.o: build-out/demometal.s - @echo 'Building build-out/demometal.s' +$(OUT_DIR)/demometal.o: $(OUT_DIR)/demometal.s + @echo 'Building $(OUT_DIR)/demometal.s' $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ -build-out/demometal: build-out/demometal.o - @echo 'Building build-out/demometal' +$(OUT_DIR)/demometal: $(OUT_DIR)/demometal.o + @echo 'Building $(OUT_DIR)/demometal' $(CXX) $(CPP_BND_FLAGS) -Wl,-eMAIN -o $@ $^ clean: @@ -55,4 +55,4 @@ clean: rm -f *.x rm -f *.lst rm -f CEEDUMP.* - rm -rf build-out + rm -rf $(OUT_DIR) diff --git a/native/c/examples/prolog/makefile b/native/c/examples/prolog/makefile index e66fd4b32..c144a3a0c 100644 --- a/native/c/examples/prolog/makefile +++ b/native/c/examples/prolog/makefile @@ -10,118 +10,41 @@ # OUT_DIR=build-out -OUT_DIRS=$(OUT_DIR_CXXLANG) -XLC_FLAGS=_CC_ACCEPTABLE_RC=0 _C89_ACCEPTABLE_RC=0 _CXX_ACCEPTABLE_RC=0 -CXX=$(XLC_FLAGS) xlc++ -CC=$(XLC_FLAGS) xlc -ASM=as -BIND=ld +.INCLUDE: ../examples_toolchain.mk -MTL_OPTS=metal,\ - langlvl(extended),\ - sscom,\ - nolongname,\ - inline,\ - genasm,\ - inlrpt,\ - csect,\ - nose,\ - list,\ - warn64,\ - optimize(2),\ - aggregate +all: $(OUT_DIR) run -MTL_OPTS64=$(MTL_OPTS),lp64 -MTL_FLAGS=-S -W "c,$(MTL_OPTS)" -MTL_FLAGS64=-S -W "c,$(MTL_OPTS64)" - -MACLIBS= -I../../../asmmac \ - -ISYS1.MACLIB \ - -ISYS1.MODGEN \ - -ICBC.SCCNSAM - -MTL_HEADERS=-I/usr/include/metal \ - -I../../chdsect \ - -I../../../c - -CPP_BND_FLAGS=-W "l,lp64,xplink,map,list" - -CPP_BND_FLAGS_AUTH=-W "l,lp64,xplink,map,list,ac=1" - -C_FLAGS=-W "c,lp64,langlvl(extended),xplink,exportall"\ - -c \ - -I../../chdsect \ - -I../../../c - -DLL_CPP_FLAGS=-W "c,lp64,langlvl(extended0x),dll,xplink,exportall"\ - -c \ - -I./chdsect - -DLL_BND_FLAGS=-W "l,lp64,dll,dynam=dll,xplink,map,list" - -CPP_FLAGS=-W "c,lp64,langlvl(extended0x),dll,xplink"\ - -c \ - -I../../chdsect \ - -I../../../c - -ASM_FLAGS=-mRENT - -# make -DBuildType=DEBUG -.IF $(BuildType) == DEBUG -# -g generates debugging information -DEBUGGER_FLAGS=-qSOURCE -g9 -OTHER_C_FLAGS=-qSHOWINC -qSHOWMACROS - -CPP_BND_FLAGS+=$(DEBUGGER_FLAGS) -CPP_BND_FLAGS_AUTH+=$(DEBUGGER_FLAGS) -C_FLAGS+=$(DEBUGGER_FLAGS) -DLL_BND_FLAGS+=$(DEBUGGER_FLAGS) -DLL_CPP_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -CPP_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -MTL_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -MTL_FLAGS64+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -ASM_FLAGS+=--verbose - -.ELSE -C_FLAGS+=-g0 -CPP_FLAGS+=-g0 -CPP_BND_FLAGS+=-g0 -CPP_BND_FLAGS_AUTH+=-g0 -DLL_BND_FLAGS+=-g0 -DLL_CPP_FLAGS+=-g0 -ASM_FLAGS+=--noverbose - -# Still investigating why we need `-g1` for the MetalC flags :'( -MTL_FLAGS+=-g1 -MTL_FLAGS64+=-g1 -.END - -all: build-out build-out/prolog - -prolog: build-out/prolog +# +# Output directories +# +$(OUT_DIR): + @echo 'Creating $(OUT_DIR)' + mkdir -p $(OUT_DIR) -build-out: - @echo 'Creating build-out' - mkdir -p build-out +run: $(OUT_DIR)/prolog + @echo 'Running ./$(OUT_DIR)/prolog' + export _BPXK_JOBLOG=STDERR && ./$(OUT_DIR)/prolog -build-out/prolog.s: prolog.c - @echo 'Building build-out/prolog.s' +$(OUT_DIR)/prolog.s: prolog.c + @echo 'Building $(OUT_DIR)/prolog.s' $(CC) $(MTL_FLAGS64) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ -build-out/prolog.o: build-out/prolog.s - @echo 'Building build-out/prolog.s' +$(OUT_DIR)/prolog.o: $(OUT_DIR)/prolog.s + @echo 'Building $(OUT_DIR)/prolog.o' $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ -build-out/prolog: build-out/prolog.o - $(BIND) $(BIND_FLAGS_64) -V -eMAIN -o $@ $^ > $*.bind.lst +$(OUT_DIR)/prolog: $(OUT_DIR)/prolog.o + @echo 'Building $(OUT_DIR)/prolog' + $(CXX) $(CPP_BND_FLAGS) -Wl,-eMAIN -o $@ $^ > $*.bind.lst clean: rm -f *.o rm -f *.dbg rm -f *.so rm -f *.a + rm -f *.u rm -f *.x rm -f *.lst rm -f CEEDUMP.* - rm -rf build-out + rm -rf $(OUT_DIR) diff --git a/native/c/examples/rcvy/makefile b/native/c/examples/rcvy/makefile index a34e5bac0..40e540cfb 100644 --- a/native/c/examples/rcvy/makefile +++ b/native/c/examples/rcvy/makefile @@ -97,23 +97,23 @@ MTL_FLAGS+=-g1 MTL_FLAGS64+=-g1 .END -all: build-out build-out/testrcvy +all: $(OUT_DIR) $(OUT_DIR)/testrcvy -testrcvy: build-out/testrcvy +testrcvy: $(OUT_DIR)/testrcvy -build-out: - @echo 'Creating build-out' - mkdir -p build-out +$(OUT_DIR): + @echo 'Creating $(OUT_DIR)' + mkdir -p $(OUT_DIR) -build-out/testrcvy.s: testrcvy.c - @echo 'Building build-out/testrcvy.s' +$(OUT_DIR)/testrcvy.s: testrcvy.c + @echo 'Building $(OUT_DIR)/testrcvy.s' $(CC) $(MTL_FLAGS64) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ -build-out/testrcvy.o: build-out/testrcvy.s - @echo 'Building build-out/testrcvy.s' +$(OUT_DIR)/testrcvy.o: $(OUT_DIR)/testrcvy.s + @echo 'Building $(OUT_DIR)/testrcvy.s' $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ -build-out/testrcvy: build-out/testrcvy.o +$(OUT_DIR)/testrcvy: $(OUT_DIR)/testrcvy.o $(BIND) $(BIND_FLAGS_64) -V -eMAIN -o $@ $^ > $*.bind.lst clean: @@ -124,4 +124,4 @@ clean: rm -f *.x rm -f *.lst rm -f CEEDUMP.* - rm -rf build-out + rm -rf $(OUT_DIR) diff --git a/native/c/examples/timer/makefile b/native/c/examples/timer/makefile index deca6861b..14117c654 100644 --- a/native/c/examples/timer/makefile +++ b/native/c/examples/timer/makefile @@ -15,25 +15,25 @@ OUT_DIR=build-out BIND=ld -all: build-out run +all: $(OUT_DIR) run -build-out: +$(OUT_DIR): @echo 'Creating build-out' - mkdir -p build-out + mkdir -p $(OUT_DIR) -run: build-out/testtime - @echo 'Running ./build-out/testtime' - export _BPXK_JOBLOG=STDERR && ./build-out/testtime +run: $(OUT_DIR)/testtime + @echo 'Running ./$(OUT_DIR)/testtime' + export _BPXK_JOBLOG=STDERR && ./$(OUT_DIR)/testtime -build-out/testtime.s: testtime.c - @echo 'Building build-out/testtime.s' +$(OUT_DIR)/testtime.s: testtime.c + @echo 'Building $(OUT_DIR)/testtime.s' $(CC) $(MTL_FLAGS64) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ -build-out/testtime.o: build-out/testtime.s - @echo 'Building build-out/testtime.s' +$(OUT_DIR)/testtime.o: $(OUT_DIR)/testtime.s + @echo 'Building $(OUT_DIR)/testtime.s' $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ -build-out/testtime: build-out/testtime.o +$(OUT_DIR)/testtime: $(OUT_DIR)/testtime.o $(BIND) $(BIND_FLAGS_64) -V -eMAIN -o $@ $^ > $*.bind.lst clean: @@ -44,4 +44,4 @@ clean: rm -f *.x rm -f *.lst rm -f CEEDUMP.* - rm -rf build-out + rm -rf $(OUT_DIR) diff --git a/native/c/examples/zcn/makefile b/native/c/examples/zcn/makefile index 794d7802d..938ef61d9 100644 --- a/native/c/examples/zcn/makefile +++ b/native/c/examples/zcn/makefile @@ -13,30 +13,30 @@ OUT_DIR=build-out .INCLUDE: ../examples_toolchain.mk -all: build-out extattr run +all: $(OUT_DIR) extattr run # # Output directories # -build-out: +$(OUT_DIR): @echo 'Creating build-out' - mkdir -p build-out + mkdir -p $(OUT_DIR) -run: build-out/demozcnx - @echo 'Running ./build-out/demozcnx' - export _BPXK_JOBLOG=STDERR && ./build-out/demozcnx +run: $(OUT_DIR)/demozcn + @echo 'Running ./build-out/demozcn' + export _BPXK_JOBLOG=STDERR && ./build-out/demozcn -build-out/demozcn.o: demozcn.cpp +$(OUT_DIR)/demozcn.o: demozcn.cpp @echo 'Building $(OUT_DIR)/demozcn.o' - cp ../../build-out/*.a build-out + cp ../../$(OUT_DIR)/*.a $(OUT_DIR) $(CXX) $(CPP_FLAGS) -c $^ -o $@ -build-out/demozcnx: build-out/demozcn.o build-out/libzcn.a build-out/libzut.a - @echo 'Building demozcnx' +$(OUT_DIR)/demozcn: $(OUT_DIR)/demozcn.o $(OUT_DIR)/libzcn.a $(OUT_DIR)/libzut.a + @echo 'Building demozcn' $(CXX) $(CPP_BND_FLAGS_AUTH) -o $@ $^ > $*.bind.lst -extattr: - extattr +ap build-out/demozcnx +extattr: $(OUT_DIR)/demozcn + extattr +ap $(OUT_DIR)/demozcn clean: rm -f *.o @@ -47,4 +47,4 @@ clean: rm -f *.x rm -f *.lst rm -f CEEDUMP.* - rm -rf $(OUT_DIR) \ No newline at end of file + rm -rf $(OUT_DIR) From 8340f71495e8baa82fe672d85e15fb72a41c403f Mon Sep 17 00:00:00 2001 From: Fernando Rijo Cedeno <37381190+zFernand0@users.noreply.github.com> Date: Fri, 10 Apr 2026 19:55:03 -0400 Subject: [PATCH 06/17] chore: fix already refactored examples :yum: Signed-off-by: Fernando Rijo Cedeno <37381190+zFernand0@users.noreply.github.com> --- native/c/examples/enq/makefile | 4 +- native/c/examples/examples_toolchain.mk | 11 ++- native/c/examples/jsonm/makefile | 4 +- native/c/examples/metal/makefile | 4 +- native/c/examples/prolog/makefile | 4 +- native/c/examples/rcvy/makefile | 95 +++---------------------- native/c/examples/timer/makefile | 4 +- native/c/examples/zcn/makefile | 6 +- 8 files changed, 30 insertions(+), 102 deletions(-) diff --git a/native/c/examples/enq/makefile b/native/c/examples/enq/makefile index d3854221f..137b303c0 100644 --- a/native/c/examples/enq/makefile +++ b/native/c/examples/enq/makefile @@ -17,7 +17,7 @@ all: $(OUT_DIR) run run: $(OUT_DIR)/runenq @echo 'Running ./$(OUT_DIR)/runenq' - ./$(OUT_DIR)/runenq + export _BPXK_JOBLOG=STDERR && ./$(OUT_DIR)/runenq $(OUT_DIR): @echo 'Creating $(OUT_DIR)' @@ -33,7 +33,7 @@ $(OUT_DIR)/runenq.o: $(OUT_DIR)/runenq.s $(OUT_DIR)/runenq: $(OUT_DIR)/runenq.o @echo 'Building $(OUT_DIR)/runenq' - $(CXX) $(CPP_BND_FLAGS) -Wl,-eMAIN -o $@ $^ + $(BIND) $(BIND_FLAGS_64) -V -eMAIN -o $@ $^ > $*.bind.lst clean: rm -f *.o diff --git a/native/c/examples/examples_toolchain.mk b/native/c/examples/examples_toolchain.mk index 6c519d9c7..530341ac5 100644 --- a/native/c/examples/examples_toolchain.mk +++ b/native/c/examples/examples_toolchain.mk @@ -18,6 +18,8 @@ MACLIBS= -I../../../asmmac -I../../../asmchdr $(MACLIBS_BASE) MTL_HEADERS=$(MTL_HEADERS_BASE) -I../../chdsect -I../../../c +BIND=ld + # Common flags for examples C_FLAGS_COMMON=-I../../chdsect -I../../../c CPP_FLAGS_COMMON=-I../../chdsect -I../../../c @@ -32,10 +34,17 @@ MTL_BASE_OPTS=metal,\ warn64,\ optimize(2) +# ---------------------------------------------------------------------------- +# Key differences between the toolchain.mk file and the examples_toolchain.mk file: +# ---------------------------------------------------------------------------- +# Remove "inline," from the MTL_BASE_OPTS definition to avoid the following warning: # WARNING CCN3396 - Option INLINE is incompatible with option TEST/DEBUG and is ignored. - # inline,\ +# inline,\ +# +# Add "NOGONUMBER" to the MTL_BASE_OPTS definition to avoid the following warning: # WARNING CCN0833 - "GONUMBER" is not compatible with "METAL". "NOGONUMBER" is being set. DEBUGGER_FLAGS=-g0 # This value was previously set to `-g` in the toolchain.mk file. +# ---------------------------------------------------------------------------- # Build type handling for examples .IF $(BuildType) == DEBUG diff --git a/native/c/examples/jsonm/makefile b/native/c/examples/jsonm/makefile index 39f351924..15315435a 100644 --- a/native/c/examples/jsonm/makefile +++ b/native/c/examples/jsonm/makefile @@ -17,7 +17,7 @@ all: $(OUT_DIR) run run: $(OUT_DIR)/json @echo 'Running ./$(OUT_DIR)/json' - ./$(OUT_DIR)/json + export _BPXK_JOBLOG=STDERR && ./$(OUT_DIR)/json $(OUT_DIR): @echo 'Creating $(OUT_DIR)' @@ -38,7 +38,7 @@ $(OUT_DIR)/json.o: $(OUT_DIR)/json.s $(OUT_DIR)/json: $(OUT_DIR)/json.o @echo 'Building $(OUT_DIR)/json' - $(CXX) $(CPP_BND_FLAGS) -o $@ $^ + $(BIND) $(BIND_FLAGS_64) -V -eMAIN -o $@ $^ > $*.bind.lst clean: rm -f *.o diff --git a/native/c/examples/metal/makefile b/native/c/examples/metal/makefile index 1dc8229aa..2504b7093 100644 --- a/native/c/examples/metal/makefile +++ b/native/c/examples/metal/makefile @@ -17,7 +17,7 @@ all: copy-mtl $(OUT_DIR) run run: $(OUT_DIR)/demometal @echo 'Running ./$(OUT_DIR)/demometal' - ./$(OUT_DIR)/demometal + export _BPXK_JOBLOG=STDERR && ./$(OUT_DIR)/demometal $(OUT_DIR): @echo 'Creating $(OUT_DIR)' @@ -45,7 +45,7 @@ $(OUT_DIR)/demometal.o: $(OUT_DIR)/demometal.s $(OUT_DIR)/demometal: $(OUT_DIR)/demometal.o @echo 'Building $(OUT_DIR)/demometal' - $(CXX) $(CPP_BND_FLAGS) -Wl,-eMAIN -o $@ $^ + $(BIND) $(BIND_FLAGS_64) -V -eMAIN -o $@ $^ > $*.bind.lst clean: rm -f *.o diff --git a/native/c/examples/prolog/makefile b/native/c/examples/prolog/makefile index c144a3a0c..a21aa3766 100644 --- a/native/c/examples/prolog/makefile +++ b/native/c/examples/prolog/makefile @@ -33,10 +33,10 @@ $(OUT_DIR)/prolog.s: prolog.c $(OUT_DIR)/prolog.o: $(OUT_DIR)/prolog.s @echo 'Building $(OUT_DIR)/prolog.o' $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ - + $(OUT_DIR)/prolog: $(OUT_DIR)/prolog.o @echo 'Building $(OUT_DIR)/prolog' - $(CXX) $(CPP_BND_FLAGS) -Wl,-eMAIN -o $@ $^ > $*.bind.lst + $(BIND) $(BIND_FLAGS_64) -V -eMAIN -o $@ $^ > $*.bind.lst clean: rm -f *.o diff --git a/native/c/examples/rcvy/makefile b/native/c/examples/rcvy/makefile index 40e540cfb..cefd4884e 100644 --- a/native/c/examples/rcvy/makefile +++ b/native/c/examples/rcvy/makefile @@ -10,96 +10,16 @@ # OUT_DIR=build-out -OUT_DIRS=$(OUT_DIR_CXXLANG) -XLC_FLAGS=_CC_ACCEPTABLE_RC=0 _C89_ACCEPTABLE_RC=0 _CXX_ACCEPTABLE_RC=0 -CXX=$(XLC_FLAGS) xlc++ -CC=$(XLC_FLAGS) xlc -ASM=as -BIND=ld - -MTL_OPTS=metal,\ - langlvl(extended),\ - sscom,\ - nolongname,\ - inline,\ - genasm,\ - inlrpt,\ - csect,\ - nose,\ - list,\ - warn64,\ - optimize(2),\ - aggregate - -MTL_OPTS64=$(MTL_OPTS),lp64 -MTL_FLAGS=-S -W "c,$(MTL_OPTS)" -MTL_FLAGS64=-S -W "c,$(MTL_OPTS64)" - -MACLIBS= -I../../../asmmac \ - -ISYS1.MACLIB \ - -ISYS1.MODGEN \ - -ICBC.SCCNSAM - -MTL_HEADERS=-I/usr/include/metal \ - -I../../chdsect \ - -I../../../c - -CPP_BND_FLAGS=-W "l,lp64,xplink,map,list" - -CPP_BND_FLAGS_AUTH=-W "l,lp64,xplink,map,list,ac=1" - -C_FLAGS=-W "c,lp64,langlvl(extended),xplink,exportall"\ - -c \ - -I../../chdsect \ - -I../../../c - -DLL_CPP_FLAGS=-W "c,lp64,langlvl(extended0x),dll,xplink,exportall"\ - -c \ - -I./chdsect +.INCLUDE: ../examples_toolchain.mk -DLL_BND_FLAGS=-W "l,lp64,dll,dynam=dll,xplink,map,list" - -CPP_FLAGS=-W "c,lp64,langlvl(extended0x),dll,xplink"\ - -c \ - -I../../chdsect \ - -I../../../c - -ASM_FLAGS=-mRENT - -# make -DBuildType=DEBUG -.IF $(BuildType) == DEBUG -# -g generates debugging information -DEBUGGER_FLAGS=-qSOURCE -g9 -OTHER_C_FLAGS=-qSHOWINC -qSHOWMACROS - -CPP_BND_FLAGS+=$(DEBUGGER_FLAGS) -CPP_BND_FLAGS_AUTH+=$(DEBUGGER_FLAGS) -C_FLAGS+=$(DEBUGGER_FLAGS) -DLL_BND_FLAGS+=$(DEBUGGER_FLAGS) -DLL_CPP_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -CPP_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -MTL_FLAGS+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -MTL_FLAGS64+=$(DEBUGGER_FLAGS) $(OTHER_C_FLAGS) -ASM_FLAGS+=--verbose - -.ELSE -C_FLAGS+=-g0 -CPP_FLAGS+=-g0 -CPP_BND_FLAGS+=-g0 -CPP_BND_FLAGS_AUTH+=-g0 -DLL_BND_FLAGS+=-g0 -DLL_CPP_FLAGS+=-g0 -ASM_FLAGS+=--noverbose - -# Still investigating why we need `-g1` for the MetalC flags :'( -MTL_FLAGS+=-g1 -MTL_FLAGS64+=-g1 -.END +BIND=ld -all: $(OUT_DIR) $(OUT_DIR)/testrcvy +all: $(OUT_DIR) run -testrcvy: $(OUT_DIR)/testrcvy +run: $(OUT_DIR)/testrcvy + @echo 'Running ./$(OUT_DIR)/testrcvy' + export _BPXK_JOBLOG=STDERR && ./$(OUT_DIR)/testrcvy $(OUT_DIR): @echo 'Creating $(OUT_DIR)' @@ -110,10 +30,11 @@ $(OUT_DIR)/testrcvy.s: testrcvy.c $(CC) $(MTL_FLAGS64) -qlist=$*.mtl.lst $(MTL_HEADERS) -o $@ $^ $(OUT_DIR)/testrcvy.o: $(OUT_DIR)/testrcvy.s - @echo 'Building $(OUT_DIR)/testrcvy.s' + @echo 'Building $(OUT_DIR)/testrcvy.o' $(ASM) $(ASM_FLAGS) -a=$*.s.lst $(MACLIBS) -o $@ $^ $(OUT_DIR)/testrcvy: $(OUT_DIR)/testrcvy.o + @echo 'Building testrcvy' $(BIND) $(BIND_FLAGS_64) -V -eMAIN -o $@ $^ > $*.bind.lst clean: diff --git a/native/c/examples/timer/makefile b/native/c/examples/timer/makefile index 14117c654..82477f30f 100644 --- a/native/c/examples/timer/makefile +++ b/native/c/examples/timer/makefile @@ -13,12 +13,10 @@ OUT_DIR=build-out .INCLUDE: ../examples_toolchain.mk -BIND=ld - all: $(OUT_DIR) run $(OUT_DIR): - @echo 'Creating build-out' + @echo 'Creating $(OUT_DIR)' mkdir -p $(OUT_DIR) run: $(OUT_DIR)/testtime diff --git a/native/c/examples/zcn/makefile b/native/c/examples/zcn/makefile index 938ef61d9..e7edaeca0 100644 --- a/native/c/examples/zcn/makefile +++ b/native/c/examples/zcn/makefile @@ -19,12 +19,12 @@ all: $(OUT_DIR) extattr run # Output directories # $(OUT_DIR): - @echo 'Creating build-out' + @echo 'Creating $(OUT_DIR)' mkdir -p $(OUT_DIR) run: $(OUT_DIR)/demozcn - @echo 'Running ./build-out/demozcn' - export _BPXK_JOBLOG=STDERR && ./build-out/demozcn + @echo 'Running ./$(OUT_DIR)/demozcn' + export _BPXK_JOBLOG=STDERR && ./$(OUT_DIR)/demozcn $(OUT_DIR)/demozcn.o: demozcn.cpp @echo 'Building $(OUT_DIR)/demozcn.o' From 24aec9b8833044bd106ad7f077dcbf732b8265c7 Mon Sep 17 00:00:00 2001 From: Fernando Rijo Cedeno <37381190+zFernand0@users.noreply.github.com> Date: Fri, 10 Apr 2026 21:04:09 -0400 Subject: [PATCH 07/17] chore: fix sample-plugin build Signed-off-by: Fernando Rijo Cedeno <37381190+zFernand0@users.noreply.github.com> --- native/c/examples/hlasm/makefile | 9 ++--- native/c/examples/rcvy/makefile | 2 - native/c/examples/sample-plugin/Makefile | 9 ----- native/c/examples/sample-plugin/makefile | 48 ++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 16 deletions(-) delete mode 100644 native/c/examples/sample-plugin/Makefile create mode 100644 native/c/examples/sample-plugin/makefile diff --git a/native/c/examples/hlasm/makefile b/native/c/examples/hlasm/makefile index 927cd57d1..a6bb90109 100644 --- a/native/c/examples/hlasm/makefile +++ b/native/c/examples/hlasm/makefile @@ -24,10 +24,6 @@ all: $(EXECUTABLES) %.o: %.s $(AS) -a=$*.s.lst -o $@ $< -# Clean target -clean: - rm -f $(OBJECTS) $(EXECUTABLES) - # Run target (example for testauth) run-testaut1: testaut1 ./testaut1 @@ -40,4 +36,7 @@ run-testasm1: testasm1 run-testasm4: testasm4 ./testasm4 -.PHONY: all clean run-testaut1 run-testasm1 run-testasm4 \ No newline at end of file +# Clean target +clean: + rm -f $(OBJECTS) $(EXECUTABLES) + diff --git a/native/c/examples/rcvy/makefile b/native/c/examples/rcvy/makefile index cefd4884e..faddd23c3 100644 --- a/native/c/examples/rcvy/makefile +++ b/native/c/examples/rcvy/makefile @@ -13,8 +13,6 @@ OUT_DIR=build-out .INCLUDE: ../examples_toolchain.mk -BIND=ld - all: $(OUT_DIR) run run: $(OUT_DIR)/testrcvy diff --git a/native/c/examples/sample-plugin/Makefile b/native/c/examples/sample-plugin/Makefile deleted file mode 100644 index 31945d725..000000000 --- a/native/c/examples/sample-plugin/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -CXX=ibm-clang++64 -CXX_FLAGS=-std=c++17 -fvisibility=default -fno-aligned-allocation -I../../ -CXX_LINK_FLAGS=-shared - -all: sample_plugin.so - -sample_plugin.so: sample_plugin.cpp - $(CXX) $(CXX_FLAGS) -c -o sample_plugin.o $^ - $(CXX) $(CXX_LINK_FLAGS) -o $@ sample_plugin.o \ No newline at end of file diff --git a/native/c/examples/sample-plugin/makefile b/native/c/examples/sample-plugin/makefile new file mode 100644 index 000000000..7a1547d21 --- /dev/null +++ b/native/c/examples/sample-plugin/makefile @@ -0,0 +1,48 @@ +# +# This program and the accompanying materials are +# made available under the terms of the Eclipse Public License v2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-v20.html +# +# SPDX-License-Identifier: EPL-2.0 +# +# Copyright Contributors to the Zowe Project. +# + +OUT_DIR=build-out + +.INCLUDE: ../examples_toolchain.mk + +all: $(OUT_DIR) run + +# TODO(zFernand0): S0C4 Abend when unloading plug-ins +# NOTE(zFernand0): Make sure to run `make clean` to remove the plugin from the build-out directory +run: $(OUT_DIR)/sample_plugin.so + @echo 'Running ./$(OUT_DIR)/sample_plugin.so' + mkdir -p ../../build-out/plugins + cp ./$(OUT_DIR)/sample_plugin.so ../../build-out/plugins/sample_plugin.so + cd ../../build-out && ./zowex plugins list + cd ../../build-out && ./zowex sample hello World + +$(OUT_DIR): + @echo 'Creating $(OUT_DIR)' + mkdir -p $(OUT_DIR) + +$(OUT_DIR)/sample_plugin.o: sample_plugin.cpp + @echo 'Building $(OUT_DIR)/sample_plugin.o' + $(CXX) $(CPP_FLAGS) -c -o $@ $^ + +$(OUT_DIR)/sample_plugin.so: $(OUT_DIR)/sample_plugin.o + @echo 'Building $(OUT_DIR)/sample_plugin.so' + $(CXX) $(DLL_BND_BASE_FLAGS) -o $@ $^ + +clean: + rm -f *.o + rm -f *.dbg + rm -f *.so + rm -f *.a + rm -f *.x + rm -f *.lst + rm -f CEEDUMP.* + rm -f ../../build-out/plugins/sample_plugin.so + rm -rf $(OUT_DIR) From 5d798b8a3d583eaa33f3a3bc69632390b7606814 Mon Sep 17 00:00:00 2001 From: Fernando Rijo Cedeno <37381190+zFernand0@users.noreply.github.com> Date: Sat, 11 Apr 2026 12:51:54 -0400 Subject: [PATCH 08/17] chore: forgot license header Signed-off-by: Fernando Rijo Cedeno <37381190+zFernand0@users.noreply.github.com> --- native/c/examples/hlasm/makefile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/native/c/examples/hlasm/makefile b/native/c/examples/hlasm/makefile index a6bb90109..aa11c4fc6 100644 --- a/native/c/examples/hlasm/makefile +++ b/native/c/examples/hlasm/makefile @@ -1,3 +1,14 @@ +# +# This program and the accompanying materials are +# made available under the terms of the Eclipse Public License v2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-v20.html +# +# SPDX-License-Identifier: EPL-2.0 +# +# Copyright Contributors to the Zowe Project. +# + # Assembler program makefile # Default assembler and linker @@ -39,4 +50,3 @@ run-testasm4: testasm4 # Clean target clean: rm -f $(OBJECTS) $(EXECUTABLES) - From de58fee32c81574776ed65d4f80b066b99bdd7bf Mon Sep 17 00:00:00 2001 From: Fernando Rijo Cedeno <37381190+zFernand0@users.noreply.github.com> Date: Sat, 11 Apr 2026 13:10:49 -0400 Subject: [PATCH 09/17] chore: makefile -> Makefile :yum: Signed-off-by: Fernando Rijo Cedeno <37381190+zFernand0@users.noreply.github.com> --- native/c/examples/ams/{makefile => Makefile} | 0 native/c/examples/enq/{makefile => Makefile} | 0 native/c/examples/hlasm/{makefile => Makefile} | 0 native/c/examples/jsoncpp/{makefile => Makefile} | 0 native/c/examples/jsonm/{makefile => Makefile} | 0 native/c/examples/metal/{makefile => Makefile} | 0 native/c/examples/prolog/{makefile => Makefile} | 0 native/c/examples/rcvy/{makefile => Makefile} | 0 native/c/examples/sample-plugin/{makefile => Makefile} | 0 native/c/examples/timer/{makefile => Makefile} | 0 native/c/examples/zcn/{makefile => Makefile} | 0 11 files changed, 0 insertions(+), 0 deletions(-) rename native/c/examples/ams/{makefile => Makefile} (100%) rename native/c/examples/enq/{makefile => Makefile} (100%) rename native/c/examples/hlasm/{makefile => Makefile} (100%) rename native/c/examples/jsoncpp/{makefile => Makefile} (100%) rename native/c/examples/jsonm/{makefile => Makefile} (100%) rename native/c/examples/metal/{makefile => Makefile} (100%) rename native/c/examples/prolog/{makefile => Makefile} (100%) rename native/c/examples/rcvy/{makefile => Makefile} (100%) rename native/c/examples/sample-plugin/{makefile => Makefile} (100%) rename native/c/examples/timer/{makefile => Makefile} (100%) rename native/c/examples/zcn/{makefile => Makefile} (100%) diff --git a/native/c/examples/ams/makefile b/native/c/examples/ams/Makefile similarity index 100% rename from native/c/examples/ams/makefile rename to native/c/examples/ams/Makefile diff --git a/native/c/examples/enq/makefile b/native/c/examples/enq/Makefile similarity index 100% rename from native/c/examples/enq/makefile rename to native/c/examples/enq/Makefile diff --git a/native/c/examples/hlasm/makefile b/native/c/examples/hlasm/Makefile similarity index 100% rename from native/c/examples/hlasm/makefile rename to native/c/examples/hlasm/Makefile diff --git a/native/c/examples/jsoncpp/makefile b/native/c/examples/jsoncpp/Makefile similarity index 100% rename from native/c/examples/jsoncpp/makefile rename to native/c/examples/jsoncpp/Makefile diff --git a/native/c/examples/jsonm/makefile b/native/c/examples/jsonm/Makefile similarity index 100% rename from native/c/examples/jsonm/makefile rename to native/c/examples/jsonm/Makefile diff --git a/native/c/examples/metal/makefile b/native/c/examples/metal/Makefile similarity index 100% rename from native/c/examples/metal/makefile rename to native/c/examples/metal/Makefile diff --git a/native/c/examples/prolog/makefile b/native/c/examples/prolog/Makefile similarity index 100% rename from native/c/examples/prolog/makefile rename to native/c/examples/prolog/Makefile diff --git a/native/c/examples/rcvy/makefile b/native/c/examples/rcvy/Makefile similarity index 100% rename from native/c/examples/rcvy/makefile rename to native/c/examples/rcvy/Makefile diff --git a/native/c/examples/sample-plugin/makefile b/native/c/examples/sample-plugin/Makefile similarity index 100% rename from native/c/examples/sample-plugin/makefile rename to native/c/examples/sample-plugin/Makefile diff --git a/native/c/examples/timer/makefile b/native/c/examples/timer/Makefile similarity index 100% rename from native/c/examples/timer/makefile rename to native/c/examples/timer/Makefile diff --git a/native/c/examples/zcn/makefile b/native/c/examples/zcn/Makefile similarity index 100% rename from native/c/examples/zcn/makefile rename to native/c/examples/zcn/Makefile From f182b939a4c3db33fa48ef21caca1f613c824574 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Sat, 11 Apr 2026 22:52:39 -0400 Subject: [PATCH 10/17] Fix S0C4 in sample plugin Signed-off-by: Timothy Johnson --- native/c/extend/plugin.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/native/c/extend/plugin.cpp b/native/c/extend/plugin.cpp index 10342821f..acd6ecdb4 100644 --- a/native/c/extend/plugin.cpp +++ b/native/c/extend/plugin.cpp @@ -259,6 +259,7 @@ void PluginManager::load_plugins() void PluginManager::unload_plugins() { + m_command_providers.clear(); for (auto it = m_plugins.begin(); it != m_plugins.end(); ++it) { if (it->handle) From 588e255b648cd7839d825d8c30af4214d6e1148e Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Sat, 11 Apr 2026 22:53:01 -0400 Subject: [PATCH 11/17] Fix sample plugin not printing to stdout Signed-off-by: Timothy Johnson --- native/c/extend/plugin.hpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/native/c/extend/plugin.hpp b/native/c/extend/plugin.hpp index ce647f3c5..1174d35a2 100644 --- a/native/c/extend/plugin.hpp +++ b/native/c/extend/plugin.hpp @@ -826,36 +826,30 @@ class Io void print(const char *s) const { - if (m_output_stream && s) + if (s) { - m_output_stream->write(s, std::strlen(s)); + output_stream().write(s, std::strlen(s)); } } void println(const char *s) const { print(s); - if (m_output_stream) - { - m_output_stream->put('\n'); - } + output_stream().put('\n'); } void err(const char *e) const { - if (m_error_stream && e) + if (e) { - m_error_stream->write(e, std::strlen(e)); + error_stream().write(e, std::strlen(e)); } } void errln(const char *e) const { err(e); - if (m_error_stream) - { - m_error_stream->put('\n'); - } + error_stream().put('\n'); } void to_err(const std::stringstream &sstr) From 7395044d1ff306df68406e41794bb857d6336f96 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Sat, 11 Apr 2026 22:53:20 -0400 Subject: [PATCH 12/17] Add plugin bridge for zowex server Signed-off-by: Timothy Johnson --- native/c/commands/server.cpp | 8 + .../examples/sample-plugin/sample_plugin.cpp | 3 + native/c/makefile | 1 + native/c/server/plugin_bridge.cpp | 171 ++++++++++++++++++ native/c/server/plugin_bridge.hpp | 38 ++++ 5 files changed, 221 insertions(+) create mode 100644 native/c/server/plugin_bridge.cpp create mode 100644 native/c/server/plugin_bridge.hpp diff --git a/native/c/commands/server.cpp b/native/c/commands/server.cpp index b91b5fb51..9daed20b3 100644 --- a/native/c/commands/server.cpp +++ b/native/c/commands/server.cpp @@ -30,6 +30,7 @@ #include "../server/dispatcher.hpp" #include "../server/logger.hpp" #include "../server/worker.hpp" +#include "../server/plugin_bridge.hpp" using namespace parser; @@ -163,6 +164,13 @@ void ZServer::run(const server::Options &opts) LOG_DEBUG("Registering command handlers"); register_all_commands(dispatcher); + // Register plugin commands to middleware + if (auto *pm = core::get_plugin_manager()) + { + LOG_DEBUG("Registering plugin commands to middleware"); + plugin_bridge::register_plugin_commands(*pm, dispatcher); + } + worker_pool.reset(new WorkerPool(options.num_workers, std::chrono::seconds(options.request_timeout))); std::atexit([]() diff --git a/native/c/examples/sample-plugin/sample_plugin.cpp b/native/c/examples/sample-plugin/sample_plugin.cpp index fb7212c74..4adfbf457 100644 --- a/native/c/examples/sample-plugin/sample_plugin.cpp +++ b/native/c/examples/sample-plugin/sample_plugin.cpp @@ -24,6 +24,9 @@ int hello_command(plugin::InvocationContext &context) { context.println(str.c_str()); } + auto result = ast::obj(); + result->set("message", ast::str(str)); + context.set_object(result); return 0; } diff --git a/native/c/makefile b/native/c/makefile index 1b5ea2811..d41ac129d 100644 --- a/native/c/makefile +++ b/native/c/makefile @@ -73,6 +73,7 @@ COMMAND_OBJS = $(OUT_DIR)/commands/console.o \ SERVER_OBJS = $(OUT_DIR)/server/builder.o \ $(OUT_DIR)/server/rpc_commands.o \ $(OUT_DIR)/server/dispatcher.o \ + $(OUT_DIR)/server/plugin_bridge.o \ $(OUT_DIR)/server/rpcio.o \ $(OUT_DIR)/server/rpc_server.o \ $(OUT_DIR)/server/validator.o \ diff --git a/native/c/server/plugin_bridge.cpp b/native/c/server/plugin_bridge.cpp new file mode 100644 index 000000000..aa730b3f0 --- /dev/null +++ b/native/c/server/plugin_bridge.cpp @@ -0,0 +1,171 @@ +/** + * This program and the accompanying materials are made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v20.html + * + * SPDX-License-Identifier: EPL-2.0 + * + * Copyright Contributors to the Zowe Project. + * + */ + +#include "plugin_bridge.hpp" +#include "dispatcher.hpp" +#include "builder.hpp" +#include "logger.hpp" +#include +#include +#include + +namespace plugin_bridge +{ + +using namespace plugin; + +// Forward declaration for recursion +static void traverse_and_register_impl(parser::Command *cmd, std::string &path_prefix, CommandDispatcher &dispatcher, int depth); + +/** + * @brief Recursively traverse command tree and register to middleware + * + * @param cmd The command to process + * @param path_prefix The command path built so far (e.g., "sample.hello") + * @param dispatcher The dispatcher to register commands to + */ +static void traverse_and_register(parser::Command *cmd, const std::string &path_prefix, CommandDispatcher &dispatcher) +{ + // Limit recursion depth to prevent stack issues on z/OS + std::string mutable_path = path_prefix; + traverse_and_register_impl(cmd, mutable_path, dispatcher, 0); +} + +static void traverse_and_register_impl(parser::Command *cmd, std::string &path_prefix, CommandDispatcher &dispatcher, int depth) +{ + if (!cmd || depth > 10) // Prevent deep recursion on z/OS + return; + + // Get handler for this command + typedef plugin::CommandProviderImpl::CommandRegistrationContext::CommandHandler CommandHandler; + CommandHandler handler = cmd->get_handler(); + + // Check if this command has subcommands + const std::map &subcommands = cmd->get_commands(); + + if (handler != nullptr) + { + // This command has a handler, register it with dot notation + std::string rpc_command_name = path_prefix; + std::replace(rpc_command_name.begin(), rpc_command_name.end(), ' ', '.'); + + try + { + LOG_DEBUG("Registering plugin command: %s (from path: %s)", rpc_command_name.c_str(), path_prefix.c_str()); + + CommandBuilder builder(handler); + + // For plugin commands, arguments from JSON are passed in camelCase by the middleware. + // Plugins typically register CLI-style argument names (kebab-case) using add_keyword_arg. + // We dynamically infer renames from the command's declared arguments. + for (const auto &arg : cmd->get_args()) + { + // Help flags and automatically generated 'no-' flags are CLI-specific + // and shouldn't be exposed as separate JSON-RPC parameters. + if (arg.is_help_flag || arg.name.rfind("no-", 0) == 0) + continue; + + // If the arg name has hyphens, map its camelCase equivalent + // to the kebab-case name expected by the handler. + if (arg.name.find('-') != std::string::npos) + { + std::string camel_name; + bool capitalize_next = false; + for (char c : arg.name) + { + if (c == '-') + { + capitalize_next = true; + } + else + { + camel_name += capitalize_next ? static_cast(std::toupper(c)) : c; + capitalize_next = false; + } + } + builder.rename_arg(camel_name, arg.name); + } + + // Also apply default values if provided + if (!arg.default_value.is_none()) + { + if (arg.default_value.is_bool()) + builder.set_default(arg.name, *arg.default_value.get_bool()); + else if (arg.default_value.is_int()) + builder.set_default(arg.name, *arg.default_value.get_int()); + else if (arg.default_value.is_double()) + builder.set_default(arg.name, *arg.default_value.get_double()); + else if (arg.default_value.is_string()) + builder.set_default(arg.name, *arg.default_value.get_string()); + } + } + + bool success = dispatcher.register_command(rpc_command_name, builder); + + if (!success) + { + LOG_ERROR("Failed to register plugin command: %s", rpc_command_name.c_str()); + } + } + catch (const std::exception &e) + { + LOG_ERROR("Exception registering plugin command %s: %s", rpc_command_name.c_str(), e.what()); + } + catch (...) + { + LOG_ERROR("Unknown exception registering plugin command: %s", rpc_command_name.c_str()); + } + } + + // Recursively process subcommands + // Build subcommand path and recurse - avoid creating many temporary strings + size_t original_length = path_prefix.length(); + for (std::map::const_iterator it = subcommands.begin(); + it != subcommands.end(); ++it) + { + if (it->second) // Null check for safety + { + // Append to existing string instead of creating new ones + path_prefix += "."; + path_prefix += it->first; + + traverse_and_register_impl(it->second.get(), path_prefix, dispatcher, depth + 1); + + // Restore original path for next sibling + path_prefix.resize(original_length); + } + } +} + +void register_plugin_commands(PluginManager &pm, CommandDispatcher &dispatcher) +{ + parser::Command temp_root("_temp_root", ""); + + // Build the command tree using the existing implementation from plugin.cpp + // This reuses all the logic instead of duplicating it + pm.register_commands(temp_root); + + // Get the commands map - the shared_ptrs will keep objects alive + const std::map &top_level_cmds = temp_root.get_commands(); + + // Traverse all top-level commands and register them to middleware + for (std::map::const_iterator it = top_level_cmds.begin(); + it != top_level_cmds.end(); ++it) + { + LOG_DEBUG("Registering top-level plugin command: %s", it->first.c_str()); + if (it->second) // Null check for safety + { + traverse_and_register(it->second.get(), it->first, dispatcher); + } + } +} + +} // namespace plugin_bridge \ No newline at end of file diff --git a/native/c/server/plugin_bridge.hpp b/native/c/server/plugin_bridge.hpp new file mode 100644 index 000000000..d1531eab0 --- /dev/null +++ b/native/c/server/plugin_bridge.hpp @@ -0,0 +1,38 @@ +/** + * This program and the accompanying materials are made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v20.html + * + * SPDX-License-Identifier: EPL-2.0 + * + * Copyright Contributors to the Zowe Project. + * + */ + +#ifndef PLUGIN_BRIDGE_HPP +#define PLUGIN_BRIDGE_HPP + +#include "../extend/plugin.hpp" +#include "../parser.hpp" + +// Forward declarations +class CommandDispatcher; + +namespace plugin_bridge +{ + +/** + * @brief Register all plugin commands to the middleware dispatcher + * + * This function takes a PluginManager that has already loaded plugins, + * and registers all their commands to the middleware CommandDispatcher + * as RPC methods using dot notation (e.g., "sample.hello"). + * + * @param pm The PluginManager containing loaded plugins + * @param dispatcher The CommandDispatcher to register commands to + */ +void register_plugin_commands(plugin::PluginManager &pm, CommandDispatcher &dispatcher); + +} // namespace plugin_bridge + +#endif \ No newline at end of file From ed77e66f21826f3eee0854154d2f461dfd4e444c Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Tue, 14 Apr 2026 08:51:06 -0400 Subject: [PATCH 13/17] Support add_to_server for plugin context Signed-off-by: Timothy Johnson --- native/c/commands/server.cpp | 8 +---- .../examples/sample-plugin/sample_plugin.cpp | 1 + native/c/extend/plugin.cpp | 20 +++++++++++ native/c/extend/plugin.hpp | 14 ++++++-- native/c/server/plugin_bridge.cpp | 33 +++++++------------ native/c/server/plugin_bridge.hpp | 8 ++--- native/c/server/rpc_commands.cpp | 1 - 7 files changed, 49 insertions(+), 36 deletions(-) diff --git a/native/c/commands/server.cpp b/native/c/commands/server.cpp index 9daed20b3..9c755ba0c 100644 --- a/native/c/commands/server.cpp +++ b/native/c/commands/server.cpp @@ -163,13 +163,7 @@ void ZServer::run(const server::Options &opts) LOG_DEBUG("Registering command handlers"); register_all_commands(dispatcher); - - // Register plugin commands to middleware - if (auto *pm = core::get_plugin_manager()) - { - LOG_DEBUG("Registering plugin commands to middleware"); - plugin_bridge::register_plugin_commands(*pm, dispatcher); - } + plugin::register_commands_with_server(*core::get_plugin_manager(), dispatcher); worker_pool.reset(new WorkerPool(options.num_workers, std::chrono::seconds(options.request_timeout))); diff --git a/native/c/examples/sample-plugin/sample_plugin.cpp b/native/c/examples/sample-plugin/sample_plugin.cpp index 4adfbf457..bc11b2b28 100644 --- a/native/c/examples/sample-plugin/sample_plugin.cpp +++ b/native/c/examples/sample-plugin/sample_plugin.cpp @@ -42,6 +42,7 @@ void BasicCommandRegistry::register_commands(CommandProviderImpl::CommandRegistr ctx.set_handler(hello, hello_command); ctx.add_subcommand(sample_group, hello); ctx.add_subcommand(root, sample_group); + ctx.add_to_server(sample_group); } void register_plugin(plugin::PluginManager &pm) diff --git a/native/c/extend/plugin.cpp b/native/c/extend/plugin.cpp index acd6ecdb4..a3872f79e 100644 --- a/native/c/extend/plugin.cpp +++ b/native/c/extend/plugin.cpp @@ -126,6 +126,20 @@ class RegistrationContextImpl } } + void add_to_server(CommandHandle command) + { + CommandRecord *record = to_record(command); + if (!record) + return; + + m_server_commands.insert(record->get_command_ptr()); + } + + const std::set &get_server_commands() const + { + return m_server_commands; + } + private: struct CommandRecord { @@ -205,6 +219,7 @@ class RegistrationContextImpl parser::Command &m_root; CommandRecord m_root_record; std::vector> m_records; + std::set m_server_commands; }; void PluginManager::load_plugins() @@ -305,5 +320,10 @@ void PluginManager::register_commands(parser::Command &rootCommand) provider->register_commands(context); } + + for (const auto &command : context.get_server_commands()) + { + m_server_commands.insert(command); + } } } // namespace plugin diff --git a/native/c/extend/plugin.hpp b/native/c/extend/plugin.hpp index 1174d35a2..84a67ec33 100644 --- a/native/c/extend/plugin.hpp +++ b/native/c/extend/plugin.hpp @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -429,6 +430,7 @@ inline Node nil() namespace parser { class Command; +typedef std::shared_ptr command_ptr; } // namespace parser namespace plugin @@ -1127,6 +1129,7 @@ class CommandProviderImpl const CommandDefaultValue *defaultValue) = 0; virtual void set_handler(CommandHandle command, CommandHandler handler) = 0; virtual void add_subcommand(CommandHandle parent, CommandHandle child) = 0; + virtual void add_to_server(CommandHandle command) = 0; }; virtual ~CommandProviderImpl() @@ -1194,6 +1197,11 @@ class PluginManager return m_plugins; } + const std::set &get_server_commands() const + { + return m_server_commands; + } + PluginManager(const PluginManager &) = delete; PluginManager &operator=(const PluginManager &) = delete; @@ -1204,6 +1212,7 @@ class PluginManager void discard_command_providers_from(std::size_t start_index); std::vector> m_command_providers; + std::set m_server_commands; std::vector m_plugins; PluginMetadata m_pending_metadata; bool m_metadata_pending; @@ -1262,9 +1271,8 @@ inline bool PluginManager::is_display_name_in_use(const std::string &name) const return false; } - return std::any_of(m_plugins.begin(), m_plugins.end(), [&name](const auto &plugin) { - return plugin.metadata.display_name == name; - }); + return std::any_of(m_plugins.begin(), m_plugins.end(), [&name](const auto &plugin) + { return plugin.metadata.display_name == name; }); } inline void PluginManager::discard_command_providers_from(std::size_t start_index) diff --git a/native/c/server/plugin_bridge.cpp b/native/c/server/plugin_bridge.cpp index aa730b3f0..53354dd4b 100644 --- a/native/c/server/plugin_bridge.cpp +++ b/native/c/server/plugin_bridge.cpp @@ -17,11 +17,9 @@ #include #include -namespace plugin_bridge +namespace plugin { -using namespace plugin; - // Forward declaration for recursion static void traverse_and_register_impl(parser::Command *cmd, std::string &path_prefix, CommandDispatcher &dispatcher, int depth); @@ -145,27 +143,20 @@ static void traverse_and_register_impl(parser::Command *cmd, std::string &path_p } } -void register_plugin_commands(PluginManager &pm, CommandDispatcher &dispatcher) +void register_commands_with_server(PluginManager &pm, CommandDispatcher &dispatcher) { - parser::Command temp_root("_temp_root", ""); - - // Build the command tree using the existing implementation from plugin.cpp - // This reuses all the logic instead of duplicating it - pm.register_commands(temp_root); - - // Get the commands map - the shared_ptrs will keep objects alive - const std::map &top_level_cmds = temp_root.get_commands(); + const std::set &server_commands = pm.get_server_commands(); + if (!server_commands.empty()) + { + LOG_DEBUG("Registering plugin commands to middleware"); + } - // Traverse all top-level commands and register them to middleware - for (std::map::const_iterator it = top_level_cmds.begin(); - it != top_level_cmds.end(); ++it) + // Traverse top-level commands and register them to middleware + for (const auto &command : server_commands) { - LOG_DEBUG("Registering top-level plugin command: %s", it->first.c_str()); - if (it->second) // Null check for safety - { - traverse_and_register(it->second.get(), it->first, dispatcher); - } + LOG_DEBUG("Registering top-level plugin command: %s", command->get_name().c_str()); + traverse_and_register(command.get(), command->get_name(), dispatcher); } } -} // namespace plugin_bridge \ No newline at end of file +} // namespace plugin diff --git a/native/c/server/plugin_bridge.hpp b/native/c/server/plugin_bridge.hpp index d1531eab0..08b269b0f 100644 --- a/native/c/server/plugin_bridge.hpp +++ b/native/c/server/plugin_bridge.hpp @@ -18,7 +18,7 @@ // Forward declarations class CommandDispatcher; -namespace plugin_bridge +namespace plugin { /** @@ -31,8 +31,8 @@ namespace plugin_bridge * @param pm The PluginManager containing loaded plugins * @param dispatcher The CommandDispatcher to register commands to */ -void register_plugin_commands(plugin::PluginManager &pm, CommandDispatcher &dispatcher); +void register_commands_with_server(plugin::PluginManager &pm, CommandDispatcher &dispatcher); -} // namespace plugin_bridge +} // namespace plugin -#endif \ No newline at end of file +#endif diff --git a/native/c/server/rpc_commands.cpp b/native/c/server/rpc_commands.cpp index 5a8aad00d..4a412c538 100644 --- a/native/c/server/rpc_commands.cpp +++ b/native/c/server/rpc_commands.cpp @@ -159,7 +159,6 @@ void register_uss_commands(CommandDispatcher &dispatcher) dispatcher.register_command("deleteFile", create_uss_builder(uss::handle_uss_delete) .validate()); - // {"id": 1, "jsonrpc": "2.0", "method": "moveFile", "params": {"source": "source-path", "target": "target-path", "force": false}} dispatcher.register_command("moveFile", create_uss_builder(uss::handle_uss_move) .validate() From 10225e15a155bb74fcf3742ec8300fbf01c51778 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Tue, 14 Apr 2026 11:54:47 -0400 Subject: [PATCH 14/17] Address PR feedback Signed-off-by: Timothy Johnson --- native/c/commands/server.cpp | 2 +- native/c/extend/plugin.cpp | 17 +++++++++-------- native/c/server/plugin_bridge.cpp | 5 +++-- native/c/server/plugin_bridge.hpp | 7 +------ 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/native/c/commands/server.cpp b/native/c/commands/server.cpp index 9c755ba0c..8f030f504 100644 --- a/native/c/commands/server.cpp +++ b/native/c/commands/server.cpp @@ -163,7 +163,7 @@ void ZServer::run(const server::Options &opts) LOG_DEBUG("Registering command handlers"); register_all_commands(dispatcher); - plugin::register_commands_with_server(*core::get_plugin_manager(), dispatcher); + plugin::register_commands_with_server(dispatcher); worker_pool.reset(new WorkerPool(options.num_workers, std::chrono::seconds(options.request_timeout))); diff --git a/native/c/extend/plugin.cpp b/native/c/extend/plugin.cpp index a3872f79e..ce5fb28f4 100644 --- a/native/c/extend/plugin.cpp +++ b/native/c/extend/plugin.cpp @@ -47,7 +47,7 @@ class RegistrationContextImpl void add_alias(CommandHandle command, const char *alias) { CommandRecord *record = to_record(command); - if (!record || !alias) + if (record == nullptr || alias == nullptr) return; record->get().add_alias(alias); @@ -63,7 +63,7 @@ class RegistrationContextImpl const DefaultValue *default_value) { CommandRecord *record = to_record(command); - if (!record || !name) + if (record == nullptr || name == nullptr) return; std::vector alias_vector; @@ -88,7 +88,7 @@ class RegistrationContextImpl const DefaultValue *default_value) { CommandRecord *record = to_record(command); - if (!record || !name) + if (record == nullptr || name == nullptr) return; parser::ArgValue default_arg = convert_default(default_value); @@ -102,7 +102,7 @@ class RegistrationContextImpl void set_handler(CommandHandle command, CommandHandler handler) { CommandRecord *record = to_record(command); - if (!record) + if (record == nullptr) return; record->get().set_handler(handler); @@ -112,7 +112,7 @@ class RegistrationContextImpl { CommandRecord *parent_record = to_record(parent); CommandRecord *child_record = to_record(child); - if (!parent_record || !child_record) + if (parent_record == nullptr || child_record == nullptr) return; if (parent_record->is_root()) @@ -129,7 +129,7 @@ class RegistrationContextImpl void add_to_server(CommandHandle command) { CommandRecord *record = to_record(command); - if (!record) + if (record == nullptr) return; m_server_commands.insert(record->get_command_ptr()); @@ -180,7 +180,7 @@ class RegistrationContextImpl parser::ArgValue convert_default(const DefaultValue *value) { - if (!value || value->kind == DefaultValue::ValueKind_None) + if (value == nullptr || value->kind == DefaultValue::ValueKind_None) { return parser::ArgValue(); } @@ -233,7 +233,7 @@ void PluginManager::load_plugins() { std::string plugin_path = std::string("./plugins/") + entry->d_name; void *plugin = dlopen(plugin_path.c_str(), RTLD_LAZY); - if (!plugin) + if (plugin == nullptr) { ZLOG_ERROR("Failed to open handle to plugin located at: %s", plugin_path.c_str()); continue; @@ -275,6 +275,7 @@ void PluginManager::load_plugins() void PluginManager::unload_plugins() { m_command_providers.clear(); + m_server_commands.clear(); for (auto it = m_plugins.begin(); it != m_plugins.end(); ++it) { if (it->handle) diff --git a/native/c/server/plugin_bridge.cpp b/native/c/server/plugin_bridge.cpp index 53354dd4b..d19c294d5 100644 --- a/native/c/server/plugin_bridge.cpp +++ b/native/c/server/plugin_bridge.cpp @@ -16,6 +16,7 @@ #include #include #include +#include "../commands/core.hpp" namespace plugin { @@ -143,9 +144,9 @@ static void traverse_and_register_impl(parser::Command *cmd, std::string &path_p } } -void register_commands_with_server(PluginManager &pm, CommandDispatcher &dispatcher) +void register_commands_with_server(CommandDispatcher &dispatcher) { - const std::set &server_commands = pm.get_server_commands(); + const auto &server_commands = core::get_plugin_manager()->get_server_commands(); if (!server_commands.empty()) { LOG_DEBUG("Registering plugin commands to middleware"); diff --git a/native/c/server/plugin_bridge.hpp b/native/c/server/plugin_bridge.hpp index 08b269b0f..306d1e14d 100644 --- a/native/c/server/plugin_bridge.hpp +++ b/native/c/server/plugin_bridge.hpp @@ -24,14 +24,9 @@ namespace plugin /** * @brief Register all plugin commands to the middleware dispatcher * - * This function takes a PluginManager that has already loaded plugins, - * and registers all their commands to the middleware CommandDispatcher - * as RPC methods using dot notation (e.g., "sample.hello"). - * - * @param pm The PluginManager containing loaded plugins * @param dispatcher The CommandDispatcher to register commands to */ -void register_commands_with_server(plugin::PluginManager &pm, CommandDispatcher &dispatcher); +void register_commands_with_server(CommandDispatcher &dispatcher); } // namespace plugin From 2f5391ddc4ed89f2cf6e3b5b49b8477de067dff5 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Mon, 27 Apr 2026 10:47:58 -0400 Subject: [PATCH 15/17] Add env var for zowex plugins dir Signed-off-by: Timothy Johnson --- native/c/commands/core.cpp | 2 +- native/c/extend/plugin.cpp | 7 ++++--- native/c/extend/plugin.hpp | 8 +++++++- native/c/zowex.cpp | 15 +++++++++++++-- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/native/c/commands/core.cpp b/native/c/commands/core.cpp index 6a60fb406..7efebc71a 100644 --- a/native/c/commands/core.cpp +++ b/native/c/commands/core.cpp @@ -119,7 +119,7 @@ int handle_plugins_list(plugin::InvocationContext &context) std::ostream &out = context.output_stream(); std::vector plugin_files; - DIR *plugins_dir = opendir("./plugins"); + DIR *plugins_dir = opendir(get_plugin_manager()->get_plugins_path().c_str()); if (plugins_dir != nullptr) { struct dirent *entry; diff --git a/native/c/extend/plugin.cpp b/native/c/extend/plugin.cpp index ce5fb28f4..85a3a6eee 100644 --- a/native/c/extend/plugin.cpp +++ b/native/c/extend/plugin.cpp @@ -222,16 +222,17 @@ class RegistrationContextImpl std::set m_server_commands; }; -void PluginManager::load_plugins() +void PluginManager::load_plugins(const std::string &plugins_path) { - auto *plugins_dir = opendir("./plugins"); + m_plugins_path = plugins_path; + auto *plugins_dir = opendir(m_plugins_path.c_str()); if (plugins_dir != nullptr) { struct dirent *entry; void (*register_plugin)(plugin::PluginManager &); while ((entry = readdir(plugins_dir)) != nullptr) { - std::string plugin_path = std::string("./plugins/") + entry->d_name; + std::string plugin_path = m_plugins_path + "/" + entry->d_name; void *plugin = dlopen(plugin_path.c_str(), RTLD_LAZY); if (plugin == nullptr) { diff --git a/native/c/extend/plugin.hpp b/native/c/extend/plugin.hpp index 84a67ec33..231def459 100644 --- a/native/c/extend/plugin.hpp +++ b/native/c/extend/plugin.hpp @@ -1190,7 +1190,12 @@ class PluginManager // Register commands from all providers, attaching them under the supplied root command. void register_commands(parser::Command &rootCommand); - void load_plugins(); + void load_plugins(const std::string &plugins_path); + + const std::string &get_plugins_path() const + { + return m_plugins_path; + } const std::vector &get_loaded_plugins() const { @@ -1213,6 +1218,7 @@ class PluginManager std::vector> m_command_providers; std::set m_server_commands; + std::string m_plugins_path; std::vector m_plugins; PluginMetadata m_pending_metadata; bool m_metadata_pending; diff --git a/native/c/zowex.cpp b/native/c/zowex.cpp index 0533ec000..8725d2761 100644 --- a/native/c/zowex.cpp +++ b/native/c/zowex.cpp @@ -40,9 +40,20 @@ static std::string get_executable_dir(const char *argv0) return "."; } +static std::string get_plugins_dir(const std::string &exec_dir) +{ + std::string plugins_path = std::string(getenv("ZOWEX_PLUGINS_DIR")); + if (plugins_path.empty()) + { + return exec_dir + "/plugins"; + } + return plugins_path; +} + int main(int argc, char *argv[]) { - ZServer::get_instance().set_exec_dir(get_executable_dir(argv[0])); + const auto exec_dir = get_executable_dir(argv[0]); + ZServer::get_instance().set_exec_dir(exec_dir); try { @@ -51,7 +62,7 @@ int main(int argc, char *argv[]) plugin::PluginManager pm; core::set_plugin_manager(&pm); - pm.load_plugins(); + pm.load_plugins(get_plugins_dir(exec_dir)); console::register_commands(root_cmd); ds::register_commands(root_cmd); From 4d2b9a096cbb8a1dff061ec55cbb56d878d29d36 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Mon, 27 Apr 2026 11:41:06 -0400 Subject: [PATCH 16/17] Address PR feedback Signed-off-by: Timothy Johnson --- native/c/server/plugin_bridge.cpp | 54 ++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/native/c/server/plugin_bridge.cpp b/native/c/server/plugin_bridge.cpp index d19c294d5..5b6ff3fdc 100644 --- a/native/c/server/plugin_bridge.cpp +++ b/native/c/server/plugin_bridge.cpp @@ -24,6 +24,36 @@ namespace plugin // Forward declaration for recursion static void traverse_and_register_impl(parser::Command *cmd, std::string &path_prefix, CommandDispatcher &dispatcher, int depth); +/** + * @brief Convert kebab-case string to camelCase + * + * Converts a string with hyphens (kebab-case) to camelCase format. + * Example: "my-flag-name" -> "myFlagName" + * + * @param kebab_str The input string in kebab-case format + * @return std::string The converted camelCase string + */ +static std::string kebab_to_camel_case(const std::string &kebab_str) +{ + std::string result; + bool capitalize_next = false; + + for (char c : kebab_str) + { + if (c == '-') + { + capitalize_next = true; + } + else + { + result += capitalize_next ? static_cast(std::toupper(c)) : c; + capitalize_next = false; + } + } + + return result; +} + /** * @brief Recursively traverse command tree and register to middleware * @@ -76,34 +106,21 @@ static void traverse_and_register_impl(parser::Command *cmd, std::string &path_p // to the kebab-case name expected by the handler. if (arg.name.find('-') != std::string::npos) { - std::string camel_name; - bool capitalize_next = false; - for (char c : arg.name) - { - if (c == '-') - { - capitalize_next = true; - } - else - { - camel_name += capitalize_next ? static_cast(std::toupper(c)) : c; - capitalize_next = false; - } - } + std::string camel_name = kebab_to_camel_case(arg.name); builder.rename_arg(camel_name, arg.name); } // Also apply default values if provided if (!arg.default_value.is_none()) { - if (arg.default_value.is_bool()) + if (arg.default_value.is_string()) + builder.set_default(arg.name, *arg.default_value.get_string()); + else if (arg.default_value.is_bool()) builder.set_default(arg.name, *arg.default_value.get_bool()); else if (arg.default_value.is_int()) builder.set_default(arg.name, *arg.default_value.get_int()); else if (arg.default_value.is_double()) builder.set_default(arg.name, *arg.default_value.get_double()); - else if (arg.default_value.is_string()) - builder.set_default(arg.name, *arg.default_value.get_string()); } } @@ -133,8 +150,7 @@ static void traverse_and_register_impl(parser::Command *cmd, std::string &path_p if (it->second) // Null check for safety { // Append to existing string instead of creating new ones - path_prefix += "."; - path_prefix += it->first; + path_prefix += "." + it->first; traverse_and_register_impl(it->second.get(), path_prefix, dispatcher, depth + 1); From e762c8ea1303ea406dd508248837dd7efd347218 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Wed, 29 Apr 2026 12:05:34 -0400 Subject: [PATCH 17/17] Address more PR feedback Signed-off-by: Timothy Johnson --- native/c/commands/core.cpp | 12 +++++++++--- native/c/server/plugin_bridge.cpp | 9 ++++++++- native/c/zowex.cpp | 5 +++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/native/c/commands/core.cpp b/native/c/commands/core.cpp index 7efebc71a..bc3b7aef0 100644 --- a/native/c/commands/core.cpp +++ b/native/c/commands/core.cpp @@ -117,9 +117,16 @@ int handle_version_simple(plugin::InvocationContext &context) int handle_plugins_list(plugin::InvocationContext &context) { std::ostream &out = context.output_stream(); - std::vector plugin_files; - DIR *plugins_dir = opendir(get_plugin_manager()->get_plugins_path().c_str()); + + auto *manager = get_plugin_manager(); + if (manager == nullptr) + { + context.error_stream() << "Error: Plugin manager not initialized" << std::endl; + return 1; + } + + DIR *plugins_dir = opendir(manager->get_plugins_path().c_str()); if (plugins_dir != nullptr) { struct dirent *entry; @@ -136,7 +143,6 @@ int handle_plugins_list(plugin::InvocationContext &context) std::sort(plugin_files.begin(), plugin_files.end()); std::set registered_files; - auto *manager = get_plugin_manager(); if (manager != nullptr) { const auto &loaded_plugins = manager->get_loaded_plugins(); diff --git a/native/c/server/plugin_bridge.cpp b/native/c/server/plugin_bridge.cpp index 5b6ff3fdc..ea3be6550 100644 --- a/native/c/server/plugin_bridge.cpp +++ b/native/c/server/plugin_bridge.cpp @@ -162,7 +162,14 @@ static void traverse_and_register_impl(parser::Command *cmd, std::string &path_p void register_commands_with_server(CommandDispatcher &dispatcher) { - const auto &server_commands = core::get_plugin_manager()->get_server_commands(); + const auto *manager = core::get_plugin_manager(); + if (manager == nullptr) + { + LOG_ERROR("Plugin manager not initialized"); + return; + } + + const auto &server_commands = manager->get_server_commands(); if (!server_commands.empty()) { LOG_DEBUG("Registering plugin commands to middleware"); diff --git a/native/c/zowex.cpp b/native/c/zowex.cpp index 8725d2761..ee07e1d6a 100644 --- a/native/c/zowex.cpp +++ b/native/c/zowex.cpp @@ -47,6 +47,11 @@ static std::string get_plugins_dir(const std::string &exec_dir) { return exec_dir + "/plugins"; } + else if (plugins_path.back() == '/') + { + plugins_path.pop_back(); // Remove trailing slash if present + } + return plugins_path; }