Commit da78d10b authored by Oliver Horst's avatar Oliver Horst
Browse files

[chg] Integrated all libc replacements into a common target

parent b595a35a
cmake_minimum_required(VERSION 3.7 FATAL_ERROR)
option(ENABLE_INSTALL "Enable target installation possibility" ON)
option(WITH_HEADERS "Enable the installation of header files" ON)
option(WITH_PORTS "Enable the build of the ports" ON)
project(
toki-libc-printf
toki-libc-repl
#
VERSION 0.1
LANGUAGES C ASM
)
find_package(
xil-headers 7.0
toki-libc-repl-headers 0.1
REQUIRED
)
find_package(
toki-libc-repl-port 0.1
REQUIRED
)
add_library(
toki-libc-printf
toki-libc-repl
#
STATIC
"" # The sources are added in the respective sub-folders
)
#target_include_directories(
#toki-libc-printf
##
#INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
#INTERFACE $<INSTALL_INTERFACE:include>
#)
target_link_libraries(
toki-libc-printf
PRIVATE
xil-headers
toki-libc-repl
PUBLIC toki-libc-repl-headers
toki-libc-repl-port
)
add_subdirectory(src)
if (WITH_PORTS)
message(STATUS "Building toki-libc-repl with\n\tport = ${TOKI_MACHINE}")
add_subdirectory(ports)
endif()
if (WITH_HEADERS)
add_subdirectory(include)
endif()
if (ENABLE_INSTALL)
# Configure and install the following files:
......@@ -51,69 +61,35 @@ if (ENABLE_INSTALL)
# ${PROJECT_NAME}-config.cmake
configure_package_config_file(
${PROJECT_NAME}-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
INSTALL_DESTINATION ${ConfigPackageLocation}
${PROJECT_NAME}-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
INSTALL_DESTINATION ${ConfigPackageLocation}
)
# ${PROJECT_NAME}-config-config-version.cmake
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
COMPATIBILITY SameMajorVersion
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
COMPATIBILITY SameMajorVersion
)
# Install exported CMake target files
install(
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION lib
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION lib
)
install(
EXPORT ${PROJECT_NAME}-targets
DESTINATION ${ConfigPackageLocation}
EXPORT_LINK_INTERFACE_LIBRARIES
EXPORT ${PROJECT_NAME}-targets
DESTINATION ${ConfigPackageLocation}
EXPORT_LINK_INTERFACE_LIBRARIES
)
# Install package/module configuration files
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
DESTINATION ${ConfigPackageLocation}
FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
DESTINATION ${ConfigPackageLocation}
)
# Install all header files of the current project
get_target_property(PROJECT_INCLUDE_DIRECTORIES ${PROJECT_NAME} INTERFACE_INCLUDE_DIRECTORIES)
foreach(DIR ${PROJECT_INCLUDE_DIRECTORIES})
string(REGEX MATCH "^.<BUILD_INTERFACE:(.*)>$" EXTRACTED_DIR ${DIR})
if (CMAKE_MATCH_1)
set(EXTRACTED_DIR "${CMAKE_MATCH_1}")
file(
GLOB_RECURSE
#
HEADER_FILES
#
FOLLOW_SYMLINKS
LIST_DIRECTORIES FALSE
RELATIVE "${EXTRACTED_DIR}"
#
"${EXTRACTED_DIR}/*.h"
"${EXTRACTED_DIR}/*.hpp"
)
foreach(FILE ${HEADER_FILES})
get_filename_component(INSTALL_PATH ${FILE} DIRECTORY)
install(
FILES ${EXTRACTED_DIR}/${FILE}
DESTINATION include/${INSTALL_PATH}
)
endforeach()
endif()
endforeach()
endif()
......@@ -4,21 +4,21 @@ option(ENABLE_INSTALL "Enable target installation possibility" ON)
project(
toki-libc-printf-headers
toki-libc-repl-headers
#
VERSION 0.1
LANGUAGES C ASM
)
add_library(
toki-libc-printf-headers
toki-libc-repl-headers
#
INTERFACE
)
target_include_directories(
toki-libc-printf-headers
toki-libc-repl-headers
#
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>
INTERFACE $<INSTALL_INTERFACE:include>
......
#ifndef TOKI_ASSERT_H
#define TOKI_ASSERT_H
#undef assert
#ifdef NDEBUG /* required by ANSI standard */
# define assert(__e) ((void)0)
#else
# define assert(__e) ((__e) ? (void)0 : __assert_func (__FILE__, __LINE__, _func__, #__e))
#endif
#endif /* TOKI_ASSERT_H */
#ifndef TOKI_CTYPE_H
#define TOKI_CTYPE_H
#define isalpha __builtin_isalpha
#define isdigit __builtin_isdigit
#define isgraph __builtin_isgraph
#define islower __builtin_islower
#define isprint __builtin_isprint
#define ispunct __builtin_ispunct
#define isspace __builtin_isspace
#define isupper __builtin_isupper
#define isxdigit __builtin_isxdigit
#define tolower __builtin_tolower
#define toupper __builtin_toupper
#endif /* TOKI_CTYPE_H */
#ifndef __MALLOC_FREELIST_H_
#define __MALLOC_FREELIST_H_
// Copyright: https://github.com/embeddedartistry/embedded-resources/tree/master/examples/c
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif //__cplusplus
/**
* Initialize malloc with a memory address and pool size
*/
void malloc_addblock(void *addr, size_t size);
/**
* Free-list malloc implementation
*/
#define malloc fl_malloc
void * fl_malloc(size_t size);
/**
* Corresponding free-list free implementation
*/
#define free fl_free
void fl_free(void * ptr);
#ifdef __cplusplus
}
#endif //__cplusplus
#endif //__MALLOC_FREELIST_H_
#ifndef TOKI_STRING_H
#define TOKI_STRING_H
#include <stddef.h>
void *memcpy(void *dest, const void *src, size_t n);
void *memset(void *s, int c, size_t n);
int strcmp(const char *s1, const char *s2);
size_t strlen(const char *s);
size_t strnlen(const char *s, size_t maxlen);
#define memchr __builtin_memchr
#define memcmp __builtin_memcmp
#define strcat __builtin_strcat
#define strchr __builtin_strchr
#define strcpy __builtin_strcpy
#define strcspn __builtin_strcspn
#define strncat __builtin_strncat
#define strncmp __builtin_strncmp
#define strncpy __builtin_strncpy
#define strpbrk __builtin_strpbrk
#define strrchr __builtin_strrchr
#define strspn __builtin_strspn
#define strstr __builtin_strstr
#endif /* TOKI_STRING_H */
......@@ -3,6 +3,6 @@
include(CMakeFindDependencyMacro)
# Import targets
include(${CMAKE_CURRENT_LIST_DIR}/toki-libc-printf-headers-targets.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/toki-libc-repl-headers-targets.cmake)
check_required_components(toki-libc-printf-headers)
check_required_components(toki-libc-repl-headers)
add_subdirectory(${TOKI_MACHINE})
......@@ -4,14 +4,14 @@ option(ENABLE_INSTALL "Enable target installation possibility" ON)
project(
toki-libc-printf-port
toki-libc-repl-port
#
VERSION 0.1
LANGUAGES C ASM
)
find_package(
toki-libc-printf-headers 0.1
toki-libc-repl-headers 0.1
REQUIRED
)
......@@ -22,16 +22,16 @@ find_package(
add_library(
toki-libc-printf-port
toki-libc-repl-port
#
STATIC
"" # The sources are added in the respective sub-folders
)
target_link_libraries(
toki-libc-printf-port
toki-libc-repl-port
PRIVATE
toki-libc-printf-headers
toki-libc-repl-headers
xil-headers
)
......@@ -50,35 +50,35 @@ if (ENABLE_INSTALL)
# ${PROJECT_NAME}-config.cmake
configure_package_config_file(
${PROJECT_NAME}-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
INSTALL_DESTINATION ${ConfigPackageLocation}
${PROJECT_NAME}-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
INSTALL_DESTINATION ${ConfigPackageLocation}
)
# ${PROJECT_NAME}-config-config-version.cmake
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
COMPATIBILITY SameMajorVersion
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
COMPATIBILITY SameMajorVersion
)
# Install exported CMake target files
install(
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION lib
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION lib
)
install(
EXPORT ${PROJECT_NAME}-targets
DESTINATION ${ConfigPackageLocation}
EXPORT_LINK_INTERFACE_LIBRARIES
EXPORT ${PROJECT_NAME}-targets
DESTINATION ${ConfigPackageLocation}
EXPORT_LINK_INTERFACE_LIBRARIES
)
# Install package/module configuration files
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
DESTINATION ${ConfigPackageLocation}
FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
DESTINATION ${ConfigPackageLocation}
)
endif()
cmake_minimum_required(VERSION 3.7 FATAL_ERROR)
target_sources(
toki-libc-printf-port
toki-libc-repl-port
#
PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/putchar.c"
......
@PACKAGE_INIT@
include(CMakeFindDependencyMacro)
find_dependency(xil-headers 7.0)
find_dependency(toki-libc-printf-headers 0.1)
# Import targets
include(${CMAKE_CURRENT_LIST_DIR}/toki-libc-printf-port-targets.cmake)
check_required_components(toki-libc-printf-port)
......@@ -3,8 +3,9 @@
include(CMakeFindDependencyMacro)
find_dependency(xil-headers 7.0)
find_dependency(toki-libc-repl-headers 0.1)
# Import targets
include(${CMAKE_CURRENT_LIST_DIR}/toki-libc-printf-targets.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/toki-libc-repl-port-targets.cmake)
check_required_components(toki-libc-printf)
check_required_components(toki-libc-repl-port)
cmake_minimum_required(VERSION 3.7 FATAL_ERROR)
target_sources(
toki-libc-printf
#
PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/printf.c"
)
add_subdirectory(malloc)
add_subdirectory(printf)
add_subdirectory(string)
cmake_minimum_required(VERSION 3.7 FATAL_ERROR)
target_sources(
toki-libc-repl
#
PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/malloc_freelist.c"
)
CC0 1.0 Universal
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.
For more information, please see
<http://creativecommons.org/publicdomain/zero/1.0/>
// Copyright Embedded Artistry LLC 2017
// Released under CC0 1.0 Universal License
// Copyright: https://github.com/embeddedartistry/embedded-resources/tree/master/examples/c
#ifndef __LL_H_
#define __LL_H_
#include <stdlib.h> //size_t, NULL
/**
* Define offsetof and container_of if we don't have them already
*/
#ifndef offsetof
#ifdef __compiler_offsetof
#define offsetof(TYPE, MEMBER) __compiler_offsetof(TYPE, MEMBER)
#else
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif
#endif //offsetof
#ifndef container_of
#define container_of(ptr, type, member) ({ \
const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
#endif //container_of
#ifdef __cplusplus
extern "C" {
#endif //__cplusplus
/*
* This is a doubly linked list structure.
* This structure should be embedded in a container structure that you want to list.
*/
typedef struct ll_head {
struct ll_head *next; /**< Next pointer */
struct ll_head *prev; /**< Previous pointer */
} ll_t;
#define list_entry(ptr, type, member) container_of(ptr, type, member)
#define list_first_entry(head, type, member) list_entry((head)->next, type, member)
#define list_for_each(pos, head) \
for (pos = (head)->next; pos != (head); pos = pos->next)
#define list_for_each_safe(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)
#define list_for_each_entry(pos, head, member) \
for (pos = list_entry((head)->next, __typeof__(*pos), member); \
&pos->member != (head); \
pos = list_entry(pos->member.next, __typeof__(*pos), member))
#define list_for_each_entry_safe(pos, n, head, member) \
for (pos = list_entry((head)->next, __typeof__(*pos), member), \
n = list_entry(pos->member.next, __typeof__(*pos), member); \
&pos->member != (head); \
pos = n, n = list_entry(n->member.next, __typeof__(*n), member))
#pragma mark - Init -
#define ll_head_INIT(name) { &(name), &(name) }
#define LIST_INIT(name) struct ll_head name = ll_head_INIT(name)
#pragma mark - Add -
static inline void list_add_(struct ll_head *n, struct ll_head *prev,
struct ll_head *next)
{
next->prev = n;
n->next = next;
n->prev = prev;
prev->next = n;
}
static inline void list_add(struct ll_head *n, struct ll_head *head)
{
list_add_(n, head, head->next);
}
static inline void list_add_tail(struct ll_head *n, struct ll_head *head)
{
list_add_(n, head->prev, head);
}