fxsdk: command-line interface for fxSDK 2.3

* Add the CMake build system
* Use CMake as the default for new projects
* Change [fxsdk new] but continue supporting the previous signature
* Automatically configure in [fxsdk build-fx] and [fxsdk build-cg]
* Improve help screen
This commit is contained in:
Lephenixnoir 2021-01-14 10:43:33 +01:00
parent d5759423db
commit e2ba617405
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495
7 changed files with 149 additions and 57 deletions

View file

@ -93,7 +93,7 @@ install-fxsdk: all-fxsdk
install -d $(PREFIX)/bin install -d $(PREFIX)/bin
install bin/fxsdk.sh $(PREFIX)/bin/fxsdk install bin/fxsdk.sh $(PREFIX)/bin/fxsdk
install -d $(PREFIX)/share/fxsdk/assets install -d $(PREFIX)/share/fxsdk/assets
install fxsdk/assets/* $(m644) $(PREFIX)/share/fxsdk/assets cp -ra fxsdk/assets $(PREFIX)/share/fxsdk/
install bin/fxsdk.sh $(m755) $(PREFIX)/bin/fxsdk install bin/fxsdk.sh $(m755) $(PREFIX)/bin/fxsdk
install -d $(PREFIX)/lib/cmake/fxsdk install -d $(PREFIX)/lib/cmake/fxsdk
install fxsdk/cmake/* $(m644) $(PREFIX)/lib/cmake/fxsdk install fxsdk/cmake/* $(m644) $(PREFIX)/lib/cmake/fxsdk

View file

@ -0,0 +1,48 @@
# Configure with [fxsdk build-fx] or [fxsdk build-cg], which provide the
# toolchain file and module path of the fxSDK
cmake_minimum_required(VERSION 3.18)
project(MyAddin)
include(GenerateG1A)
include(GenerateG3A)
include(Fxconv)
find_package(Gint 2.1 REQUIRED)
set(SOURCES
src/main.c
# ...
)
# Shared assets, fx-9860G-only assets and fx-CG-50-only assets
set(ASSETS
# ...
)
set(ASSETS_fx
assets-fx/example.png
# ...
)
set(ASSETS_cg
assets-cg/example.png
# ...
)
set_source_files_properties(${ASSETS} PROPERTIES
OBJECT_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/assets/fxconv-metadata.txt")
set_source_files_properties(${ASSETS_fx} PROPERTIES
OBJECT_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/assets-fx/fxconv-metadata.txt")
set_source_files_properties(${ASSETS_cg} PROPERTIES
OBJECT_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/assets-cg/fxconv-metadata.txt")
set_source_files_properties(${ASSETS} ${ASSETS_fx} ${ASSETS_cg}
PROPERTIES LANGUAGE FXCONV)
add_executable(myaddin ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}})
target_link_libraries(myaddin Gint::Gint)
if("${FXSDK_PLATFORM_LONG}" STREQUAL fx9860G)
generate_g1a(TARGET myaddin OUTPUT "MyAddin.g1a"
NAME "MyAddin" ICON assets-fx/icon.png)
elseif("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50)
generate_g3a(TARGET myaddin OUTPUT "MyAddin.g3a"
NAME "MyAddin" ICONS assets-cg/icon-uns.png assets-cg/icon-sel.png)
endif()

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

View file

@ -0,0 +1,3 @@
example.png:
type: bopti-image
name: img_example

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

View file

@ -0,0 +1,3 @@
example.png:
type: bopti-image
name: img_example

View file

@ -5,44 +5,39 @@ set -e
# Note: this line is edited at compile time to insert the install folder # Note: this line is edited at compile time to insert the install folder
PREFIX=\ PREFIX=\
R=$(printf "\e[31;1m")
g=$(printf "\e[32m\e[3m")
n=$(printf "\e[0m")
usage_string=$(cat << EOF usage_string=$(cat << EOF
usage: fxsdk new <folder> usage: ${R}fxsdk${n} (${R}new${n}|${R}build${n}|${R}build-fx${n}|${R}build-\
fxsdk (build|build-fx|build-cg) [-s] cg${n}|${R}send${n}|${R}send-fx${n}|${R}send-cg${n}) [${g}ARGUMENTS${n}...]
fxsdk (send|send-fx|send-cg)
This program is a command-line helper for the fxSDK, a set of tools used in This program is a command-line helper for the fxSDK, a set of tools used in
conjunction with gint to develop add-ins for CASIO fx-9860G and fx-CG 50. conjunction with gint to develop add-ins for CASIO fx-9860G and fx-CG 50.
Project creation: ${R}fxsdk new${n} ${g}<FOLDER>${n} [${R}--makefile${n}|${R}--cmake${n}] \
fxsdk new <folder> [${g}<NAME>${n}]
Create a new project in the specified folder. The default build system is
CMake. Project name can be specified now or in the project files later.
Creates a new project in the specified folder. Project info is input ${R}fxsdk build${n} [${g}-s${n}]
interactively. Creates <folder name> and populates it with default project ${R}fxsdk build-fx${n} [${g}-s${n}]
data. ${R}fxsdk build-cg${n} [${g}-s${n}]
Build the current project for fx-9860G (.g1a target) or fx-CG 50 (.g3a
Compilation:
fxsdk build [-s]
fxsdk build-fx [-s]
fxsdk build-cg [-s]
Compiles the current project for fx-9860G (.g1a target) or fx-CG 50 (.g3a
target). With 'fxsdk build', compiles every existing build folder, and ask target). With 'fxsdk build', compiles every existing build folder, and ask
interactively if none is found. interactively if none is found.
With '-s', also sends the resulting program to the calculator. With '-s', also sends the resulting program to the calculator.
Installation: ${R}fxsdk send${n}
fxsdk send ${R}fxsdk send-fx${n}
fxsdk send-fx ${R}fxsdk send-cg${n}
fxsdk send-cg
Sends the target file to the calculator. Uses p7 (which must be installed 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 externally) for fx-9860G. Currently not implemented for fx-CG 50, as it
requires detecting and mounting the calculator (same for the Graph 35+E II). requires detecting and mounting the calculator (same for the Graph 35+E II).
Project update: ${R}fxsdk update${n}
fxsdk update
Copies the latest version of the Makefile to your project. *This will Copies the latest version of the Makefile to your project. *This will
discard any changes made to your Makefile.* If you have edited your discard any changes made to your Makefile.* If you have edited your
Makefile, make a backup and merge the changes after updating. Makefile, make a backup and merge the changes after updating.
@ -55,9 +50,8 @@ usage() {
} }
error() { error() {
echo -n "error: " >&2 echo "error:" "$@" >&2
echo "$@" >&2 exit 1
echo "Try 'fxsdk --help' for more information." >&2
} }
status() { status() {
@ -66,34 +60,62 @@ status() {
echo -e "\e[0m\n" echo -e "\e[0m\n"
} }
fxsdk_new_project_interactive() { fxsdk_new_project() {
[[ -z "$1" ]] && error "please specify the project folder" && return 1 # Generator to use, output folder and project name
[[ -e "$1" ]] && error "'$1' exists, I don't dare touch it" && return 1 generator="CMake"
folder=""
name=""
echo -e "Creating a new project in folder '$1'.\n" # Parse options, then skip to positional arguments
TEMP=$(getopt -o "" -l "makefile,cmake" -n "$0" -- "$@")
eval set -- "$TEMP"
for arg; do case "$arg" in
"--makefile") generator="Makefile";;
"--cmake") generator="CMake";;
*) break;;
esac; done
while [[ "$1" != "--" ]]; do shift; done; shift
echo -ne "Full project name ? (at most 8 characters)\n> " if [[ -z "$1" ]]; then
read NAME usage 1
fi
if [[ -e "$1" && "$1" != "." ]]; then
error "$1 exists, I don't dare touch it"
fi
echo "Internal name ? ('@' followed by at most 7 uppercase letters)" # Determine name and internal name
echo -ne "(Add-in might not appear on calc if format is wrong)\n> " if [[ ! -z "$2" ]]; then
read INTERNAL NAME=${2::8}
upper=${2^^}
else
cap=${1^}
NAME=${cap::8}
upper=${1^^}
fi
INTERNAL=@${upper::7}
# Copy initial files to project folder
assets="$PREFIX/share/fxsdk/assets"
mkdir -p "$1"/{,src,assets-fx,assets-cg} mkdir -p "$1"/{,src,assets-fx,assets-cg}
assets="$PREFIX/share/fxsdk/assets" case "$generator" in
"Makefile")
sed -e "s/@NAME@/$NAME/g" -e "s/@INTERNAL@/$INTERNAL/g" \
"$assets/project.cfg" > "$1/project.cfg"
cp "$assets/Makefile" "$1";;
"CMake")
cp "$assets/CMakeLists.txt" "$1";;
esac
sed -e "s/@NAME@/$NAME/g" -e "s/@INTERNAL@/$INTERNAL/g" \
"$assets/project.cfg" > "$1/project.cfg"
cp "$assets"/Makefile "$1"
cp "$assets"/gitignore "$1"/.gitignore cp "$assets"/gitignore "$1"/.gitignore
cp "$assets"/main.c "$1"/src cp "$assets"/main.c "$1"/src
cp "$assets"/icon-fx.png "$1"/assets-fx cp "$assets"/icon-fx.png "$1"/assets-fx/icon.png
cp "$assets"/icon-cg-uns.png "$1"/assets-cg cp "$assets"/icon-cg-uns.png "$1"/assets-cg/icon-uns.png
cp "$assets"/icon-cg-sel.png "$1"/assets-cg cp "$assets"/icon-cg-sel.png "$1"/assets-cg/icon-sel.png
cp -r "$assets"/assets-fx "$1"/
cp -r "$assets"/assets-cg "$1"/
echo -e "\nYour project '$NAME' has been created.\n" echo "Created a new project $NAME (build system: $generator)."
echo "Type 'fxsdk build-fx' or 'fxsdk build-cg' to compile the program." echo "Type 'fxsdk build-fx' or 'fxsdk build-cg' to compile the program."
} }
@ -135,14 +157,12 @@ fxsdk_build() {
[[ -z $platform ]] && return [[ -z $platform ]] && return
if [[ $platform == "fx" ]]; then if [[ $platform == "fx" ]]; then
status "Making into build-fx" fxsdk_build_fx
make all-fx
return return
fi fi
if [[ $platform == "cg" ]]; then if [[ $platform == "cg" ]]; then
status "Making into build-fx" fxsdk_build_ch
make all-cg
return return
fi fi
@ -151,13 +171,33 @@ fxsdk_build() {
} }
fxsdk_build_fx() { fxsdk_build_fx() {
status "Making into build-fx" # CMake version; automatically configure
make all-fx if [[ -e "CMakeLists.txt" ]]; then
if [[ ! -e "build-fx" ]]; then
cmake -B build-fx \
-DCMAKE_MODULE_PATH="$PREFIX/lib/cmake/fxsdk" \
-DCMAKE_TOOLCHAIN_FILE="$PREFIX/lib/cmake/fxsdk/FX9860G.cmake"
fi
make --no-print-directory -C build-fx
# Makefile version
else
make all-fx
fi
} }
fxsdk_build_cg() { fxsdk_build_cg() {
status "Making into build-cg" # CMake version; automatically configure
make all-cg if [[ -e "CMakeLists.txt" ]]; then
if [[ ! -e "build-cg" ]]; then
cmake -B build-cg \
-DCMAKE_MODULE_PATH="$PREFIX/lib/cmake/fxsdk" \
-DCMAKE_TOOLCHAIN_FILE="$PREFIX/lib/cmake/fxsdk/FXCG50.cmake"
fi
make --no-print-directory -C build-cg
# Makefile version
else
make all-cg
fi
} }
fxsdk_send() { fxsdk_send() {
@ -196,12 +236,10 @@ fxsdk_update() {
# Parse command name # Parse command name
case $1 in case "$1" in
# Project creation # Project creation
"new") "new")
shift fxsdk_new_project "${@:2}";;
fxsdk_new_project_interactive "$@";;
# Project compilation # Project compilation
"build"|"b") "build"|"b")