mirror of
https://github.com/tailix/libkernaux.git
synced 2025-02-17 15:45:32 -05:00
Split features and packages, always do assertions
This commit is contained in:
parent
e3a1284aaf
commit
74cb78f63a
6 changed files with 80 additions and 73 deletions
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
|
@ -17,9 +17,9 @@ jobs:
|
||||||
null_guard: ['--enable-null-guard', '--disable-null-guard']
|
null_guard: ['--enable-null-guard', '--disable-null-guard']
|
||||||
werror:
|
werror:
|
||||||
- cflag: '-Werror'
|
- cflag: '-Werror'
|
||||||
mb2: '--disable-multiboot2'
|
mb2: '--without-multiboot2'
|
||||||
- cflag: ''
|
- cflag: ''
|
||||||
mb2: '--enable-multiboot2'
|
mb2: '--with-multiboot2'
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: dependencies
|
- name: dependencies
|
||||||
|
|
20
Makefile.am
20
Makefile.am
|
@ -10,6 +10,8 @@ AM_CFLAGS = \
|
||||||
lib_LIBRARIES = libkernaux.a
|
lib_LIBRARIES = libkernaux.a
|
||||||
|
|
||||||
TESTS = \
|
TESTS = \
|
||||||
|
examples/assert_return \
|
||||||
|
examples/assert_simple \
|
||||||
examples/printf \
|
examples/printf \
|
||||||
examples/printf_va \
|
examples/printf_va \
|
||||||
tests/test_itoa \
|
tests/test_itoa \
|
||||||
|
@ -31,29 +33,23 @@ if ARCH_X86_64
|
||||||
libkernaux_a_SOURCES += src/arch/x86_64.S
|
libkernaux_a_SOURCES += src/arch/x86_64.S
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if ENABLE_ASSERT
|
if WITH_CMDLINE
|
||||||
TESTS += \
|
|
||||||
examples/assert_return \
|
|
||||||
examples/assert_simple
|
|
||||||
endif
|
|
||||||
|
|
||||||
if ENABLE_CMDLINE
|
|
||||||
libkernaux_a_SOURCES += src/cmdline.c
|
libkernaux_a_SOURCES += src/cmdline.c
|
||||||
TESTS += \
|
TESTS += \
|
||||||
examples/cmdline \
|
examples/cmdline \
|
||||||
tests/test_cmdline
|
tests/test_cmdline
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if ENABLE_CONSOLE
|
if WITH_CONSOLE
|
||||||
libkernaux_a_SOURCES += src/console.c
|
libkernaux_a_SOURCES += src/console.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if ENABLE_ELF
|
if WITH_ELF
|
||||||
libkernaux_a_SOURCES += src/elf.c
|
libkernaux_a_SOURCES += src/elf.c
|
||||||
TESTS += tests/test_elf
|
TESTS += tests/test_elf
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if ENABLE_MULTIBOOT2
|
if WITH_MULTIBOOT2
|
||||||
libkernaux_a_SOURCES += \
|
libkernaux_a_SOURCES += \
|
||||||
src/multiboot2/helpers.c \
|
src/multiboot2/helpers.c \
|
||||||
src/multiboot2/is_valid.c \
|
src/multiboot2/is_valid.c \
|
||||||
|
@ -67,7 +63,7 @@ noinst_PROGRAMS += \
|
||||||
tests/multiboot2_print2
|
tests/multiboot2_print2
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if ENABLE_PFA
|
if WITH_PFA
|
||||||
libkernaux_a_SOURCES += src/pfa.c
|
libkernaux_a_SOURCES += src/pfa.c
|
||||||
TESTS += \
|
TESTS += \
|
||||||
examples/pfa \
|
examples/pfa \
|
||||||
|
@ -75,7 +71,7 @@ TESTS += \
|
||||||
tests/test_pfa_assert
|
tests/test_pfa_assert
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if ENABLE_UNITS
|
if WITH_UNITS
|
||||||
libkernaux_a_SOURCES += src/units.c
|
libkernaux_a_SOURCES += src/units.c
|
||||||
TESTS += \
|
TESTS += \
|
||||||
examples/units_human \
|
examples/units_human \
|
||||||
|
|
|
@ -106,7 +106,7 @@ cross-compiler in `$PATH` to make without it in `$PATH`:
|
||||||
```
|
```
|
||||||
./configure \
|
./configure \
|
||||||
--host='i386-elf' \
|
--host='i386-elf' \
|
||||||
--enable-libc \
|
--with-libc \
|
||||||
AR="$(which i386-elf-ar)" \
|
AR="$(which i386-elf-ar)" \
|
||||||
CC="$(which i386-elf-gcc)" \
|
CC="$(which i386-elf-gcc)" \
|
||||||
RANLIB="$(which i386-elf-ranlib)" \
|
RANLIB="$(which i386-elf-ranlib)" \
|
||||||
|
|
102
configure.ac
102
configure.ac
|
@ -10,62 +10,86 @@ AC_CONFIG_SRCDIR([src/pfa.c])
|
||||||
|
|
||||||
AC_CANONICAL_HOST
|
AC_CANONICAL_HOST
|
||||||
|
|
||||||
AC_ARG_ENABLE([cmdline], AS_HELP_STRING([--disable-cmdline], [disable command line parser]))
|
|
||||||
AC_ARG_ENABLE([console], AS_HELP_STRING([--disable-console], [disable serial console]))
|
|
||||||
AC_ARG_ENABLE([elf], AS_HELP_STRING([--disable-elf], [disable ELF utils]))
|
|
||||||
AC_ARG_ENABLE([multiboot2], AS_HELP_STRING([--disable-multiboot2], [disable Multiboot 2 information parser]))
|
|
||||||
AC_ARG_ENABLE([pfa], AS_HELP_STRING([--disable-pfa], [disable Page Frame Allocator]))
|
|
||||||
AC_ARG_ENABLE([units], AS_HELP_STRING([--disable-units], [disable measurement units utils]))
|
|
||||||
|
|
||||||
|
|
||||||
|
dnl Features (disabled by default)
|
||||||
AC_ARG_ENABLE([assert], AS_HELP_STRING([--enable-assert], [enable runtime assertions]))
|
AC_ARG_ENABLE([assert], AS_HELP_STRING([--enable-assert], [enable runtime assertions]))
|
||||||
AC_ARG_ENABLE([libc], AS_HELP_STRING([--enable-libc], [enable libc replacement]))
|
|
||||||
AC_ARG_ENABLE([libc-memset], AS_HELP_STRING([--enable-libc-memset], [enable memset replacement]))
|
|
||||||
AC_ARG_ENABLE([libc-strcpy], AS_HELP_STRING([--enable-libc-strcpy], [enable strcpy replacement]))
|
|
||||||
AC_ARG_ENABLE([libc-strlen], AS_HELP_STRING([--enable-libc-strlen], [enable strlen replacement]))
|
|
||||||
AC_ARG_ENABLE([null-guard], AS_HELP_STRING([--enable-null-guard], [enable NULL-guard]))
|
AC_ARG_ENABLE([null-guard], AS_HELP_STRING([--enable-null-guard], [enable NULL-guard]))
|
||||||
|
|
||||||
AC_DEFUN([do_enable_libc],
|
dnl Packages (enabled by default)
|
||||||
[
|
AC_ARG_WITH( [cmdline], AS_HELP_STRING([--without-cmdline], [without command line parser]))
|
||||||
if test -z "$enable_libc_memset"; then enable_libc_memset=yes; fi
|
AC_ARG_WITH( [console], AS_HELP_STRING([--without-console], [without serial console]))
|
||||||
if test -z "$enable_libc_strcpy"; then enable_libc_strcpy=yes; fi
|
AC_ARG_WITH( [elf], AS_HELP_STRING([--without-elf], [without ELF utils]))
|
||||||
if test -z "$enable_libc_strlen"; then enable_libc_strlen=yes; fi
|
AC_ARG_WITH( [multiboot2], AS_HELP_STRING([--without-multiboot2], [without Multiboot 2 information parser]))
|
||||||
])
|
AC_ARG_WITH( [pfa], AS_HELP_STRING([--without-pfa], [without Page Frame Allocator]))
|
||||||
AS_IF([test "$enable_libc" = yes], do_enable_libc)
|
AC_ARG_WITH( [units], AS_HELP_STRING([--without-units], [without measurement units utils]))
|
||||||
|
|
||||||
|
dnl Packages (disabled by default)
|
||||||
|
AC_ARG_WITH( [libc], AS_HELP_STRING([--with-libc], [with libc replacement]))
|
||||||
|
AC_ARG_WITH( [libc-memset], AS_HELP_STRING([--with-libc-memset], [with memset replacement]))
|
||||||
|
AC_ARG_WITH( [libc-strcpy], AS_HELP_STRING([--with-libc-strcpy], [with strcpy replacement]))
|
||||||
|
AC_ARG_WITH( [libc-strlen], AS_HELP_STRING([--with-libc-strlen], [with strlen replacement]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
AC_DEFUN([do_with_libc],
|
||||||
|
[
|
||||||
|
if test -z "$with_libc_memset"; then with_libc_memset=yes; fi
|
||||||
|
if test -z "$with_libc_strcpy"; then with_libc_strcpy=yes; fi
|
||||||
|
if test -z "$with_libc_strlen"; then with_libc_strlen=yes; fi
|
||||||
|
])
|
||||||
|
AS_IF([test "$with_libc" = yes], do_with_libc)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
dnl Architecture
|
||||||
AM_CONDITIONAL([ARCH_I386], [test "$host_cpu" = i386])
|
AM_CONDITIONAL([ARCH_I386], [test "$host_cpu" = i386])
|
||||||
AM_CONDITIONAL([ARCH_X86_64], [test "$host_cpu" = x86_64])
|
AM_CONDITIONAL([ARCH_X86_64], [test "$host_cpu" = x86_64])
|
||||||
|
|
||||||
AM_CONDITIONAL([ENABLE_CMDLINE], [test "$enable_cmdline" != no])
|
dnl Features (disabled by default)
|
||||||
AM_CONDITIONAL([ENABLE_CONSOLE], [test "$enable_console" != no])
|
|
||||||
AM_CONDITIONAL([ENABLE_ELF], [test "$enable_elf" != no])
|
|
||||||
AM_CONDITIONAL([ENABLE_MULTIBOOT2], [test "$enable_multiboot2" != no])
|
|
||||||
AM_CONDITIONAL([ENABLE_PFA], [test "$enable_pfa" != no])
|
|
||||||
AM_CONDITIONAL([ENABLE_UNITS], [test "$enable_units" != no])
|
|
||||||
|
|
||||||
AM_CONDITIONAL([ENABLE_ASSERT], [test "$enable_assert" = yes])
|
AM_CONDITIONAL([ENABLE_ASSERT], [test "$enable_assert" = yes])
|
||||||
AM_CONDITIONAL([ENABLE_LIBC], [test "$enable_libc" = yes])
|
|
||||||
AM_CONDITIONAL([ENABLE_LIBC_MEMSET], [test "$enable_libc_memset" = yes])
|
|
||||||
AM_CONDITIONAL([ENABLE_LIBC_STRCPY], [test "$enable_libc_strcpy" = yes])
|
|
||||||
AM_CONDITIONAL([ENABLE_LIBC_STRLEN], [test "$enable_libc_strlen" = yes])
|
|
||||||
AM_CONDITIONAL([ENABLE_NULL_GUARD], [test "$enable_null_guard" = yes])
|
AM_CONDITIONAL([ENABLE_NULL_GUARD], [test "$enable_null_guard" = yes])
|
||||||
|
|
||||||
|
dnl Packages (enabled by default)
|
||||||
|
AM_CONDITIONAL([WITH_CMDLINE], [test "$with_cmdline" != no])
|
||||||
|
AM_CONDITIONAL([WITH_CONSOLE], [test "$with_console" != no])
|
||||||
|
AM_CONDITIONAL([WITH_ELF], [test "$with_elf" != no])
|
||||||
|
AM_CONDITIONAL([WITH_MULTIBOOT2], [test "$with_multiboot2" != no])
|
||||||
|
AM_CONDITIONAL([WITH_PFA], [test "$with_pfa" != no])
|
||||||
|
AM_CONDITIONAL([WITH_UNITS], [test "$with_units" != no])
|
||||||
|
|
||||||
|
dnl Packages (disabled by default)
|
||||||
|
AM_CONDITIONAL([WITH_LIBC], [test "$with_libc" = yes])
|
||||||
|
AM_CONDITIONAL([WITH_LIBC_MEMSET], [test "$with_libc_memset" = yes])
|
||||||
|
AM_CONDITIONAL([WITH_LIBC_STRCPY], [test "$with_libc_strcpy" = yes])
|
||||||
|
AM_CONDITIONAL([WITH_LIBC_STRLEN], [test "$with_libc_strlen" = yes])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
dnl Architecture
|
||||||
AS_IF([test "$host_cpu" = i386], [AC_DEFINE([ARCH_I386], [1], [architecture is i386])])
|
AS_IF([test "$host_cpu" = i386], [AC_DEFINE([ARCH_I386], [1], [architecture is i386])])
|
||||||
AS_IF([test "$host_cpu" = x86_64], [AC_DEFINE([ARCH_X86_64], [1], [architecture is x86_64])])
|
AS_IF([test "$host_cpu" = x86_64], [AC_DEFINE([ARCH_X86_64], [1], [architecture is x86_64])])
|
||||||
|
|
||||||
AS_IF([test "$enable_cmdline" != no], [AC_DEFINE([ENABLE_CMDLINE], [1], [enabled command line parser])])
|
dnl Features (disabled by default)
|
||||||
AS_IF([test "$enable_console" != no], [AC_DEFINE([ENABLE_CONSOLE], [1], [enabled serial console])])
|
|
||||||
AS_IF([test "$enable_elf" != no], [AC_DEFINE([ENABLE_ELF], [1], [enabled ELF utils])])
|
|
||||||
AS_IF([test "$enable_multiboot2" != no], [AC_DEFINE([ENABLE_MULTIBOOT2], [1], [enabled Multiboot 2 information parser])])
|
|
||||||
AS_IF([test "$enable_pfa" != no], [AC_DEFINE([ENABLE_PFA], [1], [enabled Page Frame Allocator])])
|
|
||||||
AS_IF([test "$enable_units", != no], [AC_DEFINE([ENABLE_UNITS], [1], [enabled measurement units utils])])
|
|
||||||
|
|
||||||
AS_IF([test "$enable_assert" = yes], [AC_DEFINE([KERNAUX_ENABLE_ASSERT], [1], [enabled runtime assertions])])
|
AS_IF([test "$enable_assert" = yes], [AC_DEFINE([KERNAUX_ENABLE_ASSERT], [1], [enabled runtime assertions])])
|
||||||
AS_IF([test "$enable_libc" = yes], [AC_DEFINE([ENABLE_LIBC], [1], [enabled libc replacement])])
|
|
||||||
AS_IF([test "$enable_libc_memset" = yes], [AC_DEFINE([ENABLE_LIBC_MEMSET], [1], [enabled memset replacement])])
|
|
||||||
AS_IF([test "$enable_libc_strcpy" = yes], [AC_DEFINE([ENABLE_LIBC_STRCPY], [1], [enabled strcpy replacement])])
|
|
||||||
AS_IF([test "$enable_libc_strlen" = yes], [AC_DEFINE([ENABLE_LIBC_STRLEN], [1], [enabled strlen replacement])])
|
|
||||||
AS_IF([test "$enable_null_guard" = yes], [AC_DEFINE([KERNAUX_ENABLE_NULL_GUARD], [1], [enabled NULL-guard])])
|
AS_IF([test "$enable_null_guard" = yes], [AC_DEFINE([KERNAUX_ENABLE_NULL_GUARD], [1], [enabled NULL-guard])])
|
||||||
|
|
||||||
|
dnl Packages (enabled by default)
|
||||||
|
AS_IF([test "$with_cmdline" != no], [AC_DEFINE([WITH_CMDLINE], [1], [with command line parser])])
|
||||||
|
AS_IF([test "$with_console" != no], [AC_DEFINE([WITH_CONSOLE], [1], [with serial console])])
|
||||||
|
AS_IF([test "$with_elf" != no], [AC_DEFINE([WITH_ELF], [1], [with ELF utils])])
|
||||||
|
AS_IF([test "$with_multiboot2" != no], [AC_DEFINE([WITH_MULTIBOOT2], [1], [with Multiboot 2 information parser])])
|
||||||
|
AS_IF([test "$with_pfa" != no], [AC_DEFINE([WITH_PFA], [1], [with Page Frame Allocator])])
|
||||||
|
AS_IF([test "$with_units", != no], [AC_DEFINE([WITH_UNITS], [1], [with measurement units utils])])
|
||||||
|
|
||||||
|
dnl Packages (disabled by default)
|
||||||
|
AS_IF([test "$with_libc" = yes], [AC_DEFINE([WITH_LIBC], [1], [with libc replacement])])
|
||||||
|
AS_IF([test "$with_libc_memset" = yes], [AC_DEFINE([WITH_LIBC_MEMSET], [1], [with memset replacement])])
|
||||||
|
AS_IF([test "$with_libc_strcpy" = yes], [AC_DEFINE([WITH_LIBC_STRCPY], [1], [with strcpy replacement])])
|
||||||
|
AS_IF([test "$with_libc_strlen" = yes], [AC_DEFINE([WITH_LIBC_STRLEN], [1], [with strlen replacement])])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AM_INIT_AUTOMAKE([1.9 subdir-objects -Wall -Werror])
|
AM_INIT_AUTOMAKE([1.9 subdir-objects -Wall -Werror])
|
||||||
|
|
||||||
AC_CONFIG_FILES([
|
AC_CONFIG_FILES([
|
||||||
|
|
13
src/assert.c
13
src/assert.c
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
void (*kernaux_assert_cb)(const char *file, int line, const char *str) = NULL;
|
void (*kernaux_assert_cb)(const char *file, int line, const char *str) = NULL;
|
||||||
|
|
||||||
#ifdef KERNAUX_ENABLE_ASSERT
|
|
||||||
void kernaux_assert_do(
|
void kernaux_assert_do(
|
||||||
const char *const file,
|
const char *const file,
|
||||||
const int line,
|
const int line,
|
||||||
|
@ -16,15 +15,3 @@ void kernaux_assert_do(
|
||||||
) {
|
) {
|
||||||
if (kernaux_assert_cb) kernaux_assert_cb(file, line, str);
|
if (kernaux_assert_cb) kernaux_assert_cb(file, line, str);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
void kernaux_assert_do(
|
|
||||||
__attribute__((unused))
|
|
||||||
const char *const file,
|
|
||||||
__attribute__((unused))
|
|
||||||
const int line,
|
|
||||||
__attribute__((unused))
|
|
||||||
const char *const str
|
|
||||||
) {
|
|
||||||
// Do nothing.
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
12
src/libc.c
12
src/libc.c
|
@ -4,29 +4,29 @@
|
||||||
|
|
||||||
#include <kernaux/libc.h>
|
#include <kernaux/libc.h>
|
||||||
|
|
||||||
#ifdef ENABLE_LIBC_MEMSET
|
#ifdef WITH_LIBC_MEMSET
|
||||||
void *memset(void *s, int c, size_t n)
|
void *memset(void *s, int c, size_t n)
|
||||||
{
|
{
|
||||||
char *ss = s;
|
char *ss = s;
|
||||||
while (n-- > 0) *ss++ = c;
|
while (n-- > 0) *ss++ = c;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
#endif // ENABLE_LIBC_MEMSET
|
#endif // WITH_LIBC_MEMSET
|
||||||
|
|
||||||
#ifdef ENABLE_LIBC_STRCPY
|
#ifdef WITH_LIBC_STRCPY
|
||||||
char *strcpy(char *dest, const char *src)
|
char *strcpy(char *dest, const char *src)
|
||||||
{
|
{
|
||||||
char *tmp = dest;
|
char *tmp = dest;
|
||||||
while ((*dest++ = *src++) != '\0');
|
while ((*dest++ = *src++) != '\0');
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
#endif // ENABLE_LIBC_STRCPY
|
#endif // WITH_LIBC_STRCPY
|
||||||
|
|
||||||
#ifdef ENABLE_LIBC_STRLEN
|
#ifdef WITH_LIBC_STRLEN
|
||||||
size_t strlen(const char *s)
|
size_t strlen(const char *s)
|
||||||
{
|
{
|
||||||
const char *ss = s;
|
const char *ss = s;
|
||||||
while (*ss != '\0') ++ss;
|
while (*ss != '\0') ++ss;
|
||||||
return ss - s;
|
return ss - s;
|
||||||
}
|
}
|
||||||
#endif // ENABLE_LIBC_STRLEN
|
#endif // WITH_LIBC_STRLEN
|
||||||
|
|
Loading…
Add table
Reference in a new issue