Added msxhub support with caching.

This commit is contained in:
Willem Cazander 2021-07-04 02:12:48 +02:00
parent 32a797273e
commit adaf62b8f3
6 changed files with 162 additions and 122 deletions

View File

@ -5,39 +5,74 @@ Utils to use openMSX in build pipelines.
You can use these scripts as-is. But as always, feel free to extend it
for your specific needs or contribute a fix or feature.
## Makefile features
## Features
* SDCC msx build steps
* Headless openMSX buildpipe on max speed.
* SDCC msx build steps.
* Allows headless openMSX buildpipe.
* openMSX safe exit failure guards.
* Automatic disk image import + export per build step.
* wgets resources from msxhub
* Downloads and caches resources from msxhub.com
## TCL Scripts
## Dependencies
Tcl scripts for safe openMSX integrations as reliable build step
in compiling/packing/testing msx software natively.
But managed from external build tool like make or scripts.
This means that great care is given to make sure that openMSX
exits correctly.
* make
* openmsx
* sdcc
* hex2bin
* wget
The use this, pass the one or more scripts on the command line and
set the optional environment variables when executing openMSX:
## Usage
FAIL_AFTER_BOOT=30 \
FAIL_AFTER_PATH=bin/myapp \
BOOT_HDD_PATH=bin/myapp/disk \
BOOT_HDD_IMAGE=bin/myapp/disk.img \
JOYPORTA=mouse \
openmsx \
-script <path-to>/boot_env.tcl \
-script <path-to>/boot_hdd.tcl \
-script <path-to>/fail_after.tcl \
-machine ...
Include the msxbuild.mk file from your Makefile.
And override the required paths;
* PATH_SDCC ?= /usr/bin
* PATH_HEX2BIN ?= /usr/bin
* PATH_OPENMSX ?= /opt/openMSX/bin/
* PATH_MSXBUILD ?= /opt/msxbuild
Check the scripts source code for more (technical) details.
Then build result based compile rules see an example in; "test/ahello/0module.mk"
## Functions
Current set is WIP.
* mb_compile_asm
* mb_link_asm_lib
* mb_link_asm
* mb_link_asm_0000 = call mb_link_asm,$(1),$(2),0x0000
* mb_link_asm_0100
* mb_link_asm_1000
* mb_link_asm_4000
* mb_link_asm_8000
* mb_link_asm_C000
* mb_link_asm_dos = alias for mb_link_asm_0100
* mb_hex2com
* mb_hex2dat
* mb_openmsx_dos2
* mb_msxhub_file
* mb_msxhub_get_dos2_sys
* mb_msxhub_get_dos2_com
* mb_assert_file_equals = note: text file only
* mb_autoexec_append_cmd
* mb_autoexec_append_echo
* mb_autoexec_append_rem
* mb_autoexec_append_gui_mode
* mb_autoexec_append_stop_fail
* mb_autoexec_append_exit
* mb_autoexec_write_default
* mb_autoexec_open_gui
* mb_autoexec_open_gui_cmd
* mb_autoexec_cmd
* mb_autoexec_cmd_test
* mb_clean
* mb_mkdir
* mb_delete
* mb_copy
* mb_create_dist
## Errata
TODO: current wget safes in local msxbuild folder.
replace with seperate fetch script/exe which caches in ~/.cache/msxhub/repro/....
* Doesn't work on windows
* Missing dos1 support
* Missing c support

View File

@ -1,4 +1,3 @@
# TODO: clean up + make working for non-unix systems.
# OS cmds
ifeq ($(OS),Windows_NT)
@ -8,6 +7,7 @@ ifeq ($(OS),Windows_NT)
MB_COPY = copy
MB_ERRIGNORE = 2>NUL || true
MB_SEP=\\
MB_CACHE=%LOCALAPPDATA%
else
MB_RM = rm -f
MB_RMDIR = rm -rf
@ -15,6 +15,7 @@ else
MB_COPY = cp
MB_ERRIGNORE = 2>/dev/null
MB_SEP=/
MB_CACHE=~/.cache
endif
# Remove space after separator
@ -25,7 +26,6 @@ define mb_clean
test $(1) && $(MB_RMDIR) $(1)
endef
define mb_mkdir
@echo === Create module build folder.
$(MB_MKDIR) $(1)
endef
define mb_delete
@ -34,11 +34,6 @@ endef
define mb_copy
$(MB_COPY) $(1) $(2)
endef
define mb_file_info
sha1sum $(1)
ls -lah $(1)
endef
define mb_create_dist
tar -czf $(1) -C $(2) `ls $(2)`
$(call mb_file_info,$(1))
endef

