1
0
Fork 0
mirror of https://github.com/tailix/libclayer.git synced 2024-11-20 11:06:24 -05:00

Separate libc and libclayer

This commit is contained in:
Alex Kotov 2022-12-27 13:05:30 +04:00
parent c06e977c84
commit 881f6ecb5b
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
25 changed files with 249 additions and 199 deletions

View file

@ -83,26 +83,6 @@ jobs:
- name: install
run: sudo make install
cond:
runs-on: ubuntu-latest
strategy:
matrix:
packages:
- without: 'all'
- without: 'io'
steps:
- uses: actions/checkout@v2
- name: autogen
run: ./autogen.sh
- name: configure
run: ./configure --enable-checks --without-${{matrix.packages.without}}
- name: make
run: make
- name: check
run: make check
- name: install
run: sudo make install
freestanding:
runs-on: ubuntu-latest
steps:

View file

@ -10,7 +10,18 @@ if ENABLE_CHECKS
SUBDIRS += tests
endif
lib_LTLIBRARIES = libclayer.la
lib_LTLIBRARIES =
if ENABLE_LIBCLAYER
lib_LTLIBRARIES += libclayer.la
libclayer_la_SOURCES = $(common_sources)
endif
if ENABLE_LIBC
lib_LTLIBRARIES += libc.la
libc_la_SOURCES = $(common_sources)
libc_la_CFLAGS = $(AM_CFLAGS) -DLIBCLAYER_NOPREFIX
endif
if ENABLE_PKG_CONFIG
pkgconfigdir = @pkgconfdir@
@ -21,7 +32,7 @@ endif
# Required files #
##################
libclayer_la_SOURCES = \
common_sources = \
src/ctype.c \
src/errno.c \
src/libclayer.c \
@ -29,13 +40,13 @@ libclayer_la_SOURCES = \
src/string.c
if ASM_I386
libclayer_la_SOURCES += \
common_sources += \
src/asm/i386/longjmp.S \
src/asm/i386/setjmp.S
endif
if ASM_X86_64
libclayer_la_SOURCES += \
common_sources += \
src/asm/x86_64/longjmp.S \
src/asm/x86_64/setjmp.S
endif

View file

