From 58fbbbca5a1f6b94885ce47e46c28e1cd03583d7 Mon Sep 17 00:00:00 2001 From: axtloss Date: Sun, 14 Jul 2024 17:44:20 +0200 Subject: move to autotools --- Makefile | 43 ------------------------------------------- Makefile.am | 8 ++++++++ configure.ac | 30 ++++++++++++++++++++++++++++++ extlib.pc.in | 3 ++- src/Makefile.am | 4 ++++ src/extlib.c | 7 +++---- src/extlib.h | 4 +++- src/memset_s.c | 2 +- 8 files changed, 51 insertions(+), 50 deletions(-) delete mode 100644 Makefile create mode 100644 Makefile.am create mode 100644 configure.ac create mode 100644 src/Makefile.am diff --git a/Makefile b/Makefile deleted file mode 100644 index 4934e3c..0000000 --- a/Makefile +++ /dev/null @@ -1,43 +0,0 @@ -.POSIX: - -CC = cc -CFLAGS = -g -PREFIX = /usr - -TESTCFLAGS!=pkg-config --cflags extlib -TESTCFLAGS+=-g -fsanitize=undefined,address -TESTLDFLAGS!=pkg-config --libs extlib - -extlib: extlib.o extstring.o constraint_handler.o memset_s.o - $(CC) src/extlib.o src/extstring.o src/constraint_handler.o src/memset_s.o $(CFLAGS) -shared -fPIC -o libextlib.so - -extlib.pc: extlib.pc.in - sed 's|@prefix@|$(PREFIX)|g' extlib.pc.in > extlib.pc - sed 's|@libdir@|$(PREFIX)/lib|g' extlib.pc > extlib.pc.tmp - sed 's|@includedir@|$(PREFIX)/include|g' extlib.pc.tmp > extlib.pc - rm extlib.pc.tmp - -extlib.o: - $(CC) src/extlib.c $(CFLAGS) -c -fPIC -o src/extlib.o - -extstring.o: - $(CC) src/extstring.c $(CFLAGS) -c -fPIC -o src/extstring.o - -constraint_handler.o: - $(CC) src/constraint_handler.c $(CFLAGS) -c -fPIC -o src/constraint_handler.o - -memset_s.o: - $(CC) src/memset_s.c $(CFLAGS) -c -fPIC -o src/memset_s.o - -clean: - rm -r src/extlib.o src/exststring.o libextlib.so extlib.pc test - -install: extlib extlib.pc - install -Dm655 libextlib.so $(PREFIX)/lib/ - install -Dm655 src/extlib.h $(PREFIX)/include/ - install -Dm655 extlib.pc $(PREFIX)/share/pkgconfig/ - -test: FORCE - cd tests && make test - -FORCE: ; # PHONY is a non standard extension diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..45dfac9 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,8 @@ +test: FORCE + cd tests && make test + +FORCE: ; + + +SUBDIRS = src +ACLOCAL_AMFLAGS = -I m4 diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..26a4f8f --- /dev/null +++ b/configure.ac @@ -0,0 +1,30 @@ +AC_PREREQ([2.71]) +AC_INIT([extlib], [1.0.0], [axtlos@disroot.org]) +AM_INIT_AUTOMAKE([-Wall -Werror foreign]) +AC_CONFIG_MACRO_DIRS([m4]) + +AC_PROG_CC +AM_PROG_AR + +LT_INIT + +AC_CHECK_HEADERS([strings.h + ctype.h + unistd.h + stdint.h + errno.h]) + +AC_TYPE_SIZE_T + +AC_FUNC_MALLOC + +AC_CHECK_FUNC([memset_s], [AC_DEFINE([HAVE_MEMSET_S], [1], + [Define if memset_s exists])]) + +AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_FILES([ + Makefile + src/Makefile + extlib.pc +]) +AC_OUTPUT diff --git a/extlib.pc.in b/extlib.pc.in index 5b816f0..8a11d29 100644 --- a/extlib.pc.in +++ b/extlib.pc.in @@ -1,9 +1,10 @@ prefix=@prefix@ +exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ Name: extlib Description: extension for stdlib -Version: 1.0.0 +Version: @VERSION@ Libs: -L${libdir} -lextlib Cflags: -I${includedir} diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..f51de0c --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,4 @@ +lib_LTLIBRARIES = libextlib.la +libextlib_la_SOURCES = constraint_handler.c extlib.c extstring.c memset_s.c +libextlib_la_LDFLAGS = -version-info 1:0:0 +include_HEADERS = extlib.h diff --git a/src/extlib.c b/src/extlib.c index ce11709..4ee5744 100644 --- a/src/extlib.c +++ b/src/extlib.c @@ -27,7 +27,6 @@ #include #include #include -#include #undef free #undef malloc @@ -67,13 +66,13 @@ fcopy (FILE *src, FILE *dst) if (src == NULL || dst == NULL) return -1; - while ((n = fread (buffer, sizeof (char), sizeof (buffer), f1)) > 0) + while ((n = fread (buffer, sizeof (char), sizeof (buffer), src)) > 0) { - if (fwrite (buffer, sizeof (char), n, f2) != n) { + if (fwrite (buffer, sizeof (char), n, dst) != n) { fprintf (stderr, "Failed to copy data"); return -1; } - fflush (f2); + fflush (dst); copied += n; } return copied; diff --git a/src/extlib.h b/src/extlib.h index 5264195..80c79d0 100644 --- a/src/extlib.h +++ b/src/extlib.h @@ -19,7 +19,9 @@ void *malloc_secure (size_t len); #endif #if (__STDC_WANT_LIB_EXT1__ == 1) +#ifndef RSIZE_MAX #define RSIZE_MAX SIZE_MAX +#endif typedef int errno_t; typedef size_t rsize_t; @@ -60,5 +62,5 @@ char *strupr(char *s); char *trim (char *s, int *rem_front, int *rem_back); /// Match string s for old and replace it with string replace -char *replace_str (char *s, char *old, char *replace); + char *replace_str (char *s, char *old, char *replace); diff --git a/src/memset_s.c b/src/memset_s.c index dbe26ca..039be20 100644 --- a/src/memset_s.c +++ b/src/memset_s.c @@ -6,10 +6,10 @@ #include "extlib.h" #include - errno_t memset_s(void *s, rsize_t smax, int c, rsize_t n) { + puts ("memset"); volatile unsigned char *dest = (unsigned char *) s; errno_t ret = EINVAL; rsize_t limit = n < smax ? n : smax; -- cgit v1.2.3