Compare commits

...

3 Commits

Author SHA1 Message Date
Lephenixnoir 9828d2e3f2
meta: update build instructions 2022-08-21 11:55:28 +02:00
Lephenixnoir 65aaba96e1
install: trim the set of installed headers (and libm.a)
This is because all of these headers are included in direct style with
no subfolder so we need them to be in a quite public `include/` folder.
The Makefile installs in `include/openlibm/` but this only works with
extra `-I` flags that are quite annoying to enforce.

With this change, the only OpenLibm headers that are installed are named
`openlibm_*.h`, which is sufficient in terms of namespacing.

Also add a symlink libm.a -> libopenlibm.a.
2022-08-19 16:02:05 +02:00
Lephenixnoir feba6242e4
fenv: avoid internal includes in user-facing headers
A future cleanup will drastically reduce the set of headers being installed,
and we don't want to install internal headers in particular.
2022-08-19 16:02:05 +02:00
4 changed files with 63 additions and 37 deletions

View File

@ -93,6 +93,9 @@ install-static: libopenlibm.a
mkdir -p $(DESTDIR)$(libdir)
cp -RpP -f libopenlibm.a $(DESTDIR)$(libdir)/
install-static-superh: install-static
ln -sf libopenlibm.a $(DESTDIR)$(libdir)/libm.a
install-shared: libopenlibm.$(OLM_MAJOR_MINOR_SHLIB_EXT)
mkdir -p $(DESTDIR)$(shlibdir)
cp -RpP -f libopenlibm.*$(SHLIB_EXT)* $(DESTDIR)$(shlibdir)/
@ -106,4 +109,15 @@ install-headers:
cp -RpP -f include/*.h $(DESTDIR)$(includedir)/openlibm
cp -RpP -f src/*.h $(DESTDIR)$(includedir)/openlibm
install: install-static install-shared install-pkgconfig install-headers
install-headers-superh:
mkdir -p $(DESTDIR)$(includedir)
cp -RpP -f \
include/openlibm.h \
include/openlibm_complex.h \
include/openlibm_defs.h \
include/openlibm_fenv.h \
include/openlibm_fenv_sh3eb.h \
include/openlibm_math.h \
$(DESTDIR)$(includedir)
install: install-static install-shared install-pkgconfig

View File

@ -1,57 +1,60 @@
# Soft-FP sh3eb port of OpenLibm
This is a fork of [OpenLibm](https://github.com/JuliaMath/openlibm) with
support for the sh3eb architecture, intended for add-in programming on fx-9860G
and fx-CG 50.
This is a fork of [OpenLibm](https://github.com/JuliaMath/openlibm) with support for the sh3eb architecture, intended for add-in programming on SuperH CASIO calculators.
## Installing with GiteaPC
This library can be installed automatically with [GiteaPC](https://gitea.planet-casio.com/Lephenixnoir/GiteaPC).
This library can be installed automatically as part of the fxSDK with [GiteaPC](https://gitea.planet-casio.com/Lephenixnoir/GiteaPC):
```
```bash
% giteapc install Lephenixnoir/OpenLibm
```
## Building manually
You will need a GCC toolchain built with `--target=sh3eb-elf`, such as the
`sh-elf-gcc` commonly used on Planète Casio.
You will need a GCC toolchain built with `--target=sh3eb-elf`, such as the [`sh-elf-gcc`](https://gitea.planet-casio.com/Lephenixnoir/sh-elf-gcc) commonly used on Planète Casio.
First locate the compiler's install directory. This is normally the
`lib/gcc/sh3eb-elf/<version>/` folder inside the install path of the compiler.
You can install directly in the internal folder of your compiler, or somewhere else if you have a more detailed setup.
```
% PREFIX=$(sh-elf-gcc --print-search-dirs | grep install | sed 's/install: //')
```bash
# Example 1: Use the compiler's internal folder
% COMPILER_DIR="$(sh-elf-gcc --print-file-name=.)"
% LIBDIR="$COMPILER_DIR"
% INCDIR="$COMPILER_DIR/include"
# Example 2: Using the fxSDK's custom setup
% LIBDIR="$(fxsdk path lib)"
% INCDIR="$(fxsdk path include)"
```
You can then build and install the static `libopenlibm.a` archive and the headers.
You can then build and install the static library and the headers.
```
% make USEGCC=1 TOOLPREFIX=sh-elf- AR=sh-elf-ar CC=sh-elf-gcc libdir="$PREFIX" includedir="$PREFIX/include" install-static install-headers
```bash
% make USEGCC=1 TOOLPREFIX=sh-elf- AR=sh-elf-ar CC=sh-elf-gcc \
libdir="$LIBDIR" includedir="$INCDIR" \
install-static-superh install-headers-superh
```
## Using in a Makefile-based add-in
The `-superh` targets differ from the the normal targets in the following ways:
Link with `-lopenlibm` as you would do with `-lm`. Since OpenLibm headers
reference themselves by file name (`#include <openlibm_complex.h>`) even though
they are installed in a subfolder, you need a `-I` flag:
* `install-static-superh` also creates a symlink `libm.a -> libopenlibm.a`.
* `install-headers-superh` installs directly in `$LIBDIR` instead of `$LIBDIR/openlibm` since OpenLibm headers reference each other without that prefix and enforcing the correct `-I` in every project is quite painful. In addition, it skips internal and non-SuperH headers.
## Using the library
Include the headers `<openlibm_complex.h>`, `<openlibm_fenv.h>` and `<openlibm_math.h>`. Or, if you are using a suitable libc like [fxlibc](https://gitea.planet-casio.com/Vhex-Kernel-Core/fxlibc/), include directly the standard headers `<complex.h>`, `<fenv.h>` and `<math.h>`.
Link with `-lm`. In a Makefile, update your `LDFLAGS`:
```
CFLAGS += -I $(shell sh-elf-gcc -print-file-name=include/openlibm)
LDFLAGS += -lopenlibm
LDFLAGS += -lm
```
## Using in a CMake-based add-in
In CMake, use [`target_link_libraries()`](https://cmake.org/cmake/help/latest/command/target_link_libraries.html):
When using CMake with the fxSDK, add the include folder and library like this.
```
target_include_directories(<TARGET> PRIVATE "${FXSDK_COMPILER_INSTALL}/include/openlibm")
target_link_libraries(<TARGET> -lopenlibm)
```cmake
target_link_libraries(<TARGET> PUBLIC -lm)
```
## README and Licensing
See the original README file in [README-OpenLibm.md](README-OpenLibm.md).
OpenLibm contains code covered by various licenses, see
[LICENSE.md](LICENSE.md).
See the original README file in [README-OpenLibm.md](README-OpenLibm.md). OpenLibm contains code covered by various licenses, see [LICENSE.md](LICENSE.md).

View File

@ -1,17 +1,22 @@
# giteapc: version=1 depends=Lephenixnoir/sh-elf-gcc
# giteapc: version=1 depends=Lephenixnoir/fxsdk,Lephenixnoir/sh-elf-gcc
-include giteapc-config.make
PREFIX ?= $(shell sh-elf-gcc --print-search-dirs | grep install | sed 's/install: //')
# Use the fxSDK's default paths unless specified otherwise on the command line
LIBDIR ?= $(shell fxsdk path lib)
INCDIR ?= $(shell fxsdk path include)
FLAGS := USEGCC=1 TOOLPREFIX=sh-elf- CC=sh-elf-gcc AR=sh-elf-ar \
libdir="$(LIBDIR)" includedir="$(INCDIR)"
configure:
@ true
build:
@ make USEGCC=1 TOOLPREFIX=sh-elf- CC=sh-elf-gcc AR=sh-elf-ar libdir="$(PREFIX)" includedir="$(PREFIX)/include"
@ make $(FLAGS)
install:
@ make USEGCC=1 TOOLPREFIX=sh-elf- CC=sh-elf-gcc AR=sh-elf-ar libdir="$(PREFIX)" includedir="$(PREFIX)/include" install-static install-headers
@ make $(FLAGS) install-static-superh install-headers-superh
uninstall:
@ echo "uninstall not supported for OpenLibm, skipping"

View File

@ -30,7 +30,6 @@
#define _FENV_H_
#include <stdint.h>
#include "cdefs-compat.h"
#ifndef __fenv_static
#define __fenv_static static
@ -57,7 +56,10 @@ typedef uint32_t fexcept_t;
#define FE_DOWNWARD 0x0003
#define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \
FE_UPWARD | FE_TOWARDZERO)
__BEGIN_DECLS
#ifdef __cplusplus
extern "C" {
#endif
/* Default floating-point environment */
extern const fenv_t __fe_dfl_env;
@ -89,6 +91,8 @@ int fegetexcept(void);
#endif /* __BSD_VISIBLE */
__END_DECLS
#ifdef __cplusplus
}
#endif
#endif /* !_FENV_H_ */