~crm/cstring

da6af4863c09169ebe9134915e97931360669464 — Christos Margiolis 3 years ago a4d9b35
added config.mk
8 files changed, 80 insertions(+), 50 deletions(-)

M Makefile
M README.md
A config.mk
M cstring.3
M cstring.h
M tests/Makefile
M tests/test_basic.c
M tests/test_insert.c
M Makefile => Makefile +7 -27
@@ 1,37 1,16 @@
# See LICENSE file for copyright and license details.
# cstring - a simple and lightweight string library for C
.POSIX:

include config.mk

LIB = cstring
VERSION = 0.1
DIST = ${LIB}-${VERSION}
MAN3 = ${LIB}.3
PREFIX = /usr/local
MAN_DIR = ${PREFIX}/man/man3
INC_DIR = ${PREFIX}/include
LIB_DIR = ${PREFIX}/lib

EXT = c
#SRC = ${wildcard *.${EXT}}
#OBJ = ${SRC:%.${EXT}=%.o}
SRC = cstring.c
OBJ = cstring.o

AR = ar
ARFLAGS = rs
CC = gcc
INCS = -Iinclude
# Uncomment if you want to compile the library in debug mode
#CPPFLAGS = -DCSTRING_DBG -DVERSION=\"${VERSION}\"
CPPFLAGS = -DVERSION=\"${VERSION}\"
CFLAGS = -Wall -std=c99 -pedantic -O3 ${INCS} ${CPPFLAGS}
LDFLAGS = -Llib

CP = cp -f
RM = rm -f
RM_DIR = rm -rf
MKDIR = mkdir -p
TAR = tar -cf
GZIP = gzip

all: options ${LIB}

options:


@@ 43,12 22,13 @@ options:
${LIB}: ${OBJ}
	${AR} ${ARFLAGS} lib${LIB}.a ${OBJ}

${OBJ}: ${SRC}
${OBJ}: ${SRC} cstring.h
	${CC} ${CFLAGS} -c ${SRC} -o $@

dist: clean
	${MKDIR} ${DIST}
	${CP} -R tests ${SRC} ${MAN3} LICENSE Makefile README.md ${DIST}
	${CP} -R tests/ config.mk ${MAN3} ${SRC} cstring.h LICENSE Makefile \
		README.md ${DIST}
	${TAR} ${DIST}.tar ${DIST}
	${GZIP} ${DIST}.tar
	${RM_DIR} ${DIST}

M README.md => README.md +17 -6
@@ 6,23 6,34 @@ but with a many additions.
## Building

`cstring` is a static library. The header file is installed in `/usr/local/include` and
the library file in `/usr/local/lib`. In order to install it do the following
the library file in `/usr/local/lib`. 

In order to install it do the following
```shell
$ cd /path/to/cstring
$ sudo make install
$ make clean
$ sudo make install clean
```

If you want to uninstall the library do the following
You can also run a few tests
```shell
$ cd /path/to/cstring/tests
$ make && make run clean
```

In order to make a distribution do
```shell
$ cd /path/to/cstring
$ make dist
```

If you want to uninstall the library do the following
```shell
$ cd /path/to/cstring
$ sudo make uninstall
```

In order to link `cstring` to your project use the `-lcstring` flag during compilation.  
In case you want to run your project in debug mode, compile it using the `-DCSTRING_DBG` option.
A file using `cstring` has to be linked using the `-lcstring` linker flag.  
In case you want to run your project in debug mode, compile the library using the `-DCSTRING_DBG` option.

## Usage


A config.mk => config.mk +40 -0
@@ 0,0 1,40 @@
# See LICENSE file for copyright and license details.
# cstring version
VERSION = 0.1

# paths
PREFIX = /usr/local
#MAN_DIR = ${PREFIX}/man/man1
BIN_DIR = ${PREFIX}/bin
# uncomment if you're making a library
MAN_DIR = ${PREFIX}/man/man3
INC_DIR = ${PREFIX}/include
LIB_DIR = ${PREFIX}/lib

# includes and libs
INCS = -Iinclude 
LIBS = -Llib

# flags
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L \
	   -DVERSION=\"${VERSION}\"
CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations \
	 -O3 ${INCS} ${CPPFLAGS}
LDFLAGS = ${LIBS}
# uncomment if you're making a library
ARFLAGS = rs

# utils
CP = cp -f
RM = rm -f
RM_DIR = rm -rf
MV = mv
MKDIR = mkdir -p
RM_DIR = rm -rf
TAR = tar -cf
GZIP = gzip

# compiler
CC = gcc
# uncomment if you're making a library
AR = ar

M cstring.3 => cstring.3 +1 -1
@@ 27,9 27,9 @@ option.
.Bl -tag -width Ds
.It cstring
struct cstring {
        char   *str;      /* contents of string */
        size_t  len;      /* string length */
        size_t  capacity; /* string capacity */
        char   *str;      /* contents of string */
.br
};
.It cstring_sort_flags

M cstring.h => cstring.h +1 -1
@@ 41,9 41,9 @@ extern "C" {
#endif /* CSTRING_DBG */

struct cstring {
        char     *str;
        size_t    len;
        size_t    capacity;
        char     *str;
};

enum cstring_sort_flags {

M tests/Makefile => tests/Makefile +12 -13
@@ 1,3 1,7 @@
# See LICENSE file for copyright and license details.
# cstring tests
.POSIX:

BINS = test_basic test_insert
CC = gcc
CFLAGS = -Wall -std=c99 -pedantic -O3


@@ 12,19 16,14 @@ options:
	@echo "CC       = ${CC}"

run:
	@echo "---------------------------"
	@echo "---------------------------"
	@echo "RUNNING: test_basic"
	@echo "---------------------------"
	@echo "---------------------------"
	./test_basic
	
	@echo "---------------------------"
	@echo "---------------------------"
	@echo "RUNNING: test_insert"
	@echo "---------------------------"
	@echo "---------------------------"
	./test_insert
	for bin in ${BINS}; do \
		echo "---------------------------"; \
		echo "---------------------------"; \
		echo "RUNNING: $${bin}"; \
		echo "---------------------------"; \
		echo "---------------------------"; \
		./$${bin}; \
	done

clean:
	rm -f ${BINS} *.o

M tests/test_basic.c => tests/test_basic.c +1 -1
@@ 3,7 3,7 @@
// Compilation: gcc test_basic.c -lcstring

int
main(int argc, char **argv)
main(int argc, char *argv[])
{
        cstring s = cstring_create("Hello world");
        printf("cstring_create: %s (Len: %ld, Capacity: %ld)\n", s.str, s.len, s.capacity);

M tests/test_insert.c => tests/test_insert.c +1 -1
@@ 3,7 3,7 @@
// Compilation: gcc test_insert.c -lcstring

int
main(int argc, char **argv)
main(int argc, char *argv[])
{
        cstring s = cstring_create("HHHHHHEEEEEEEEEEEEEEEEEEEEEYYYYYYYYYYYYYY");
        printf("%s\n", s.str);