From 8993049f4ed0e4b30b4ca93aed66857251ffe810 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Sun, 9 May 2021 17:32:28 +0200 Subject: [PATCH] update README and CMake install rules --- .gitignore | 3 +- CMakeLists.txt | 12 +++-- README.md | 121 +++++++++++++++++++++++++------------------------ 3 files changed, 72 insertions(+), 64 deletions(-) diff --git a/.gitignore b/.gitignore index 7a8654b..39008ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /build*/ +/script +/prefix *.txt !CMakeLists.txt -script diff --git a/CMakeLists.txt b/CMakeLists.txt index f8da321..b38b16a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.16) -project(FxLibC VERSION 1.0.0 LANGUAGES C ASM) +project(FxLibc VERSION 1.0.0 LANGUAGES C ASM) # Options @@ -123,8 +123,14 @@ endif() add_library(fxlibc ${SOURCES}) target_include_directories(fxlibc PRIVATE include/) +set_target_properties(fxlibc PROPERTIES + OUTPUT_NAME "c") # libc.a + # Install -# TODO: Install in compiler vs. in another folder - install(TARGETS fxlibc DESTINATION lib/) +install(DIRECTORY include/ DESTINATION include/ PATTERN "target" EXCLUDE) + +foreach(FOLDER IN LISTS TARGET_FOLDERS) + install(DIRECTORY include/target/${FOLDER}/ DESTINATION include/) +endforeach() diff --git a/README.md b/README.md index cf1a97c..a1d597f 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # The FX C Library -This directory contains the sources of the FxLibc Library. -See the `make version` command to see for what release version you have. +This directory contains the sources of the FxLibc Library. See `CMakeLists.txt` +to see what release version you have. -The Fx C Library is the standard system C library implementation for all Casio -Fx calculator, and is an important part of what makes up programs on these +The FxLibc is the standard system C library implementation for all Casio +fx calculators, and is an important part of what makes up programs on these devices. It provides the system API for all programs written in C and C-compatible languages such as C++ and Objective-C; the runtime facilities of other programming languages use the C library to access the underlying operating @@ -13,59 +13,65 @@ system. --- ## Dependencies -Fx C library depends on a suitable GCC toolchain in the PATH. You can absolutely -not build `fxlibc` with your system compiler! +FxLibc requires a GCC compiler toolchain the PATH to build for any calculator. +You cannot build with your system compiler! The tutorial on Planète Casio +builds an `sh-elf` toolchain that supports all models using multilib. -* The tutorial on Planète Casio builds an sh-elf that works everywhere. -* For fx-9860G II, `sh3eb-elf` is strongly advised. -* For fx-CG 50, `sh4eb-elf` (with `-m4-nofpu`) is slightly better but `sh3eb-elf` -is completely fine. +For Vhex and gint targets, the headers of the kernel are also required. --- -## Building and installating FxLibc -You can choose to build `fxlibc` standalone or with the support of the fx-9860G -II (monochrome calculators, aka Graph 85 family) Casio ABI, fx-CG 50 (color -calculators, aka Prizm or Graph 90 family), Vhex kernel ABI or all of them (this -will generate 3 distinct libraries). +## Building and installing FxLibc +FxLibc supports several targets: +* Vhex on SH targets (`vhex-sh`) +* CASIOWIN for fx-9860G-like calculators (`casiowin-fx`) +* CASIOWIN for fx-CG-series calculators (`casiowin-cg`) +* gint for all targets (`gint`) -Each ABI support add many functionalities provided by the operating system, like -I/O abstraction (open, close, fcntl, stat, ...). (see "supported features" on -the wiki) +Each target supports different features depending on what the kernel/OS +provides. #### Configuration and support -The Fx C library supports these ABI: -* `fx9860g` for the support of Casio ABI used by fx9860g-like devices. -* `fxcg50` for the support of Casio ABI used by the fxcg50 device. -* `vhex` for the support of Vhex kernel ABI. -* (nothing) compile only standing functions. -The Fx C library support these format: -* `static` generate static libraries. -* `dynamic` generate dynamic libraries (Only for the Vhex kernel). +Configure with CMake; specify the target with `-DFXLIBC_TARGET`. For SH +platforms, set the toolchain to `cmake/toolchain-sh.cmake`. -Note that the shared feature is not currently implemented because of -non-support of the shared library generation by the GCC compiler for SuperH -architecture. A workaround can be used but it requires a static library to do -the dynamic symbols resolving (Thanks Kristaba). +The FxLibc supports shared libraries when building with Vhex (TODO); set +`-DSHARED=1` to enable this behavior. -For more information about library build configuration, you can use the -`./configure --help` command. +You can either install FxLibc in the compiler's `include` folder, or installl +in another location of your choice. In the second case, you will need a `-I` +option when using the library. + +To use the compiler, set `PREFIX` like this: + +``` +% PREFIX=$(sh-elf-gcc -print-file-name=.) +``` + +To use another location, set `PREFIX` manually (recommended): + +``` +% PREFIX="$HOME/.sh-prefix/" +``` + +Example for a static Vhex build: + +``` +% cmake -B build-vhex-sh -DFXLIBC_TARGET=vhex-sh -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-sh.cmake -DCMAKE_INSTALL_PREFIX="$PREFIX" +``` #### Building -Create a build directory and configure in it: -``` -% mkdir build && cd build -% ../configure --static --support=vhex,fx9860g,fxcg50 -``` - -Then build the source and install the library files to the selected directory. -You might need root access if you selected a target directory owned by root with -`--prefix`, or if you built your compiler as root. +Build in the directory specified in `cmake -B`. ``` -% make -% make install +% make -C build +``` + +To install, run the `install` target. + +``` +% make -C build install ``` --- @@ -77,28 +83,23 @@ welcome. If you are interested in doing a port, or want to contribute to this project, please, try to respect these constraints: * Document your code. -* One function per files. -* Each file name content only the name of the function. -* Respect the Linux Coding style as much as possible (if you are not familiar - with this norm, you can use `indent -linux` utility to help to format). -* Header must respect the `/usr/include` architecture. -* Avoid modules hardware-specific code which can generate interruptions - (DMA, SPU, ...) except if you are absolutely sure that the operating - system can handle them. +* One function per file (named like the function). +* Use the same formatting conventions as the rest of the code. +* Only use hardware-related code (DMA, SPU, etc) in target-specified files + when the target explicitly supports it. --- -### Using Fx C Library +### Using FxLibc -To use Fx C library as your runtime environment, the bare minimum is: +Include headers normally (`#include `); on SH platforms where +`sh-elf-gcc` is used, link with `-lc` (by default the `-nostdlib` flag is +used for a number of reasons). -* You must add `fxlibc/` instead of each include file (for example, if you want - to include `stdio.h` you mush use `#include `. -* Link with: - * `-lfxlibc-fx9860g` for Casio ABI support for monochrome devices - * `-lfxlibc-fxcg50` for Casio ABI support for primz devices - * `-lfxlibc-vhex` for Vhex kernel support. - * `-lfxlibc` for standalone features +If you're installing in a custom folder, you also need `-I "$PREFIX/include"` +and `-L "$PREFIX/lib"`. If you're installing in the GCC install folder, you +don't need `-I` but you still need the `-L` as the default location for +libraries is at the root instead of in a `lib` subfolder. ---