diff mbox

[V6,1/5] libqblock build system

Message ID 1349587956-21436-2-git-send-email-xiaxia347os@163.com
State New
Headers show

Commit Message

wenchao xia Oct. 7, 2012, 5:32 a.m. UTC
From: Wenchao Xia <xiawenc@linux.vnet.ibm.com>

  Libqblock was placed in new directory ./libqblock, libtool will build
dynamic library there, source files of block layer remains in ./block.
So block related source code will generate 3 sets of binary, first is old
ones used in qemu, second and third are non PIC and PIC ones in ./libqblock.
  GCC compiler flag visibility=hidden was used with special macro, to export
only symbols that was marked as PUBLIC.

Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
---
 Makefile                       |   11 +++++-
 libqblock/Makefile             |   72 ++++++++++++++++++++++++++++++++++++++++
 libqblock/libqblock.pc.in      |   13 +++++++
 3 files changed, 95 insertions(+), 1 deletions(-)
 create mode 100644 libqblock/Makefile
 create mode 100644 libqblock/libqblock-error.c
 create mode 100644 libqblock/libqblock-error.h
 create mode 100644 libqblock/libqblock-internal.h
 create mode 100644 libqblock/libqblock-types.h
 create mode 100644 libqblock/libqblock.c
 create mode 100644 libqblock/libqblock.h
 create mode 100644 libqblock/libqblock.pc.in

Comments

Blue Swirl Oct. 7, 2012, 8:35 p.m. UTC | #1
On Sun, Oct 7, 2012 at 5:32 AM, Wenchao Xia <xiaxia347os@163.com> wrote:
> From: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
>
>   Libqblock was placed in new directory ./libqblock, libtool will build
> dynamic library there, source files of block layer remains in ./block.
> So block related source code will generate 3 sets of binary, first is old
> ones used in qemu, second and third are non PIC and PIC ones in ./libqblock.
>   GCC compiler flag visibility=hidden was used with special macro, to export
> only symbols that was marked as PUBLIC.
>
> Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
> ---
>  Makefile                       |   11 +++++-
>  libqblock/Makefile             |   72 ++++++++++++++++++++++++++++++++++++++++
>  libqblock/libqblock.pc.in      |   13 +++++++
>  3 files changed, 95 insertions(+), 1 deletions(-)
>  create mode 100644 libqblock/Makefile
>  create mode 100644 libqblock/libqblock-error.c
>  create mode 100644 libqblock/libqblock-error.h
>  create mode 100644 libqblock/libqblock-internal.h
>  create mode 100644 libqblock/libqblock-types.h
>  create mode 100644 libqblock/libqblock.c
>  create mode 100644 libqblock/libqblock.h
>  create mode 100644 libqblock/libqblock.pc.in
>
> diff --git a/Makefile b/Makefile
> index a9c22bf..53006c1 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -169,6 +169,15 @@ qemu-io$(EXESUF): qemu-io.o cmd.o $(tools-obj-y) $(block-obj-y)
>
>  qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o
>
> +######################################################################
> +# Support building shared library libqblock
> +libqblock.la:
> +       $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C libqblock V="$(V)" TARGET_DIR="$*/" libqblock.la,)

Does not work for out of tree build:
$ make -C obj-amd64 libqblock.la
make: Entering directory `/src/qemu/obj-amd64'
make: Entering an unknown directory
make: *** libqblock: No such file or directory.  Stop.
make: Leaving an unknown directory
make: *** [libqblock.la] Error 2
make: Leaving directory `/src/qemu/obj-amd64'

If I fake what 'configure' should be doing and add the directory and
link to Makefile, there are still problems:
$ make -C obj-amd64 libqblock.la
make: Entering directory `/src/qemu/obj-amd64'
make[1]: *** No rule to make target `libqblock.lo', needed by
`libqblock.la'.  Stop.
make: *** [libqblock.la] Error 2

I think the library should be built by default, like vscclient which
probably nobody uses.

> +
> +install-libqblock:
> +       $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C libqblock V="$(V)" TARGET_DIR="$*/" install-libqblock,)
> +###########################################################################
> +
>  vscclient$(EXESUF): $(libcacard-y) $(oslib-obj-y) $(trace-obj-y) $(tools-obj-y) qemu-timer-common.o libcacard/vscclient.o
>         $(call quiet-command,$(CC) $(LDFLAGS) -o $@ $^ $(libcacard_libs) $(LIBS),"  LINK  $@")
>
> @@ -232,7 +241,7 @@ clean:
>         rm -rf qapi-generated
>         rm -rf qga/qapi-generated
>         $(MAKE) -C tests/tcg clean
> -       for d in $(ALL_SUBDIRS) $(QEMULIBS) libcacard; do \
> +       for d in $(ALL_SUBDIRS) $(QEMULIBS) libcacard libqblock; do \
>         if test -d $$d; then $(MAKE) -C $$d $@ || exit 1; fi; \
>         rm -f $$d/qemu-options.def; \
>          done
> diff --git a/libqblock/Makefile b/libqblock/Makefile
> new file mode 100644
> index 0000000..cd5f4c1
> --- /dev/null
> +++ b/libqblock/Makefile
> @@ -0,0 +1,72 @@
> +###########################################################################
> +# libqblock Makefile
> +# Todo:
> +#    1 trace related files is generated in this directory, move
> +#  them to the root directory.
> +##########################################################################
> +-include ../config-host.mak
> +-include $(SRC_PATH)/Makefile.objs
> +-include $(SRC_PATH)/rules.mak
> +
> +#############################################################################
> +# Library settings
> +#############################################################################
> +$(call set-vpath, $(SRC_PATH))
> +
> +#expand the foldered vars,especially ./block
> +dummy := $(call unnest-vars)
> +
> +#library objects
> +libqblock-y=libqblock.o libqblock-error.o
> +tools-obj-y =  $(oslib-obj-y) $(trace-obj-y) qemu-tool.o qemu-timer.o \
> +       qemu-timer-common.o main-loop.o notify.o \
> +       iohandler.o cutils.o iov.o async.o
> +tools-obj-$(CONFIG_POSIX) += compatfd.o
> +
> +
> +QEMU_OBJS= $(libqblock-y) $(block-obj-y) $(tools-obj-y)
> +QEMU_OBJS_LIB=$(patsubst %.o, %.lo, $(QEMU_OBJS))
> +
> +QEMU_CFLAGS+= -I../ -I../include
> +#adding magic macro define for symbol hiding and exposing
> +QEMU_CFLAGS+= -fvisibility=hidden -D LIBQB_BUILD
> +
> +#dependency libraries
> +LIBS+=-lz $(LIBS_TOOLS)
> +
> +#header files to be installed
> +libqblock-pub-headers=libqblock.h libqblock-types.h libqblock-error.h
> +libqblock_includedir=$(includedir)/qblock
> +libqblock_srcpath=$(SRC_PATH)/libqblock
> +
> +#################################################################
> +# Runtime rules
> +#################################################################
> +clean:
> +       rm -f *.lo *.o *.d *.la libqblock-test trace.c trace.c-timestamp *.pc
> +       rm -rf .libs block trace audio fsdev hw net qapi qga qom slirp ui
> +
> +all: libqblock.la libqblock.pc
> +# Dummy command so that make thinks it has done something
> +       @true
> +
> +libqblock.la: $(QEMU_OBJS_LIB)
> +       $(call quiet-command,$(LIBTOOL) --mode=link --quiet --tag=CC $(CC) -rpath $(libdir) -o $@ $^ $(LIBS),"  lt LINK $@")
> +
> +libqblock.pc: $(libqblock_srcpath)/libqblock.pc.in
> +       $(call quiet-command,sed -e 's|@LIBDIR@|$(libdir)|' \
> +               -e 's|@INCLUDEDIR@|$(libqblock_includedir)|' \
> +           -e 's|@VERSION@|$(shell cat $(SRC_PATH)/VERSION)|' \
> +               -e 's|@PREFIX@|$(prefix)|' \
> +               < $(libqblock_srcpath)/libqblock.pc.in > libqblock.pc,\
> +       "  GEN   $@")
> +
> +.PHONY: install-libqblock
> +
> +install-libqblock: libqblock.la libqblock.pc
> +       $(INSTALL_DIR) "$(DESTDIR)$(libdir)"
> +       $(INSTALL_DIR) "$(DESTDIR)$(libdir)/pkgconfig"
> +       $(INSTALL_DIR) "$(DESTDIR)$(libqblock_includedir)"
> +       $(LIBTOOL) --mode=install $(INSTALL_DATA) libqblock.la "$(DESTDIR)$(libdir)"
> +       $(LIBTOOL) --mode=install $(INSTALL_DATA) libqblock.pc "$(DESTDIR)$(libdir)/pkgconfig"
> +       $(LIBTOOL) --mode=install $(INSTALL_DATA) $(libqblock-pub-headers) "$(DESTDIR)$(libqblock_includedir)"
> diff --git a/libqblock/libqblock-error.c b/libqblock/libqblock-error.c
> new file mode 100644
> index 0000000..e69de29
> diff --git a/libqblock/libqblock-error.h b/libqblock/libqblock-error.h
> new file mode 100644
> index 0000000..e69de29
> diff --git a/libqblock/libqblock-internal.h b/libqblock/libqblock-internal.h
> new file mode 100644
> index 0000000..e69de29
> diff --git a/libqblock/libqblock-types.h b/libqblock/libqblock-types.h
> new file mode 100644
> index 0000000..e69de29
> diff --git a/libqblock/libqblock.c b/libqblock/libqblock.c
> new file mode 100644
> index 0000000..e69de29
> diff --git a/libqblock/libqblock.h b/libqblock/libqblock.h
> new file mode 100644
> index 0000000..e69de29
> diff --git a/libqblock/libqblock.pc.in b/libqblock/libqblock.pc.in
> new file mode 100644
> index 0000000..d2a7d06
> --- /dev/null
> +++ b/libqblock/libqblock.pc.in
> @@ -0,0 +1,13 @@
> +prefix=@PREFIX@
> +exec_prefix=${prefix}
> +libdir=@LIBDIR@
> +includedir=@INCLUDEDIR@
> +
> +Name: qblock
> +Description: QEMU block layer library
> +Version: @VERSION@
> +
> +Requires:  rt gthread-2.0 glib-2.0 z curl cap-ng uuid
> +Libs: -L${libdir} -lqblock
> +Libs.private:
> +Cflags: -I${includedir}
> --
> 1.7.1
>
>
>
wenchao xia Oct. 8, 2012, 1:39 a.m. UTC | #2
> On Sun, Oct 7, 2012 at 5:32 AM, Wenchao Xia <xiaxia347os@163.com> wrote:
>> From: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
>>
>>    Libqblock was placed in new directory ./libqblock, libtool will build
>> dynamic library there, source files of block layer remains in ./block.
>> So block related source code will generate 3 sets of binary, first is old
>> ones used in qemu, second and third are non PIC and PIC ones in ./libqblock.
>>    GCC compiler flag visibility=hidden was used with special macro, to export
>> only symbols that was marked as PUBLIC.
>>
>> Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
>> ---
>>   Makefile                       |   11 +++++-
>>   libqblock/Makefile             |   72 ++++++++++++++++++++++++++++++++++++++++
>>   libqblock/libqblock.pc.in      |   13 +++++++
>>   3 files changed, 95 insertions(+), 1 deletions(-)
>>   create mode 100644 libqblock/Makefile
>>   create mode 100644 libqblock/libqblock-error.c
>>   create mode 100644 libqblock/libqblock-error.h
>>   create mode 100644 libqblock/libqblock-internal.h
>>   create mode 100644 libqblock/libqblock-types.h
>>   create mode 100644 libqblock/libqblock.c
>>   create mode 100644 libqblock/libqblock.h
>>   create mode 100644 libqblock/libqblock.pc.in
>>
>> diff --git a/Makefile b/Makefile
>> index a9c22bf..53006c1 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -169,6 +169,15 @@ qemu-io$(EXESUF): qemu-io.o cmd.o $(tools-obj-y) $(block-obj-y)
>>
>>   qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o
>>
>> +######################################################################
>> +# Support building shared library libqblock
>> +libqblock.la:
>> +       $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C libqblock V="$(V)" TARGET_DIR="$*/" libqblock.la,)
>
> Does not work for out of tree build:
> $ make -C obj-amd64 libqblock.la
> make: Entering directory `/src/qemu/obj-amd64'
> make: Entering an unknown directory
> make: *** libqblock: No such file or directory.  Stop.
> make: Leaving an unknown directory
> make: *** [libqblock.la] Error 2
> make: Leaving directory `/src/qemu/obj-amd64'
>
> If I fake what 'configure' should be doing and add the directory and
> link to Makefile, there are still problems:
> $ make -C obj-amd64 libqblock.la
> make: Entering directory `/src/qemu/obj-amd64'
> make[1]: *** No rule to make target `libqblock.lo', needed by
> `libqblock.la'.  Stop.
> make: *** [libqblock.la] Error 2
>
   Could u give more tip about this error? what is obj-amd64?
My understanding is you tried to build the library from another
directory similar as:
/extend_disk/xiawenc/qemu/qemu have the qemu source code, then
[xiawenc@RedHat62GAWSWenchao xiawenc]$ pwd
/extend_disk/xiawenc
[xiawenc@RedHat62GAWSWenchao xiawenc]$ make -C qemu/qemu libqblock.la
failed.
Please correct me.

> I think the library should be built by default, like vscclient which
> probably nobody uses.
>
   libvirt can't link to it now for OOM issue, but I will wrapper the
APIs with RPC later.

>> +
>> +install-libqblock:
>> +       $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C libqblock V="$(V)" TARGET_DIR="$*/" install-libqblock,)
>> +###########################################################################
>> +
>>   vscclient$(EXESUF): $(libcacard-y) $(oslib-obj-y) $(trace-obj-y) $(tools-obj-y) qemu-timer-common.o libcacard/vscclient.o
>>          $(call quiet-command,$(CC) $(LDFLAGS) -o $@ $^ $(libcacard_libs) $(LIBS),"  LINK  $@")
>>
>> @@ -232,7 +241,7 @@ clean:
>>          rm -rf qapi-generated
>>          rm -rf qga/qapi-generated
>>          $(MAKE) -C tests/tcg clean
>> -       for d in $(ALL_SUBDIRS) $(QEMULIBS) libcacard; do \
>> +       for d in $(ALL_SUBDIRS) $(QEMULIBS) libcacard libqblock; do \
>>          if test -d $$d; then $(MAKE) -C $$d $@ || exit 1; fi; \
>>          rm -f $$d/qemu-options.def; \
>>           done
>> diff --git a/libqblock/Makefile b/libqblock/Makefile
>> new file mode 100644
>> index 0000000..cd5f4c1
>> --- /dev/null
>> +++ b/libqblock/Makefile
>> @@ -0,0 +1,72 @@
>> +###########################################################################
>> +# libqblock Makefile
>> +# Todo:
>> +#    1 trace related files is generated in this directory, move
>> +#  them to the root directory.
>> +##########################################################################
>> +-include ../config-host.mak
>> +-include $(SRC_PATH)/Makefile.objs
>> +-include $(SRC_PATH)/rules.mak
>> +
>> +#############################################################################
>> +# Library settings
>> +#############################################################################
>> +$(call set-vpath, $(SRC_PATH))
>> +
>> +#expand the foldered vars,especially ./block
>> +dummy := $(call unnest-vars)
>> +
>> +#library objects
>> +libqblock-y=libqblock.o libqblock-error.o
>> +tools-obj-y =  $(oslib-obj-y) $(trace-obj-y) qemu-tool.o qemu-timer.o \
>> +       qemu-timer-common.o main-loop.o notify.o \
>> +       iohandler.o cutils.o iov.o async.o
>> +tools-obj-$(CONFIG_POSIX) += compatfd.o
>> +
>> +
>> +QEMU_OBJS= $(libqblock-y) $(block-obj-y) $(tools-obj-y)
>> +QEMU_OBJS_LIB=$(patsubst %.o, %.lo, $(QEMU_OBJS))
>> +
>> +QEMU_CFLAGS+= -I../ -I../include
>> +#adding magic macro define for symbol hiding and exposing
>> +QEMU_CFLAGS+= -fvisibility=hidden -D LIBQB_BUILD
>> +
>> +#dependency libraries
>> +LIBS+=-lz $(LIBS_TOOLS)
>> +
>> +#header files to be installed
>> +libqblock-pub-headers=libqblock.h libqblock-types.h libqblock-error.h
>> +libqblock_includedir=$(includedir)/qblock
>> +libqblock_srcpath=$(SRC_PATH)/libqblock
>> +
>> +#################################################################
>> +# Runtime rules
>> +#################################################################
>> +clean:
>> +       rm -f *.lo *.o *.d *.la libqblock-test trace.c trace.c-timestamp *.pc
>> +       rm -rf .libs block trace audio fsdev hw net qapi qga qom slirp ui
>> +
>> +all: libqblock.la libqblock.pc
>> +# Dummy command so that make thinks it has done something
>> +       @true
>> +
>> +libqblock.la: $(QEMU_OBJS_LIB)
>> +       $(call quiet-command,$(LIBTOOL) --mode=link --quiet --tag=CC $(CC) -rpath $(libdir) -o $@ $^ $(LIBS),"  lt LINK $@")
>> +
>> +libqblock.pc: $(libqblock_srcpath)/libqblock.pc.in
>> +       $(call quiet-command,sed -e 's|@LIBDIR@|$(libdir)|' \
>> +               -e 's|@INCLUDEDIR@|$(libqblock_includedir)|' \
>> +           -e 's|@VERSION@|$(shell cat $(SRC_PATH)/VERSION)|' \
>> +               -e 's|@PREFIX@|$(prefix)|' \
>> +               < $(libqblock_srcpath)/libqblock.pc.in > libqblock.pc,\
>> +       "  GEN   $@")
>> +
>> +.PHONY: install-libqblock
>> +
>> +install-libqblock: libqblock.la libqblock.pc
>> +       $(INSTALL_DIR) "$(DESTDIR)$(libdir)"
>> +       $(INSTALL_DIR) "$(DESTDIR)$(libdir)/pkgconfig"
>> +       $(INSTALL_DIR) "$(DESTDIR)$(libqblock_includedir)"
>> +       $(LIBTOOL) --mode=install $(INSTALL_DATA) libqblock.la "$(DESTDIR)$(libdir)"
>> +       $(LIBTOOL) --mode=install $(INSTALL_DATA) libqblock.pc "$(DESTDIR)$(libdir)/pkgconfig"
>> +       $(LIBTOOL) --mode=install $(INSTALL_DATA) $(libqblock-pub-headers) "$(DESTDIR)$(libqblock_includedir)"
>> diff --git a/libqblock/libqblock-error.c b/libqblock/libqblock-error.c
>> new file mode 100644
>> index 0000000..e69de29
>> diff --git a/libqblock/libqblock-error.h b/libqblock/libqblock-error.h
>> new file mode 100644
>> index 0000000..e69de29
>> diff --git a/libqblock/libqblock-internal.h b/libqblock/libqblock-internal.h
>> new file mode 100644
>> index 0000000..e69de29
>> diff --git a/libqblock/libqblock-types.h b/libqblock/libqblock-types.h
>> new file mode 100644
>> index 0000000..e69de29
>> diff --git a/libqblock/libqblock.c b/libqblock/libqblock.c
>> new file mode 100644
>> index 0000000..e69de29
>> diff --git a/libqblock/libqblock.h b/libqblock/libqblock.h
>> new file mode 100644
>> index 0000000..e69de29
>> diff --git a/libqblock/libqblock.pc.in b/libqblock/libqblock.pc.in
>> new file mode 100644
>> index 0000000..d2a7d06
>> --- /dev/null
>> +++ b/libqblock/libqblock.pc.in
>> @@ -0,0 +1,13 @@
>> +prefix=@PREFIX@
>> +exec_prefix=${prefix}
>> +libdir=@LIBDIR@
>> +includedir=@INCLUDEDIR@
>> +
>> +Name: qblock
>> +Description: QEMU block layer library
>> +Version: @VERSION@
>> +
>> +Requires:  rt gthread-2.0 glib-2.0 z curl cap-ng uuid
>> +Libs: -L${libdir} -lqblock
>> +Libs.private:
>> +Cflags: -I${includedir}
>> --
>> 1.7.1
>>
>>
>>
wenchao xia Oct. 9, 2012, 12:01 a.m. UTC | #3
>>> +######################################################################
>>> +# Support building shared library libqblock
>>> +libqblock.la:
>>> +       $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C libqblock
>>> V="$(V)" TARGET_DIR="$*/" libqblock.la,)
>>
>> Does not work for out of tree build:
>> $ make -C obj-amd64 libqblock.la
>> make: Entering directory `/src/qemu/obj-amd64'
>> make: Entering an unknown directory
>> make: *** libqblock: No such file or directory.  Stop.
>> make: Leaving an unknown directory
>> make: *** [libqblock.la] Error 2
>> make: Leaving directory `/src/qemu/obj-amd64'
>>
>> If I fake what 'configure' should be doing and add the directory and
>> link to Makefile, there are still problems:
>> $ make -C obj-amd64 libqblock.la
>> make: Entering directory `/src/qemu/obj-amd64'
>> make[1]: *** No rule to make target `libqblock.lo', needed by
>> `libqblock.la'.  Stop.
>> make: *** [libqblock.la] Error 2
>>
>    Could u give more tip about this error? what is obj-amd64?
> My understanding is you tried to build the library from another
> directory similar as:
> /extend_disk/xiawenc/qemu/qemu have the qemu source code, then
> [xiawenc@RedHat62GAWSWenchao xiawenc]$ pwd
> /extend_disk/xiawenc
> [xiawenc@RedHat62GAWSWenchao xiawenc]$ make -C qemu/qemu libqblock.la
> failed.
> Please correct me.
>
>> I think the library should be built by default, like vscclient which
>> probably nobody uses.
>>
>    libvirt can't link to it now for OOM issue, but I will wrapper the
> APIs with RPC later.
>
   I can't reproduce the issue, hope you can show how to make it happen.
Paolo Bonzini Oct. 9, 2012, 2:25 p.m. UTC | #4
Il 09/10/2012 02:01, wenchao xia ha scritto:
>>
>    Could u give more tip about this error? what is obj-amd64?
> My understanding is you tried to build the library from another
> directory similar as:
> /extend_disk/xiawenc/qemu/qemu have the qemu source code, then
> [xiawenc@RedHat62GAWSWenchao xiawenc]$ pwd
> /extend_disk/xiawenc
> [xiawenc@RedHat62GAWSWenchao xiawenc]$ make -C qemu/qemu libqblock.la
> failed.
> Please correct me.

mkdir obj-amd64
cd obj-amd64
../configure
make

Paolo
wenchao xia Oct. 11, 2012, 1:39 a.m. UTC | #5
于 2012-10-9 22:25, Paolo Bonzini 写道:
> Il 09/10/2012 02:01, wenchao xia ha scritto:
>>>
>>     Could u give more tip about this error? what is obj-amd64?
>> My understanding is you tried to build the library from another
>> directory similar as:
>> /extend_disk/xiawenc/qemu/qemu have the qemu source code, then
>> [xiawenc@RedHat62GAWSWenchao xiawenc]$ pwd
>> /extend_disk/xiawenc
>> [xiawenc@RedHat62GAWSWenchao xiawenc]$ make -C qemu/qemu libqblock.la
>> failed.
>> Please correct me.
>
> mkdir obj-amd64
> cd obj-amd64
> ../configure
> make
>
> Paolo
>
Thank you for the declaration, I'll fix it.
diff mbox

Patch

diff --git a/Makefile b/Makefile
index a9c22bf..53006c1 100644
--- a/Makefile
+++ b/Makefile
@@ -169,6 +169,15 @@  qemu-io$(EXESUF): qemu-io.o cmd.o $(tools-obj-y) $(block-obj-y)
 
 qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o
 
+######################################################################
+# Support building shared library libqblock
+libqblock.la:
+	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C libqblock V="$(V)" TARGET_DIR="$*/" libqblock.la,)
+
+install-libqblock:
+	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C libqblock V="$(V)" TARGET_DIR="$*/" install-libqblock,)
+###########################################################################
+
 vscclient$(EXESUF): $(libcacard-y) $(oslib-obj-y) $(trace-obj-y) $(tools-obj-y) qemu-timer-common.o libcacard/vscclient.o
 	$(call quiet-command,$(CC) $(LDFLAGS) -o $@ $^ $(libcacard_libs) $(LIBS),"  LINK  $@")
 
@@ -232,7 +241,7 @@  clean:
 	rm -rf qapi-generated
 	rm -rf qga/qapi-generated
 	$(MAKE) -C tests/tcg clean
-	for d in $(ALL_SUBDIRS) $(QEMULIBS) libcacard; do \
+	for d in $(ALL_SUBDIRS) $(QEMULIBS) libcacard libqblock; do \
 	if test -d $$d; then $(MAKE) -C $$d $@ || exit 1; fi; \
 	rm -f $$d/qemu-options.def; \
         done
diff --git a/libqblock/Makefile b/libqblock/Makefile
new file mode 100644
index 0000000..cd5f4c1
--- /dev/null
+++ b/libqblock/Makefile
@@ -0,0 +1,72 @@ 
+###########################################################################
+# libqblock Makefile
+# Todo:
+#    1 trace related files is generated in this directory, move
+#  them to the root directory.
+##########################################################################
+-include ../config-host.mak
+-include $(SRC_PATH)/Makefile.objs
+-include $(SRC_PATH)/rules.mak
+
+#############################################################################
+# Library settings
+#############################################################################
+$(call set-vpath, $(SRC_PATH))
+
+#expand the foldered vars,especially ./block
+dummy := $(call unnest-vars)
+
+#library objects
+libqblock-y=libqblock.o libqblock-error.o
+tools-obj-y =  $(oslib-obj-y) $(trace-obj-y) qemu-tool.o qemu-timer.o \
+       qemu-timer-common.o main-loop.o notify.o \
+       iohandler.o cutils.o iov.o async.o
+tools-obj-$(CONFIG_POSIX) += compatfd.o
+
+
+QEMU_OBJS= $(libqblock-y) $(block-obj-y) $(tools-obj-y)
+QEMU_OBJS_LIB=$(patsubst %.o, %.lo, $(QEMU_OBJS))
+
+QEMU_CFLAGS+= -I../ -I../include
+#adding magic macro define for symbol hiding and exposing
+QEMU_CFLAGS+= -fvisibility=hidden -D LIBQB_BUILD
+
+#dependency libraries
+LIBS+=-lz $(LIBS_TOOLS)
+
+#header files to be installed
+libqblock-pub-headers=libqblock.h libqblock-types.h libqblock-error.h
+libqblock_includedir=$(includedir)/qblock
+libqblock_srcpath=$(SRC_PATH)/libqblock
+
+#################################################################
+# Runtime rules
+#################################################################
+clean:
+	rm -f *.lo *.o *.d *.la libqblock-test trace.c trace.c-timestamp *.pc
+	rm -rf .libs block trace audio fsdev hw net qapi qga qom slirp ui
+
+all: libqblock.la libqblock.pc
+# Dummy command so that make thinks it has done something
+	@true
+
+libqblock.la: $(QEMU_OBJS_LIB)
+	$(call quiet-command,$(LIBTOOL) --mode=link --quiet --tag=CC $(CC) -rpath $(libdir) -o $@ $^ $(LIBS),"  lt LINK $@")
+
+libqblock.pc: $(libqblock_srcpath)/libqblock.pc.in
+	$(call quiet-command,sed -e 's|@LIBDIR@|$(libdir)|' \
+		-e 's|@INCLUDEDIR@|$(libqblock_includedir)|' \
+	    -e 's|@VERSION@|$(shell cat $(SRC_PATH)/VERSION)|' \
+		-e 's|@PREFIX@|$(prefix)|' \
+		< $(libqblock_srcpath)/libqblock.pc.in > libqblock.pc,\
+	"  GEN   $@")
+
+.PHONY: install-libqblock
+
+install-libqblock: libqblock.la libqblock.pc
+	$(INSTALL_DIR) "$(DESTDIR)$(libdir)"
+	$(INSTALL_DIR) "$(DESTDIR)$(libdir)/pkgconfig"
+	$(INSTALL_DIR) "$(DESTDIR)$(libqblock_includedir)"
+	$(LIBTOOL) --mode=install $(INSTALL_DATA) libqblock.la "$(DESTDIR)$(libdir)"
+	$(LIBTOOL) --mode=install $(INSTALL_DATA) libqblock.pc "$(DESTDIR)$(libdir)/pkgconfig"
+	$(LIBTOOL) --mode=install $(INSTALL_DATA) $(libqblock-pub-headers) "$(DESTDIR)$(libqblock_includedir)"
diff --git a/libqblock/libqblock-error.c b/libqblock/libqblock-error.c
new file mode 100644
index 0000000..e69de29
diff --git a/libqblock/libqblock-error.h b/libqblock/libqblock-error.h
new file mode 100644
index 0000000..e69de29
diff --git a/libqblock/libqblock-internal.h b/libqblock/libqblock-internal.h
new file mode 100644
index 0000000..e69de29
diff --git a/libqblock/libqblock-types.h b/libqblock/libqblock-types.h
new file mode 100644
index 0000000..e69de29
diff --git a/libqblock/libqblock.c b/libqblock/libqblock.c
new file mode 100644
index 0000000..e69de29
diff --git a/libqblock/libqblock.h b/libqblock/libqblock.h
new file mode 100644
index 0000000..e69de29
diff --git a/libqblock/libqblock.pc.in b/libqblock/libqblock.pc.in
new file mode 100644
index 0000000..d2a7d06
--- /dev/null
+++ b/libqblock/libqblock.pc.in
@@ -0,0 +1,13 @@ 
+prefix=@PREFIX@
+exec_prefix=${prefix}
+libdir=@LIBDIR@
+includedir=@INCLUDEDIR@
+
+Name: qblock
+Description: QEMU block layer library
+Version: @VERSION@
+
+Requires:  rt gthread-2.0 glib-2.0 z curl cap-ng uuid
+Libs: -L${libdir} -lqblock
+Libs.private:
+Cflags: -I${includedir}