Compare commits

..

14 commits

Author SHA1 Message Date
Lephenixnoir
6df36ce8d3
cmake: install in the fxSDK sysroot 2022-08-19 16:38:35 +02:00
Lephenixnoir
5b669e5529
harden macros 2022-08-16 09:07:12 +02:00
Lephenixnoir
6d82009532
add C++ header guards 2022-02-27 16:27:45 +00:00
Lephenixnoir
b6657c0834
add non-recursive, faster versions of enter/leave 2021-09-27 22:01:04 +02:00
Lephenixnoir
ac348bce34
cmake: lower minimum required version to 3.15 2021-05-10 15:27:47 +02:00
Lephenixnoir
c0d5b053d9
udpate to gint 2.4.0 2021-04-27 16:25:48 +02:00
Lephenixnoir
fd90842b82
cmake: force linking before gint 2021-02-04 21:55:04 +01:00
Lephenixnoir
08ee98cef1
cmake: only require version 3.16 2021-02-01 22:28:11 +01:00
Lephenixnoir
a9f1dc3ec8
build: fix uninstall command for sh-based OSes 2021-01-29 19:05:11 +01:00
Lephenixnoir
8c34abe3ca
update README 2021-01-28 22:53:20 +01:00
Lephenixnoir
6b5685a35e
add version and a find_package() module 2021-01-28 22:23:33 +01:00
Lephenixnoir
91bb658d6c
update README 2021-01-27 15:20:55 +01:00
Lephenixnoir
02774004a2
switch build system to CMake 2021-01-27 15:04:26 +01:00
Lephenixnoir
05e6463139
add support for quick build with GiteaPC 2021-01-25 15:58:52 +01:00
8 changed files with 129 additions and 73 deletions

7
.gitignore vendored
View file

@ -1,3 +1,6 @@
# Build files # Build files
build/ build*/
libprof.a
# GiteaPC configuration files
giteapc-config-*.make
giteapc-config.make

21
CMakeLists.txt Normal file
View file

@ -0,0 +1,21 @@
# Build system for the libprof library for gint
cmake_minimum_required(VERSION 3.15)
project(libprof VERSION 2.4.0 LANGUAGES C)
find_package(Gint 2.4.0 REQUIRED)
configure_file(libprof.h libprof.h)
set(NAME "prof-${FXSDK_PLATFORM}")
add_library(${NAME} STATIC libprof.c)
target_compile_options(${NAME} PUBLIC -Wall -Wextra -std=c11 -Os)
target_include_directories(${NAME} PUBLIC "${CMAKE_CURRENT_BINARY_DIR}")
target_link_libraries(${NAME} Gint::Gint)
install(TARGETS ${NAME}
DESTINATION "${FXSDK_LIB}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libprof.h"
DESTINATION "${FXSDK_INCLUDE}")
install(FILES cmake/FindLibProf.cmake
DESTINATION "${FXSDK_CMAKE_MODULE_PATH}")

View file

@ -1,46 +0,0 @@
#! /usr/bin/make -f
# libprof Makefile
cflags := -m3 -mb -ffreestanding -nostdlib -fstrict-volatile-bitfields -Wall \
-Wextra -Os -I .
target ?= sh-elf
lib := libprof.a
header := libprof.h
PREFIX ?= $(shell $(target)-gcc -print-search-dirs | grep install \
| sed 's/install: //')
ifeq "$(PREFIX)" ""
$(error "Cannot determine compiler install path")
endif
src := $(wildcard *.c)
obj := $(src:%=build/%.o)
# Rules
all: $(lib)
$(lib): $(obj)
$(target)-ar rcs $@ $^
build/%.c.o: %.c | build/
$(target)-gcc -c $< -o $@ $(cflags)
# Misc rules
clean:
@ rm -rf build
distclean: clean
@ rm -f $(lib)
%/:
mkdir -p $@
.PRECIOUS: %/
# Install
install: $(lib)
cp $(lib) $(DESTDIR)$(PREFIX)
cp $(header) $(DESTDIR)$(PREFIX)/include

View file