58
lib/make/mb_build.mk Normal file
View File

@ -0,0 +1,58 @@
MB_BUILD_FLAG_CPU ?= -mz80
MB_BUILD_FLAG_LD ?= --nostdinc
MB_BUILD_SDASM_FLAGS ?= -g -l -c -o
MB_BUILD_SDAR_FLAGS ?= -rc
MB_BUILD_H2B_CMD ?= $(PATH_HEX2BIN)/hex2bin
MB_BUILD_SDCC_CMD ?= $(PATH_SDCC)/sdcc
MB_BUILD_SDASM_CMD ?= $(PATH_SDCC)/sdasz80
MB_BUILD_SDAR_CMD ?= $(PATH_SDCC)/sdar
# TODO: Add C + mixed support;
#$(MB_SDASM) -I$(MB_LIBASM_SRC)/include
#-l$(LIBASM_LINK)
define mb_compile_asm
@echo === Compile module asm.
$(MB_BUILD_SDASM_CMD) $(MB_BUILD_SDASM_FLAGS) $(1) $(2)
endef
define mb_link_asm_lib
@echo === Link module asm lib.
$(MB_BUILD_SDAR_CMD) $(MB_BUILD_SDAR_FLAGS) $(1) $(2)
endef
define mb_link_asm
@echo === Link asm module at $(3)
$(MB_BUILD_SDCC_CMD) $(MB_BUILD_FLAG_CPU) --no-std-crt0 --code-loc $(3) -o $(1) $(2)
endef
define mb_link_asm_0000
$(call mb_link_asm,$(1),$(2),0x0000)
endef
define mb_link_asm_0100
$(call mb_link_asm,$(1),$(2),0x0100)
endef
define mb_link_asm_1000
$(call mb_link_asm,$(1),$(2),0x1000)
endef
define mb_link_asm_4000
$(call mb_link_asm,$(1),$(2),0x4000)
endef
define mb_link_asm_8000
$(call mb_link_asm,$(1),$(2),0x8000)
endef
define mb_link_asm_C000
$(call mb_link_asm,$(1),$(2),0xC000)
endef
define mb_link_asm_dos
$(call mb_link_asm_0100,$(1),$(2))
endef
define mb_hex2com
@echo === Extracting hex2com
cd $(dir $(1)) && $(MB_BUILD_H2B_CMD) -e com $(notdir $(1))
endef
define mb_hex2dat
@echo === Extracting hex2dat
cd $(dir $(1)) && $(MB_BUILD_H2B_CMD) -e dat $(notdir $(1))
endef

23
lib/make/mb_msxhub.mk Normal file
View File

@ -0,0 +1,23 @@
MB_MSXHUB_API ?= https://msxhub.com/api
MB_MSXHUB_CACHE ?= $(MB_CACHE)/msxhub/repro-v0
MB_MSXHUB_WGET ?= wget
define _mb_msxhub_fetch_file
@echo === Fetch msxhub file
$(call mb_mkdir,$(dir $(MB_MSXHUB_CACHE)/$(subst $(MB_MSXHUB_API)/,,$(1))))
test -f $(MB_MSXHUB_CACHE)/$(subst $(MB_MSXHUB_API)/,,$(1)) || $(MB_MSXHUB_WGET) -O $(MB_MSXHUB_CACHE)/$(subst $(MB_MSXHUB_API)/,,$(1)) $(1)
endef
define mb_msxhub_file
$(if $(wildcard $(MB_MSXHUB_CACHE)/$(subst $(MB_MSXHUB_API)/,,$(2))),,$(call _mb_msxhub_fetch_file,$(2)))
$(call mb_copy,$(MB_MSXHUB_CACHE)/$(subst $(MB_MSXHUB_API)/,,$(2)),$(1))
endef
define mb_msxhub_get_dos2_sys
$(call mb_msxhub_file,$(1)/MSXDOS2.SYS,$(MB_MSXHUB_API)/MSXDOS2/2.20-1/get/MSXDOS2/MSXDOS2.SYS)
endef
define mb_msxhub_get_dos2_com
$(call mb_msxhub_file,$(1)/COMMAND2.COM,$(MB_MSXHUB_API)/MSXDOS2/2.20-1/get/MSXDOS2/COMMAND2.COM)
endef

View File

