Compare commits
2 Commits
4fe839df19
...
6ccb5f2264
Author | SHA1 | Date | |
---|---|---|---|
6ccb5f2264 | |||
fb203bbcae |
@@ -19,6 +19,7 @@ LD := ld
|
|||||||
BEAR := bear
|
BEAR := bear
|
||||||
TOUCH := touch
|
TOUCH := touch
|
||||||
RM := rm
|
RM := rm
|
||||||
|
MKDIR := mkdir -p
|
||||||
RMDIR := rmdir
|
RMDIR := rmdir
|
||||||
|
|
||||||
SRCDIR := ./src
|
SRCDIR := ./src
|
||||||
@@ -27,6 +28,7 @@ OBJDIR := ./obj
|
|||||||
LIBDIR := ./lib
|
LIBDIR := ./lib
|
||||||
BINDIR := ./bin
|
BINDIR := ./bin
|
||||||
DEPDIR := ./dep
|
DEPDIR := ./dep
|
||||||
|
TESTDIR := ./test
|
||||||
|
|
||||||
SRC := $(wildcard $(SRCDIR)/*.c) # brlib sources
|
SRC := $(wildcard $(SRCDIR)/*.c) # brlib sources
|
||||||
SRC_FN := $(notdir $(SRC)) # source basename
|
SRC_FN := $(notdir $(SRC)) # source basename
|
||||||
@@ -39,17 +41,23 @@ DLIB := $(addsuffix .so, $(LIBDIR)/lib$(LIB)) # dynamic lib
|
|||||||
DEP_FN := $(SRC_FN) $(LIBSRC_FN)
|
DEP_FN := $(SRC_FN) $(LIBSRC_FN)
|
||||||
DEP := $(addprefix $(DEPDIR)/,$(DEP_FN:.c=.d))
|
DEP := $(addprefix $(DEPDIR)/,$(DEP_FN:.c=.d))
|
||||||
|
|
||||||
##################################### emacs projectile/ccls
|
TESTSRC := $(wildcard $(TESTDIR)/*.c)
|
||||||
|
TEST_FN := $(notdir $(TESTSRC))
|
||||||
|
BIN := $(addprefix $(BINDIR)/,$(TEST_FN:.c=))
|
||||||
|
|
||||||
|
##################################### emacs projectile/ccls dirs & files
|
||||||
PRJROOT := .projectile
|
PRJROOT := .projectile
|
||||||
|
EMACSLSP := .dir-locals.el
|
||||||
|
|
||||||
CCLSROOT := .ccls-root
|
CCLSROOT := .ccls-root
|
||||||
|
CCLSFILE := .ccls
|
||||||
CCLSCMDS := compile_commands.json
|
CCLSCMDS := compile_commands.json
|
||||||
|
|
||||||
##################################### pre-processor flags
|
##################################### pre-processor flags
|
||||||
CPPFLAGS := -I$(INCDIR)
|
CPPFLAGS := -I$(INCDIR)
|
||||||
#CPPFLAGS += -DDEBUG # global
|
#CPPFLAGS += -DDEBUG # global
|
||||||
CPPFLAGS += -DDEBUG_DEBUG # enable log() functions
|
|
||||||
#CPPFLAGS += -DDEBUG_DEBUG_C # log() funcs debug
|
#CPPFLAGS += -DDEBUG_DEBUG_C # log() funcs debug
|
||||||
PPFLAGS += -DDEBUG_DEBUG # activate logs funcs
|
CPPFLAGS += -DDEBUG_DEBUG # activate logs funcs
|
||||||
CPPFLAGS += -DDEBUG_POOL # mem pools
|
CPPFLAGS += -DDEBUG_POOL # mem pools
|
||||||
|
|
||||||
# remove extraneous spaces (due to spaces before comments)
|
# remove extraneous spaces (due to spaces before comments)
|
||||||
@@ -78,16 +86,20 @@ LDFLAGS := -L$(LIBDIR)
|
|||||||
DEPFLAGS = -MMD -MP -MF $(DEPDIR)/$*.d
|
DEPFLAGS = -MMD -MP -MF $(DEPDIR)/$*.d
|
||||||
|
|
||||||
##################################### General targets
|
##################################### General targets
|
||||||
.PHONY: all compile clean cleanall
|
.PHONY: all compile clean cleanall cleanallall
|
||||||
|
|
||||||
all: libs
|
all: libs
|
||||||
|
|
||||||
compile: objs
|
compile: objs
|
||||||
|
|
||||||
|
test: testbins
|
||||||
|
|
||||||
clean: cleandep cleanobj cleanlib cleanbin
|
clean: cleandep cleanobj cleanlib cleanbin
|
||||||
|
|
||||||
cleanall: clean cleandepdir cleanobjdir cleanlibdir cleanbindir
|
cleanall: clean cleandepdir cleanobjdir cleanlibdir cleanbindir
|
||||||
|
|
||||||
|
cleanallall: cleanall cleanemacs
|
||||||
|
|
||||||
# setup emacs projectile/ccls
|
# setup emacs projectile/ccls
|
||||||
emacs: emacs-setup
|
emacs: emacs-setup
|
||||||
# update compile-commands.json
|
# update compile-commands.json
|
||||||
@@ -141,7 +153,7 @@ alldirs: $(ALLDIRS)
|
|||||||
# a will be built if (1) older than a, or (2) does not exist. Here only (2).
|
# a will be built if (1) older than a, or (2) does not exist. Here only (2).
|
||||||
$(ALLDIRS): $@
|
$(ALLDIRS): $@
|
||||||
@echo creating $@ directory.
|
@echo creating $@ directory.
|
||||||
@mkdir -p $@
|
@$(MKDIR) $@
|
||||||
|
|
||||||
##################################### Dependencies files
|
##################################### Dependencies files
|
||||||
.PHONY: cleandep cleandepdir
|
.PHONY: cleandep cleandepdir
|
||||||
@@ -188,17 +200,18 @@ cleanlibdir:
|
|||||||
#$(DLIB): CFLAGS += -fPIC
|
#$(DLIB): CFLAGS += -fPIC
|
||||||
$(DLIB): LDFLAGS += -shared
|
$(DLIB): LDFLAGS += -shared
|
||||||
$(DLIB): $(OBJ) | $(LIBDIR)
|
$(DLIB): $(OBJ) | $(LIBDIR)
|
||||||
@echo "building $@ shared library ($?)."
|
@echo "building shared library ($@)."
|
||||||
$(CC) $(CFLAGS) $(LDFLAGS) $? -o $@
|
$(CC) $(CFLAGS) $(LDFLAGS) $? -o $@
|
||||||
|
|
||||||
$(SLIB): $(OBJ) | $(LIBDIR)
|
$(SLIB): $(OBJ) | $(LIBDIR)
|
||||||
@echo "building $@ static library ($?)."
|
@echo "building static library ($@)."
|
||||||
$(AR) $(ARFLAGS) $@ $? > /dev/null
|
$(AR) $(ARFLAGS) $@ $? > /dev/null
|
||||||
|
|
||||||
##################################### brchess binaries
|
##################################### tests
|
||||||
.PHONY: targets cleanbin cleanbindir
|
.PHONY: testbins cleanbin cleanbindir
|
||||||
|
|
||||||
targets: $(TARGET)
|
testbins: $(BIN)
|
||||||
|
echo $^
|
||||||
|
|
||||||
cleanbin:
|
cleanbin:
|
||||||
$(call rmfiles,$(TARGET),binary)
|
$(call rmfiles,$(TARGET),binary)
|
||||||
@@ -215,21 +228,15 @@ cleanbindir:
|
|||||||
@echo generating $@
|
@echo generating $@
|
||||||
@$(CC) -S -fverbose-asm $(CPPFLAGS) $(CFLAGS) $< -o $@
|
@$(CC) -S -fverbose-asm $(CPPFLAGS) $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
##################################### LSP (ccls)
|
##################################### Emacs
|
||||||
.PHONY: emacs-setup
|
.PHONY: emacs-setup cleanemacs
|
||||||
|
|
||||||
PRJROOT := .projectile
|
emacs-setup: $(PRJROOT) $(EMACSLSP)
|
||||||
CCLSROOT := .ccls-root
|
|
||||||
CCLSFILE := .ccls
|
|
||||||
CCLSCMDS := compile_commands.json
|
|
||||||
|
|
||||||
emacs-setup: $(PRJROOT) $(CCLSROOT) $(CCLSCMDS)
|
cleanemacs:
|
||||||
|
$(call rmfiles, $(PRJROOT) $(EMACSLSP), Emacs);
|
||||||
|
|
||||||
#$(CCLSFILE):
|
$(PRJROOT) $(EMACSLSP):
|
||||||
# @echo "creating CCLS's $@ project root file."
|
|
||||||
# echo '%compile_commands.json' > $@
|
|
||||||
|
|
||||||
$(CCLSROOT) $(PRJROOT):
|
|
||||||
@if [[ $(@) = $(PRJROOT) ]] ; \
|
@if [[ $(@) = $(PRJROOT) ]] ; \
|
||||||
then \
|
then \
|
||||||
echo "creating Emacs's projectile root file." ; \
|
echo "creating Emacs's projectile root file." ; \
|
||||||
@@ -238,6 +245,16 @@ $(CCLSROOT) $(PRJROOT):
|
|||||||
fi
|
fi
|
||||||
@$(TOUCH) $@
|
@$(TOUCH) $@
|
||||||
|
|
||||||
|
##################################### LSP (ccls)
|
||||||
|
.PHONY: cleanccls
|
||||||
|
|
||||||
|
cleanccls:
|
||||||
|
$(call rmfiles, $(CCLSROOT), ccls);
|
||||||
|
|
||||||
|
$(CCLSROOT):
|
||||||
|
echo "creating ccls root file."
|
||||||
|
@$(TOUCH) $@
|
||||||
|
|
||||||
# generate compile_commands.json.
|
# generate compile_commands.json.
|
||||||
# TODO: add includes and Makefile dependencies.
|
# TODO: add includes and Makefile dependencies.
|
||||||
# also, if cclsfile is newer than sources, no need to clean objects file
|
# also, if cclsfile is newer than sources, no need to clean objects file
|
||||||
|
@@ -124,22 +124,3 @@ void debug(int lev, bool timestamp, int indent, const char *src,
|
|||||||
if (flush)
|
if (flush)
|
||||||
fflush(stream);
|
fflush(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BIN_debug
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
int foo=1;
|
|
||||||
debug_init(5);
|
|
||||||
|
|
||||||
log(0, "log0=%d\n", foo++);
|
|
||||||
log(1, "log1=%d\n", foo++);
|
|
||||||
log(2, "log2=%d\n", foo++);
|
|
||||||
log_i(2, "log_i 2=%d\n", foo++);
|
|
||||||
log_i(5, "log_i 5=%d\n", foo++);
|
|
||||||
log_i(6, "log_i 6=%d\n", foo++);
|
|
||||||
log_it(4, "log_it 4=%d\n", foo++);
|
|
||||||
log_f(1, "log_f 5=%d\n", foo++);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
@@ -161,59 +161,3 @@ void pool_destroy(pool_t *pool)
|
|||||||
# endif
|
# endif
|
||||||
free(pool);
|
free(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BIN_pool
|
|
||||||
struct d {
|
|
||||||
u16 data1;
|
|
||||||
char c;
|
|
||||||
struct list_head list;
|
|
||||||
};
|
|
||||||
|
|
||||||
static LIST_HEAD (head);
|
|
||||||
|
|
||||||
int main(int ac, char**av)
|
|
||||||
{
|
|
||||||
pool_t *pool;
|
|
||||||
int total;
|
|
||||||
int action=0;
|
|
||||||
u16 icur=0;
|
|
||||||
char ccur='z';
|
|
||||||
struct d *elt;
|
|
||||||
|
|
||||||
debug_init(3);
|
|
||||||
log_f(1, "%s: sizeof(d)=%lu sizeof(*d)=%lu off=%lu\n", *av, sizeof(elt),
|
|
||||||
sizeof(*elt), offsetof(struct d, list));
|
|
||||||
|
|
||||||
if ((pool = pool_create("dummy", 3, sizeof(*elt)))) {
|
|
||||||
pool_stats(pool);
|
|
||||||
for (int cur=1; cur<ac; ++cur) {
|
|
||||||
total = atoi(av[cur]);
|
|
||||||
if (action == 0) { /* add elt to list */
|
|
||||||
log_f(2, "adding %d elements\n", total);
|
|
||||||
for (int i = 0; i < total; ++i) {
|
|
||||||
elt = pool_get(pool);
|
|
||||||
elt->data1 = icur++;
|
|
||||||
elt->c = ccur--;
|
|
||||||
list_add(&elt->list, &head);
|
|
||||||
}
|
|
||||||
pool_stats(pool);
|
|
||||||
action = 1;
|
|
||||||
} else { /* remove one elt from list */
|
|
||||||
log_f(2, "deleting %d elements\n", total);
|
|
||||||
for (int i = 0; i < total; ++i) {
|
|
||||||
if (!list_empty(&head)) {
|
|
||||||
elt = list_last_entry(&head, struct d, list);
|
|
||||||
printf("elt=[%d, %c]\n", elt->data1, elt->c);
|
|
||||||
list_del(&elt->list);
|
|
||||||
pool_add(pool, elt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pool_stats(pool);
|
|
||||||
action = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pool_stats(pool);
|
|
||||||
pool_destroy(pool);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
17
c/brlib/test/test/tst-debug.c
Normal file
17
c/brlib/test/test/tst-debug.c
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#include <unistd.h>
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int foo=1;
|
||||||
|
debug_init(5);
|
||||||
|
|
||||||
|
log(0, "log0=%d\n", foo++);
|
||||||
|
log(1, "log1=%d\n", foo++);
|
||||||
|
log(2, "log2=%d\n", foo++);
|
||||||
|
log_i(2, "log_i 2=%d\n", foo++);
|
||||||
|
log_i(5, "log_i 5=%d\n", foo++);
|
||||||
|
log_i(6, "log_i 6=%d\n", foo++);
|
||||||
|
log_it(4, "log_it 4=%d\n", foo++);
|
||||||
|
log_f(1, "log_f 5=%d\n", foo++);
|
||||||
|
}
|
57
c/brlib/test/tst-pool.c
Normal file
57
c/brlib/test/tst-pool.c
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include "bits.h"
|
||||||
|
#include "pool.h"
|
||||||
|
|
||||||
|
struct d {
|
||||||
|
u16 data1;
|
||||||
|
char c;
|
||||||
|
struct list_head list;
|
||||||
|
};
|
||||||
|
|
||||||
|
static LIST_HEAD (head);
|
||||||
|
|
||||||
|
int main(int ac, char**av)
|
||||||
|
{
|
||||||
|
pool_t *pool;
|
||||||
|
int total;
|
||||||
|
int action=0;
|
||||||
|
u16 icur=0;
|
||||||
|
char ccur='z';
|
||||||
|
struct d *elt;
|
||||||
|
|
||||||
|
debug_init(3);
|
||||||
|
log_f(1, "%s: sizeof(d)=%lu sizeof(*d)=%lu off=%lu\n", *av, sizeof(elt),
|
||||||
|
sizeof(*elt), offsetof(struct d, list));
|
||||||
|
|
||||||
|
if ((pool = pool_create("dummy", 3, sizeof(*elt)))) {
|
||||||
|
pool_stats(pool);
|
||||||
|
for (int cur=1; cur<ac; ++cur) {
|
||||||
|
total = atoi(av[cur]);
|
||||||
|
if (action == 0) { /* add elt to list */
|
||||||
|
log_f(2, "adding %d elements\n", total);
|
||||||
|
for (int i = 0; i < total; ++i) {
|
||||||
|
elt = pool_get(pool);
|
||||||
|
elt->data1 = icur++;
|
||||||
|
elt->c = ccur--;
|
||||||
|
list_add(&elt->list, &head);
|
||||||
|
}
|
||||||
|
pool_stats(pool);
|
||||||
|
action = 1;
|
||||||
|
} else { /* remove one elt from list */
|
||||||
|
log_f(2, "deleting %d elements\n", total);
|
||||||
|
for (int i = 0; i < total; ++i) {
|
||||||
|
if (!list_empty(&head)) {
|
||||||
|
elt = list_last_entry(&head, struct d, list);
|
||||||
|
printf("elt=[%d, %c]\n", elt->data1, elt->c);
|
||||||
|
list_del(&elt->list);
|
||||||
|
pool_add(pool, elt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pool_stats(pool);
|
||||||
|
action = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pool_stats(pool);
|
||||||
|
pool_destroy(pool);
|
||||||
|
}
|
Reference in New Issue
Block a user