aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--makefile43
-rw-r--r--qidx.c20
-rw-r--r--qidx.h3
3 files changed, 57 insertions, 9 deletions
diff --git a/makefile b/makefile
index 8328469..8f28203 100644
--- a/makefile
+++ b/makefile
@@ -6,20 +6,24 @@ ifeq ($(BINDIR),)
BINDIR := /bin
endif
-CMD=qidx
+name := qidx
+cmd := qidx
+
+so_major := 0
+so_minor := 1
CC=gcc
-DEBUG := -fsanitize=address -O2
-CFLAGS := -Wall -pedantic -g
-LDFLAGS := -lhts -lm
+CFLAGS = -Wall -pedantic $(debug)
+LDFLAGS := -lhts -lm -fPIC
+# debug = -fsanitize=address -O2 -g
SRC_EXT:=%.c
_STD_BUILD=$(CC) $(CFLAGS) $(filter $(SRC_EXT) %.o, $^) -o $@
STD_BUILD=$(_STD_BUILD) $(LDFLAGS)
-STD_COMPILE=$(_STD_BUILD) -c
+STD_COMPILE=$(_STD_BUILD) -fPIC -c
OBJS = ./util/hash.o
OBJS += ./util/prime_search.o
@@ -28,13 +32,36 @@ OBJS += ./util/sds/sds.o
OBJS += ./util/err.o
OBJS += ./qidx.o
-make: $(CMD)
+devname = lib$(name).so
+lib_so = lib$(name).so.$(so_major).$(so_minor)
+soname = lib$(name).so.$(so_major)
+
+make: $(cmd) $(lib_so)
-$(CMD): ./main.c $(OBJS)
+$(cmd): ./main.c $(OBJS)
$(STD_BUILD)
+$(lib_so): $(OBJS)
+ $(CC) $(LDFLAGS) -shared -Wl,-soname=$(soname) -fPIC -o $@ $^
+ [ -n "$(soname)" ] && ln -s $(lib_so) $(soname) || true
+ [ -n "$(devname)" ] && ln -s $(soname) $(devname) || true
+
clean:
- $(RM) $(CMD) $(OBJS)
+ $(RM) $(cmd) $(OBJS) $(devname) $(lib_so) $(soname)
+.PHONY: clean
%.o: %.c
$(STD_COMPILE)
+
+.PHONY: install
+install:
+ mkdir -p $(DESTDIR)$(PREFIX)/include $(DESTDIR)$(PREFIX)/lib
+ cp qidx.h $(DESTDIR)$(PREFIX)/include/qidx.h
+ cp -d $(lib_so) $(soname) $(devname) $(DESTDIR)$(PREFIX)/lib/
+
+.PHONY: uninstall
+uninstall:
+ rm -f $(DESTDIR)$(PREFIX)/include/qidx.h
+ rm -f $(DESTDIR)$(PREFIX)/lib/$(lib_so)
+ [ -n "$(soname)" ] && rm -f $(DESTDIR)$(PREFIX)/lib/$(soname) || true
+ [ -n "$(devname)" ] && rm -f $(DESTDIR)$(PREFIX)/lib/$(devname) || true
diff --git a/qidx.c b/qidx.c
index bcee165..acad8e9 100644
--- a/qidx.c
+++ b/qidx.c
@@ -670,7 +670,7 @@ qidx_err_t qidx_table_add(qidx_htable_t * tab, qidx_record_t const * rec) {
return QIDX_OK;
}
-qidx_err_t qidx_table_get(qidx_htable_t const * tab,
+static qidx_err_t qidx_table_get(qidx_htable_t const * tab,
char const * qname, qidx_record_t ** rec) {
qidx_bucket_t * bucket = _qidx_bucket(qname, tab);
@@ -697,6 +697,24 @@ qidx_err_t qidx_table_get(qidx_htable_t const * tab,
return QIDX_OK;
}
+qidx_err_t qidx_lookup_alnrec(qidx_fp_t * fp,
+ char const * qname, qidx_record_t ** rec) {
+ qidx_err_t err;
+
+ if((err = qidx_table_get(fp->htab, qname, rec))) {
+ return err;
+ }
+
+ return QIDX_OK;
+}
+
+void qidx_free_alnrec(qidx_record_t * rec) {
+ free(rec->alns);
+ sdsfree(rec->qname);
+ free(rec);
+}
+
+
void qidx_record_print(FILE * file, qidx_record_t * rec) {
fprintf(file, "qname: %s\n", rec->qname);
for(size_t i = 0; i < rec->n_alns; i++) {
diff --git a/qidx.h b/qidx.h
index fdc1046..c5c1f2f 100644
--- a/qidx.h
+++ b/qidx.h
@@ -54,6 +54,9 @@ typedef struct qidx_fp qidx_fp_t;
qidx_err_t qidx_open(qidx_fp_t ** fp, int fd);
qidx_err_t qidx_create(qidx_fp_t ** fp, int fd, uint32_t _n_buckets,
uint32_t max_bucket_size);
+qidx_err_t qidx_lookup_alnrec(qidx_fp_t * fp,
+ char const * qname, qidx_record_t ** rec);
+void qidx_free_alnrec(qidx_record_t * rec);
qidx_err_t qidx_close(qidx_fp_t * fp);
qidx_err_t qidx_create_index3(htsFile * fp, int fd, qidx_fp_t ** q_fp,