@ -42,7 +42,7 @@ AC_SUBST([PACKAGE_DESCR], ['libc for both hosted and freestanding environments']
dnl Features (enabled by default)
AC_ARG_ENABLE([float], AS_HELP_STRING([--disable-float], [disable floating-point arithmetic]))
AC_ARG_ENABLE([prefix], AS_HELP_STRING([--disable-prefix], [disable name prefix]))
AC_ARG_ENABLE([libclayer], AS_HELP_STRING([--disable-libclayer], [install as libclayer]))
AC_ARG_ENABLE([werror], AS_HELP_STRING([--disable-werror], [disable -Werror]))
dnl Features (disabled by default)
@ -50,6 +50,7 @@ AC_ARG_ENABLE([freestanding], AS_HELP_STRING([--enable-freestanding], [bui
AC_ARG_ENABLE([checks], AS_HELP_STRING([--enable-checks], [enable usual tests]))
AC_ARG_ENABLE([checks-all], AS_HELP_STRING([--enable-checks-all], [enable all checks]))
AC_ARG_ENABLE([checks-cppcheck], AS_HELP_STRING([--enable-checks-cppcheck], [enable cppcheck]))
AC_ARG_ENABLE([libc], AS_HELP_STRING([--enable-libc], [install as libc]))
dnl Features (with parameter)
AC_ARG_ENABLE([pkg-config], AS_HELP_STRING([--enable-pkg-config@<:@=PATH@:>@], [install pkg-config files @<:@PATH='${libdir}/pkgconfig'@:>@]))
@ -75,7 +76,7 @@ AS_IF([test "$enable_checks_all" = yes], do_enable_checks_all)
dnl Features (enabled by default)
AS_IF([test "$enable_float" = no ], [enable_float=no], [enable_float=yes])
AS_IF([test "$enable_prefix" = no ], [enable_prefix=no], [enable_prefix=yes])
AS_IF([test "$enable_libclayer" = no ], [enable_libclayer=no], [enable_libclayer=yes])
AS_IF([test "$enable_werror" = no ], [enable_werror=no], [enable_werror=yes])
dnl Features (disabled by default)
@ -83,6 +84,7 @@ AS_IF([test "$enable_freestanding" = yes], [enable_freestanding=yes], [ena
AS_IF([test "$enable_checks" = yes], [enable_checks=yes], [enable_checks=no])
AS_IF([test "$enable_checks_all" = yes], [enable_checks_all=yes], [enable_checks_all=no])
AS_IF([test "$enable_checks_cppcheck" = yes], [enable_checks_cppcheck=yes], [enable_checks_cppcheck=no])
AS_IF([test "$enable_libc" = yes], [enable_libc=yes], [enable_libc=no])
dnl Features (with parameter)
AS_IF([test "$enable_pkg_config" = yes], [enable_pkg_config='${libdir}/pkgconfig'])
@ -95,7 +97,6 @@ AS_IF([test "$enable_pkg_config" = no ], [enable_pkg_config=''])
#############
AS_IF([test "$enable_checks" = yes -a "$enable_freestanding" = yes], AC_MSG_ERROR([can not build freestanding tests]))
AS_IF([test "$enable_checks" = yes -a "$enable_prefix" = no ], AC_MSG_ERROR([can not build tests without prefix]))
@ -113,13 +114,14 @@ AM_CONDITIONAL([ASM_X86], [test "$host_cpu" = i386 -o "$host_cpu"
dnl Features (enabled by default)
AM_CONDITIONAL([ENABLE_FLOAT], [test "$enable_float" = yes])
AM_CONDITIONAL([ENABLE_PREFIX], [test "$enable_prefix" = yes])
AM_CONDITIONAL([ENABLE_LIBCLAYER], [test "$enable_libclayer" = yes])
AM_CONDITIONAL([ENABLE_WERROR], [test "$enable_werror" = yes])
dnl Features (disabled by default)
AM_CONDITIONAL([ENABLE_FREESTANDING], [test "$enable_freestanding" = yes])
AM_CONDITIONAL([ENABLE_CHECKS], [test "$enable_checks" = yes])
AM_CONDITIONAL([ENABLE_CHECKS_CPPCHECK], [test "$enable_checks_cppcheck" = yes])
AM_CONDITIONAL([ENABLE_LIBC], [test "$enable_libc" = yes])
dnl Features (with parameter)
AM_CONDITIONAL([ENABLE_PKG_CONFIG], [test ! -z "$enable_pkg_config"])
@ -141,16 +143,14 @@ AS_IF([test "$host_cpu" = x86_64], [AC_DEFINE([ASM_X86],
dnl Features (enabled by default)
AS_IF([test "$enable_float" = yes], [AC_DEFINE([ENABLE_FLOAT], [1], [enabled floating-point arithmetic])])
AS_IF([test "$enable_prefix" = yes], [AC_DEFINE([ENABLE_PREFIX], [1], [enabled prefix])])
AS_IF([test "$enable_libclayer" = yes], [AC_DEFINE([ENABLE_LIBCLAYER], [1], [install as libclayer])])
AS_IF([test "$enable_werror" = yes], [AC_DEFINE([ENABLE_WERROR], [1], [enabled -Werror])])
dnl Features (disabled by default)
AS_IF([test "$enable_freestanding" = yes], [AC_DEFINE([ENABLE_FREESTANDING], [1], [build for freestanding environment])])
AS_IF([test "$enable_checks" = yes], [AC_DEFINE([ENABLE_CHECKS], [1], [enabled usual tests])])
AS_IF([test "$enable_checks_cppcheck" = yes], [AC_DEFINE([ENABLE_CHECKS_CPPCHECK], [1], [enabled cppcheck])])
dnl Additional
AS_IF([test "$enable_prefix" = yes], [AC_DEFINE([LIBCLAYER_PREFIX], [libclayer_], [prefix])])
AS_IF([test "$enable_libc" = yes], [AC_DEFINE([ENABLE_LIBC], [1], [install as libc])])

View file

@ -1,9 +1,20 @@
nobase_include_HEADERS = \
libclayer.h \
libclayer/ctype.h \
libclayer/errno.h \
libclayer/inttypes.h \
libclayer/setjmp.h \
libclayer/stdlib.h \
libclayer/string.h \
libclayer/sys/types.h
if ENABLE_LIBC
nobase_include_HEADERS += \
ctype.h \
errno.h \
inttypes.h \
libclayer.h \
setjmp.h \
stdlib.h \
string.h \
sys/types.h
endif

View file

@ -1,22 +1,7 @@
#ifndef _CTYPE_H
#define _CTYPE_H 1
#ifdef __cplusplus
extern "C" {
#endif
#include <libclayer.h>
int LIBCLAYER(isdigit)(int c);
int LIBCLAYER(islower)(int c);
int LIBCLAYER(isspace)(int c);
int LIBCLAYER(isupper)(int c);
int LIBCLAYER(tolower)(int c);
int LIBCLAYER(toupper)(int c);
#ifdef __cplusplus
}
#endif
#ifdef LIBCLAYER_NOPREFIX
#include <libclayer/ctype.h>
#else
#define LIBCLAYER_NOPREFIX
#include <libclayer/ctype.h>
#undef LIBCLAYER_NOPREFIX
#endif

View file

@ -1,18 +1,7 @@
#ifndef _ERRNO_H
#define _ERRNO_H 1
#ifdef __cplusplus
extern "C" {
#endif
#include <libclayer.h>
#define ERANGE 1
extern int LIBCLAYER(errno);
#ifdef __cplusplus
}
#endif
#ifdef LIBCLAYER_NOPREFIX
#include <libclayer/errno.h>
#else
#define LIBCLAYER_NOPREFIX
#include <libclayer/errno.h>
#undef LIBCLAYER_NOPREFIX
#endif

View file

@ -1,12 +1,7 @@
#ifndef _INTTYPES_H
#define _INTTYPES_H 1
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#ifdef LIBCLAYER_NOPREFIX
#include <libclayer/inttypes.h>
#else
#define LIBCLAYER_NOPREFIX
#include <libclayer/inttypes.h>
#undef LIBCLAYER_NOPREFIX
#endif

View file

@ -7,12 +7,10 @@ extern "C" {
#include <stddef.h>
#ifndef LIBCLAYER_PREFIX
#ifdef LIBCLAYER_NOPREFIX
#define LIBCLAYER(name) name
#else
#define LIBCLAYER(name) LIBCLAYER2(LIBCLAYER_PREFIX, name)
#define LIBCLAYER2(prefix, name) LIBCLAYER3(prefix, name)
#define LIBCLAYER3(prefix, name) prefix ## name
#define LIBCLAYER(name) libclayer_ ## name
#endif
struct Libclayer {

22
include/libclayer/ctype.h Normal file
View file

@ -0,0 +1,22 @@
#ifndef _LIBCLAYER_CTYPE_H
#define _LIBCLAYER_CTYPE_H 1
#ifdef __cplusplus
extern "C" {
#endif
#include <libclayer.h>
int LIBCLAYER(isdigit)(int c);
int LIBCLAYER(islower)(int c);
int LIBCLAYER(isspace)(int c);
int LIBCLAYER(isupper)(int c);
int LIBCLAYER(tolower)(int c);
int LIBCLAYER(toupper)(int c);
#ifdef __cplusplus
}
#endif
#endif

18
include/libclayer/errno.h Normal file
View file

@ -0,0 +1,18 @@
#ifndef _LIBCLAYER_ERRNO_H
#define _LIBCLAYER_ERRNO_H 1
#ifdef __cplusplus
extern "C" {
#endif
#include <libclayer.h>
#define ERANGE 1
extern int LIBCLAYER(errno);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,12 @@
#ifndef _LIBCLAYER_INTTYPES_H
#define _LIBCLAYER_INTTYPES_H 1
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,26 @@
#ifndef _LIBCLAYER_SETJMP_H
#define _LIBCLAYER_SETJMP_H 1
#ifdef __cplusplus
extern "C" {
#endif
#include <libclayer.h>
// TODO: define in architecture-specific header
typedef unsigned long __jmp_buf[sizeof(long) == 8 ? 8 : 6];
typedef struct __jmp_buf_tag {
__jmp_buf __jb;
unsigned long __fl;
unsigned long __ss[128 / sizeof(long)];
} jmp_buf[1];
int LIBCLAYER(setjmp)(jmp_buf env) __attribute__((returns_twice));
void LIBCLAYER(longjmp)(jmp_buf env, int val) __attribute__((noreturn));
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,28 @@
#ifndef _LIBCLAYER_STDLIB_H
#define _LIBCLAYER_STDLIB_H 1
#ifdef __cplusplus
extern "C" {
#endif
#include <libclayer.h>
#include <stddef.h>
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
int LIBCLAYER(atoi)(const char *str);
void LIBCLAYER(abort)() __attribute__((noreturn));
void LIBCLAYER(exit)(int status) __attribute__((noreturn));
void *LIBCLAYER(calloc)(size_t nmemb, size_t size);
void LIBCLAYER(free)(void *ptr);
void *LIBCLAYER(malloc)(size_t size);
void *LIBCLAYER(realloc)(void *ptr, size_t size);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,38 @@
#ifndef _LIBCLAYER_STRING_H
#define _LIBCLAYER_STRING_H 1
#ifdef __cplusplus
extern "C" {
#endif
#include <libclayer.h>
#include <stddef.h>
// mem*
int LIBCLAYER(memcmp)(const void *s1, const void *s2, size_t n);
void *LIBCLAYER(memcpy)(void *dest, const void *src, size_t n);
void *LIBCLAYER(memmove)(void *dest, const void *src, size_t n);
void *LIBCLAYER(memchr)(const void *s, int c, size_t n);
void *LIBCLAYER(memset)(void *s, int c, size_t n);
// str*
char *LIBCLAYER(strcat)(char *dest, const char *src);
char *LIBCLAYER(strchr)(const char *s, int c);
int LIBCLAYER(strcmp)(const char *s1, const char *s2);
char *LIBCLAYER(strcpy)(char *dest, const char *src);
size_t LIBCLAYER(strlen)(const char *s);
// strn*
char *LIBCLAYER(strncat)(char *dest, const char *src, size_t n);
int LIBCLAYER(strncmp)(const char *s1, const char *s2, size_t n);
char *LIBCLAYER(strncpy)(char *dest, const char *src, size_t n);
size_t LIBCLAYER(strnlen)(const char *s, size_t maxlen);
// str*
char *LIBCLAYER(strstr)(const char *haystack, const char *needle);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,12 @@
#ifndef _SYS_TYPES_H
#define _SYS_TYPES_H 1
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif

View file

@ -1,26 +1,7 @@
#ifndef _SETJMP_H
#define _SETJMP_H 1
#ifdef __cplusplus
extern "C" {
#endif
#include <libclayer.h>
// TODO: define in architecture-specific header
typedef unsigned long __jmp_buf[sizeof(long) == 8 ? 8 : 6];
typedef struct __jmp_buf_tag {
__jmp_buf __jb;
unsigned long __fl;
unsigned long __ss[128 / sizeof(long)];
} jmp_buf[1];
int LIBCLAYER(setjmp)(jmp_buf env) __attribute__((returns_twice));
void LIBCLAYER(longjmp)(jmp_buf env, int val) __attribute__((noreturn));
#ifdef __cplusplus
}
#endif
#ifdef LIBCLAYER_NOPREFIX
#include <libclayer/setjmp.h>
#else
#define LIBCLAYER_NOPREFIX
#include <libclayer/setjmp.h>
#undef LIBCLAYER_NOPREFIX
#endif

View file

@ -1,28 +1,7 @@
#ifndef _STDLIB_H
#define _STDLIB_H 1
#ifdef __cplusplus
extern "C" {
#endif
#include <libclayer.h>
#include <stddef.h>
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
int LIBCLAYER(atoi)(const char *str);
void LIBCLAYER(abort)() __attribute__((noreturn));
void LIBCLAYER(exit)(int status) __attribute__((noreturn));
void *LIBCLAYER(calloc)(size_t nmemb, size_t size);
void LIBCLAYER(free)(void *ptr);
void *LIBCLAYER(malloc)(size_t size);
void *LIBCLAYER(realloc)(void *ptr, size_t size);
#ifdef __cplusplus
}
#endif
#ifdef LIBCLAYER_NOPREFIX
#include <libclayer/stdlib.h>
#else
#define LIBCLAYER_NOPREFIX
#include <libclayer/stdlib.h>
#undef LIBCLAYER_NOPREFIX
#endif

View file

@ -1,38 +1,7 @@
#ifndef _STRING_H
#define _STRING_H 1
#ifdef __cplusplus
extern "C" {
#endif
#include <libclayer.h>
#include <stddef.h>
// mem*
int LIBCLAYER(memcmp)(const void *s1, const void *s2, size_t n);
void *LIBCLAYER(memcpy)(void *dest, const void *src, size_t n);
void *LIBCLAYER(memmove)(void *dest, const void *src, size_t n);
void *LIBCLAYER(memchr)(const void *s, int c, size_t n);
void *LIBCLAYER(memset)(void *s, int c, size_t n);
// str*
char *LIBCLAYER(strcat)(char *dest, const char *src);
char *LIBCLAYER(strchr)(const char *s, int c);
int LIBCLAYER(strcmp)(const char *s1, const char *s2);
char *LIBCLAYER(strcpy)(char *dest, const char *src);
size_t LIBCLAYER(strlen)(const char *s);
// strn*
char *LIBCLAYER(strncat)(char *dest, const char *src, size_t n);
int LIBCLAYER(strncmp)(const char *s1, const char *s2, size_t n);
char *LIBCLAYER(strncpy)(char *dest, const char *src, size_t n);
size_t LIBCLAYER(strnlen)(const char *s, size_t maxlen);
// str*
char *LIBCLAYER(strstr)(const char *haystack, const char *needle);
#ifdef __cplusplus
}
#endif
#ifdef LIBCLAYER_NOPREFIX
#include <libclayer/string.h>
#else
#define LIBCLAYER_NOPREFIX
#include <libclayer/string.h>
#undef LIBCLAYER_NOPREFIX
#endif

View file

@ -1,12 +1,7 @@
#ifndef _SYS_TYPES_H
#define _SYS_TYPES_H 1
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#ifdef LIBCLAYER_NOPREFIX
#include <libclayer/sys/types.h>
#else
#define LIBCLAYER_NOPREFIX
#include <libclayer/sys/types.h>
#undef LIBCLAYER_NOPREFIX
#endif

View file

@ -13,7 +13,6 @@ CPPCHECK_ARGS = \
--error-exitcode=1 \
--std=c99 \
--inline-suppr \
-ULIBCLAYER_PREFIX \
--enable=warning,style,performance,portability
CPPCHECK_INC = \

View file

@ -2,7 +2,7 @@
#include "config.h"
#endif
#include <ctype.h>
#include <libclayer/ctype.h>
int LIBCLAYER(isdigit)(const int c)
{

View file

@ -2,6 +2,6 @@
#include "config.h"
#endif
#include <errno.h>
#include <libclayer/errno.h>
int LIBCLAYER(errno) = 0;

View file

@ -3,11 +3,11 @@
#endif
#include <libclayer.h>
#include <libclayer/ctype.h>
#include <libclayer/stdlib.h>
#include <libclayer/string.h>
#include <ctype.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
void LIBCLAYER(exit)(const int status)
{

View file

@ -2,8 +2,9 @@
#include "config.h"
#endif
#include <libclayer/string.h>
#include <stddef.h>
#include <string.h>
int LIBCLAYER(memcmp)(const void *s1, const void *s2, size_t n)
{

View file

@ -1,6 +1,7 @@
#include <libclayer/string.h>
#include <assert.h>
#include <stddef.h>
#include <string.h>
void test_main()
{