@ -1,26 +1,19 @@
# TODO move to new msxhub native posix+win cmd tool
# + local userdir caching like ~/.cache/msxhub/repro/m/s/x/msxdos2
CMD_WGET ?= wget
PATH_OPENMSX ?= /usr/bin
# Define openmsx defaults
MB_OPENMSX_BOOT_TIMEOUT ?= 25
MB_OPENMSX_MACHINE ?= Philips_NMS_8250
MB_OPENMSX_JOYPORTA ?=
MB_OPENMSX_JOYPORTB ?=
# Workaround for include msxbuild.mk file and 'older' openmsx segfaults on relative settings path.
MB_OPENMSX_SETTING := $(if $(realpath $(PATH_MSXBUILD)),$(realpath $(PATH_MSXBUILD)),$(PATH_MSXBUILD))/lib/openmsx/boot_settings.xml
MB_OPENMSX_EXTS_ORG += -ext ide -ext ram4mb
MB_OPENMSX_MACHINE ?= Philips_NMS_8250
MB_OPENMSX_JOYPORTA ?=
MB_OPENMSX_JOYPORTB ?=
MB_OPENMSX_SETTING ?= $(PATH_MSXBUILD)/lib/openmsx/boot_settings.xml
MB_OPENMSX_EXTS ?=
MB_OPENMSX_EXTRA_MEM ?= -ext ram4mb
MB_OPENMSX_ARGS = \
-setting $(MB_OPENMSX_SETTING) \
-machine $(MB_OPENMSX_MACHINE) \
-ext slotexpander $(MB_OPENMSX_EXTS_ORG) $(MB_OPENMSX_EXTS) \
-ext slotexpander -ext ide $(MB_OPENMSX_EXTRA_MEM) $(MB_OPENMSX_EXTS) \
-script $(PATH_MSXBUILD)/lib/openmsx/boot_env.tcl \
-script $(PATH_MSXBUILD)/lib/openmsx/boot_hdd.tcl \
-script $(PATH_MSXBUILD)/lib/openmsx/fail_after.tcl \
-script $(PATH_MSXBUILD)/bin/wget/omsxctl.tcl
-script $(MB_MSXHUB_CACHE)/OMSXCTL/1.0-1/get/OMSXCTL/omsxctl.tcl
# TODO: add run flag to disable xml output like "-control stdio-boot-only"
ifeq ($(OS),Windows_NT)
@ -29,8 +22,8 @@ else
MB_OPENMSX_CMD = $(PATH_OPENMSX)/openmsx $(MB_OPENMSX_ARGS) -control stdio < $(PATH_MSXBUILD)/lib/openmsx/boot_stdio.xml | sed -n -e 's/.*>\(.*\)<.*/\1/p' | tail -n+3
endif
define _mb_openmsx_run
@echo === Running openmsx
test -f $(PATH_MSXBUILD)/bin/wget/omsxctl.tcl || $(CMD_WGET) -O $(PATH_MSXBUILD)/bin/wget/omsxctl.tcl https://msxhub.com/api/OMSXCTL/1.0-1/get/OMSXCTL/omsxctl.tcl
@echo === Running openMSX
$(if $(wildcard $(MB_MSXHUB_CACHE)/OMSXCTL/1.0-1/get/OMSXCTL/omsxctl.tcl),,$(call _mb_msxhub_fetch_file,$(MB_MSXHUB_API)/OMSXCTL/1.0-1/get/OMSXCTL/omsxctl.tcl))
FAIL_AFTER_BOOT=$(MB_OPENMSX_BOOT_TIMEOUT) \
FAIL_AFTER_PATH=bin \
BOOT_HDD_PATH="$(1)" \
@ -40,23 +33,16 @@ define _mb_openmsx_run
$(MB_OPENMSX_CMD)
endef
define _mb_openmsx_run_dos
@echo === run openmsx
test -f $(PATH_MSXBUILD)/bin/wget/omsxctl.com || $(CMD_WGET) -O $(PATH_MSXBUILD)/bin/wget/omsxctl.com https://msxhub.com/api/OMSXCTL/1.0-1/get/OMSXCTL/omsxctl.com
$(call mb_copy,$(PATH_MSXBUILD)/bin/wget/omsxctl.com,$(1))
$(call mb_msxhub_file,$(1)/omsxctl.com,$(MB_MSXHUB_API)/OMSXCTL/1.0-1/get/OMSXCTL/omsxctl.com)
$(call _mb_openmsx_run,$(1))
endef
# TODO: add msx1+allversions of dos to https://github.com/fr3nd/msxhub-packages/issues/18
#define mb_openmsx_dos1
# @echo === Run openmsx_dos1
# cp build/msxdos1/* $(1)
# $(call _mb_openmsx_run_dos,$(1))
#endef
define mb_openmsx_dos2
@echo === Prepare openmsx run with dos2
test -f $(PATH_MSXBUILD)/bin/wget/msxdos2.sys || $(MB_MKDIR) $(PATH_MSXBUILD)/bin/wget
test -f $(PATH_MSXBUILD)/bin/wget/msxdos2.sys || $(CMD_WGET) -O $(PATH_MSXBUILD)/bin/wget/msxdos2.sys https://msxhub.com/api/MSXDOS2/2.20-1/get/MSXDOS2/MSXDOS2.SYS
test -f $(PATH_MSXBUILD)/bin/wget/command2.com || $(CMD_WGET) -O $(PATH_MSXBUILD)/bin/wget/command2.com https://msxhub.com/api/MSXDOS2/2.20-1/get/MSXDOS2/COMMAND2.COM
$(call mb_copy,$(PATH_MSXBUILD)/bin/wget/msxdos2.sys,$(1))
$(call mb_copy,$(PATH_MSXBUILD)/bin/wget/command2.com,$(1))
$(call mb_msxhub_get_dos2_sys,$(1))
$(call mb_msxhub_get_dos2_com,$(1))
$(call _mb_openmsx_run_dos, $(1))
endef

