mirror of
https://git.planet-casio.com/Vhex-Kernel-Core/fxlibc.git
synced 2024-12-28 04:23:38 +01:00
Release the 0.3.0 (add README + LICENSE and fix norm)
This commit is contained in:
parent
38ff31fc47
commit
565a159370
16 changed files with 404 additions and 123 deletions
121
LICENSE
Normal file
121
LICENSE
Normal file
|
@ -0,0 +1,121 @@
|
||||||
|
Creative Commons Legal Code
|
||||||
|
|
||||||
|
CC0 1.0 Universal
|
||||||
|
|
||||||
|
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
||||||
|
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
||||||
|
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
||||||
|
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
||||||
|
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
||||||
|
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
||||||
|
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
||||||
|
HEREUNDER.
|
||||||
|
|
||||||
|
Statement of Purpose
|
||||||
|
|
||||||
|
The laws of most jurisdictions throughout the world automatically confer
|
||||||
|
exclusive Copyright and Related Rights (defined below) upon the creator
|
||||||
|
and subsequent owner(s) (each and all, an "owner") of an original work of
|
||||||
|
authorship and/or a database (each, a "Work").
|
||||||
|
|
||||||
|
Certain owners wish to permanently relinquish those rights to a Work for
|
||||||
|
the purpose of contributing to a commons of creative, cultural and
|
||||||
|
scientific works ("Commons") that the public can reliably and without fear
|
||||||
|
of later claims of infringement build upon, modify, incorporate in other
|
||||||
|
works, reuse and redistribute as freely as possible in any form whatsoever
|
||||||
|
and for any purposes, including without limitation commercial purposes.
|
||||||
|
These owners may contribute to the Commons to promote the ideal of a free
|
||||||
|
culture and the further production of creative, cultural and scientific
|
||||||
|
works, or to gain reputation or greater distribution for their Work in
|
||||||
|
part through the use and efforts of others.
|
||||||
|
|
||||||
|
For these and/or other purposes and motivations, and without any
|
||||||
|
expectation of additional consideration or compensation, the person
|
||||||
|
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
||||||
|
is an owner of Copyright and Related Rights in the Work, voluntarily
|
||||||
|
elects to apply CC0 to the Work and publicly distribute the Work under its
|
||||||
|
terms, with knowledge of his or her Copyright and Related Rights in the
|
||||||
|
Work and the meaning and intended legal effect of CC0 on those rights.
|
||||||
|
|
||||||
|
1. Copyright and Related Rights. A Work made available under CC0 may be
|
||||||
|
protected by copyright and related or neighboring rights ("Copyright and
|
||||||
|
Related Rights"). Copyright and Related Rights include, but are not
|
||||||
|
limited to, the following:
|
||||||
|
|
||||||
|
i. the right to reproduce, adapt, distribute, perform, display,
|
||||||
|
communicate, and translate a Work;
|
||||||
|
ii. moral rights retained by the original author(s) and/or performer(s);
|
||||||
|
iii. publicity and privacy rights pertaining to a person's image or
|
||||||
|
likeness depicted in a Work;
|
||||||
|
iv. rights protecting against unfair competition in regards to a Work,
|
||||||
|
subject to the limitations in paragraph 4(a), below;
|
||||||
|
v. rights protecting the extraction, dissemination, use and reuse of data
|
||||||
|
in a Work;
|
||||||
|
vi. database rights (such as those arising under Directive 96/9/EC of the
|
||||||
|
European Parliament and of the Council of 11 March 1996 on the legal
|
||||||
|
protection of databases, and under any national implementation
|
||||||
|
thereof, including any amended or successor version of such
|
||||||
|
directive); and
|
||||||
|
vii. other similar, equivalent or corresponding rights throughout the
|
||||||
|
world based on applicable law or treaty, and any national
|
||||||
|
implementations thereof.
|
||||||
|
|
||||||
|
2. Waiver. To the greatest extent permitted by, but not in contravention
|
||||||
|
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
||||||
|
irrevocably and unconditionally waives, abandons, and surrenders all of
|
||||||
|
Affirmer's Copyright and Related Rights and associated claims and causes
|
||||||
|
of action, whether now known or unknown (including existing as well as
|
||||||
|
future claims and causes of action), in the Work (i) in all territories
|
||||||
|
worldwide, (ii) for the maximum duration provided by applicable law or
|
||||||
|
treaty (including future time extensions), (iii) in any current or future
|
||||||
|
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
||||||
|
including without limitation commercial, advertising or promotional
|
||||||
|
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
||||||
|
member of the public at large and to the detriment of Affirmer's heirs and
|
||||||
|
successors, fully intending that such Waiver shall not be subject to
|
||||||
|
revocation, rescission, cancellation, termination, or any other legal or
|
||||||
|
equitable action to disrupt the quiet enjoyment of the Work by the public
|
||||||
|
as contemplated by Affirmer's express Statement of Purpose.
|
||||||
|
|
||||||
|
3. Public License Fallback. Should any part of the Waiver for any reason
|
||||||
|
be judged legally invalid or ineffective under applicable law, then the
|
||||||
|
Waiver shall be preserved to the maximum extent permitted taking into
|
||||||
|
account Affirmer's express Statement of Purpose. In addition, to the
|
||||||
|
extent the Waiver is so judged Affirmer hereby grants to each affected
|
||||||
|
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
||||||
|
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
||||||
|
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
||||||
|
maximum duration provided by applicable law or treaty (including future
|
||||||
|
time extensions), (iii) in any current or future medium and for any number
|
||||||
|
of copies, and (iv) for any purpose whatsoever, including without
|
||||||
|
limitation commercial, advertising or promotional purposes (the
|
||||||
|
"License"). The License shall be deemed effective as of the date CC0 was
|
||||||
|
applied by Affirmer to the Work. Should any part of the License for any
|
||||||
|
reason be judged legally invalid or ineffective under applicable law, such
|
||||||
|
partial invalidity or ineffectiveness shall not invalidate the remainder
|
||||||
|
of the License, and in such case Affirmer hereby affirms that he or she
|
||||||
|
will not (i) exercise any of his or her remaining Copyright and Related
|
||||||
|
Rights in the Work or (ii) assert any associated claims and causes of
|
||||||
|
action with respect to the Work, in either case contrary to Affirmer's
|
||||||
|
express Statement of Purpose.
|
||||||
|
|
||||||
|
4. Limitations and Disclaimers.
|
||||||
|
|
||||||
|
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
||||||
|
surrendered, licensed or otherwise affected by this document.
|
||||||
|
b. Affirmer offers the Work as-is and makes no representations or
|
||||||
|
warranties of any kind concerning the Work, express, implied,
|
||||||
|
statutory or otherwise, including without limitation warranties of
|
||||||
|
title, merchantability, fitness for a particular purpose, non
|
||||||
|
infringement, or the absence of latent or other defects, accuracy, or
|
||||||
|
the present or absence of errors, whether or not discoverable, all to
|
||||||
|
the greatest extent permissible under applicable law.
|
||||||
|
c. Affirmer disclaims responsibility for clearing rights of other persons
|
||||||
|
that may apply to the Work or any use thereof, including without
|
||||||
|
limitation any person's Copyright and Related Rights in the Work.
|
||||||
|
Further, Affirmer disclaims responsibility for obtaining any necessary
|
||||||
|
consents, permissions or other rights required for any use of the
|
||||||
|
Work.
|
||||||
|
d. Affirmer understands and acknowledges that Creative Commons is not a
|
||||||
|
party to this document and has no duty or obligation with respect to
|
||||||
|
this CC0 or use of the Work.
|
107
README.md
Normal file
107
README.md
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
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
|
||||||
|
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
|
||||||
|
system.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
Fx C library depends on a suitable GCC toolchain in the PATH. You can absolutely
|
||||||
|
not build gint with your system compiler!
|
||||||
|
|
||||||
|
* 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.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 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).
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
#### Configuration and support
|
||||||
|
The Fx C library supports these ABI:
|
||||||
|
* `casio-abi-fx9860g` for the support of Casio ABI used by fx9860g-like devices.
|
||||||
|
* `casio-abi-fxcg50` for the support of Casio ABI used by the fxcg50 device.
|
||||||
|
* `vhex-kernel` for the support of Vhex kernel ABI.
|
||||||
|
* (nothing) compile only standing functions.
|
||||||
|
|
||||||
|
The Fx C library support these format:
|
||||||
|
* `static` generate static libraries.
|
||||||
|
* `shared` generate shared libraries (Only for the Vhex kernel).
|
||||||
|
|
||||||
|
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).
|
||||||
|
|
||||||
|
For more information about library build configuration, you can use the
|
||||||
|
`../configure --help` command.
|
||||||
|
|
||||||
|
#### Building
|
||||||
|
Create a build directory and configure in it:
|
||||||
|
```
|
||||||
|
% mkdir build && cd build
|
||||||
|
% ../configure
|
||||||
|
```
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
```
|
||||||
|
% make
|
||||||
|
% make install
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Contributing
|
||||||
|
Bug reports, feature suggestions and especially code contributions are most
|
||||||
|
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` utilities 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.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Using Fx C Library
|
||||||
|
|
||||||
|
To use Fx C library as your runtime environment, the bare minimum is:
|
||||||
|
* You must add `fxlibc/` instead of each include file (for example, if you want
|
||||||
|
to include `stdio.h` you mush use `#include <fxlibc/stdio.h>`.
|
||||||
|
* Link with:
|
||||||
|
* `-lfxlibc` for standalone feature
|
||||||
|
* `-lfxlibc-casio-abi-fx9860g` for Casio ABI support for monochrome devices
|
||||||
|
* `-lfxlibc-casio-abi-fxcg50` for Casio ABI support for primz devices
|
||||||
|
* `-lfxlibc-vhex` for Vhex kernel support.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Licences
|
||||||
|
This work is licensed under a CC0 1.0 Universal License. To view a copy of this
|
||||||
|
license, visit: https://creativecommons.org/publicdomain/zero/1.0/legalcode.txt
|
||||||
|
Or see the LICENSE file.
|
|
@ -3,8 +3,8 @@
|
||||||
#
|
#
|
||||||
# fxlibc project Makefile
|
# fxlibc project Makefile
|
||||||
#
|
#
|
||||||
# This makefile is grandly inspired by the Gint unikernel
|
# This makefile is grandly inspired by the one used for the Gint (unikernel)
|
||||||
# projet, many thanks to Lephenixnoir !
|
# project, many thanks to Lephenixnoir !
|
||||||
#
|
#
|
||||||
# Build architecture:
|
# Build architecture:
|
||||||
# build/
|
# build/
|
||||||
|
@ -30,12 +30,13 @@
|
||||||
# `--- libfxlibc-casio-abi-fxcg50.so
|
# `--- libfxlibc-casio-abi-fxcg50.so
|
||||||
#
|
#
|
||||||
# TODO:
|
# TODO:
|
||||||
# * handle versionning
|
# * handle dynamic versioning
|
||||||
|
# * handle verbose option
|
||||||
#---
|
#---
|
||||||
MAJOR := 0
|
MAJOR := 0
|
||||||
MINOR := 2
|
MINOR := 3
|
||||||
PATCH := 5
|
PATCH := 0
|
||||||
EXTRAVERSION := -rc
|
EXTRAVERSION :=
|
||||||
|
|
||||||
|
|
||||||
#---
|
#---
|
||||||
|
@ -61,26 +62,21 @@ blue := \033[1;34m
|
||||||
white := \033[1;37m
|
white := \033[1;37m
|
||||||
nocolor := \033[1;0m
|
nocolor := \033[1;0m
|
||||||
|
|
||||||
# Define all directory used to stored informations
|
# Define all directories used to stored information
|
||||||
dir_object := object
|
dir_object := object
|
||||||
dir_output := output
|
dir_output := output
|
||||||
|
|
||||||
# Output configurations
|
# Output configurations
|
||||||
name := fxlibc
|
name := fxlibc
|
||||||
|
|
||||||
# automated variable
|
# Automated variables
|
||||||
directory := $(shell find ../src -not -path "*/\.*" -type d)
|
directory := $(shell find ../src -not -path "*/\.*" -type d)
|
||||||
src := $(foreach path,$(directory), \
|
src := $(foreach path,$(directory), \
|
||||||
$(wildcard $(path)/*.c) \
|
$(wildcard $(path)/*.c) \
|
||||||
$(wildcard $(path)/*.S) \
|
$(wildcard $(path)/*.S) \
|
||||||
$(wildcard $(path)/*.s))
|
$(wildcard $(path)/*.s))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#---
|
|
||||||
# Toolchain
|
# Toolchain
|
||||||
#---
|
|
||||||
gcc = $(CONFIG.TOOLCHAIN)-gcc
|
gcc = $(CONFIG.TOOLCHAIN)-gcc
|
||||||
as = $(CONFIG.TOOLCHAIN)-as
|
as = $(CONFIG.TOOLCHAIN)-as
|
||||||
ld = $(CONFIG.TOOLCHAIN)-ld
|
ld = $(CONFIG.TOOLCHAIN)-ld
|
||||||
|
@ -110,26 +106,27 @@ first: all
|
||||||
#---
|
#---
|
||||||
# Generate building rules
|
# Generate building rules
|
||||||
#---
|
#---
|
||||||
# common part used to compile source file
|
# This function will generate compilation rule for each source.
|
||||||
# @params:
|
# @params:
|
||||||
# *1 - source file path
|
# *1 - source file path
|
||||||
# *2 - build directory path (output)
|
# *2 - build directory path (output)
|
||||||
# *3 - build flags
|
# *3 - build flags
|
||||||
# TODO:
|
# TODO:
|
||||||
# * handle verbose option
|
# * handle verbose option
|
||||||
define compile-src
|
define generate-compilation-rule
|
||||||
$(patsubst .._src_%,$2%.o,$(subst /,_,$(basename $1))): $1 | $2/
|
$(patsubst .._src_%,$2%.o,$(subst /,_,$(basename $1))): $1 | $2/
|
||||||
@ printf "$(green)>$(nocolor) $(white)$$@$(nocolor)\n"
|
@ printf "$(green)>$(nocolor) $(white)$$@$(nocolor)\n"
|
||||||
@ $(gcc) $3 -o $$@ -c $$< -lgcc
|
@ $(gcc) $3 -o $$@ -c $$< -lgcc
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# common part used by all library geneation
|
# Function that will generate all rules for building each library.
|
||||||
# @params:
|
# @params:
|
||||||
# * 1 - library name
|
# * 1 - library name
|
||||||
# * 2 - format (dynamic/static)
|
# * 2 - format (dynamic/static)
|
||||||
# * 3 - source file list
|
# * 3 - source file list
|
||||||
define generate-target
|
define generate-target
|
||||||
# generate the library name based on the wanted formats
|
# Generate all variables (library name based on the wanted formats, output
|
||||||
|
# directory, ...) used by each rule that will be generated.
|
||||||
lib-output-dir := $(dir_output)/$2/
|
lib-output-dir := $(dir_output)/$2/
|
||||||
lib-build-dir := $(dir_object)/$2/$1/
|
lib-build-dir := $(dir_object)/$2/$1/
|
||||||
ifeq ($2,dynamic)
|
ifeq ($2,dynamic)
|
||||||
|
@ -140,10 +137,7 @@ lib-name := $$(lib-output-dir)lib$1.a
|
||||||
lib-cflags := $(cflags)
|
lib-cflags := $(cflags)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# indicate the new lib that will be ouputed
|
# add custom project-specific flags based on the target ABI
|
||||||
generated-libs += $$(lib-name)
|
|
||||||
|
|
||||||
# add custom flags based on the target ABI
|
|
||||||
ifeq ($1,fxlibc-vhex)
|
ifeq ($1,fxlibc-vhex)
|
||||||
lib-cflags += -D __SUPPORT_VHEX_KERNEL
|
lib-cflags += -D __SUPPORT_VHEX_KERNEL
|
||||||
else ifeq ($1,fxlibc-casio-abi-fx9860g)
|
else ifeq ($1,fxlibc-casio-abi-fx9860g)
|
||||||
|
@ -152,14 +146,21 @@ else ifeq ($1,fxlibc-casio-abi-fxcf50)
|
||||||
lib-cflags += -D __SUPPORT_CASIO_ABI_FXCG50
|
lib-cflags += -D __SUPPORT_CASIO_ABI_FXCG50
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# generate all file object name
|
# Generate all file compilation rules
|
||||||
$$(foreach source,$3,$$(eval \
|
$$(foreach source,$3,$$(eval \
|
||||||
$$(call compile-src,$$(source),$$(lib-build-dir),$$(lib-cflags)) \
|
$$(call generate-compilation-rule,$$(source),$$(lib-build-dir),$$(lib-cflags)) \
|
||||||
))
|
))
|
||||||
|
|
||||||
# link the library
|
# Register the library building rule name
|
||||||
# @note: we need to generate the library verion information manually
|
# @note:
|
||||||
# TODO: find a better way to generate the version symbols
|
# This rule list (lib-generation-rules) is used by the main compiling rule like
|
||||||
|
# a dependency. And it's this dependency that will involve all generated rules
|
||||||
|
# for building each library.
|
||||||
|
lib-generation-rules += $$(lib-name)
|
||||||
|
|
||||||
|
# Generate the linking library rule
|
||||||
|
# TODO
|
||||||
|
# * Find better way to generate binary files name dependency
|
||||||
$$(lib-name): $$(patsubst .._src_%,$$(lib-build-dir)%.o,$$(subst /,_,$$(basename $3))) | $$(lib-output-dir)
|
$$(lib-name): $$(patsubst .._src_%,$$(lib-build-dir)%.o,$$(subst /,_,$$(basename $3))) | $$(lib-output-dir)
|
||||||
ifeq ($2,dynamic)
|
ifeq ($2,dynamic)
|
||||||
$(gcc) -shared -Wl,-soname=$$@ -o $$@ $$^ -nostdlib -lgcc
|
$(gcc) -shared -Wl,-soname=$$@ -o $$@ $$^ -nostdlib -lgcc
|
||||||
|
@ -168,21 +169,21 @@ else
|
||||||
endif
|
endif
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# create all "target" variable used to determine which format
|
# Create all "target" variable used to determine which format and which
|
||||||
# and which libraries will be generated.
|
# libraries will be generated.
|
||||||
# @note:
|
# @note: we force default variable if nothing is set
|
||||||
# * we force default variable if nothing is set
|
|
||||||
target-formats := $(if $(CONFIG.FORMAT),$(CONFIG.FORMAT),static)
|
target-formats := $(if $(CONFIG.FORMAT),$(CONFIG.FORMAT),static)
|
||||||
target-libs := $(if $(CONFIG.TARGET),$(CONFIG.TARGET),fxlibc)
|
target-libs := $(if $(CONFIG.TARGET),$(CONFIG.TARGET),fxlibc)
|
||||||
|
|
||||||
# create a variable that will be updated during the generation of
|
# Create a variable that will be updated during the dynamic makecode generation
|
||||||
# the dynamic make code generation (generated by the "foreach")
|
# (generated by the "foreach"). This variable will list all rules generated for
|
||||||
generated-libs :=
|
# building each library and used like a dependency by the main rule.
|
||||||
|
lib-generation-rules :=
|
||||||
|
|
||||||
# generate the library version
|
# Generate the library version (used only by the dynamic library format).
|
||||||
lib-version := $(MAJOR).$(MINOR).$(PATCH)$(EXTRAVERSION)
|
lib-version := $(MAJOR).$(MINOR).$(PATCH)$(EXTRAVERSION)
|
||||||
|
|
||||||
# Generate all targets
|
# Generate all building rules
|
||||||
$(foreach format,$(target-formats), \
|
$(foreach format,$(target-formats), \
|
||||||
$(foreach lib,$(target-libs),$(eval \
|
$(foreach lib,$(target-libs),$(eval \
|
||||||
$(call generate-target,$(lib),$(format),$(src)) \
|
$(call generate-target,$(lib),$(format),$(src)) \
|
||||||
|
@ -193,9 +194,9 @@ $(foreach format,$(target-formats), \
|
||||||
|
|
||||||
|
|
||||||
#---
|
#---
|
||||||
# Build rule
|
# Build rules
|
||||||
#---
|
#---
|
||||||
all: $(generated-libs)
|
all: $(lib-generation-rules)
|
||||||
|
|
||||||
version:
|
version:
|
||||||
@ echo "$(lib-version)"
|
@ echo "$(lib-version)"
|
||||||
|
@ -209,38 +210,38 @@ version:
|
||||||
# @note:
|
# @note:
|
||||||
# *1 - library pathname
|
# *1 - library pathname
|
||||||
define generate-install-rule
|
define generate-install-rule
|
||||||
# generate the rulename
|
# get the library name (remove path information)
|
||||||
# @note: basically, it is the library name
|
|
||||||
lib-basename := $(notdir $1)
|
lib-basename := $(notdir $1)
|
||||||
|
|
||||||
# genetate rule name
|
# Genetate rules name
|
||||||
lib-install-rule := $$(basename $$(lib-basename))-install
|
lib-install-rule := $$(basename $$(lib-basename))-install
|
||||||
lib-uninstall-rule := $$(basename $$(lib-basename))-uninstall
|
lib-uninstall-rule := $$(basename $$(lib-basename))-uninstall
|
||||||
|
|
||||||
|
# Generate the installation rule
|
||||||
$$(lib-install-rule):
|
$$(lib-install-rule):
|
||||||
install -d $(CONFIG.PREFIX)
|
install -d $(CONFIG.PREFIX)
|
||||||
install $1 -m 644 $(CONFIG.PREFIX)
|
install $1 -m 644 $(CONFIG.PREFIX)
|
||||||
|
|
||||||
|
# Generate the uninstallation rule
|
||||||
$$(lib-uninstall-rule):
|
$$(lib-uninstall-rule):
|
||||||
rm -f $(CONFIG.PREFIX)$$(lib-basename)
|
rm -f $(CONFIG.PREFIX)$$(lib-basename)
|
||||||
|
|
||||||
|
# Register generated rules into their appropriate list
|
||||||
# register generated rules into appropriate variable
|
|
||||||
lib-installation-rules += $$(lib-install-rule)
|
lib-installation-rules += $$(lib-install-rule)
|
||||||
lib-uninstallation-rules += $$(lib-uninstall-rule)
|
lib-uninstallation-rules += $$(lib-uninstall-rule)
|
||||||
|
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# internal variable used to store all rules about installation/uninstallation
|
# Internal variable used to store all rules about installation/uninstallation
|
||||||
lib-installation-rules :=
|
lib-installation-rules :=
|
||||||
lib-uninstallation-rules :=
|
lib-uninstallation-rules :=
|
||||||
|
|
||||||
# generate all installation/ unstallation rules
|
# Generate all installation/unstallation rules
|
||||||
$(foreach libs,$(generated-libs),$(eval \
|
$(foreach libs,$(lib-generation-rules),$(eval \
|
||||||
$(call generate-install-rule,$(libs)) \
|
$(call generate-install-rule,$(libs)) \
|
||||||
))
|
))
|
||||||
|
|
||||||
# Generate the include install directory.
|
# Generate the path where include directory will be installed.
|
||||||
lib-install-header-dir := $(CONFIG.PREFIX)include/fxlibc
|
lib-install-header-dir := $(CONFIG.PREFIX)include/fxlibc
|
||||||
|
|
||||||
|
|
||||||
|
@ -249,7 +250,7 @@ lib-install-header-dir := $(CONFIG.PREFIX)include/fxlibc
|
||||||
#---
|
#---
|
||||||
# Installation rules
|
# Installation rules
|
||||||
#---
|
#---
|
||||||
install: $(generated-libs) $(lib-installation-rules)
|
install: $(lib-generation-rules) $(lib-installation-rules)
|
||||||
rm -rf $(lib-install-header-dir)
|
rm -rf $(lib-install-header-dir)
|
||||||
cp -r ../include $(lib-install-header-dir)
|
cp -r ../include $(lib-install-header-dir)
|
||||||
|
|
||||||
|
@ -260,7 +261,7 @@ uninstall: $(lib-uninstallation-rules)
|
||||||
|
|
||||||
|
|
||||||
#---
|
#---
|
||||||
# debug rule
|
# (internal ) debug rule
|
||||||
#---
|
#---
|
||||||
#DEBUG=$(call generate-target,fxlibc-vhex,static,$(dir_objects),$(src))
|
#DEBUG=$(call generate-target,fxlibc-vhex,static,$(dir_objects),$(src))
|
||||||
DEBUG=$(call generate-install-rule,/output/static/fxlibc.a)
|
DEBUG=$(call generate-install-rule,/output/static/fxlibc.a)
|
||||||
|
@ -268,7 +269,7 @@ export DEBUG
|
||||||
debug:
|
debug:
|
||||||
@ echo "$$DEBUG"
|
@ echo "$$DEBUG"
|
||||||
@ echo "target-lib: $(target-libs)"
|
@ echo "target-lib: $(target-libs)"
|
||||||
@ echo "generated lib: $(generated-libs)"
|
@ echo "generated lib: $(lib-generation-rules)"
|
||||||
@ echo "target format: $(target-formats)"
|
@ echo "target format: $(target-formats)"
|
||||||
@ echo "install-rules: $(lib-installation-rules)"
|
@ echo "install-rules: $(lib-installation-rules)"
|
||||||
@ echo "uninstall-rules: $(lib-uninstallation-rules)"
|
@ echo "uninstall-rules: $(lib-uninstallation-rules)"
|
||||||
|
@ -277,7 +278,7 @@ debug:
|
||||||
|
|
||||||
|
|
||||||
#---
|
#---
|
||||||
# clean rules
|
# cleaning rules
|
||||||
#---
|
#---
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(dir_object)
|
rm -rf $(dir_object)
|
||||||
|
|
|
@ -26,9 +26,12 @@ void (*action[26])(struct printf_opt *opt, char n) = {
|
||||||
//---
|
//---
|
||||||
// Disp part
|
// Disp part
|
||||||
//---
|
//---
|
||||||
static void base_to_str(struct printf_opt *opt, uint32_t num, int base, int digits)
|
static void base_to_str(struct printf_opt *opt, uint32_t num, int base,
|
||||||
|
int digits)
|
||||||
{
|
{
|
||||||
char *hexa = (opt->uppercase == 1) ? "0123456789ABCDEF" : "0123456789abcdef";
|
char *hexa = "0123456789abcdef";
|
||||||
|
if (opt->uppercase == 1)
|
||||||
|
hexa = "0123456789ABCDEF";
|
||||||
|
|
||||||
opt->digits = 0;
|
opt->digits = 0;
|
||||||
while (num != 0 || opt->digits < digits) {
|
while (num != 0 || opt->digits < digits) {
|
||||||
|
@ -53,7 +56,8 @@ static void disp_format(struct printf_opt *opt)
|
||||||
(opt->base[0] != '\0') + (opt->base[1] != '\0');
|
(opt->base[0] != '\0') + (opt->base[1] != '\0');
|
||||||
total = opt->width - total;
|
total = opt->width - total;
|
||||||
while (--total >= 0)
|
while (--total >= 0)
|
||||||
(*opt->disp_char)(opt, (opt->flags.zero == 1) ? '0' : ' ');
|
(*opt->disp_char)(opt,
|
||||||
|
(opt->flags.zero == 1) ? '0' : ' ');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,13 +83,20 @@ static void disp_format(struct printf_opt *opt)
|
||||||
static uint32_t get_arg_i(struct printf_opt *opt)
|
static uint32_t get_arg_i(struct printf_opt *opt)
|
||||||
{
|
{
|
||||||
switch (opt->lenght) {
|
switch (opt->lenght) {
|
||||||
case 0: return ((signed char)va_arg(opt->ap, int));
|
case 0:
|
||||||
case 1: return ((short int)va_arg(opt->ap, int));
|
return ((signed char)va_arg(opt->ap, int));
|
||||||
case 2: return (va_arg(opt->ap, long int));
|
case 1:
|
||||||
case 3: return (va_arg(opt->ap, long long int));
|
return ((short int)va_arg(opt->ap, int));
|
||||||
case 4: return (va_arg(opt->ap, intmax_t));
|
case 2:
|
||||||
case 5: return (va_arg(opt->ap, size_t));
|
return (va_arg(opt->ap, long int));
|
||||||
case 6: return (va_arg(opt->ap, ptrdiff_t));
|
case 3:
|
||||||
|
return (va_arg(opt->ap, long long int));
|
||||||
|
case 4:
|
||||||
|
return (va_arg(opt->ap, intmax_t));
|
||||||
|
case 5:
|
||||||
|
return (va_arg(opt->ap, size_t));
|
||||||
|
case 6:
|
||||||
|
return (va_arg(opt->ap, ptrdiff_t));
|
||||||
}
|
}
|
||||||
return (va_arg(opt->ap, int));
|
return (va_arg(opt->ap, int));
|
||||||
}
|
}
|
||||||
|
@ -93,13 +104,20 @@ static uint32_t get_arg_i(struct printf_opt *opt)
|
||||||
static uint32_t get_arg_u(struct printf_opt *opt)
|
static uint32_t get_arg_u(struct printf_opt *opt)
|
||||||
{
|
{
|
||||||
switch (opt->lenght) {
|
switch (opt->lenght) {
|
||||||
case 0: return ((unsigned char)va_arg(opt->ap, int));
|
case 0:
|
||||||
case 1: return ((unsigned short int)va_arg(opt->ap, int));
|
return ((unsigned char)va_arg(opt->ap, int));
|
||||||
case 2: return (va_arg(opt->ap, unsigned long int));
|
case 1:
|
||||||
case 3: return (va_arg(opt->ap, unsigned long long int));
|
return ((unsigned short int)va_arg(opt->ap, int));
|
||||||
case 4: return (va_arg(opt->ap, intmax_t));
|
case 2:
|
||||||
case 5: return (va_arg(opt->ap, size_t));
|
return (va_arg(opt->ap, unsigned long int));
|
||||||
case 6: return (va_arg(opt->ap, ptrdiff_t));
|
case 3:
|
||||||
|
return (va_arg(opt->ap, unsigned long long int));
|
||||||
|
case 4:
|
||||||
|
return (va_arg(opt->ap, intmax_t));
|
||||||
|
case 5:
|
||||||
|
return (va_arg(opt->ap, size_t));
|
||||||
|
case 6:
|
||||||
|
return (va_arg(opt->ap, ptrdiff_t));
|
||||||
}
|
}
|
||||||
return (va_arg(opt->ap, unsigned int));
|
return (va_arg(opt->ap, unsigned int));
|
||||||
}
|
}
|
||||||
|
@ -161,9 +179,15 @@ static void action_uint(struct printf_opt *opt, char n)
|
||||||
|
|
||||||
// Get appropriate base
|
// Get appropriate base
|
||||||
switch (n) {
|
switch (n) {
|
||||||
case 'o': base = 8; break;
|
case 'o':
|
||||||
case 'x': base = 16; break;
|
base = 8;
|
||||||
default: base = 10; break;
|
break;
|
||||||
|
case 'x':
|
||||||
|
base = 16;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
base = 10;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display extra symbols if needed
|
// Display extra symbols if needed
|
||||||
|
|
|
@ -7,18 +7,22 @@
|
||||||
//TODO: precision handling
|
//TODO: precision handling
|
||||||
int printf_common(struct printf_opt *opt, const char *restrict format)
|
int printf_common(struct printf_opt *opt, const char *restrict format)
|
||||||
{
|
{
|
||||||
extern int printf_get_options(struct printf_opt *opt, const char *restrict format);
|
extern int printf_get_options(struct printf_opt *opt,
|
||||||
|
const char *restrict format);
|
||||||
int saved_p;
|
int saved_p;
|
||||||
|
char tmp;
|
||||||
int p;
|
int p;
|
||||||
|
|
||||||
p = -1;
|
p = -1;
|
||||||
opt->counter = 0;
|
opt->counter = 0;
|
||||||
opt->buffer_cursor = 0;
|
opt->buffer_cursor = 0;
|
||||||
while (format[++p] != '\0')
|
while (format[++p] != '\0') {
|
||||||
{
|
|
||||||
// Check printable char
|
// Check printable char
|
||||||
if (format[p] != '%' || format[p + 1] == '%') {
|
if (format[p] != '%' || format[p + 1] == '%') {
|
||||||
(*opt->disp_char)(opt, (format[p] != '%') ? format[p] : format[++p]);
|
tmp = format[p];
|
||||||
|
if (format[p] != '%')
|
||||||
|
tmp = format[++p];
|
||||||
|
(*opt->disp_char)(opt,tmp);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +34,8 @@ int printf_common(struct printf_opt *opt, const char *restrict format)
|
||||||
if (((format[p + 1] >= 'a' && format[p + 1] <= 'z') ||
|
if (((format[p + 1] >= 'a' && format[p + 1] <= 'z') ||
|
||||||
(format[p + 1] >= 'A' && format[p + 1] <= 'Z')) &&
|
(format[p + 1] >= 'A' && format[p + 1] <= 'Z')) &&
|
||||||
action[(format[p + 1] | 0x20) - 'a'] != NULL) {
|
action[(format[p + 1] | 0x20) - 'a'] != NULL) {
|
||||||
(*action[(format[p + 1] | 0x20) - 'a'])(opt, format[p + 1] | 0x20);
|
tmp = (format[p + 1] | 0x20) - 'a';
|
||||||
|
(*action[(int)tmp]) (opt,tmp);
|
||||||
p = p + 1;
|
p = p + 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,16 +14,25 @@ static int get_flags(struct printf_opt *opt, const char *restrict format)
|
||||||
opt->flags.minus = 0;
|
opt->flags.minus = 0;
|
||||||
opt->flags.space = 0;
|
opt->flags.space = 0;
|
||||||
opt->flags.plus = 0;
|
opt->flags.plus = 0;
|
||||||
while (format[++i] != '\0')
|
while (format[++i] != '\0') {
|
||||||
{
|
switch (format[i]) {
|
||||||
switch (format[i])
|
case '#':
|
||||||
{
|
opt->flags.diez = 1;
|
||||||
case '#': opt->flags.diez = 1; break;
|
break;
|
||||||
case '0': opt->flags.zero = 1; break;
|
case '0':
|
||||||
case '-': opt->flags.minus = 1; break;
|
opt->flags.zero = 1;
|
||||||
case ' ': opt->flags.space = 1; break;
|
break;
|
||||||
case '+': opt->flags.plus = 1; break;
|
case '-':
|
||||||
default: return (i);
|
opt->flags.minus = 1;
|
||||||
|
break;
|
||||||
|
case ' ':
|
||||||
|
opt->flags.space = 1;
|
||||||
|
break;
|
||||||
|
case '+':
|
||||||
|
opt->flags.plus = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return (i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (i);
|
return (i);
|
||||||
|
@ -76,14 +85,24 @@ static int get_precision(struct printf_opt *opt, const char *restrict format)
|
||||||
static int get_lenght(struct printf_opt *opt, const char *restrict format)
|
static int get_lenght(struct printf_opt *opt, const char *restrict format)
|
||||||
{
|
{
|
||||||
opt->lenght = -1;
|
opt->lenght = -1;
|
||||||
switch (format[0])
|
switch (format[0]) {
|
||||||
{
|
case 'h':
|
||||||
case 'h': opt->lenght = (format[1] == 'h') ? 1 : 0; break;
|
opt->lenght = (format[1] == 'h') ? 1 : 0;
|
||||||
case 'l': opt->lenght = (format[1] == 'l') ? 3 : 2; break;
|
break;
|
||||||
case 'j': opt->lenght = 4; break;
|
case 'l':
|
||||||
case 'z': opt->lenght = 5; break;
|
opt->lenght = (format[1] == 'l') ? 3 : 2;
|
||||||
case 't': opt->lenght = 6; break;
|
break;
|
||||||
default: return (0);
|
case 'j':
|
||||||
|
opt->lenght = 4;
|
||||||
|
break;
|
||||||
|
case 'z':
|
||||||
|
opt->lenght = 5;
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
opt->lenght = 6;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
return ((opt->lenght == 1 || opt->lenght == 3) ? 2 : 1);
|
return ((opt->lenght == 1 || opt->lenght == 3) ? 2 : 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,8 @@ static void disp_char(struct printf_opt *opt, char n)
|
||||||
*/
|
*/
|
||||||
int vdprintf(int fd, const char *restrict format, va_list ap)
|
int vdprintf(int fd, const char *restrict format, va_list ap)
|
||||||
{
|
{
|
||||||
extern int printf_common(struct printf_opt *opt, const char *restrict format);
|
extern int printf_common(struct printf_opt *opt,
|
||||||
|
const char *restrict format);
|
||||||
struct printf_opt opt;
|
struct printf_opt opt;
|
||||||
|
|
||||||
opt.fd = fd;
|
opt.fd = fd;
|
||||||
|
|
|
@ -24,9 +24,11 @@ static void disp_fflush(struct printf_opt *opt)
|
||||||
** functions do not call the va_end macro. Because they invoke the va_arg macro,
|
** functions do not call the va_end macro. Because they invoke the va_arg macro,
|
||||||
** the value of ap is undefined after the call.
|
** the value of ap is undefined after the call.
|
||||||
*/
|
*/
|
||||||
int vsnprintf(char *restrict str, size_t size, const char *restrict format, va_list ap)
|
int vsnprintf(char *restrict str, size_t size, const char *restrict format,
|
||||||
|
va_list ap)
|
||||||
{
|
{
|
||||||
extern int printf_common(struct printf_opt *opt, const char *restrict format);
|
extern int printf_common(struct printf_opt *opt,
|
||||||
|
const char *restrict format);
|
||||||
struct printf_opt opt;
|
struct printf_opt opt;
|
||||||
|
|
||||||
opt.str = str;
|
opt.str = str;
|
||||||
|
|
|
@ -34,6 +34,7 @@ int strncmp(const char *s1, const char *s2, size_t n)
|
||||||
if (s1 == NULL || s2 == NULL || n == 0)
|
if (s1 == NULL || s2 == NULL || n == 0)
|
||||||
return (0);
|
return (0);
|
||||||
size_t i = -1;
|
size_t i = -1;
|
||||||
while (++i < n - 1 && s1[i] != '\0' && s2[i] != '\0' && s1[i] == s2[i]);
|
while (++i < n - 1 && s1[i] != '\0' && s2[i] != '\0'
|
||||||
|
&& s1[i] == s2[i]) ;
|
||||||
return (s1[i] - s2[i]);
|
return (s1[i] - s2[i]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue