diff --git a/lib/mqnic/Makefile b/lib/mqnic/Makefile new file mode 100644 index 000000000..4a18ff499 --- /dev/null +++ b/lib/mqnic/Makefile @@ -0,0 +1,40 @@ + +PREFIX ?= /usr/local +INCDIR = $(DESTDIR)$(PREFIX)/include +LIBDIR = $(DESTDIR)$(PREFIX)/lib +DEVLIBDIR = $(LIBDIR) + +CC ?= gcc +CFLAGS ?= -O3 -fPIC + +CFLAGS += -Wall +CPPFLAGS += + +LIB = libmqnic.a +INCLUDES = mqnic.h mqnic_hw.h mqnic_ioctl.h reg_block.h + +GENDEPFLAGS = -MD -MP -MF .$(@F).d + +ALL_CFLAGS = $(CFLAGS) $(CPPFLAGS) $(GENDEPFLAGS) + +all: $(LIB) + +%.o: %.c + $(CC) $(ALL_CFLAGS) -c -o $@ $< + +libmqnic.a: mqnic.o reg_block.o + ar rcs $@ $^ + +install: + install -d $(DEVLIBDIR) $(INCDIR)/mqnic + install -m 0644 $(LIB) $(DEVLIBDIR) + install -m 0644 $(INCLUDES) $(INCDIR)/mqnic + +clean: + rm -f $(LIB) + rm -f *.o + rm -f .*.d + +-include $(wildcard .*.d) + +.PHONY: all install clean diff --git a/utils/mqnic.c b/lib/mqnic/mqnic.c similarity index 99% rename from utils/mqnic.c rename to lib/mqnic/mqnic.c index 403f12235..ab125692e 100644 --- a/utils/mqnic.c +++ b/lib/mqnic/mqnic.c @@ -32,6 +32,7 @@ either expressed or implied, of The Regents of the University of California. */ #include "mqnic.h" +#include "mqnic_ioctl.h" #include #include diff --git a/utils/mqnic.h b/lib/mqnic/mqnic.h similarity index 99% rename from utils/mqnic.h rename to lib/mqnic/mqnic.h index cef34941e..5d5cc7911 100644 --- a/utils/mqnic.h +++ b/lib/mqnic/mqnic.h @@ -39,7 +39,6 @@ either expressed or implied, of The Regents of the University of California. #include #include "mqnic_hw.h" -#include "mqnic_ioctl.h" #include "reg_block.h" #define mqnic_reg_read32(base, reg) (((volatile uint32_t *)(base))[(reg)/4]) diff --git a/lib/mqnic/mqnic_hw.h b/lib/mqnic/mqnic_hw.h new file mode 120000 index 000000000..8ddd9df99 --- /dev/null +++ b/lib/mqnic/mqnic_hw.h @@ -0,0 +1 @@ +../../modules/mqnic/mqnic_hw.h \ No newline at end of file diff --git a/lib/mqnic/mqnic_ioctl.h b/lib/mqnic/mqnic_ioctl.h new file mode 120000 index 000000000..f74c629d4 --- /dev/null +++ b/lib/mqnic/mqnic_ioctl.h @@ -0,0 +1 @@ +../../modules/mqnic/mqnic_ioctl.h \ No newline at end of file diff --git a/utils/reg_block.c b/lib/mqnic/reg_block.c similarity index 100% rename from utils/reg_block.c rename to lib/mqnic/reg_block.c diff --git a/utils/reg_block.h b/lib/mqnic/reg_block.h similarity index 100% rename from utils/reg_block.h rename to lib/mqnic/reg_block.h diff --git a/utils/Makefile b/utils/Makefile index a65c1efae..b49999ee6 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -6,7 +6,11 @@ CC ?= gcc CFLAGS ?= -O3 CFLAGS += -Wall -CPPFLAGS += -I../modules/mqnic -I ../include +CPPFLAGS += -Ilib -Iinclude +LDFLAGS += -Llib/mqnic +LDLIBS += -lmqnic + +LIBMQNIC = lib/mqnic/libmqnic.a BIN = mqnic-config BIN += mqnic-dump @@ -20,23 +24,28 @@ ALL_CFLAGS = $(CFLAGS) $(CPPFLAGS) $(GENDEPFLAGS) all: $(BIN) +FORCE: + +$(LIBMQNIC): FORCE + $(MAKE) -C $(dir $@) $(notdir $@) + %.o: %.c $(CC) $(ALL_CFLAGS) -c -o $@ $< -mqnic-config: mqnic-config.o mqnic.o reg_block.o timespec.o - $(CC) $(ALL_CFLAGS) $(LDFLAGS) $^ -o $@ +mqnic-config: mqnic-config.o timespec.o $(LIBMQNIC) + $(CC) $(ALL_CFLAGS) $(LDFLAGS) $^ -o $@ $(LDLIBS) -mqnic-dump: mqnic-dump.o mqnic.o reg_block.o - $(CC) $(ALL_CFLAGS) $(LDFLAGS) $^ -o $@ +mqnic-dump: mqnic-dump.o $(LIBMQNIC) + $(CC) $(ALL_CFLAGS) $(LDFLAGS) $^ -o $@ $(LDLIBS) -mqnic-fw: mqnic-fw.o mqnic.o reg_block.o flash.o flash_spi.o flash_bpi.o fpga_id.o bitfile.o - $(CC) $(ALL_CFLAGS) $(LDFLAGS) $^ -o $@ +mqnic-fw: mqnic-fw.o flash.o flash_spi.o flash_bpi.o fpga_id.o bitfile.o $(LIBMQNIC) + $(CC) $(ALL_CFLAGS) $(LDFLAGS) $^ -o $@ $(LDLIBS) -mqnic-bmc: mqnic-bmc.o mqnic.o reg_block.o - $(CC) $(ALL_CFLAGS) $(LDFLAGS) $^ -o $@ +mqnic-bmc: mqnic-bmc.o $(LIBMQNIC) + $(CC) $(ALL_CFLAGS) $(LDFLAGS) $^ -o $@ $(LDLIBS) perout: perout.o timespec.o - $(CC) $(ALL_CFLAGS) $(LDFLAGS) $^ -o $@ + $(CC) $(ALL_CFLAGS) $(LDFLAGS) $^ -o $@ $(LDLIBS) install: install -d $(BINDIR) @@ -49,4 +58,4 @@ clean: -include $(wildcard .*.d) -.PHONY: all install clean +.PHONY: all install clean FORCE diff --git a/utils/include b/utils/include new file mode 120000 index 000000000..3a1af68fd --- /dev/null +++ b/utils/include @@ -0,0 +1 @@ +../include/ \ No newline at end of file diff --git a/utils/lib b/utils/lib new file mode 120000 index 000000000..5bf80bf13 --- /dev/null +++ b/utils/lib @@ -0,0 +1 @@ +../lib/ \ No newline at end of file diff --git a/utils/mqnic-bmc.c b/utils/mqnic-bmc.c index acaefc4c0..93a5487da 100644 --- a/utils/mqnic-bmc.c +++ b/utils/mqnic-bmc.c @@ -35,7 +35,7 @@ either expressed or implied, of The Regents of the University of California. #include #include -#include "mqnic.h" +#include static void usage(char *name) { diff --git a/utils/mqnic-config.c b/utils/mqnic-config.c index 518d05c29..835ec44b7 100644 --- a/utils/mqnic-config.c +++ b/utils/mqnic-config.c @@ -50,7 +50,7 @@ either expressed or implied, of The Regents of the University of California. #include "timespec.h" -#include "mqnic.h" +#include #define NSEC_PER_SEC 1000000000 diff --git a/utils/mqnic-dump.c b/utils/mqnic-dump.c index 9fedf5082..822576f01 100644 --- a/utils/mqnic-dump.c +++ b/utils/mqnic-dump.c @@ -35,7 +35,7 @@ either expressed or implied, of The Regents of the University of California. #include #include -#include "mqnic.h" +#include static void usage(char *name) { diff --git a/utils/mqnic-fw.c b/utils/mqnic-fw.c index f532916b6..37e462aa0 100644 --- a/utils/mqnic-fw.c +++ b/utils/mqnic-fw.c @@ -42,7 +42,7 @@ either expressed or implied, of The Regents of the University of California. #include #include -#include "mqnic.h" +#include #include "bitfile.h" #include "flash.h" #include "fpga_id.h"