View File

@ -1,74 +1,17 @@
#
# msxbuild.mk - Makefile helper to use with msx projects.
#
# note: this needs more work.
#
# Required tools paths
# Setup required tools paths
PATH_HEX2BIN ?= /usr/bin
PATH_SDCC ?= /usr/bin
PATH_OPENMSX ?= /usr/bin
PATH_MSXBUILD ?= $(dir $(lastword $(MAKEFILE_LIST)))../..
# Include features
include $(PATH_MSXBUILD)/lib/make/mb_base.mk
include $(PATH_MSXBUILD)/lib/make/mb_autoexec.mk
include $(PATH_MSXBUILD)/lib/make/mb_msxhub.mk
include $(PATH_MSXBUILD)/lib/make/mb_openmsx.mk
include $(PATH_MSXBUILD)/lib/make/mb_assert.mk
CMD_H2B ?= $(PATH_HEX2BIN)/hex2bin
CMD_SDCC ?= $(PATH_SDCC)/sdcc
CMD_SDASM ?= $(PATH_SDCC)/sdasz80
CMD_SDAR ?= $(PATH_SDCC)/sdar
# Define build flags
MB_SDCC_FLAG_CPU ?= -mz80
MB_SDCC_FLAG_LD ?= --nostdinc
MB_SDASM_FLAGS ?= -g -l -c -o
MB_SDAR_FLAGS ?= -rc
#$(MB_SDASM) -I$(MB_LIBASM_SRC)/include
define mb_compile_asm
@echo === Compile module asm.
$(CMD_SDASM) $(MB_SDASM_FLAGS) $(1) $(2)
endef
define mb_link_asm_lib
@echo === Link module asm lib.
$(CMD_SDAR) $(MB_SDAR_FLAGS) $(1) $(2)
endef
define mb_link_asm
@echo === Link asm module at $(3)
$(CMD_SDCC) $(MB_SDCC_FLAG_CPU) --no-std-crt0 --code-loc $(3) -o $(1) $(2)
endef
define mb_link_asm_0000
$(call mb_link_asm,$(1),$(2),0x0000)
endef
define mb_link_asm_dos
$(call mb_link_asm,$(1),$(2),0x0100)
endef
define mb_link_asm_1000
$(call mb_link_asm,$(1),$(2),0x1000)
endef
define mb_link_asm_4000
$(call mb_link_asm,$(1),$(2),0x4000)
endef
define mb_link_asm_8000
$(call mb_link_asm,$(1),$(2),0x8000)
endef
define mb_link_asm_C000
$(call mb_link_asm,$(1),$(2),0xC000)
endef
#-l$(LIBASM_LINK)
define mb_hex2com
@echo === Convert to binary: $(notdir $(1)).com
cd $(dir $(1)) && $(CMD_H2B) -e com $(notdir $(1))
$(call mb_file_info,$(2))
@echo === Done $(notdir $(2))
endef
define mb_hex2dat
@echo === Convert to binary $(notdir $(1)).dat
cd $(dir $(1)) && $(CMD_H2B) -e dat $(notdir $(1))
$(call mb_file_info,$(2))
@echo === Done $(notdir $(2))
endef
include $(PATH_MSXBUILD)/lib/make/mb_build.mk