fxsdk: new build system

This commit is contained in:
Lephenixnoir 2019-09-12 14:34:26 +02:00
parent d74785d34d
commit 46b19bab62
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495
2 changed files with 164 additions and 64 deletions

View file

@ -10,42 +10,63 @@
include project.cfg
# Compiler flags
cf := -mb -ffreestanding -nostdlib -Wall -Wextra \
-fstrict-volatile-bitfields $(CFLAGS)
cf-fx := $(cf) -m3 -DFX9860G
cf-cg := $(cf) -m4-nofpu -DFXCG50
CFLAGSFX := $(CFLAGS) $(CFLAGS_FX) $(INCLUDE)
CFLAGSCG := $(CFLAGS) $(CFLAGS_CG) $(INCLUDE)
# Linker flags
lf-fx := -Tfx9860g.ld -lgint-fx $(LDFLAGS) -lgcc -Wl,-Map=build-fx/map
lf-cg := -Tfxcg50.ld -lgint-cg $(LDFLAGS) -lgcc -Wl,-Map=build-cg/map
LDFLAGSFX := $(LDFLAGS) $(LDFLAGS_FX)
LDFLAGSCG := $(LDFLAGS) $(LDFLAGS_CG)
dflags = -MMD -MT $@ -MF $(@:.o=.d) -MP
cpflags := -R .bss -R .gint_bss
# Dependency list generation flags
depflags = -MMD -MT $@ -MF $(@:.o=.d) -MP
# ELF to binary flags
BINFLAGS := -R .bss -R .gint_bss
g1af := -i "$(ICON_FX)" -n "$(NAME)" --internal="$(INTERNAL)"
g3af := -n basic:"$(NAME)" -i uns:"$(ICON_CG_UNS)" -i sel:"$(ICON_CG_SEL)"
# G1A and G3A generation flags
NAME_G1A ?= $(NAME)
NAME_G3A ?= $(NAME)
G1AF := -i "$(ICON_FX)" -n "$(NAME_G1A)" --internal="$(INTERNAL)"
G3AF := -n basic:"$(NAME_G3A)" -i uns:"$(ICON_CG_UNS)" -i sel:"$(ICON_CG_SEL)"
ifeq "$(TOOLCHAIN_FX)" ""
TOOLCHAIN_FX := sh3eb-elf
endif
ifeq "$(TOOLCHAIN_CG)" ""
TOOLCHAIN_CG := sh4eb-elf
endif
# fxconv flags
FXCONVFX := --fx --toolchain=$(TOOLCHAIN_FX)
FXCONVCG := --cg --toolchain=$(TOOLCHAIN_CG)
#
# File listings
#
null :=
filename := $(subst $(null) $(null),-,$(NAME))
ifeq "$(TARGET)" ""
NULL :=
TARGET := $(subst $(NULL) $(NULL),-,$(NAME))
endif
elf = $(dir $<)$(filename).elf
bin = $(dir $<)$(filename).bin
target-fx := $(filename).g1a
target-cg := $(filename).g3a
elf = $(dir $<)$(TARGET).elf
bin = $(dir $<)$(TARGET).bin
TARGETFX := $(TARGET).g1a
TARGETCG := $(TARGET).g3a
# Source files
src := $(wildcard src/*.[csS] src/*/*.[csS] src/*/*/*.[csS] \
src := $(wildcard src/*.[csS] \
src/*/*.[csS] \
src/*/*/*.[csS] \
src/*/*/*/*.[csS])
assets-fx := $(wildcard assets-fx/*/*)
assets-cg := $(wildcard assets-cg/*/*)
# Object files
obj-fx := $(src:%.c=build-fx/%.o) $(assets-fx:assets-fx/%=build-fx/assets/%.o)
obj-cg := $(src:%.c=build-cg/%.o) $(assets-cg:assets-cg/%=build-cg/assets/%.o)
obj-fx := $(src:%=build-fx/%.o) \
$(assets-fx:assets-fx/%=build-fx/assets/%.o)
obj-cg := $(src:%=build-cg/%.o) \
$(assets-cg:assets-cg/%=build-cg/assets/%.o)
# Additional dependencies
deps-fx := $(ICON_FX)
@ -66,60 +87,66 @@ endif
all: $(all)
all-fx: $(target-fx)
all-cg: $(target-cg)
all-fx: $(TARGETFX)
all-cg: $(TARGETCG)
$(target-fx): $(obj-fx) $(deps-fx)
$(TARGETFX): $(obj-fx) $(deps-fx)
$(TOOLCHAIN_FX)-gcc -o $(elf) $(obj-fx) $(CFLAGSFX) $(LDFLAGSFX)
$(TOOLCHAIN_FX)-objcopy -O binary $(BINFLAGS) $(elf) $(bin)
fxg1a $(bin) -o $@ $(G1AF)
sh3eb-elf-gcc -o $(elf) $(obj-fx) $(cf-fx) $(lf-fx)
sh3eb-elf-objcopy -O binary $(cpflags) $(elf) $(bin)
fxg1a $(bin) -o $@ $(g1af)
$(target-cg): $(obj-cg) $(deps-cg)
sh4eb-elf-gcc -o $(elf) $(obj-cg) $(cf-cg) $(lf-cg)
sh4eb-elf-objcopy -O binary $(cpflags) $(elf) $(bin)
mkg3a $(g3af) $(bin) $@
$(TARGETCG): $(obj-cg) $(deps-cg)
$(TOOLCHAIN_CG)-gcc -o $(elf) $(obj-cg) $(CFLAGSCG) $(LDFLAGSCG)
$(TOOLCHAIN_CG)-objcopy -O binary $(COPY) $(elf) $(bin)
mkg3a $(G3AF) $(bin) $@
# C sources
build-fx/%.o: %.c
build-fx/%.c.o: %.c
@ mkdir -p $(dir $@)
sh3eb-elf-gcc -c $< -o $@ $(cf-fx) $(dflags)
build-cg/%.o: %.c
$(TOOLCHAIN_FX)-gcc -c $< -o $@ $(CFLAGSFX) $(depflags)
build-cg/%.c.o: %.c
@ mkdir -p $(dir $@)
sh4eb-elf-gcc -c $< -o $@ $(cf-cg) $(dflags)
$(TOOLCHAIN_CG)-gcc -c $< -o $@ $(CFLAGSCG) $(depflags)
# Assembler sources
build-fx/%.o: %.s
build-fx/%.s.o: %.s
@ mkdir -p $(dir $@)
sh3eb-elf-gcc -c $< -o $@
build-fx/%.o: %.S
$(TOOLCHAIN_FX)-gcc -c $< -o $@
build-cg/%.s.o: %.s
@ mkdir -p $(dir $@)
sh3eb-elf-gcc -c $< -o $@ $(sflags)
build-cg/%.o: %.s
$(TOOLCHAIN_CG)-gcc -c $< -o $@
# Preprocessed assembler sources
build-fx/%.S.o: %.S
@ mkdir -p $(dir $@)
sh4eb-elf-gcc -c $< -o $@
build-cg/%.o: %.S
$(TOOLCHAIN_FX)-gcc -c $< -o $@ $(INCLUDE)
build-cg/%.S.o: %.S
@ mkdir -p $(dir $@)
sh4eb-elf-gcc -c $< -o $@ $(sflags)
$(TOOLCHAIN_CG)-gcc -c $< -o $@ $(INCLUDE)
# Images
build-fx/assets/img/%.o: assets-fx/img/%
@ mkdir -p $(dir $@)
fxconv -i $< -o $@ --fx name:img_$(basename $*)
fxconv -i $< -o $@ $(FXCONVFX) name:img_$(basename $*) $(IMG.$*)
build-cg/assets/img/%.o: assets-cg/img/%
@ mkdir -p $(dir $@)
fxconv -i $< -o $@ --cg name:img_$(basename $*)
fxconv -i $< -o $@ $(FXCONVCG) name:img_$(basename $*) $(IMG.$*)
# Fonts
build-fx/assets/fonts/%.o: assets-fx/fonts/%
@ mkdir -p $(dir $@)
fxconv -f $< -o $@ name:font_$(basename $*) $(FONT.$*)
fxconv -f $< -o $@ $(FXCONVFX) name:font_$(basename $*) $(FONT.$*)
build-cg/assets/fonts/%.o: assets-cg/fonts/%
@ mkdir -p $(dir $@)
fxconv -f $< -o $@ name:font_$(basename $*) $(FONT.$*)
fxconv -f $< -o $@ $(FXCONVCG) name:font_$(basename $*) $(FONT.$*)
# Binaries
build-fx/assets/bin/%.o: assets-fx/bin/%
@ mkdir -p $(dir $@)
fxconv -b $< -o $@ $(FXCONVFX) name:bin_$(basename $*) $(BIN.$*)
build-cg/assets/bin/%.o: assets-cg/bin/%
@ mkdir -p $(dir $@)
fxconv -b $< -o $@ $(FXCONVCG) name:bin_$(basename $*) $(BIN.$*)
#
# Cleaning and utilities
@ -131,14 +158,23 @@ build-fx/%.d: ;
build-cg/%.d: ;
.PRECIOUS: build-fx build-cg build-fx/%.d build-cg/%.d %/
clean:
@ rm -rf build*
distclean: clean
@ rm -f $(target-fx) $(target-cg)
clean-fx:
@ rm -rf build-fx/
clean-cg:
@ rm -rf build-cg/
install-fx: $(target-fx)
distclean-fx: clean-fx
@ rm -f $(TARGETFX)
distclean-cg: clean-cg
@ rm -f $(TARGETCG)
clean: clean-fx clean-cg
distclean: distclean-fx distclean-cg
install-fx: $(TARGETFX)
p7 send -f $<
install-cg: $(target-cg)
install-cg: $(TARGETCG)
@ while [[ ! -h /dev/Prizm1 ]]; do sleep 0.25; done
@ while ! mount /dev/Prizm1; do sleep 0.25; done
@ rm -f /mnt/prizm/$<

View file

@ -38,7 +38,7 @@ Installation:
Sends the target file to the calculator. Uses p7 (which must be installed
externally) for fx-9860G. Currently not implemented for fx-CG 50, as it
requires detecting and mounting the calculator (same of the Graph 35+E II).
requires detecting and mounting the calculator (same for the Graph 35+E II).
Project update:
fxsdk update
@ -103,7 +103,8 @@ fxsdk_new_project_interactive() {
echo -ne "Full project name ? (at most 8 characters)\n> "
read NAME
echo -ne "Internal name ? ('@' followed by at most 7 uppercase letters)\n> "
echo "Internal name ? ('@' followed by at most 7 uppercase letters)"
echo -ne "(Add-in might not appear on calc if format is wrong)\n> "
read INTERNAL
mkdir -p "$1"/{,src,assets-fx,assets-cg}
@ -133,9 +134,17 @@ fxsdk_create_config() {
#---
# Project name, should be at most 8 bytes long.
NAME = $NAME
# (You can also specify NAME_G1A or NAME_G3A to override individually.)
NAME := $NAME
# Internal name, should be '@' followed by at most 7 uppercase letters.
INTERNAL = $INTERNAL
# WARNING: If this convention is not followed, the add-in might not appear in
# the main menu of the calculator!
INTERNAL := $INTERNAL
# Output file name, your add-in will be named <TARGET>.g1a (or g3a).
# The default is to take <NAME> and replace spaces with dashes.
TARGET :=
# fx-9860G icon location
ICON_FX = assets-fx/icon-fx.png
@ -143,11 +152,66 @@ ICON_FX = assets-fx/icon-fx.png
ICON_CG_UNS = assets-cg/icon-cg-uns.png
ICON_CG_SEL = assets-cg/icon-cg-sel.png
# Additional compiler flags
CFLAGS = -std=c11 -Os
# Additional linker flags. This is followed by -lgcc. When using fxlib, add
# libfx.a to the projet directory and set LDFLAGS to "-L . -lfx".
LDFLAGS =
#---
# Toolchain selection
#---
# Toolchain for fx9860g. Please see also CFLAGS_FX below.
TOOLCHAIN_FX := sh3eb-elf
# Toolchain for fxcg50. Please see also CFLAGS_CG below.
TOOLCHAIN_CG := sh4eb-elf
#---
# Compiler flags
#---
# Base compiler flags for the fxSDK, you usually want to keep these.
CFLAGS := -mb -ffreestanding -nostdlib -fstrict-volatile-bitfields
# Platform-specific compiler flags.
# <> If you are using sh3eb-elf, use -m3. (You can do this on both FX and CG.)
# <> If you are using sh4eb-elf, use -m4-nofpu. (Not ideal on FX but works.)
# <> If you are using sh4eb-nofpu-elf, then your compiler will likely use the
# FPU and cause problems on the calculator. Consider another configuration.
# <> If you are using an sh-elf with several targets, specify whichever you
# support. I recommend -m3 on FX and -m4-nofpu on CG.
# Please see also TOOLCHAIN_FX and TOOLCHAIN_CG above.
CFLAGS_FX := -D FX9860G -m3
CFLAGS_CG := -D FXCG50 -m4-nofpu
# Additional compiler flags, change to your own taste!
CFLAGS += -Wall -Wextra -Os
# Include paths. Add one -I option for each folder from which you want to
# be able to include files with #include<>.
INCLUDE := -I include
# Libraries. Add one -l option for each library you are using, and also
# suitable -L options if you have library files in custom folders. To use
# fxlib, add libfx.a to the project directory and use "-L . -lfx".
LIBS :=
# Base linker flags for the fxSDK, you usually want to keep these.
LDFLAGS_FX := -T fx9860g.ld -lgint-fx \$(LIBS) -lgint-fx -lgcc
LDFLAGS_CG := -T fxcg50.ld -lgint-cg \$(LIBS) -lgint-cg -lgcc
# Additional linker flags, if you need any.
LDFLAGS :=
# Additional platform-specific linker flags.
LDFLAGS_FX += -Wl,-Map=build-fx/map
LDFLAGS_CG += -Wl,-Map=build-cg/map
#---
# File conversion parameters
#---
# Here you can add fxconv options for each converted file, individually.
# The syntax is "<type>.<file>". For example, to specify the parameters for a
# font name "hexa.png", you might write:
#
# FONT.hexa.png = charset:print grid:size:3x5 grid.padding:1
EOF
}