diff --git a/Makefile b/Makefile index 956609a..1f03c95 100755 --- a/Makefile +++ b/Makefile @@ -180,16 +180,15 @@ $(eval $(call make-obj-rule,$(src)))) $(call qcmd,$(INST) -m 755 -d "$(IBINDIR)") $(call qcmd,tools/write-config \ --name=$(NAME) --version=$(VERSION) --target="$(TARGET)" \ - --runlibs="$(RLIBS)" \ --maintainer="$(MAINTAINER_NAME) <$(MAINTAINER_MAIL)>" \ - --incdir="$(OIINCDIR)/lib$(NAME)-$(VERSION)" --libdir="$(OILIBDIR)" \ >"$(IBINDIR)/$(TARGET)lib$(NAME)-config" \ && chmod 755 "$(IBINDIR)/$(TARGET)lib$(NAME)-config") $(call imsg,Installing the pkg-config configuration.) $(call qcmd,$(INST) -m 755 -d "$(IPKGDIR)") $(call qcmd,tools/write-pkg-config \ - --name=$(NAME) --version=$(VERSION) --runlibs="$(RLIBS)" \ + --name=$(NAME) --version=$(VERSION) \ + --deps="$(DEPS)" --deps.private="$(DEPS_PRIV)" \ --description="$(DESCRIPTION)" \ --incdir="$(OIINCDIR)/lib$(NAME)-$(VERSION)" --libdir="$(OILIBDIR)" \ >"$(IPKGDIR)/lib$(NAME).pc" \ diff --git a/Makefile.vars b/Makefile.vars index a36a55e..97dc4fb 100755 --- a/Makefile.vars +++ b/Makefile.vars @@ -56,11 +56,10 @@ ANAME := $(if $(FOR_WINDOWS),lib$(NAME).lib,lib$(NAME).a) ANAMES := lib$(NAME).lib lib$(NAME).a lib$(NAME).dll.a -# Runtime libs - RLIBS := libfontcharacter - -# Compilation time libs - LIBS := zlib $(RLIBS) +# Libs + DEPS := libfontcharacter + DEPS_PRIV := zlib + ALLDEPS := $(DEPS) $(DEPS_PRIV) #******************************************************************************# # Binary utilities # @@ -85,7 +84,7 @@ endif CFLAGS := -I $(INCDIR) $(CWARN) -std=gnu11 \ $(if $(STATIC),,-fPIC) $(if $(OPTIMIZE_SIZE),-Os,-O2) \ -D LOGLEVEL="ll_$(LOG_LEVEL)" \ - $(shell $(PKGCONFIG) --cflags $(LIBS) 2>/dev/null) \ + $(shell $(PKGCONFIG) --cflags $(ALLDEPS) 2>/dev/null) \ $(CMOREFLAGS) # Linker @@ -97,7 +96,7 @@ endif -Wl,-z,relro -Wl,-z,combreloc -Wl,-z,defs) # - Linker flags LDFLAGS := $(if $(STATIC),,-shared) \ - $(shell $(PKGCONFIG) --libs $(LIBS) 2>/dev/null) \ + $(shell $(PKGCONFIG) --libs $(ALLDEPS) 2>/dev/null) -lm \ $(if $(FOR_WINDOWS),$(LDFLAGS_Windows),$(LDFLAGS_Linux)) \ $(LDMOREFLAGS) diff --git a/README.md b/README.md index 26fc5fb..8704512 100644 --- a/README.md +++ b/README.md @@ -15,14 +15,15 @@ Side note : the library might work with older versions of these dependencies, I took these as a reference because these are the ones I work with. ### Making-only dependencies -| Name | Version | -| -------------------------------------------------- | -------- | -| [make](https://www.gnu.org/software/make/) | >= 4.0 | -| [gcc](https://gcc.gnu.org/) | >= 4.9 | -| [binutils](https://www.gnu.org/software/binutils/) | >= 2.25 | -| [asciidoc](http://asciidoc.org/) | >= 8.6.9 | -| [gzip](https://www.gnu.org/software/gzip/) | >= 1.6 | -| [python3](https://www.python.org/) | >= 3.5 | +| Name | Version | +| ------------------------------------------------------------------- | -------- | +| [make](https://www.gnu.org/software/make/) | >= 4.0 | +| [gcc](https://gcc.gnu.org/) | >= 4.9 | +| [binutils](https://www.gnu.org/software/binutils/) | >= 2.25 | +| [asciidoc](http://asciidoc.org/) | >= 8.6.9 | +| [gzip](https://www.gnu.org/software/gzip/) | >= 1.6 | +| [python3](https://www.python.org/) | >= 3.5 | +| [pkg-config](https://www.freedesktop.org/wiki/Software/pkg-config/) | any | ### Runtime dependencies | Name | Version | diff --git a/include/libg1m/bcd.h b/include/libg1m/bcd.h index 0e774af..a50983f 100644 --- a/include/libg1m/bcd.h +++ b/include/libg1m/bcd.h @@ -122,6 +122,10 @@ void g1m_bcd_tomcs(const g1m_bcd_t *bcd, mcs_bcd_t *raw); int g1m_bcd_fromcas(const cas_bcd_t *raw, g1m_bcd_t *bcd); void g1m_bcd_tocas(const g1m_bcd_t *bcd, cas_bcd_t *raw); +/* From and to C-double */ +void g1m_bcd_fromdouble(double dbl, g1m_bcd_t *bcd); +double g1m_bcd_todouble(const g1m_bcd_t *bcd); + /* Make a string out of a BCD */ size_t g1m_bcdtoa(const g1m_bcd_t *bcd, char *buf, size_t len); diff --git a/include/libg1m/format/casemul.h b/include/libg1m/format/casemul.h index 6e8a0b0..fb54a55 100644 --- a/include/libg1m/format/casemul.h +++ b/include/libg1m/format/casemul.h @@ -18,6 +18,7 @@ * ************************************************************************** */ #ifndef LIBG1M_FORMAT_CASEMUL_H # define LIBG1M_FORMAT_CASEMUL_H +# include # pragma pack(1) /* Casemul files are made of an overall header, a source part and an @@ -174,7 +175,9 @@ struct casemul_mtrx_header { uint32_t lines, columns; }; -/* TODO: describe the matrix format more precisely. */ +/* Then it's simply a tab of `lines*columns` `double` numbers, + * ordered by lines (y). They are the real parts, as the numbers in those + * matrixes have got no imaginary parts. */ /* ************************************************************************** */ /* List */ /* ************************************************************************** */ @@ -186,7 +189,8 @@ struct casemul_list_header { uint32_t lines; }; -/* TODO: describe the list format more precisely. */ +/* Then it's simply a tab of `lines` `double` numbers. + * The numbers in these have no imaginary parts. */ # pragma pack() #endif /* LIBG1M_FORMAT_CASEMUL_H */ diff --git a/include/libg1m/internals/log.h b/include/libg1m/internals/log.h index 0e16eef..7361eb6 100644 --- a/include/libg1m/internals/log.h +++ b/include/libg1m/internals/log.h @@ -45,11 +45,12 @@ # define ll_none 4 /* Macros */ -# define log(P, S, ...) fprintf(stderr, P "%s: " S "\n", __FUNCTION__, ##__VA_ARGS__) +# define g1m_log(P, S, ...) \ + fprintf(stderr, P "%s: " S "\n", __FUNCTION__, ##__VA_ARGS__) # define logm(S, M, N) g1m_log_mem(S, M, N) # if LOGLEVEL <= ll_info -# define log_info(S, ...) log("[libg1m info] ", S, ##__VA_ARGS__) +# define log_info(S, ...) g1m_log("[libg1m info] ", S, ##__VA_ARGS__) # define logm_info(M, N) logm("[libg1m info] ", M, N) # else # define log_info(S, ...) @@ -57,7 +58,7 @@ # endif # if LOGLEVEL <= ll_warn -# define log_warn(S, ...) log("[libg1m warn] ", S, ##__VA_ARGS__) +# define log_warn(S, ...) g1m_log("[libg1m warn] ", S, ##__VA_ARGS__) # define logm_warn(M, N) logm("[libg1m warn] ", M, N) # else # define log_warn(S, ...) @@ -65,13 +66,13 @@ # endif # if LOGLEVEL <= ll_error -# define log_error(S, ...) log("[libg1m error] ", S, ##__VA_ARGS__) +# define log_error(S, ...) g1m_log("[libg1m error] ", S, ##__VA_ARGS__) # else # define log_error(S, ...) # endif # if LOGLEVEL <= ll_fatal -# define log_fatal(S, ...) log("[libg1m fatal] ", S, ##__VA_ARGS__) +# define log_fatal(S, ...) g1m_log("[libg1m fatal] ", S, ##__VA_ARGS__) # else # define log_fatal(S, ...) # endif diff --git a/src/bcd/double.c b/src/bcd/double.c new file mode 100644 index 0000000..bbbdeaa --- /dev/null +++ b/src/bcd/double.c @@ -0,0 +1,74 @@ +/* ***************************************************************************** + * bcd/double.c -- make a libg1m BCD out of a double. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * This file is part of libg1m. + * libg1m is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3.0 of the License, + * or (at your option) any later version. + * + * libg1m is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libg1m; if not, see . + * ************************************************************************** */ +#include +#include + +/** + * g1m_bcd_fromdouble: + * Make a libg1m BCD number out of a C-double. + * + * @arg dbl the double. + * @arg bcd the BCD to set. + */ + +void g1m_bcd_fromdouble(double dbl, g1m_bcd_t *bcd) +{ + /* check if is negative */ + int neg = 0; + if (dbl < 0) { + neg = 1; + dbl = -dbl; + } + + /* check the exponent, normalize the number */ + int exp = 1; + while (dbl >= 10) { + exp++; + dbl /= 10; + } + while (dbl < 1) { + exp--; + dbl *= 10; + } + + /* get the mantissa */ + for (int i = 0; i < 15; i++) { + double work = floor(dbl); + bcd->mant[i] = (int)work; + dbl = (dbl - work) * 10; + } + + /* set the flags */ + bcd->flags = g1m_make_bcdflags(0, neg, 15); + bcd->exp = exp; +} + +/** + * g1m_bcd_todouble: + * Make a C-double out of a libg1m BCD number. + * + * @arg bcd the BCD to convert. + * @return the double. + */ + +double g1m_bcd_todouble(const g1m_bcd_t *bcd) +{ + /* TODO */ + return (0); +} diff --git a/tools/write-config b/tools/write-config index 8100e49..9df0151 100755 --- a/tools/write-config +++ b/tools/write-config @@ -9,23 +9,18 @@ version="" # Maintainer maintainer="Some unknown guy " -# Directories -libdir='' -incdir='' - #******************************************************************************# # Read arguments # #******************************************************************************# for arg ; do case "$arg" in --name=*) name="${arg#*=}" ;; --target=*) target="${arg#*=}" ;; ---runlibs=*) runlibs="${arg#*=}" ;; --version=*) version="${arg#*=}" ;; --maintainer=*) maintainer="${arg#*=}" ;; ---libdir=*) libdir="${arg#*=}" ;; ---incdir=*) incdir="${arg#*=}" ;; esac; done +[ "$target" ] && target="${target}-" + #******************************************************************************# # Write result # #******************************************************************************# @@ -76,15 +71,11 @@ for arg ; do case "\$arg" in esac; done # Put -if [ \$put_cflags ]; then - echo "-I$incdir" - for rdep in ${runlibs}; do ${target}\${rdep}-config --cflags; done -fi -if [ \$put_libs ]; then - echo "-L$libdir -l$name" - for rdep in ${runlibs}; do ${target}\${rdep}-config --libs; done -fi +opt="" [ \$put_cflags\$put_libs ] || usage +[ \$put_cflags ] && opt+="--cflags " +[ \$put_libs ] && opt+="--libs " +${target}pkg-config ${runlibs} \$opt # End of file _EOF diff --git a/tools/write-pkg-config b/tools/write-pkg-config index 6fcf114..096577a 100755 --- a/tools/write-pkg-config +++ b/tools/write-pkg-config @@ -18,11 +18,11 @@ for arg ; do case "$arg" in --name=*) name="${arg#*=}" ;; --description=*) description="${arg#*=}" ;; --version=*) version="${arg#*=}" ;; ---runlibs=*) runlibs="${arg#*=}" ;; +--deps=*) deps="${arg#*=}" ;; +--deps.private=*) privdeps="${arg#*=}" ;; --libdir=*) libdir="${arg#*=}" ;; --incdir=*) incdir="${arg#*=}" ;; esac; done - #******************************************************************************# # Write result # #******************************************************************************# @@ -33,7 +33,9 @@ libdir=$libdir Name: lib$name Description: $description Version: $version -Requires: $runlibs +Requires: $deps +Requires.private: $privdeps Libs: -L\${libdir} -l$name +Libs.private: -lm Cflags: -I\${includedir} EOF