Compare commits
2 Commits
4fe839df19
...
6ccb5f2264
Author | SHA1 | Date | |
---|---|---|---|
6ccb5f2264 | |||
fb203bbcae |
@@ -19,6 +19,7 @@ LD := ld
|
||||
BEAR := bear
|
||||
TOUCH := touch
|
||||
RM := rm
|
||||
MKDIR := mkdir -p
|
||||
RMDIR := rmdir
|
||||
|
||||
SRCDIR := ./src
|
||||
@@ -27,6 +28,7 @@ OBJDIR := ./obj
|
||||
LIBDIR := ./lib
|
||||
BINDIR := ./bin
|
||||
DEPDIR := ./dep
|
||||
TESTDIR := ./test
|
||||
|
||||
SRC := $(wildcard $(SRCDIR)/*.c) # brlib sources
|
||||
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 := $(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
|
||||
EMACSLSP := .dir-locals.el
|
||||
|
||||
CCLSROOT := .ccls-root
|
||||
CCLSFILE := .ccls
|
||||
CCLSCMDS := compile_commands.json
|
||||
|
||||
##################################### pre-processor flags
|
||||
CPPFLAGS := -I$(INCDIR)
|
||||
#CPPFLAGS += -DDEBUG # global
|
||||
CPPFLAGS += -DDEBUG_DEBUG # enable log() functions
|
||||
#CPPFLAGS += -DDEBUG_DEBUG_C # log() funcs debug
|
||||
PPFLAGS += -DDEBUG_DEBUG # activate logs funcs
|
||||
CPPFLAGS += -DDEBUG_DEBUG # activate logs funcs
|
||||
CPPFLAGS += -DDEBUG_POOL # mem pools
|
||||
|
||||
# remove extraneous spaces (due to spaces before comments)
|
||||
@@ -78,16 +86,20 @@ LDFLAGS := -L$(LIBDIR)
|
||||
DEPFLAGS = -MMD -MP -MF $(DEPDIR)/$*.d
|
||||
|
||||
##################################### General targets
|
||||
.PHONY: all compile clean cleanall
|
||||
.PHONY: all compile clean cleanall cleanallall
|
||||
|
||||
all: libs
|
||||
|
||||
compile: objs
|
||||
|
||||
test: testbins
|
||||
|
||||
clean: cleandep cleanobj cleanlib cleanbin
|
||||
|
||||
cleanall: clean cleandepdir cleanobjdir cleanlibdir cleanbindir
|
||||
|
||||
cleanallall: cleanall cleanemacs
|
||||
|
||||
# setup emacs projectile/ccls
|
||||
emacs: emacs-setup
|
||||
# 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).
|
||||
$(ALLDIRS): $@
|
||||
@echo creating $@ directory.
|
||||
@mkdir -p $@
|
||||
@$(MKDIR) $@
|
||||
|
||||
##################################### Dependencies files
|
||||
.PHONY: cleandep cleandepdir
|
||||
@@ -188,17 +200,18 @@ cleanlibdir:
|
||||
#$(DLIB): CFLAGS += -fPIC
|
||||
$(DLIB): LDFLAGS += -shared
|
||||
$(DLIB): $(OBJ) | $(LIBDIR)
|
||||
@echo "building $@ shared library ($?)."
|
||||
@echo "building shared library ($@)."
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) $? -o $@
|
||||
|
||||
$(SLIB): $(OBJ) | $(LIBDIR)
|
||||
@echo "building $@ static library ($?)."
|
||||
@echo "building static library ($@)."
|
||||
$(AR) $(ARFLAGS) $@ $? > /dev/null
|
||||
|
||||
##################################### brchess binaries
|
||||
.PHONY: targets cleanbin cleanbindir
|
||||
##################################### tests
|
||||
.PHONY: testbins cleanbin cleanbindir
|
||||
|
||||
targets: $(TARGET)
|
||||
testbins: $(BIN)
|
||||
echo $^
|
||||
|
||||
cleanbin:
|
||||
$(call rmfiles,$(TARGET),binary)
|
||||
@@ -215,21 +228,15 @@ cleanbindir:
|
||||
@echo generating $@
|
||||
@$(CC) -S -fverbose-asm $(CPPFLAGS) $(CFLAGS) $< -o $@
|
||||
|
||||
##################################### LSP (ccls)
|
||||
.PHONY: emacs-setup
|
||||
##################################### Emacs
|
||||
.PHONY: emacs-setup cleanemacs
|
||||
|
||||
PRJROOT := .projectile
|
||||
CCLSROOT := .ccls-root
|
||||
CCLSFILE := .ccls
|
||||
CCLSCMDS := compile_commands.json
|
||||
emacs-setup: $(PRJROOT) $(EMACSLSP)
|
||||
|
||||
emacs-setup: $(PRJROOT) $(CCLSROOT) $(CCLSCMDS)
|
||||
cleanemacs:
|
||||
$(call rmfiles, $(PRJROOT) $(EMACSLSP), Emacs);
|
||||
|
||||
#$(CCLSFILE):
|
||||
# @echo "creating CCLS's $@ project root file."
|
||||
# echo '%compile_commands.json' > $@
|
||||
|
||||
$(CCLSROOT) $(PRJROOT):
|
||||
$(PRJROOT) $(EMACSLSP):
|
||||
@if [[ $(@) = $(PRJROOT) ]] ; \
|
||||
then \
|
||||
echo "creating Emacs's projectile root file." ; \
|
||||
@@ -238,6 +245,16 @@ $(CCLSROOT) $(PRJROOT):
|
||||
fi
|
||||
@$(TOUCH) $@
|
||||
|
||||
##################################### LSP (ccls)
|
||||
.PHONY: cleanccls
|
||||
|
||||
cleanccls:
|
||||
$(call rmfiles, $(CCLSROOT), ccls);
|
||||
|
||||
$(CCLSROOT):
|
||||
echo "creating ccls root file."
|
||||
@$(TOUCH) $@
|
||||
|
||||
# generate compile_commands.json.
|
||||
# TODO: add includes and Makefile dependencies.
|
||||
# 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)
|
||||
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
|
||||
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