From 25297879700f87f6234e177f240227936200ad8e Mon Sep 17 00:00:00 2001 From: Tom Fiset Date: Thu, 4 Mar 2021 21:07:33 -0500 Subject: [PATCH 01/12] Update Makefile to build on OSX --- Makefile | 12 +++++------ scripts/darwin.mk | 15 ++++++++++++++ scripts/emu.mk | 12 ++++++++++- scripts/env.mk | 47 ++++++++++++++++++++++++++++-------------- scripts/linux.mk | 2 +- scripts/mod-builder.mk | 7 ++++++- 6 files changed, 71 insertions(+), 24 deletions(-) create mode 100644 scripts/darwin.mk diff --git a/Makefile b/Makefile index a0c14934..bf557017 100644 --- a/Makefile +++ b/Makefile @@ -60,15 +60,15 @@ pbl-clean: +$(MAKE) -f scripts/pbl.mk clean emu: - +$(MAKE) -f scripts/lua.mk ARCH=linux - +$(MAKE) -f scripts/miniz.mk ARCH=linux - +$(MAKE) -f scripts/lodepng.mk ARCH=linux + +$(MAKE) -f scripts/lua.mk + +$(MAKE) -f scripts/miniz.mk + +$(MAKE) -f scripts/lodepng.mk +$(MAKE) -f scripts/emu.mk emu-clean: - +$(MAKE) -f scripts/lua.mk ARCH=linux clean - +$(MAKE) -f scripts/miniz.mk ARCH=linux clean - +$(MAKE) -f scripts/lodepng.mk ARCH=linux clean + +$(MAKE) -f scripts/lua.mk clean + +$(MAKE) -f scripts/miniz.mk clean + +$(MAKE) -f scripts/lodepng.mk clean +$(MAKE) -f scripts/emu.mk clean dist-clean: diff --git a/scripts/darwin.mk b/scripts/darwin.mk new file mode 100644 index 00000000..36ba5c7c --- /dev/null +++ b/scripts/darwin.mk @@ -0,0 +1,15 @@ +# Build Tools for OSX +CC := gcc-10 -fdiagnostics-color -fmax-errors=5 +CPP := g++-10 -fdiagnostics-color -fmax-errors=5 +OBJCOPY := objcopy +OBJDUMP := objdump +ADDR2LINE := addr2line +LD := ld +AR := gcc-ar-10 +SIZE := size +STRIP := strip +READELF := readelf +NM := nm +SWIG := swig +PYTHON := python3 +ZIP := zip \ No newline at end of file diff --git a/scripts/emu.mk b/scripts/emu.mk index d224b22b..253fb945 100644 --- a/scripts/emu.mk +++ b/scripts/emu.mk @@ -29,6 +29,16 @@ CFLAGS += -DFIRMWARE_NAME=\"$(FIRMWARE_NAME)\" CFLAGS += -DFIRMWARE_STATUS=\"$(FIRMWARE_STATUS)\" LFLAGS = -Wl,--export-dynamic -Wl,--gc-sections -lSDL2 -lSDL2_ttf -lfftw3f -lm -ldl -lstdc++ +ifeq ($(ARCH),darwin) +# Locate our deps using brew +sdl2 := $(shell brew --prefix sdl2) +sdl2_ttf := $(shell brew --prefix sdl2_ttf) +fftw := $(shell brew --prefix fftw) + +CFLAGS += -I$(sdl2)/include -I$(sdl2)/include/SDL2 -I$(sdl2_ttf)/include +LFLAGS += -L$(sdl2)/lib -L$(sdl2_ttf)/lib -L$(fftw)/lib +endif + all: $(out_dir)/$(program_name).elf $(objects): scripts/env.mk scripts/emu.mk @@ -36,7 +46,7 @@ $(objects): scripts/env.mk scripts/emu.mk $(out_dir)/$(program_name).elf: $(objects) $(libraries) @mkdir -p $(@D) @echo $(describe_env) LINK $(describe_target) - @$(CC) $(CFLAGS) -o $@ $(objects) $(libraries) $(LFLAGS) + @$(LD) -o $@ $(objects) $(libraries) $(LFLAGS) clean: rm -rf $(out_dir) diff --git a/scripts/env.mk b/scripts/env.mk index 6f6d2e2e..26e23ad1 100644 --- a/scripts/env.mk +++ b/scripts/env.mk @@ -1,14 +1,22 @@ - -ARCH ?= am335x -#ARCH = linux -PROFILE ?= testing -#PROFILE = release -#PROFILE = debug - FIRMWARE_NAME ?= Thoon FIRMWARE_VERSION ?= 0.6.02 FIRMWARE_STATUS ?= unstable +# Determine ARCH if it's not provided... +# linux | darwin | am335x +SYSTEM_NAME := $(shell uname -s) +ifeq ($(SYSTEM_NAME),Linux) +ARCH ?= linux +endif +ifeq ($(SYSTEM_NAME),Darwin) +ARCH ?= darwin +endif +ARCH ?= am335x + +# Determine PROFILE if it's not provided... +# testing | release | debug +PROFILE ?= testing + scriptname := $(word 1, $(MAKEFILE_LIST)) scriptname := $(scriptname:scripts/%=%) @@ -47,11 +55,16 @@ CFLAGS.size = -Os symbols = includes = +# Default card locations +front_card_label = front +front_card_dir = ~/.od/$(front_card_label) +rear_card_label = rear +rear_card_dir = ~/.od/$(rear_card_label) + ########################### #### am335x-specific ifeq ($(ARCH),am335x) - CFLAGS.release ?= $(CFLAGS.speed) -Wno-unused CFLAGS.testing ?= $(CFLAGS.speed) -DBUILDOPT_TESTING CFLAGS.debug ?= -g -DBUILDOPT_TESTING @@ -69,27 +82,31 @@ include scripts/am335x.mk symbols += gcc am335x am3359 evmAM335x CFLAGS.am335x = -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=hard -mabi=aapcs -Dfar= -D__DYNAMIC_REENT__ - endif #### linux-specific ifeq ($(ARCH),linux) - CFLAGS.release ?= $(CFLAGS.speed) -Wno-unused CFLAGS.testing ?= -g -DBUILDOPT_TESTING CFLAGS.debug ?= -g -DBUILDOPT_TESTING -front_card_label = front -front_card_dir = ~/.od/$(front_card_label) -rear_card_label = rear -rear_card_dir = ~/.od/$(rear_card_label) - include scripts/linux.mk # symbols += BUILDOPT_LUA_USE_REALLOC CFLAGS.linux = -Wno-deprecated-declarations -msse4 -fPIC endif +### darwin-specific +ifeq ($(ARCH),darwin) +CFLAGS.release ?= $(CFLAGS.speed) -Wno-unused +CFLAGS.testing ?= -g -DBUILDOPT_TESTING +CFLAGS.debug ?= -g -DBUILDOPT_TESTING + +include scripts/darwin.mk + +CFLAGS.darwin = -Wno-deprecated-declarations -fPIC +endif + ########################### ifndef CFLAGS.$(PROFILE) diff --git a/scripts/linux.mk b/scripts/linux.mk index e8f84b72..9f7486e0 100644 --- a/scripts/linux.mk +++ b/scripts/linux.mk @@ -4,7 +4,7 @@ CPP := g++ -fdiagnostics-color -fmax-errors=5 OBJCOPY := objcopy OBJDUMP := objdump ADDR2LINE := addr2line -LD := gcc -fdiagnostics-color +LD := ld AR := gcc-ar SIZE := size STRIP := strip diff --git a/scripts/mod-builder.mk b/scripts/mod-builder.mk index 94d5c0d5..e21bfcac 100644 --- a/scripts/mod-builder.mk +++ b/scripts/mod-builder.mk @@ -62,6 +62,11 @@ ifeq ($(ARCH),linux) LFLAGS = -shared endif +ifeq ($(ARCH),darwin) +# Do not try to resolve dynamic links when linking. +LFLAGS = -dynamic -undefined dynamic_lookup -lSystem +endif + # Prevent swig from placing symbols exported by mods in the global namespace. SWIGFLAGS += -nomoduleglobal -small -fvirtual @@ -72,7 +77,7 @@ $(objects): scripts/env.mk scripts/mod-builder.mk $(lib_file): $(objects) @echo $(describe_env) LINK $(describe_target) @mkdir -p $(@D) - @$(CC) $(CFLAGS) -o $@ $(objects) $(LFLAGS) + @$(LD) -o $@ $(objects) $(LFLAGS) @$(SIZE) $@ $(package_file): $(lib_file) $(assets) From d29e714fa2e3adb98b59b25ef48a9da43bacd7e2 Mon Sep 17 00:00:00 2001 From: Tom Fiset Date: Thu, 4 Mar 2021 21:22:29 -0500 Subject: [PATCH 02/12] Remove explicit ARCH= --- scripts/emu.mk | 13 ++++++------- scripts/libemu.mk | 13 ++++++------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/scripts/emu.mk b/scripts/emu.mk index 253fb945..46d0d0e0 100644 --- a/scripts/emu.mk +++ b/scripts/emu.mk @@ -1,4 +1,3 @@ -ARCH=linux include scripts/env.mk include scripts/utils.mk @@ -61,13 +60,13 @@ missing: $(objects) $(libraries) @$(PYTHON) list-undefined.py $(out_dir)/error.log > $(out_dir)/missing.log libs: - +$(MAKE) -f lua.mk ARCH=linux - +$(MAKE) -f miniz.mk ARCH=linux - +$(MAKE) -f lodepng.mk ARCH=linux + +$(MAKE) -f lua.mk + +$(MAKE) -f miniz.mk + +$(MAKE) -f lodepng.mk clean-libs: - +$(MAKE) -f lua.mk clean ARCH=linux - +$(MAKE) -f miniz.mk clean ARCH=linux - +$(MAKE) -f lodepng.mk clean ARCH=linux + +$(MAKE) -f lua.mk clean + +$(MAKE) -f miniz.mk clean + +$(MAKE) -f lodepng.mk clean include scripts/rules.mk diff --git a/scripts/libemu.mk b/scripts/libemu.mk index 7f1567ee..c5113e68 100644 --- a/scripts/libemu.mk +++ b/scripts/libemu.mk @@ -1,4 +1,3 @@ -ARCH=linux include scripts/env.mk include scripts/utils.mk @@ -40,13 +39,13 @@ clean: # WARNING. This will overwrite the shared lib build dir. Needs to be fixed. libs: - +CFLAGS=-fpic $(MAKE) -f lua.mk ARCH=linux - +CFLAGS=-fpic $(MAKE) -f miniz.mk ARCH=linux - +CFLAGS=-fpic $(MAKE) -f lodepng.mk ARCH=linux + +CFLAGS=-fpic $(MAKE) -f lua.mk + +CFLAGS=-fpic $(MAKE) -f miniz.mk + +CFLAGS=-fpic $(MAKE) -f lodepng.mk clean-libs: - +$(MAKE) -f lua.mk clean ARCH=linux - +$(MAKE) -f miniz.mk clean ARCH=linux - +$(MAKE) -f lodepng.mk clean ARCH=linux + +$(MAKE) -f lua.mk clean + +$(MAKE) -f miniz.mk clean + +$(MAKE) -f lodepng.mk clean include scripts/rules.mk From 1db71d9b2257b9100940ee18c3090a934bc21c84 Mon Sep 17 00:00:00 2001 From: Tom Fiset Date: Thu, 4 Mar 2021 21:37:13 -0500 Subject: [PATCH 03/12] Set the correct source dir --- scripts/env.mk | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/env.mk b/scripts/env.mk index 26e23ad1..c92ae8a5 100644 --- a/scripts/env.mk +++ b/scripts/env.mk @@ -7,11 +7,14 @@ FIRMWARE_STATUS ?= unstable SYSTEM_NAME := $(shell uname -s) ifeq ($(SYSTEM_NAME),Linux) ARCH ?= linux +arch_source ?= linux endif ifeq ($(SYSTEM_NAME),Darwin) ARCH ?= darwin +arch_source ?= linux endif ARCH ?= am335x +arch_source ?= am335x # Determine PROFILE if it's not provided... # testing | release | debug @@ -32,7 +35,7 @@ describe_env = $(blueON)[$(scriptname) $(ARCH) $(PROFILE)]$(blueOFF) # Frequently used paths build_dir = $(PROFILE)/$(ARCH) libs_build_dir = $(build_dir)/libs -arch_dir = arch/$(ARCH) +arch_dir = arch/$(arch_source) mods_dir = mods od_dir = od libs_dir = libs From ac42d8a655ef8a6382d80b32a69bd07fec75ebb7 Mon Sep 17 00:00:00 2001 From: Tom Fiset Date: Thu, 4 Mar 2021 23:45:09 -0500 Subject: [PATCH 04/12] Get scripts working --- scripts/darwin.mk | 4 ++-- scripts/emu.mk | 18 ++++++++++++------ scripts/env.mk | 2 +- scripts/libemu.mk | 18 ++++++++++++++++-- scripts/mod-builder.mk | 2 +- 5 files changed, 32 insertions(+), 12 deletions(-) diff --git a/scripts/darwin.mk b/scripts/darwin.mk index 36ba5c7c..a22179f8 100644 --- a/scripts/darwin.mk +++ b/scripts/darwin.mk @@ -1,6 +1,6 @@ # Build Tools for OSX -CC := gcc-10 -fdiagnostics-color -fmax-errors=5 -CPP := g++-10 -fdiagnostics-color -fmax-errors=5 +CC := gcc-10 -fdiagnostics-color -fmax-errors=5 -rdynamic +CPP := g++-10 -fdiagnostics-color -fmax-errors=5 -lm OBJCOPY := objcopy OBJDUMP := objdump ADDR2LINE := addr2line diff --git a/scripts/emu.mk b/scripts/emu.mk index 46d0d0e0..6caa5ce1 100644 --- a/scripts/emu.mk +++ b/scripts/emu.mk @@ -22,11 +22,10 @@ objects := $(addprefix $(out_dir)/,$(c_sources:%.c=%.o) $(cpp_sources:%.cpp=%.o) # Manually add objects objects += $(out_dir)/od/glue/app_swig.o objects += $(out_dir)/libs/SDL_FontCache/SDL_FontCache.o - -CFLAGS += -DFIRMWARE_VERSION=\"$(FIRMWARE_VERSION)\" -CFLAGS += -DFIRMWARE_NAME=\"$(FIRMWARE_NAME)\" -CFLAGS += -DFIRMWARE_STATUS=\"$(FIRMWARE_STATUS)\" -LFLAGS = -Wl,--export-dynamic -Wl,--gc-sections -lSDL2 -lSDL2_ttf -lfftw3f -lm -ldl -lstdc++ + +ifeq ($(ARCH),linux) +LFLAGS += -Wl,--export-dynamic -Wl,--gc-sections +endif ifeq ($(ARCH),darwin) # Locate our deps using brew @@ -34,10 +33,17 @@ sdl2 := $(shell brew --prefix sdl2) sdl2_ttf := $(shell brew --prefix sdl2_ttf) fftw := $(shell brew --prefix fftw) +CFLAGS += -rdynamic CFLAGS += -I$(sdl2)/include -I$(sdl2)/include/SDL2 -I$(sdl2_ttf)/include +#LFLAGS += -export-dynamic LFLAGS += -L$(sdl2)/lib -L$(sdl2_ttf)/lib -L$(fftw)/lib endif +CFLAGS += -DFIRMWARE_VERSION=\"$(FIRMWARE_VERSION)\" +CFLAGS += -DFIRMWARE_NAME=\"$(FIRMWARE_NAME)\" +CFLAGS += -DFIRMWARE_STATUS=\"$(FIRMWARE_STATUS)\" +LFLAGS += -lSDL2 -lSDL2_ttf -lfftw3f -lm -ldl -lstdc++ + all: $(out_dir)/$(program_name).elf $(objects): scripts/env.mk scripts/emu.mk @@ -45,7 +51,7 @@ $(objects): scripts/env.mk scripts/emu.mk $(out_dir)/$(program_name).elf: $(objects) $(libraries) @mkdir -p $(@D) @echo $(describe_env) LINK $(describe_target) - @$(LD) -o $@ $(objects) $(libraries) $(LFLAGS) + @$(CC) $(CFLAGS) -o $@ $(objects) $(libraries) $(LFLAGS) clean: rm -rf $(out_dir) diff --git a/scripts/env.mk b/scripts/env.mk index c92ae8a5..23711674 100644 --- a/scripts/env.mk +++ b/scripts/env.mk @@ -107,7 +107,7 @@ CFLAGS.debug ?= -g -DBUILDOPT_TESTING include scripts/darwin.mk -CFLAGS.darwin = -Wno-deprecated-declarations -fPIC +CFLAGS.darwin = -Wno-deprecated-declarations -msse4 -fPIC endif ########################### diff --git a/scripts/libemu.mk b/scripts/libemu.mk index c5113e68..08f1c545 100644 --- a/scripts/libemu.mk +++ b/scripts/libemu.mk @@ -23,9 +23,23 @@ objects := $(addprefix $(out_dir)/,$(c_sources:%.c=%.o) $(cpp_sources:%.cpp=%.o) objects += $(out_dir)/od/glue/app_swig.o objects += $(out_dir)/emu/emu_swig.o objects += $(out_dir)/libs/SDL_FontCache/SDL_FontCache.o - + +ifeq ($(ARCH),linux) +LFLAGS += --gc-sections +endif + +ifeq ($(ARCH),darwin) +# Locate our deps using brew +sdl2 := $(shell brew --prefix sdl2) +sdl2_ttf := $(shell brew --prefix sdl2_ttf) +fftw := $(shell brew --prefix fftw) + +CFLAGS += -I$(sdl2)/include -I$(sdl2)/include/SDL2 -I$(sdl2_ttf)/include +LFLAGS += -L$(sdl2)/lib -L$(sdl2_ttf)/lib -L$(fftw)/lib +endif + CFLAGS += -fpic -LFLAGS = -shared -Wl,--gc-sections -lSDL2 -lSDL2_ttf -lfftw3f -lm -ldl -lstdc++ +LFLAGS += -lSDL2 -lSDL2_ttf -lfftw3f -lm -ldl -lstdc++ all: $(out_dir)/$(program_name).so diff --git a/scripts/mod-builder.mk b/scripts/mod-builder.mk index e21bfcac..8569f1e1 100644 --- a/scripts/mod-builder.mk +++ b/scripts/mod-builder.mk @@ -77,7 +77,7 @@ $(objects): scripts/env.mk scripts/mod-builder.mk $(lib_file): $(objects) @echo $(describe_env) LINK $(describe_target) @mkdir -p $(@D) - @$(LD) -o $@ $(objects) $(LFLAGS) + @$(CC) $(CFLAGS) -o $@ $(objects) $(LFLAGS) @$(SIZE) $@ $(package_file): $(lib_file) $(assets) From faead3e0a45309245a9a204c421b879d61d06bdf Mon Sep 17 00:00:00 2001 From: Tom Fiset Date: Thu, 4 Mar 2021 23:51:10 -0500 Subject: [PATCH 05/12] Clean up --- scripts/darwin.mk | 4 ++-- scripts/emu.mk | 1 - scripts/linux.mk | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/darwin.mk b/scripts/darwin.mk index a22179f8..36ba5c7c 100644 --- a/scripts/darwin.mk +++ b/scripts/darwin.mk @@ -1,6 +1,6 @@ # Build Tools for OSX -CC := gcc-10 -fdiagnostics-color -fmax-errors=5 -rdynamic -CPP := g++-10 -fdiagnostics-color -fmax-errors=5 -lm +CC := gcc-10 -fdiagnostics-color -fmax-errors=5 +CPP := g++-10 -fdiagnostics-color -fmax-errors=5 OBJCOPY := objcopy OBJDUMP := objdump ADDR2LINE := addr2line diff --git a/scripts/emu.mk b/scripts/emu.mk index 6caa5ce1..cca4fed1 100644 --- a/scripts/emu.mk +++ b/scripts/emu.mk @@ -35,7 +35,6 @@ fftw := $(shell brew --prefix fftw) CFLAGS += -rdynamic CFLAGS += -I$(sdl2)/include -I$(sdl2)/include/SDL2 -I$(sdl2_ttf)/include -#LFLAGS += -export-dynamic LFLAGS += -L$(sdl2)/lib -L$(sdl2_ttf)/lib -L$(fftw)/lib endif diff --git a/scripts/linux.mk b/scripts/linux.mk index 9f7486e0..e8f84b72 100644 --- a/scripts/linux.mk +++ b/scripts/linux.mk @@ -4,7 +4,7 @@ CPP := g++ -fdiagnostics-color -fmax-errors=5 OBJCOPY := objcopy OBJDUMP := objdump ADDR2LINE := addr2line -LD := ld +LD := gcc -fdiagnostics-color AR := gcc-ar SIZE := size STRIP := strip From 567f4ab582050c3bea22e520806d78784f538fae Mon Sep 17 00:00:00 2001 From: Tom Fiset Date: Thu, 4 Mar 2021 23:53:20 -0500 Subject: [PATCH 06/12] More clean up --- scripts/env.mk | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/env.mk b/scripts/env.mk index 23711674..43a0c9ce 100644 --- a/scripts/env.mk +++ b/scripts/env.mk @@ -68,6 +68,7 @@ rear_card_dir = ~/.od/$(rear_card_label) #### am335x-specific ifeq ($(ARCH),am335x) + CFLAGS.release ?= $(CFLAGS.speed) -Wno-unused CFLAGS.testing ?= $(CFLAGS.speed) -DBUILDOPT_TESTING CFLAGS.debug ?= -g -DBUILDOPT_TESTING @@ -89,6 +90,7 @@ endif #### linux-specific ifeq ($(ARCH),linux) + CFLAGS.release ?= $(CFLAGS.speed) -Wno-unused CFLAGS.testing ?= -g -DBUILDOPT_TESTING CFLAGS.debug ?= -g -DBUILDOPT_TESTING @@ -97,10 +99,12 @@ include scripts/linux.mk # symbols += BUILDOPT_LUA_USE_REALLOC CFLAGS.linux = -Wno-deprecated-declarations -msse4 -fPIC + endif ### darwin-specific ifeq ($(ARCH),darwin) + CFLAGS.release ?= $(CFLAGS.speed) -Wno-unused CFLAGS.testing ?= -g -DBUILDOPT_TESTING CFLAGS.debug ?= -g -DBUILDOPT_TESTING From 85fc2b8851c99a9735bf3a76fd05bf3083c2c5d2 Mon Sep 17 00:00:00 2001 From: Tom Fiset Date: Thu, 4 Mar 2021 23:54:31 -0500 Subject: [PATCH 07/12] Cleanup diff --- scripts/env.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/env.mk b/scripts/env.mk index 43a0c9ce..1261c2c0 100644 --- a/scripts/env.mk +++ b/scripts/env.mk @@ -86,6 +86,7 @@ include scripts/am335x.mk symbols += gcc am335x am3359 evmAM335x CFLAGS.am335x = -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=hard -mabi=aapcs -Dfar= -D__DYNAMIC_REENT__ + endif #### linux-specific From a83afe0e3292c39039c697357c8b4d6f260385e6 Mon Sep 17 00:00:00 2001 From: Tom Fiset Date: Fri, 5 Mar 2021 00:03:12 -0500 Subject: [PATCH 08/12] Update README --- README.md | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 0b1b3566..a6326cd2 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ Edit this file with your own values to configure various items like key mappings Packages encapsulate unit presets (*.unit), unit definitions (*.lua), and shared libraries (*.so) into one shareable bundle along with any necessary assets (e.g. sound files and so on). The core units are also distributed as a package, so let's use the core package as an example. First, to compile and create the core package, execute: ```bash -make core ARCH=linux +make core ``` Next, let's go over the two main methods for installing packages. @@ -188,7 +188,7 @@ First, you will need to install the TI-RTOS development tools for the AM335x. 4. ***When asked, please set the destination folder to ```~/ti```.*** This is the path assumed by the project makefiles. If instead you install to a different folder then before executing any cross-compilation commands, you will need to set the TI_INSTALL_DIR shell environment variable to the actual path that you used. If you don't want to change your shell environment then you can also pass the path on the commandline like this: ```bash -make core TI_INSTALL_DIR=~/your-path-to-ti-sdk +make core TI_INSTALL_DIR=~/your-path-to-ti-sdk ARCH=am355x ``` This documentation will assume that you used the default location. @@ -206,7 +206,7 @@ sudo apt install swig python3 zip gcc-multilib A good test of your build environment is to see if you can successfully build the factory mods: ```bash -make core teletype +make core teletype ARCH=am355x ``` ## USB Functions @@ -223,10 +223,11 @@ All build outputs are placed in a sub folder composed of the build profile and t * debug: No optimizations. Logging enabled. * release: All optimizations enabled. Logging disabled. -And here are the 2 supported target architectures: +And here are the 3 supported target architectures: * am335x * linux +* darwin (OSX) So for example, if I execute the following make command: @@ -234,10 +235,4 @@ So for example, if I execute the following make command: make core PROFILE=debug ARCH=linux ``` -Then the build outputs will be placed in the ```debug/linux``` directory of the project root. Generally, the default profile is **testing** and the default architecture for everything except the emulator is **am335x**. So if you execute just: - -```bash -make core -``` - -Then the build outputs will appear in the ```testing/am335x``` directory of the project root. See the [top-level Makefile](Makefile) for more details. +Then the build outputs will be placed in the ```debug/linux``` directory of the project root. Generally, the default profile is **testing** and the default architecture is determined by your OS (`uname -s`). See the [top-level Makefile](Makefile) for more details. From 998672c5c5b4b9293e46fe0789c93bb0a57a491a Mon Sep 17 00:00:00 2001 From: Tom Fiset Date: Fri, 5 Mar 2021 01:41:12 -0500 Subject: [PATCH 09/12] Fix logic error --- scripts/env.mk | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/scripts/env.mk b/scripts/env.mk index 1261c2c0..c695e7d8 100644 --- a/scripts/env.mk +++ b/scripts/env.mk @@ -4,17 +4,23 @@ FIRMWARE_STATUS ?= unstable # Determine ARCH if it's not provided... # linux | darwin | am335x -SYSTEM_NAME := $(shell uname -s) -ifeq ($(SYSTEM_NAME),Linux) -ARCH ?= linux -arch_source ?= linux +ifndef ARCH + SYSTEM_NAME := $(shell uname -s) + ifeq ($(SYSTEM_NAME),Linux) + ARCH = linux + else ifeq ($(SYSTEM_NAME),Darwin) + ARCH = darwin + else + $(error Unsupported system $(SYSTEM_NAME)) + endif endif -ifeq ($(SYSTEM_NAME),Darwin) -ARCH ?= darwin -arch_source ?= linux + +# Use the linux source files unless we're building am335x +arch_source = linux +ifeq ($(ARCH),am335x) + arch_source = am335x endif -ARCH ?= am335x -arch_source ?= am335x + # Determine PROFILE if it's not provided... # testing | release | debug From 378f977efc8b0abc570796b8de47c99a2074675c Mon Sep 17 00:00:00 2001 From: Tom Fiset Date: Fri, 5 Mar 2021 00:13:05 -0500 Subject: [PATCH 10/12] Source changes to support osx --- arch/linux/hal/fileops.c | 7 ++++--- hal/pump/rfifo4.c | 4 ++-- od/extras/AlignmentAllocator.h | 5 +++-- od/extras/BufferPool.h | 4 ++-- od/extras/SystemBuffer.cpp | 4 ++-- od/glue/Interpreter.cpp | 2 +- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/arch/linux/hal/fileops.c b/arch/linux/hal/fileops.c index 6cb6df7d..35133533 100644 --- a/arch/linux/hal/fileops.c +++ b/arch/linux/hal/fileops.c @@ -1,6 +1,7 @@ #include #include -#include +#include +#include #include #include #include @@ -155,7 +156,7 @@ int diskFreeSpaceMB(const char *path) struct statfs fsinfo; if (statfs(path, &fsinfo) == 0) { - uint64_t bytes = fsinfo.f_frsize * fsinfo.f_blocks; + uint64_t bytes = fsinfo.f_bsize * fsinfo.f_blocks; return (int)(bytes / 1024 / 1024); } return 0; @@ -166,7 +167,7 @@ int diskTotalSpaceMB(const char *path) struct statfs fsinfo; if (statfs(path, &fsinfo) == 0) { - uint64_t bytes = fsinfo.f_frsize * fsinfo.f_bavail; + uint64_t bytes = fsinfo.f_bsize * fsinfo.f_bavail; return (int)(bytes / 1024 / 1024); } return 0; diff --git a/hal/pump/rfifo4.c b/hal/pump/rfifo4.c index eff7151e..44d06338 100644 --- a/hal/pump/rfifo4.c +++ b/hal/pump/rfifo4.c @@ -1,7 +1,7 @@ #include #include #include "rfifo4.h" -#include +#include void rfifo4_alloc(rfifo4_t *fifo, int length) { @@ -10,7 +10,7 @@ void rfifo4_alloc(rfifo4_t *fifo, int length) fifo->wpos = 0; fifo->numread = length; int bytes = length * 2 * sizeof(float32x4_t); - fifo->buffer = (float32x4_t *)memalign(CACHELINE_SIZE_MAX, bytes); + posix_memalign((void **)&fifo->buffer, CACHELINE_SIZE_MAX, bytes); logAssert(fifo->buffer); bzero(fifo->buffer, bytes); fifo->length = length; diff --git a/od/extras/AlignmentAllocator.h b/od/extras/AlignmentAllocator.h index c0ecdef9..6a1b86f2 100644 --- a/od/extras/AlignmentAllocator.h +++ b/od/extras/AlignmentAllocator.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include @@ -42,7 +41,9 @@ namespace od inline pointer allocate(size_type n) { - return (pointer)memalign(N, n * sizeof(value_type)); + pointer p; + posix_memalign((void **)&p, N, n * sizeof(value_type)); + return p; } inline void deallocate(pointer p, size_type) diff --git a/od/extras/BufferPool.h b/od/extras/BufferPool.h index 2bde9dad..513ed9f3 100644 --- a/od/extras/BufferPool.h +++ b/od/extras/BufferPool.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include #include @@ -27,7 +27,7 @@ namespace od { deallocate(); uint32_t poolSizeInBytes = bufferCount * bufferSize * sizeof(T); - mPool = (T *)memalign(CACHELINE_SIZE_MAX, poolSizeInBytes); + posix_memalign((void **)&mPool, CACHELINE_SIZE_MAX, poolSizeInBytes); if (mPool) { bzero(mPool, poolSizeInBytes); diff --git a/od/extras/SystemBuffer.cpp b/od/extras/SystemBuffer.cpp index c236e319..f31edb7f 100644 --- a/od/extras/SystemBuffer.cpp +++ b/od/extras/SystemBuffer.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include namespace od { @@ -17,7 +17,7 @@ namespace od bool SystemBuffer::allocate(int n) { deallocate(); - mpData = (char *)memalign(CACHELINE_SIZE_MAX, n); + posix_memalign((void **)&mpData, CACHELINE_SIZE_MAX, n); if (mpData) { mSizeInBytes = n; diff --git a/od/glue/Interpreter.cpp b/od/glue/Interpreter.cpp index 88c679b7..a2d0c22a 100644 --- a/od/glue/Interpreter.cpp +++ b/od/glue/Interpreter.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include extern "C" { From aace34193fdbae2e85efa9f53a57c7250cdfa494 Mon Sep 17 00:00:00 2001 From: Tom Fiset Date: Fri, 5 Mar 2021 23:37:41 -0500 Subject: [PATCH 11/12] Create a simple AR dsp unit --- Makefile | 3 ++ mods/example/AR.cpp | 82 +++++++++++++++++++++++++++++ mods/example/AR.h | 34 ++++++++++++ mods/example/assets/AR.lua | 97 +++++++++++++++++++++++++++++++++++ mods/example/assets/toc.lua | 13 +++++ mods/example/example.cpp.swig | 14 +++++ scripts/example.mk | 9 ++++ 7 files changed, 252 insertions(+) create mode 100644 mods/example/AR.cpp create mode 100644 mods/example/AR.h create mode 100644 mods/example/assets/AR.lua create mode 100644 mods/example/assets/toc.lua create mode 100644 mods/example/example.cpp.swig create mode 100644 scripts/example.mk diff --git a/Makefile b/Makefile index bf557017..a64b9008 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,9 @@ core: teletype: +$(MAKE) -f scripts/teletype.mk +example: + +$(MAKE) -f scripts/example.mk + core-clean: +$(MAKE) -f scripts/core.mk clean diff --git a/mods/example/AR.cpp b/mods/example/AR.cpp new file mode 100644 index 00000000..2181d64e --- /dev/null +++ b/mods/example/AR.cpp @@ -0,0 +1,82 @@ +#include +#include +#include +#include +#include + +namespace example { + + AR::AR() { + addInput(mGateInput); + addInput(mAttack); + addInput(mRelease); + addOutput(mOutput); + + mAttackStage = &od::LookupTables::ConcaveParabolicRise; + mReleaseStage = &od::LookupTables::ConcaveParabolicFall; + } + + AR::~AR() { } + + void AR::process() { + float *gate = mGateInput.buffer(); + float *attack = mAttack.buffer(); + float *release = mRelease.buffer(); + float *out = mOutput.buffer(); + + mAttackPhaseChange = globalConfig.samplePeriod / MAX(0.0001f, attack[0]); + mReleasePhaseChange = globalConfig.samplePeriod / MAX(0.0001f, release[0]); + + for (int i = 0; i < FRAMELENGTH; i++) { + out[i] = next(gate[i]); + } + } + + inline float AR::next(float currentGate) { + switch (mStage) { + case 0: + if (currentGate > 0.5f) { + mStage = 1; + mPhase = 0.0f; + mCapture = mCurrentValue; + } + break; + + case 1: + mPhase += mAttackPhaseChange; + if (mPhase < 1.0f) { + mCurrentValue = mCapture + (1.0f - mCapture) * mAttackStage->get(mPhase); + } else { + mCapture = mCurrentValue; + mPhase = 0.0f; + mStage = 2; + } + break; + + case 2: + mCurrentValue = 1.0f; + if (currentGate < 0.5f) { + mCapture = mCurrentValue; + mPhase = 0.0f; + mStage = 3; + } + break; + + case 3: + mPhase += mReleasePhaseChange; + if (mPhase < 1.0f) { + mCurrentValue = mCapture * mReleaseStage->get(mPhase); + } else { + mCapture = 0.0f; + mPhase = 0.0f; + mStage = 0; + + // Force to zero, possible discontinuity + mCurrentValue = 0.0f; + } + break; + } + + return mCurrentValue; + } +} \ No newline at end of file diff --git a/mods/example/AR.h b/mods/example/AR.h new file mode 100644 index 00000000..784860e2 --- /dev/null +++ b/mods/example/AR.h @@ -0,0 +1,34 @@ +#pragma once + +#include +#include + +namespace example { + class AR : public od::Object { + public: + AR(); + virtual ~AR(); + +#ifndef SWIGLUA + virtual void process(); + od::Inlet mGateInput{"Gate"}; + od::Inlet mAttack{"Attack"}; + od::Inlet mRelease{"Release"}; + od::Outlet mOutput{"Out"}; +#endif + + private: + float next(float sustain); + + int mStage = 0; + + float mPhase = 0.0f; + float mCapture = 0.0f; + float mAttackPhaseChange = 0.0f; + float mReleasePhaseChange = 0.0f; + float mCurrentValue = 0.0f; + + od::LookupTable *mAttackStage = NULL; + od::LookupTable *mReleaseStage = NULL; + }; +} diff --git a/mods/example/assets/AR.lua b/mods/example/assets/AR.lua new file mode 100644 index 00000000..de9a72f8 --- /dev/null +++ b/mods/example/assets/AR.lua @@ -0,0 +1,97 @@ +local app = app +local libexample = require "example.libexample" +local Class = require "Base.Class" +local Unit = require "Unit" +local GainBias = require "Unit.ViewControl.GainBias" +local InputGate = require "Unit.ViewControl.InputGate" +local Encoder = require "Encoder" + +local AR = Class {} +AR:include(Unit) + +function AR:init(args) + args.title = "AR" + args.mnemonic = "En" + Unit.init(self, args) +end + +function AR:onLoadGraph(channelCount) + if channelCount == 2 then + self:loadStereoGraph() + else + self:loadMonoGraph() + end +end + +function AR:loadMonoGraph() + local gate = self:addObject("gate", app.Comparator()) + gate:setGateMode() + local ar = self:addObject("ar", libexample.AR()) + local attack = self:addObject("attack", app.GainBias()) + local release = self:addObject("release", app.GainBias()) + local attackRange = self:addObject("attackRange", app.MinMax()) + local releaseRange = self:addObject("releaseRange", app.MinMax()) + + connect(self, "In1", gate, "In") + connect(gate, "Out", ar, "Gate") + connect(ar, "Out", self, "Out1") + + connect(attack, "Out", ar, "Attack") + connect(release, "Out", ar, "Release") + + connect(attack, "Out", attackRange, "In") + connect(release, "Out", releaseRange, "In") + + self:addMonoBranch("attack", attack, "In", attack, "Out") + self:addMonoBranch("release", release, "In", release, "Out") +end + +function AR:loadStereoGraph() + self:loadMonoGraph() + connect(self.objects.ar, "Out", self, "Out2") +end + +local views = { + expanded = { + "input", + "attack", + "release" + }, + collapsed = {} +} + +function AR:onLoadViews(objects, branches) + local controls = {} + + controls.input = InputGate { + button = "input", + description = "Unit Input", + comparator = objects.gate + } + + controls.attack = GainBias { + button = "A", + branch = branches.attack, + description = "Attack", + gainbias = objects.attack, + range = objects.attackRange, + biasMap = Encoder.getMap("ADSR"), + biasUnits = app.unitSecs, + initialBias = 0.050 + } + + controls.release = GainBias { + button = "R", + branch = branches.release, + description = "Release", + gainbias = objects.release, + range = objects.releaseRange, + biasMap = Encoder.getMap("ADSR"), + biasUnits = app.unitSecs, + initialBias = 0.100 + } + + return controls, views +end + +return AR diff --git a/mods/example/assets/toc.lua b/mods/example/assets/toc.lua new file mode 100644 index 00000000..d82624ff --- /dev/null +++ b/mods/example/assets/toc.lua @@ -0,0 +1,13 @@ +return { + title = "Example Library", + author = "tomf", + name = "example", + keyword = "", + units = { + { + title = "AR", + moduleName = "AR", + keywords = "" + } + } +} \ No newline at end of file diff --git a/mods/example/example.cpp.swig b/mods/example/example.cpp.swig new file mode 100644 index 00000000..696e95b6 --- /dev/null +++ b/mods/example/example.cpp.swig @@ -0,0 +1,14 @@ +%module example_libexample +%include + +%{ + +#undef SWIGLUA + +#include + +#define SWIGLUA + +%} + +%include diff --git a/scripts/example.mk b/scripts/example.mk new file mode 100644 index 00000000..1e9883ef --- /dev/null +++ b/scripts/example.mk @@ -0,0 +1,9 @@ +include scripts/env.mk + +MODNAME := example +src_dir = $(mods_dir)/$(MODNAME) +asset_dir = $(src_dir)/assets + +includes += . $(mods_dir) $(arch_dir) $(lua_dir) + +include scripts/mod-builder.mk From 0d263bddaad4f6a5d5332d5ff9ad4fcb23d3cfd5 Mon Sep 17 00:00:00 2001 From: Tom Fiset Date: Sat, 6 Mar 2021 00:28:35 -0500 Subject: [PATCH 12/12] Add loop toggle --- mods/example/AR.cpp | 12 +++++++++--- mods/example/AR.h | 3 ++- mods/example/assets/AR.lua | 13 +++++++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/mods/example/AR.cpp b/mods/example/AR.cpp index 2181d64e..21ef44fe 100644 --- a/mods/example/AR.cpp +++ b/mods/example/AR.cpp @@ -8,6 +8,7 @@ namespace example { AR::AR() { addInput(mGateInput); + addInput(mLoopInput); addInput(mAttack); addInput(mRelease); addOutput(mOutput); @@ -20,6 +21,7 @@ namespace example { void AR::process() { float *gate = mGateInput.buffer(); + float *loop = mLoopInput.buffer(); float *attack = mAttack.buffer(); float *release = mRelease.buffer(); float *out = mOutput.buffer(); @@ -28,14 +30,14 @@ namespace example { mReleasePhaseChange = globalConfig.samplePeriod / MAX(0.0001f, release[0]); for (int i = 0; i < FRAMELENGTH; i++) { - out[i] = next(gate[i]); + out[i] = next(gate[i], loop[i]); } } - inline float AR::next(float currentGate) { + inline float AR::next(float currentGate, float currentLoop) { switch (mStage) { case 0: - if (currentGate > 0.5f) { + if (currentGate > 0.5f || currentLoop > 0.5f) { mStage = 1; mPhase = 0.0f; mCapture = mCurrentValue; @@ -73,6 +75,10 @@ namespace example { // Force to zero, possible discontinuity mCurrentValue = 0.0f; + + if (currentLoop > 0.5f) { + mStage = 1; + } } break; } diff --git a/mods/example/AR.h b/mods/example/AR.h index 784860e2..0addb1d5 100644 --- a/mods/example/AR.h +++ b/mods/example/AR.h @@ -12,13 +12,14 @@ namespace example { #ifndef SWIGLUA virtual void process(); od::Inlet mGateInput{"Gate"}; + od::Inlet mLoopInput{"Loop"}; od::Inlet mAttack{"Attack"}; od::Inlet mRelease{"Release"}; od::Outlet mOutput{"Out"}; #endif private: - float next(float sustain); + float next(float currentGate, float currentLoop); int mStage = 0; diff --git a/mods/example/assets/AR.lua b/mods/example/assets/AR.lua index de9a72f8..17048eff 100644 --- a/mods/example/assets/AR.lua +++ b/mods/example/assets/AR.lua @@ -4,6 +4,7 @@ local Class = require "Base.Class" local Unit = require "Unit" local GainBias = require "Unit.ViewControl.GainBias" local InputGate = require "Unit.ViewControl.InputGate" +local Gate = require "Unit.ViewControl.Gate" local Encoder = require "Encoder" local AR = Class {} @@ -26,6 +27,8 @@ end function AR:loadMonoGraph() local gate = self:addObject("gate", app.Comparator()) gate:setGateMode() + local loop = self:addObject("loop", app.Comparator()) + loop:setToggleMode() local ar = self:addObject("ar", libexample.AR()) local attack = self:addObject("attack", app.GainBias()) local release = self:addObject("release", app.GainBias()) @@ -34,6 +37,7 @@ function AR:loadMonoGraph() connect(self, "In1", gate, "In") connect(gate, "Out", ar, "Gate") + connect(loop, "Out", ar, "Loop") connect(ar, "Out", self, "Out1") connect(attack, "Out", ar, "Attack") @@ -42,6 +46,7 @@ function AR:loadMonoGraph() connect(attack, "Out", attackRange, "In") connect(release, "Out", releaseRange, "In") + self:addMonoBranch("loop", loop, "In", loop, "Out") self:addMonoBranch("attack", attack, "In", attack, "Out") self:addMonoBranch("release", release, "In", release, "Out") end @@ -54,6 +59,7 @@ end local views = { expanded = { "input", + "loop", "attack", "release" }, @@ -69,6 +75,13 @@ function AR:onLoadViews(objects, branches) comparator = objects.gate } + controls.loop = Gate { + button = "loop", + description = "Loop", + branch = branches.loop, + comparator = objects.loop + } + controls.attack = GainBias { button = "A", branch = branches.attack,