aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-05-16 10:38:24 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-05-16 10:38:24 -0700
commit3f7474df0645224ce61fedcd908028f41971189e (patch)
tree0bd98f69f9ba09ec9c1cb19fe0c96bf89d8b6ee6
parentfa25c8f3df6791727b9384c9b405c996ac68b8ab (diff)
fix: linking errors associated to linking bins against all dependencies. partitioned more explictly now
-rw-r--r--Makefile5
-rwxr-xr-xbin/initmk9
-rw-r--r--include/libn/macro/map.h68
-rw-r--r--rules.mk8
-rw-r--r--share/paths.mk9
-rw-r--r--sys/libbio/rules.mk11
-rw-r--r--sys/libmath/rules.mk18
-rw-r--r--sys/libn/rules.mk24
8 files changed, 91 insertions, 61 deletions
diff --git a/Makefile b/Makefile
index be2ff44..af78982 100644
--- a/Makefile
+++ b/Makefile
@@ -16,8 +16,7 @@ CINIT := $(LIB_DIR)/crt/crt1.o $(LIB_DIR)/crt/x86_64/crti.o `gcc --print-file-na
CFINI := `gcc --print-file-name=crtendS.o` $(LIB_DIR)/crt/x86_64/crtn.o
# Flags, Libraries and Includes
-CFLAGS := -g -march=native \
- -ffast-math -fno-strict-aliasing -fwrapv -fms-extensions
+CFLAGS := -g -march=native -fno-strict-aliasing -fwrapv -fms-extensions
STATIC := -static -nodefaultlibs -nostartfiles
AFLAGS := -f elf64
INCS := -isystem $(INC_DIR)/vendor/libc -I $(INC_DIR)
@@ -27,7 +26,7 @@ ELIBS := -L$(LIB_DIR) -lc
COMPILE = @echo "CC "$^;\
$(CC) -MD $(CFLAGS) $(TCFLAGS) $(INCS) $(TCINCS) -o $@ -c $<
LINK = @echo "LD "$@;\
- $(CC) -MD $(CFLAGS) $(STATIC) $(TCFLAGS) -o $@ $(CINIT) $^ $(CFINI) $(TCLIBS) $(ELIBS)
+ $(CC) -MD $(CFLAGS) $(STATIC) $(TCFLAGS) -o $@ $(CINIT) $< $(CFINI) $(TCLIBS) $(ELIBS)
COMPLINK = @echo "LD "$@;\
$(CC) -MD $(CFLAGS) $(STATIC) $(TCFLAGS) $(INCS) $(TCINCS) -o $@ $(CINIT) $^ $(CFINI) $(TCLIBS) $(ELIBS)
ASSEMBLE = @echo "AS "$^;\
diff --git a/bin/initmk b/bin/initmk
index 141764d..2ea018f 100755
--- a/bin/initmk
+++ b/bin/initmk
@@ -8,12 +8,12 @@ TEMPLATE = """include share/push.mk
# Iterate through subdirectory tree
# Local sources
-SRCS_$(d) := $(wildcard $(d)/*.c)
+SRCS_$(d) :=
LIBS_$(d) :=
BINS_$(d) :=
-TSTS_$(d) := $(wildcard $(d)/*_test.c:.c=.test)
+TSTS_$(d) :=
-include share/pop.mk
+include share/paths.mk
# Local rules
# $(LIBS_$(d)) = TCFLAGS :=
@@ -26,6 +26,9 @@ $(LIBS_$(d)): $(OBJS_$(d))
$(BINS_$(d)): $(OBJS_$(d))
$(LINK)
+$(UNTS_$(d)): $(TOBJS_$(d)) $(LIBS_$(d))
+ $(LINK)
+
include share/pop.mk"""
if __name__ == "__main__":
diff --git a/include/libn/macro/map.h b/include/libn/macro/map.h
index 37b7dfd..45eb745 100644
--- a/include/libn/macro/map.h
+++ b/include/libn/macro/map.h
@@ -25,25 +25,21 @@ static const double __ac_HASH_UPPER = 0.77;
#define __ac_fsize(m) ((m) < 16 ? 1 : (m) >> 4)
#define MAP_STRUCT_BODY(key_t, val_t) \
- mem·Allocator heap; \
- void *h; \
int32 n_buckets, size, n_occupied, upper_bound; \
int32 *flags; \
key_t *keys; \
val_t *vals;
-#define MAP_MAKE(type) \
+#define MAP_MAKE(type, h, alloc) \
type *map; \
- map = heap.alloc((h), 1, sizeof(*map)); \
- map->heap = heap; \
- map->h = h; \
+ map = alloc((h), 1, sizeof(*map)); \
return map
-#define MAP_FREE(map) \
- map->heap.free(map->h, map->keys); \
- map->heap.free(map->h, map->flags); \
- map->heap.free(map->h, map->vals); \
- map->heap.free(map->h, map);
+#define MAP_FREE(map, free, h) \
+ free(h, map->keys); \
+ free(h, map->flags); \
+ free(h, map->vals); \
+ free(h, map);
#define MAP_RESET(map) \
if (map && map->flags) { \
@@ -51,28 +47,30 @@ static const double __ac_HASH_UPPER = 0.77;
map->size = map->n_occupied = 0; \
}
-#define MAP_GET(map, key, hashfunc, equalfunc) \
+#define MAP_GET(i, map, key, hashfunc, equalfunc ) \
+ int32 k, last, mask, step; \
if (map->n_buckets) { \
- int32 k = 0; \
- int32 i = 0; \
- int32 last = 0; \
- int32 mask = 0; \
- int32 step = 0; \
+ k = 0; \
+ i = 0; \
+ last = 0; \
+ mask = 0; \
+ step = 0; \
mask = map->n_buckets - 1; \
- k = hashfunc(key); \
- i = k & mask; \
+ k = hashfunc(key); \
+ i = k & mask; \
last = i; \
while (!__ac_isempty(map->flags, i) && \
(__ac_isdel(map->flags, i) || !equalfunc(map->keys[i], key))) { \
i = (i + (++step)) & mask; \
if (i == last) \
- return map->n_buckets; \
+ i = map->n_buckets; \
} \
- return __ac_iseither(map->flags, i) ? map->n_buckets : i; \
+ if (__ac_iseither(map->flags, i)) \
+ i = map->n_buckets; \
} else \
- return 0;
+ i = 0;
-#define MAP_GROW(map, key_t, val_t, new_n_buckets, hashfunc) \
+#define MAP_GROW(map, key_t, val_t, new_n_buckets, hashfunc, alloc, free, h) \
int32 *new_flags = nil; \
int32 j = 1; \
{ \
@@ -83,25 +81,25 @@ static const double __ac_HASH_UPPER = 0.77;
j = 0; \
else { \
new_flags = \
- map->heap.alloc(map->h, __ac_fsize(new_n_buckets), sizeof(int32)); \
+ alloc(h, __ac_fsize(new_n_buckets), sizeof(int32)); \
if (!new_flags) return -1; \
memset(new_flags, 0xaa, __ac_fsize(new_n_buckets) * sizeof(int32)); \
if (map->n_buckets < new_n_buckets) { /* expand */ \
key_t *new_keys = \
- map->heap.alloc(map->h, new_n_buckets, sizeof(key_t)); \
+ alloc(h, new_n_buckets, sizeof(key_t)); \
if (!new_keys) { \
- map->heap.free(map->h, new_flags); \
+ free(h, new_flags); \
return -1; \
} \
- map->heap.free(map->h, map->keys); \
+ free(h, map->keys); \
map->keys = new_keys; \
val_t *new_vals = \
- map->heap.alloc(map->h, new_n_buckets, sizeof(val_t)); \
+ alloc(h, new_n_buckets, sizeof(val_t)); \
if (!new_vals) { \
- map->heap.free(map->h, new_flags); \
+ free(h, new_flags); \
return -1; \
} \
- map->heap.free(map->h, map->vals); \
+ free(h, map->vals); \
map->vals = new_vals; \
} \
} \
@@ -143,15 +141,15 @@ static const double __ac_HASH_UPPER = 0.77;
} \
} \
if (map->n_buckets > new_n_buckets) { /* shrink the hash table */ \
- key_t *new_keys = map->heap.alloc(map->h, new_n_buckets, sizeof(key_t)); \
- map->heap.free(map->h, map->keys); \
+ key_t *new_keys = alloc(h, new_n_buckets, sizeof(key_t)); \
+ free(h, map->keys); \
map->keys = new_keys; \
\
- val_t *new_vals = map->heap.alloc(map->h, new_n_buckets, sizeof(val_t)); \
- map->heap.free(map->h, map->vals); \
+ val_t *new_vals = alloc(h, new_n_buckets, sizeof(val_t)); \
+ free(h, map->vals); \
map->vals = new_vals; \
} \
- map->heap.free(map->h, map->flags); /* free the working space */ \
+ free(h, map->flags); /* free the working space */ \
map->flags = new_flags; \
map->n_buckets = new_n_buckets; \
map->n_occupied = map->size; \
diff --git a/rules.mk b/rules.mk
index 7e4a911..eea0dcb 100644
--- a/rules.mk
+++ b/rules.mk
@@ -7,7 +7,7 @@ all: targets
debug: CFLAGS += -DDEBUG
debug: targets
-release: CFLAGS += -O3 -flto #-DNDEBUG
+release: CFLAGS += -O3 -flto -ffast-math #-DNDEBUG
release: targets
# Targets & array of sources & intermediates
@@ -17,7 +17,7 @@ DEPS :=
LIBS :=
BINS :=
-TSTS :=
+UNTS :=
# Iterate through directory tree
DIR := sys
@@ -39,14 +39,14 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.s
$(OBJ_DIR)/%: $(SRC_DIR)/%.c
$(COMPLNK)
-targets: $(LIBS) $(BINS) $(TSTS)
+targets: $(LIBS) $(BINS) $(UNTS)
clean:
rm -f $(OBJS)
rm -f $(DEPS)
rm -f $(LIBS)
rm -f $(BINS)
- rm -f $(TSTS)
+ rm -f $(UNTS)
install: targets
@echo installing executables
diff --git a/share/paths.mk b/share/paths.mk
index e4fabcc..2998014 100644
--- a/share/paths.mk
+++ b/share/paths.mk
@@ -3,7 +3,10 @@ OBJS_$(d) += $(filter %.o, $(SRCS_$(d):.s=.o))
OBJS_$(d) := $(patsubst $(SRC_DIR)/%, $(OBJ_DIR)/%, $(OBJS_$(d)))
DEPS_$(d) := $(OBJS_$(d):.o=.d)
-OBJS := $(OBJS) $(OBJS_$(d))
+TOBJS_$(d) := $(TSTS_$(d):.c=.o)
+TOBJS_$(d) := $(patsubst $(SRC_DIR)/%, $(OBJ_DIR)/%, $(TOBJS_$(d)))
+
+OBJS := $(OBJS) $(OBJS_$(d)) $(TOBJS_$(d))
DEPS := $(DEPS) $(DEPS_$(d))
LIBS_$(d) := $(patsubst $(SRC_DIR)/%, $(OBJ_DIR)/%, $(LIBS_$(d)))
@@ -12,5 +15,5 @@ LIBS := $(LIBS) $(LIBS_$(d))
BINS_$(d) := $(patsubst $(SRC_DIR)/%, $(OBJ_DIR)/%, $(BINS_$(d)))
BINS := $(BINS) $(BINS_$(d))
-TSTS_$(d) := $(patsubst $(SRC_DIR)/%, $(TST_DIR)/%, $(TSTS_$(d)))
-TSTS := $(TSTS) $(TSTS_$(d))
+UNTS_$(d) := $(patsubst $(SRC_DIR)/%, $(TST_DIR)/%, $(TSTS_$(d):.c=))
+UNTS := $(UNTS) $(UNTS_$(d))
diff --git a/sys/libbio/rules.mk b/sys/libbio/rules.mk
index cabc1b3..fdb4c74 100644
--- a/sys/libbio/rules.mk
+++ b/sys/libbio/rules.mk
@@ -5,10 +5,14 @@ DIR := $(d)/io
include $(DIR)/rules.mk
# Local sources
-SRCS_$(d) := $(wildcard $(d)/*.c)
+SRCS_$(d) := \
+ $(d)/align.c \
+ $(d)/phylo.c
LIBS_$(d) := $(d)/libbio.a
BINS_$(d) :=
-TSTS_$(d) := $(d)/test $(d)/simulate
+TSTS_$(d) := \
+ $(d)/test.c \
+ $(d)/simulate.c
include share/paths.mk
@@ -20,7 +24,8 @@ include share/paths.mk
$(LIBS_$(d)): $(OBJS_$(d)) $(OBJS_$(d)/io)
$(ARCHIVE)
-$(TSTS_$(d)): $(LIBS_$(d)) $(OBJ_DIR)/libn/libn.a
+$(UNTS_$(d)): TCLIBS := $(LIBS_$(d)) $(OBJ_DIR)/libn/libn.a
+$(UNTS_$(d)): $(TOBJS_$(d)) $(TCLIBS)
$(LINK)
include share/pop.mk
diff --git a/sys/libmath/rules.mk b/sys/libmath/rules.mk
index f948686..c7d8d61 100644
--- a/sys/libmath/rules.mk
+++ b/sys/libmath/rules.mk
@@ -3,19 +3,25 @@ include share/push.mk
# Iterate through subdirectory tree
# Local sources
-SRCS_$(d) := $(wildcard $(d)/*.c)
-LIBS_$(d) :=
+SRCS_$(d) := \
+ $(d)/basic.c \
+ $(d)/blas1.c \
+ $(d)/blas2.c \
+ $(d)/linalg.c
+LIBS_$(d) := $(d)/libmath.a
BINS_$(d) :=
-TSTS_$(d) := $(d)/blas
+TSTS_$(d) := \
+ $(d)/blas.c \
+ $(d)/test.c
include share/paths.mk
$(LIBS_$(d)): $(OBJS_$(d))
$(ARCHIVE)
-$(TSTS_$(d)): TCFLAGS := -D_GNU_SOURCE
-$(TSTS_$(d)): TCLIBS := -lpthread -lm
-$(TSTS_$(d)): $(OBJS_$(d)) $(OBJ_DIR)/libn/libn.a $(LIB_DIR)/vendor/libblas.a
+$(UNTS_$(d)): TCFLAGS := -D_GNU_SOURCE
+$(UNTS_$(d)): TCLIBS := -lpthread -lm $(LIB_DIR)/vendor/libblas.a $(OBJ_DIR)/libn/libn.a $(LIBS_$(d))
+$(UNTS_$(d)): $(TOBJS_$(d)) $(LIBS_$(d)) $(OBJ_DIR)/libn/libn.a
$(LINK)
include share/pop.mk
diff --git a/sys/libn/rules.mk b/sys/libn/rules.mk
index 85f3df7..3e9b810 100644
--- a/sys/libn/rules.mk
+++ b/sys/libn/rules.mk
@@ -5,17 +5,33 @@ include share/push.mk
# include $(DIR)/rules.mk
# Local sources
-SRCS_$(d) := $(wildcard $(d)/*.c) $(wildcard $(d)/*.s)
-LIBS_$(d) := $(d)/libnbn.a
+SRCS_$(d) := \
+ $(d)/bufio.c \
+ $(d)/coro_unix_x64.s \
+ $(d)/coro.c \
+ $(d)/error.c \
+ $(d)/flate.c \
+ $(d)/gz.c \
+ $(d)/io.c \
+ $(d)/memory.c \
+ $(d)/mmap.c \
+ $(d)/random.c \
+ $(d)/sort.c \
+ $(d)/string.c
+
+TSTS_$(d) := \
+ $(d)/test.c
+
+LIBS_$(d) := $(d)/libn.a
BINS_$(d) :=
-TSTS_$(d) := $(d)/test
include share/paths.mk
$(LIBS_$(d)): $(OBJS_$(d))
$(ARCHIVE)
-$(TSTS_$(d)): $(LIBS_$(d))
+$(UNTS_$(d)): TCLIBS := $(LIBS_$(d))
+$(UNTS_$(d)): $(TOBJS_$(d)) $(TCLIBS)
$(LINK)
include share/pop.mk