@ -8,32 +8,46 @@ libprof's measurements are accurate down to the microsecond-level thanks to
precise hardware timers, so it can also be used to time even small portions of precise hardware timers, so it can also be used to time even small portions of
code. code.
## Building ## Installing and using libprof in a program
libprof is built and installed only once for both fx-9860G and fx-CG 50. The **Installing with GiteaPC**
dependencies are:
* A GCC cross-compiler for a SuperH architecture libprof can be built and installed with [GiteaPC](https://gitea.planet-casio.com/Lephenixnoir/GiteaPC), an automation tool for the fxSDK.
* The [gint kernel](/Lephenixnoir/gint)
The Makefile will build and install the library without further instructions. ```bash
% giteapc install Lephenixnoir/libprof
```sh
% make
% make install
``` ```
By default `sh-elf` is used to build; you can override this by setting the **Installing manually**
`target` variable.
```sh libprof should be built with the [fxSDK](/Lephenixnoir/fxsdk), which provides
% make target=sh4eb-elf compiler settings and library interfaces to build on the calculator.
% make install target=sh4eb-elf
Simply run `fxsdk build-fx` or `fxsdk build-cg`. The fxSDK will invoke CMake
with a suitable toolchain file while exposing CMake modules for the calculator.
```bash
% fxsdk build-fx install
% fxsdk build-cg install
``` ```
If you have the older setup with two toolchains (`sh3eb-elf` and `sh4eb-elf`), **Using in a CMake-based add-in**
instead of the new one with two targets on the same toolchain (`sh-elf`), you
will need to make and install twice. Find the `LibProf` package, which has a `LibProf` target. Versions are numbered like gint, so aim for your version of gint.
```cmake
find_package(LibProf 2.1 REQUIRED)
target_link_libraries(<target_name> LibProf::LibProf)
```
**Using in a Makefile-based add-in**
Link with `-lprof-fx` on fx-9860G and `-lprof-cg` on fx-CG 50. In `project.cfg`:
```makefile
LIBS_FX := -lprof-fx
LIBS_CG := -lprof-cg
```
## Basic use ## Basic use

19
cmake/FindLibProf.cmake Normal file
View file

@ -0,0 +1,19 @@
include(FindSimpleLibrary)
include(FindPackageHandleStandardArgs)
find_package(Gint 2.2.1 REQUIRED)
find_simple_library("libprof-${FXSDK_PLATFORM}.a" libprof.h
"PROF_VERSION" PATH_VAR PROF_PATH VERSION_VAR PROF_VERSION)
find_package_handle_standard_args(LibProf
REQUIRED_VARS PROF_PATH PROF_VERSION
VERSION_VAR PROF_VERSION)
if(LibProf_FOUND)
add_library(LibProf::LibProf UNKNOWN IMPORTED)
set_target_properties(LibProf::LibProf PROPERTIES
IMPORTED_LOCATION "${PROF_PATH}"
INTERFACE_LINK_OPTIONS -lprof-${FXSDK_PLATFORM}
IMPORTED_LINK_INTERFACE_LIBRARIES Gint::Gint)
endif()

25
giteapc.make Normal file
View file

@ -0,0 +1,25 @@
# giteapc: version=1 depends=Lephenixnoir/gint
-include giteapc-config.make
configure:
@ fxsdk build-fx -c
@ fxsdk build-cg -c
build:
@ fxsdk build-fx
@ fxsdk build-cg
install:
@ fxsdk build-fx install
@ fxsdk build-cg install
uninstall:
@ if [ -e build-fx/install_manifest.txt ]; then \
xargs rm -f < build-fx/install_manifest.txt; \
fi
@ if [ -e build-cg/install_manifest.txt ]; then \
xargs rm -f < build-cg/install_manifest.txt; \
fi
.PHONY: configure build install uninstall

View file

@ -22,7 +22,8 @@ int prof_init(void)
int timer = -1; int timer = -1;
for(int t = 2; t >= 0 && timer == -1; t--) for(int t = 2; t >= 0 && timer == -1; t--)
{ {
timer = timer_setup(t | TIMER_Pphi_4, 0xffffffff, callback); timer = timer_configure(t | TIMER_Pphi_4, 0xffffffff,
GINT_CALL(callback));
} }
if(timer == -1) if(timer == -1)
{ {

View file

@ -5,9 +5,16 @@
#ifndef LIBPROF_LIBPROF #ifndef LIBPROF_LIBPROF
#define LIBPROF_LIBPROF #define LIBPROF_LIBPROF
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h> #include <stdint.h>
#include <gint/defs/attributes.h> #include <gint/defs/attributes.h>
/* This is substituted by CMake at compile-time */
#define PROF_VERSION "@libprof_VERSION@"
//--- //---
// Initialization // Initialization
//--- //---
@ -51,7 +58,7 @@ extern uint32_t volatile *prof_tcnt;
function was already executing then the deepest instance in the stack is function was already executing then the deepest instance in the stack is
used instead of creating a new counter. */ used instead of creating a new counter. */
#define prof_enter(prof) { \ #define prof_enter(prof) { \
if(!prof.rec++) prof.elapsed += *prof_tcnt; \ if(!(prof).rec++) (prof).elapsed += *prof_tcnt; \
} }
/* prof_leave(): Stop counting time for a function /* prof_leave(): Stop counting time for a function
@ -60,7 +67,15 @@ extern uint32_t volatile *prof_tcnt;
are not as exactly as many prof_leave()'s as prof_enter()'s then the are not as exactly as many prof_leave()'s as prof_enter()'s then the
resulting time measure will not be relevant at all. */ resulting time measure will not be relevant at all. */
#define prof_leave(prof) { \ #define prof_leave(prof) { \
if(!--prof.rec) prof.elapsed -= *prof_tcnt; \ if(!--(prof).rec) (prof).elapsed -= *prof_tcnt; \
}
/* Variant of prof_enter()/prof_leave() for non-recursive contexts */
#define prof_enter_norec(prof) { \
(prof).elapsed += *prof_tcnt; \
}
#define prof_leave_norec(prof) { \
(prof).elapsed -= *prof_tcnt; \
} }
/* prof_exec(): Measure a single block of code /* prof_exec(): Measure a single block of code
@ -72,11 +87,11 @@ extern uint32_t volatile *prof_tcnt;
exec_code(); exec_code();
}); */ }); */
#define prof_exec(code) ({ \ #define prof_exec(code) ({ \
prof_t prof = prof_make(); \ prof_t _prof = prof_make(); \
prof_enter(prof); \ prof_enter(_prof); \
code; \ code; \
prof_leave(prof); \ prof_leave(_prof); \
prof_time(prof); \ prof_time(_prof); \
}) })
//--- //---
@ -87,4 +102,8 @@ extern uint32_t volatile *prof_tcnt;
Should only be called when the context is not currently executing. */ Should only be called when the context is not currently executing. */
uint32_t prof_time(prof_t prof); uint32_t prof_time(prof_t prof);
#ifdef __cplusplus
}
#endif
#endif /* LIBPROF_LIBPROF */ #endif /* LIBPROF_LIBPROF */