diff options
author | M.Gergő | 2020-05-26 17:39:24 +0200 |
---|---|---|
committer | M.Gergő | 2020-05-26 17:39:24 +0200 |
commit | b3867d1d28968cf0790fbfa4413d0a8aec7949ef (patch) | |
tree | e89440dee6ae98956885470caf2a6e7efb2a0c0a | |
parent | fa19b34f49f6c85a4abf211762a15285d9f76310 (diff) | |
download | lightconfini-b3867d1d28968cf0790fbfa4413d0a8aec7949ef.tar.gz lightconfini-b3867d1d28968cf0790fbfa4413d0a8aec7949ef.zip |
Make dynamic lib
-rw-r--r-- | makefile | 51 | ||||
-rw-r--r-- | src/ini_read.c | 16 | ||||
-rw-r--r-- | src/ini_write.c | 13 | ||||
-rw-r--r-- | src/inirw_internal.h | 16 |
4 files changed, 68 insertions, 28 deletions
@@ -1,4 +1,4 @@ -.PHONY: all clean debug distclean +.PHONY: all clean install copylib ldconf lib debug distclean # buid & link with gcc CC = gcc @@ -8,60 +8,87 @@ LD = gcc MKD = /bin/mkdir -p # A '-' jel miatt átugorja a hibát RM = -/bin/rm - +CP = -/bin/cp # fordíto általános flagek -CFLAGS = -Wall +CFLAGS = -Wall -c LDFLAGS = LDLIBS = - +# Ha libdir-be "lib"-et írunk, akkor körbeforgó fggőség lesz belőle BINDIR = bin +LIBDIR = libdir OBJDIR = build + # .o fájlok -OBJ = main.o ini_read.o +OBJ = main.o ini_read.o ini_write.o PROG = $(BINDIR)/lightconfini +LIB = $(LIBDIR)/liblightconfini.so.1.0.1 +lib: OBJ := $(filter-out main.o, $(OBJ)) OBJS = $(addprefix $(OBJDIR)/,$(OBJ)) # ALL kell legyen legelőször! +# Az sem mindegy, hogy mellette van, vagy alatta egy sorral! all: $(PROG) +lib: clean $(LIB) +debug: clean all +install: lib copylib +testlib: clean all # debug-hoz felüldefiniálva -debug: CFLAGS = -Wall -g -g3 -ggdb -std=c89 -Wpedantic -Wmissing-prototypes +debug: CFLAGS = -Wall -c -g -g3 -ggdb -std=c89 -Wpedantic -Wmissing-prototypes debug: LDFLAGS = debug: LDLIBS = -lefence +# make lib FLAGS: not link: -c, relative addresses: -fPIC +lib: CFLAGS = -fPIC -c -Wall +lib: LDFLAGS = -shared -Wl,-soname,liblightconfini.so.1 +lib: LDLIBS = -lc # nem mindegy, hogy mellette van, vagy alatta egy sorral! -debug: clean all # Ha még nem létezik az obj könyvtár, létrehozza $(OBJS): | $(OBJDIR) $(PROG): | $(BINDIR) +$(LIB): | $(LIBDIR) # Fordított sorrend: először a főprogram $(PROG): $(OBJS) - $(LD) $(LDFLAGS) $(OBJS) -o $(PROG) $(LDLIBS) + $(LD) $(LDFLAGS) -o $(PROG) $(OBJS) $(LDLIBS) + @echo ' ' + +# For shared library +$(LIB): $(OBJS) + $(LD) $(LDFLAGS) $(OBJS) -o $(LIB) $(LDLIBS) @echo ' ' # Utána: A forrásfájlok fordítása egyesével $(OBJS): $(OBJDIR)/%.o: ./src/%.c - $(CC) $(CFLAGS) -c -o "$@" "$<" + $(CC) $(CFLAGS) -o "$@" "$<" # OBJ létrehozáshoz $(BINDIR): $(MKD) $(BINDIR) $(OBJDIR): $(MKD) $(OBJDIR) +$(LIBDIR): + $(MKD) $(LIBDIR) rebuild: clean all +copylib: + $(CP) -r $(LIBDIR)/* /usr/local/lib/ + ldconfig + +ldconf: + ldconfig -n $(LIBDIR) + clean: - $(RM) $(PROG) $(OBJS) + $(RM) $(OBJS) -distclean: - $(RM) -r $(PROG) $(OBJS) bin/ build/ +distclean: clean + $(RM) -r $(OBJS) $(LIBDIR) $(BINDIR) $(OBJDIR) diff --git a/src/ini_read.c b/src/ini_read.c index 854625c..66799a1 100644 --- a/src/ini_read.c +++ b/src/ini_read.c @@ -13,7 +13,7 @@ -static size_t strNullLen(const uint8_t *str){ +size_t strNullLen(const uint8_t *str){ if(str == NULL){ return 0; } else { @@ -22,7 +22,7 @@ static size_t strNullLen(const uint8_t *str){ } -static size_t strLcpy(uint8_t *dst, size_t dstlen, const uint8_t *src, size_t srclen){ /* Safe strncpy() */ +size_t strLcpy(uint8_t *dst, size_t dstlen, const uint8_t *src, size_t srclen){ /* Safe strncpy() */ uint8_t *tdst=dst; const uint8_t *tsrc=src; size_t i=dstlen, j=srclen; @@ -39,7 +39,7 @@ static size_t strLcpy(uint8_t *dst, size_t dstlen, const uint8_t *src, size_t sr } -static uint8_t *lciniStrResize(uint8_t *ptr, size_t oldsize, size_t newsize){ +uint8_t *lciniStrResize(uint8_t *ptr, size_t oldsize, size_t newsize){ uint8_t *tmp=NULL; if(newsize <= 0){ /* deleting */ @@ -67,7 +67,7 @@ static uint8_t *lciniStrResize(uint8_t *ptr, size_t oldsize, size_t newsize){ } -static uint8_t unescape(uint8_t c){ +uint8_t unescape(uint8_t c){ if(c == 'n'){ /* Newline */ return '\n'; } else if(c == 'a'){ /* Bell */ @@ -92,7 +92,7 @@ static uint8_t unescape(uint8_t c){ } #ifdef ini_write_c -static uint8_t eescape(uint8_t c){ +uint8_t eescape(uint8_t c){ if(c == '\n'){ /* Newline */ return 'n'; } else if(c == '\a'){ /* Bell */ @@ -115,7 +115,7 @@ static uint8_t eescape(uint8_t c){ } #endif -static uint8_t isascalnum(uint8_t c){ /* Check if input is ASCII Alpha-numeric */ +uint8_t isascalnum(uint8_t c){ /* Check if input is ASCII Alpha-numeric */ if( 0x30 <= c && c <= 0x39){ /* Numeric */ return 1; } else if (0x41 <= c && c <= 0x5a){ /* UPPER */ @@ -127,7 +127,7 @@ static uint8_t isascalnum(uint8_t c){ /* Check if input is ASCII Alpha-numeric * } } -static uint8_t checkspace(uint8_t c){ /* Only for ASCII characters */ +uint8_t checkspace(uint8_t c){ /* Only for ASCII characters */ switch (c) { case 0x20: /* space (SPC) */ return 1; @@ -171,7 +171,7 @@ size_t lciniFileMaxLineLen(FILE *tfd){ } } -static struct lcini_data *iniFSM(struct lcini_data *data, const uint8_t *in, int32_t len){ +struct lcini_data *iniFSM(struct lcini_data *data, const uint8_t *in, int32_t len){ int32_t i,j, vallen=len; enum lcini_states pstate=Start, state=Start; diff --git a/src/ini_write.c b/src/ini_write.c new file mode 100644 index 0000000..785f35f --- /dev/null +++ b/src/ini_write.c @@ -0,0 +1,13 @@ +/* INI fájl olvasás */ + +#include <stdio.h> +#include <string.h> /* strncpy + strerror */ +#include <stdlib.h> /* malloc(), atoi(), exit(EXIT_FALIURE) */ +#include <errno.h> /* errno */ +#include <stdarg.h> +#include <stdint.h> /* int64_t */ + +#define ini_write_c +#include "inirw_internal.h" +#include "lightconfini.h" + diff --git a/src/inirw_internal.h b/src/inirw_internal.h index f698f29..8bab129 100644 --- a/src/inirw_internal.h +++ b/src/inirw_internal.h @@ -42,20 +42,20 @@ size_t getFileMaxLineLen(FILE *tfd); #if defined(ini_read_c) || defined(ini_write_c) enum lcini_states {Start, BgnSp, CommEndW, SectEndW, SectEndD, EqW1, EqW2, ValPSP, ValW, ValFSP, DqmW, Bslsh, Error, Stop }; - static size_t strNullLen(const uint8_t *str); - static struct lcini_data *iniFSM(struct lcini_data *data, const uint8_t *in, int32_t len); + size_t strNullLen(const uint8_t *str); + struct lcini_data *iniFSM(struct lcini_data *data, const uint8_t *in, int32_t len); - static uint8_t isascalnum(uint8_t c); /* Check if input is ASCII Alpha-numeric */ - static uint8_t checkspace(uint8_t c); /* Only for ASCII characters */ - static size_t strLcpy(uint8_t *dst, size_t dstlen, const uint8_t *src, size_t srclen); - static uint8_t *lciniStrResize(uint8_t *ptr, size_t oldsize, size_t newsize); - static uint8_t unescape(uint8_t c); + uint8_t isascalnum(uint8_t c); /* Check if input is ASCII Alpha-numeric */ + uint8_t checkspace(uint8_t c); /* Only for ASCII characters */ + size_t strLcpy(uint8_t *dst, size_t dstlen, const uint8_t *src, size_t srclen); + uint8_t *lciniStrResize(uint8_t *ptr, size_t oldsize, size_t newsize); + uint8_t unescape(uint8_t c); #ifdef ini_read_c /* int unescape(int c); */ #endif /* ini_read_c */ #ifdef ini_write_c - static uint8_t eescape(uint8_t c); + uint8_t eescape(uint8_t c); #endif /*ini_write_c*/ #endif /* ini_read_c, ini_write_c*/ |