diff mbox

[V3,1/5] libqblock build system

Message ID 1347958919-30380-2-git-send-email-xiawenc@linux.vnet.ibm.com
State New
Headers show

Commit Message

Wayne Xia Sept. 18, 2012, 9:01 a.m. UTC
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                    |   13 ++++++++-
 Makefile.objs               |    6 ++++
 libqblock/Makefile          |   64 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 82 insertions(+), 1 deletions(-)
 create mode 100644 libqblock/Makefile
 create mode 100644 libqblock/libqblock-error.c
 create mode 100644 libqblock/libqblock.c

diff --git a/libqblock/libqblock-error.c b/libqblock/libqblock-error.c
new file mode 100644
index 0000000..e69de29
diff --git a/libqblock/libqblock.c b/libqblock/libqblock.c
new file mode 100644
index 0000000..e69de29

Comments

Paolo Bonzini Sept. 18, 2012, 10:05 a.m. UTC | #1
Il 18/09/2012 11:01, Wenchao Xia ha scritto:
>   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                    |   13 ++++++++-
>  Makefile.objs               |    6 ++++
>  libqblock/Makefile          |   64 +++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 82 insertions(+), 1 deletions(-)
>  create mode 100644 libqblock/Makefile
>  create mode 100644 libqblock/libqblock-error.c
>  create mode 100644 libqblock/libqblock.c
> 
> diff --git a/Makefile b/Makefile
> index 971e92f..b0b9b8d 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -164,6 +164,17 @@ 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
> +ifeq ($(LIBTOOL),)
> +$(libqblock-lib-la):
> +	@echo "libtool is missing, please install and rerun configure"; exit 1
> +else
> +$(libqblock-lib-la):
> +	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C libqblock V="$(V)" TARGET_DIR="$*/" $(libqblock-lib-la),)
> +endif
> +###########################################################################
> +
>  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  $@")
>  
> @@ -227,7 +238,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/Makefile.objs b/Makefile.objs
> index 4412757..8a4c9fc 100644
> --- a/Makefile.objs
> +++ b/Makefile.objs
> @@ -248,3 +248,9 @@ nested-vars += \
>  	common-obj-y \
>  	extra-obj-y
>  dummy := $(call unnest-vars)
> +
> +#############################################################################
> +# libqblock
> +
> +libqblock-lib-la = libqblock.la
> +libqblock-lib-path = libqblock
> diff --git a/libqblock/Makefile b/libqblock/Makefile
> new file mode 100644
> index 0000000..bf7abcc
> --- /dev/null
> +++ b/libqblock/Makefile
> @@ -0,0 +1,64 @@
> +###########################################################################
> +# 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-1)
> +
> +#library objects
> +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

Do you really need all of these?

(BTW, I posted recently a patch to move tools-obj-y to Makefile.objs.
It doesn't apply anymore, I'll repost---but the conflicts are trivial).

> +libqblock-y=libqblock.o libqblock-error.o
> +libqblock-lib-y=$(patsubst %.o,%.lo,$(libqblock-y))
> +
> +QEMU_OBJS=$(tools-obj-y) $(block-obj-y)
> +QEMU_OBJS_FILTERED=$(filter %.o,$(QEMU_OBJS))

What does this filter out?

Paolo

> +QEMU_OBJS_LIB=$(patsubst %.o, %.lo,$(QEMU_OBJS_FILTERED))
> +
> +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)
> +
> +#################################################################
> +# Runtime rules
> +#################################################################
> +clean:
> +	rm -f *.lo *.o *.d *.la libqblock-test trace.c trace.c-timestamp
> +	rm -rf .libs block trace
> +
> +all: libqblock-test
> +	@true
> +
> +help:
> +	@echo type make libqblock-test at root dirtory, libtool is required
> +
> +#make dir block at runtime which would hold the output of block/*.c
> +block:
> +	@mkdir block
> +
> +ifeq ($(LIBTOOL),)
> +$(libqblock-lib-la):
> +	@echo "libtool is missing, please install and rerun configure"; exit 1
> +else
> +$(libqblock-lib-la): $(libqblock-lib-y) $(QEMU_OBJS_LIB)
> +	$(call quiet-command,$(LIBTOOL) --mode=link --quiet --tag=CC $(CC) -rpath $(libdir) -o $@ $^ $(LIBS),"  lt LINK $@")
> +endif
> +
> +.PHONY: libqblock.la
> diff --git a/libqblock/libqblock-error.c b/libqblock/libqblock-error.c
> new file mode 100644
> index 0000000..e69de29
> diff --git a/libqblock/libqblock.c b/libqblock/libqblock.c
> new file mode 100644
> index 0000000..e69de29
>
Paolo Bonzini Sept. 18, 2012, 10:31 a.m. UTC | #2
Il 18/09/2012 11:01, Wenchao Xia ha scritto:
>   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                    |   13 ++++++++-
>  Makefile.objs               |    6 ++++
>  libqblock/Makefile          |   64 +++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 82 insertions(+), 1 deletions(-)
>  create mode 100644 libqblock/Makefile
>  create mode 100644 libqblock/libqblock-error.c
>  create mode 100644 libqblock/libqblock.c
> 
> diff --git a/Makefile b/Makefile
> index 971e92f..b0b9b8d 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -164,6 +164,17 @@ 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
> +ifeq ($(LIBTOOL),)
> +$(libqblock-lib-la):
> +	@echo "libtool is missing, please install and rerun configure"; exit 1
> +else
> +$(libqblock-lib-la):
> +	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C libqblock V="$(V)" TARGET_DIR="$*/" $(libqblock-lib-la),)
> +endif
> +###########################################################################
> +
>  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  $@")
>  
> @@ -227,7 +238,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/Makefile.objs b/Makefile.objs
> index 4412757..8a4c9fc 100644
> --- a/Makefile.objs
> +++ b/Makefile.objs
> @@ -248,3 +248,9 @@ nested-vars += \
>  	common-obj-y \
>  	extra-obj-y
>  dummy := $(call unnest-vars)
> +
> +#############################################################################
> +# libqblock
> +
> +libqblock-lib-la = libqblock.la
> +libqblock-lib-path = libqblock
> diff --git a/libqblock/Makefile b/libqblock/Makefile
> new file mode 100644
> index 0000000..bf7abcc
> --- /dev/null
> +++ b/libqblock/Makefile
> @@ -0,0 +1,64 @@
> +###########################################################################
> +# 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-1)
> +
> +#library objects
> +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

Do you really need all of these?

(BTW, I posted recently a patch to move tools-obj-y to Makefile.objs.
It doesn't apply anymore, I'll repost---but the conflicts are trivial).

> +libqblock-y=libqblock.o libqblock-error.o
> +libqblock-lib-y=$(patsubst %.o,%.lo,$(libqblock-y))
> +
> +QEMU_OBJS=$(tools-obj-y) $(block-obj-y)
> +QEMU_OBJS_FILTERED=$(filter %.o,$(QEMU_OBJS))

What does this filter out?

> +QEMU_OBJS_LIB=$(patsubst %.o, %.lo,$(QEMU_OBJS_FILTERED))
> +
> +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)
> +
> +#################################################################
> +# Runtime rules
> +#################################################################
> +clean:
> +	rm -f *.lo *.o *.d *.la libqblock-test trace.c trace.c-timestamp
> +	rm -rf .libs block trace
> +
> +all: libqblock-test

Do not put yet the libqblock-test rules in here, please.

Paolo

> +	@true
> +
> +help:
> +	@echo type make libqblock-test at root dirtory, libtool is required
> +
> +#make dir block at runtime which would hold the output of block/*.c
> +block:
> +	@mkdir block
> +
> +ifeq ($(LIBTOOL),)
> +$(libqblock-lib-la):
> +	@echo "libtool is missing, please install and rerun configure"; exit 1
> +else
> +$(libqblock-lib-la): $(libqblock-lib-y) $(QEMU_OBJS_LIB)
> +	$(call quiet-command,$(LIBTOOL) --mode=link --quiet --tag=CC $(CC) -rpath $(libdir) -o $@ $^ $(LIBS),"  lt LINK $@")
> +endif
> +
> +.PHONY: libqblock.la
> diff --git a/libqblock/libqblock-error.c b/libqblock/libqblock-error.c
> new file mode 100644
> index 0000000..e69de29
> diff --git a/libqblock/libqblock.c b/libqblock/libqblock.c
> new file mode 100644
> index 0000000..e69de29
>
Wayne Xia Sept. 19, 2012, 6:35 a.m. UTC | #3
于 2012-9-18 18:05, Paolo Bonzini 写道:
> Il 18/09/2012 11:01, Wenchao Xia ha scritto:
>>    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                    |   13 ++++++++-
>>   Makefile.objs               |    6 ++++
>>   libqblock/Makefile          |   64 +++++++++++++++++++++++++++++++++++++++++++
>>   3 files changed, 82 insertions(+), 1 deletions(-)
>>   create mode 100644 libqblock/Makefile
>>   create mode 100644 libqblock/libqblock-error.c
>>   create mode 100644 libqblock/libqblock.c
>>
>> diff --git a/Makefile b/Makefile
>> index 971e92f..b0b9b8d 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -164,6 +164,17 @@ 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
>> +ifeq ($(LIBTOOL),)
>> +$(libqblock-lib-la):
>> +	@echo "libtool is missing, please install and rerun configure"; exit 1
>> +else
>> +$(libqblock-lib-la):
>> +	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C libqblock V="$(V)" TARGET_DIR="$*/" $(libqblock-lib-la),)
>> +endif
>> +###########################################################################
>> +
>>   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  $@")
>>
>> @@ -227,7 +238,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/Makefile.objs b/Makefile.objs
>> index 4412757..8a4c9fc 100644
>> --- a/Makefile.objs
>> +++ b/Makefile.objs
>> @@ -248,3 +248,9 @@ nested-vars += \
>>   	common-obj-y \
>>   	extra-obj-y
>>   dummy := $(call unnest-vars)
>> +
>> +#############################################################################
>> +# libqblock
>> +
>> +libqblock-lib-la = libqblock.la
>> +libqblock-lib-path = libqblock
>> diff --git a/libqblock/Makefile b/libqblock/Makefile
>> new file mode 100644
>> index 0000000..bf7abcc
>> --- /dev/null
>> +++ b/libqblock/Makefile
>> @@ -0,0 +1,64 @@
>> +###########################################################################
>> +# 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-1)
>> +
>> +#library objects
>> +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
>
> Do you really need all of these?
>
   I guess only some .o are needed, but not sure how to pick them out, 
is there some tools which can help detect which object files are needed
in final linkage?

> (BTW, I posted recently a patch to move tools-obj-y to Makefile.objs.
> It doesn't apply anymore, I'll repost---but the conflicts are trivial).
>
   greate, then I can use tools-obj-y directly.

>> +libqblock-y=libqblock.o libqblock-error.o
>> +libqblock-lib-y=$(patsubst %.o,%.lo,$(libqblock-y))
>> +
>> +QEMU_OBJS=$(tools-obj-y) $(block-obj-y)
>> +QEMU_OBJS_FILTERED=$(filter %.o,$(QEMU_OBJS))
>
> What does this filter out?
>
   $(block-obj-y) contains /block, which would cause trouble in building,
so filtered it out.

> Paolo
>
>> +QEMU_OBJS_LIB=$(patsubst %.o, %.lo,$(QEMU_OBJS_FILTERED))
>> +
>> +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)
>> +
>> +#################################################################
>> +# Runtime rules
>> +#################################################################
>> +clean:
>> +	rm -f *.lo *.o *.d *.la libqblock-test trace.c trace.c-timestamp
>> +	rm -rf .libs block trace
>> +
>> +all: libqblock-test
>> +	@true
>> +
>> +help:
>> +	@echo type make libqblock-test at root dirtory, libtool is required
>> +
>> +#make dir block at runtime which would hold the output of block/*.c
>> +block:
>> +	@mkdir block
>> +
>> +ifeq ($(LIBTOOL),)
>> +$(libqblock-lib-la):
>> +	@echo "libtool is missing, please install and rerun configure"; exit 1
>> +else
>> +$(libqblock-lib-la): $(libqblock-lib-y) $(QEMU_OBJS_LIB)
>> +	$(call quiet-command,$(LIBTOOL) --mode=link --quiet --tag=CC $(CC) -rpath $(libdir) -o $@ $^ $(LIBS),"  lt LINK $@")
>> +endif
>> +
>> +.PHONY: libqblock.la
>> diff --git a/libqblock/libqblock-error.c b/libqblock/libqblock-error.c
>> new file mode 100644
>> index 0000000..e69de29
>> diff --git a/libqblock/libqblock.c b/libqblock/libqblock.c
>> new file mode 100644
>> index 0000000..e69de29
>>
>
Paolo Bonzini Sept. 19, 2012, 9:57 a.m. UTC | #4
Il 19/09/2012 08:35, Wenchao Xia ha scritto:
>>>
>>> +QEMU_OBJS=$(tools-obj-y) $(block-obj-y)
>>> +QEMU_OBJS_FILTERED=$(filter %.o,$(QEMU_OBJS))
>>
>> What does this filter out?
>>
>   $(block-obj-y) contains /block, which would cause trouble in building,
> so filtered it out.

I think that's because you have to call unnest-vars, not unnest-vars-1.

Paolo
Wayne Xia Sept. 27, 2012, 2:15 a.m. UTC | #5
于 2012-9-19 17:57, Paolo Bonzini 写道:
> Il 19/09/2012 08:35, Wenchao Xia ha scritto:
>>>>
>>>> +QEMU_OBJS=$(tools-obj-y) $(block-obj-y)
>>>> +QEMU_OBJS_FILTERED=$(filter %.o,$(QEMU_OBJS))
>>>
>>> What does this filter out?
>>>
>>    $(block-obj-y) contains /block, which would cause trouble in building,
>> so filtered it out.
>
> I think that's because you have to call unnest-vars, not unnest-vars-1.
>
> Paolo
>
   Tried with unnest-vars, it will create some unnessary directories in
./libqblock, unnest-vars-1 seems more reasonable.
Paolo Bonzini Sept. 27, 2012, 7:14 a.m. UTC | #6
Il 27/09/2012 04:15, Wenchao Xia ha scritto:
> 于 2012-9-19 17:57, Paolo Bonzini 写道:
>> Il 19/09/2012 08:35, Wenchao Xia ha scritto:
>>>>>
>>>>> +QEMU_OBJS=$(tools-obj-y) $(block-obj-y)
>>>>> +QEMU_OBJS_FILTERED=$(filter %.o,$(QEMU_OBJS))
>>>>
>>>> What does this filter out?
>>>>
>>>    $(block-obj-y) contains /block, which would cause trouble in
>>> building,
>>> so filtered it out.
>>
>> I think that's because you have to call unnest-vars, not unnest-vars-1.
>>
>> Paolo
>>
>   Tried with unnest-vars, it will create some unnessary directories in
> ./libqblock, unnest-vars-1 seems more reasonable.

Don't worry about unnecessary directories, worry about correctness.

Paolo
diff mbox

Patch

diff --git a/Makefile b/Makefile
index 971e92f..b0b9b8d 100644
--- a/Makefile
+++ b/Makefile
@@ -164,6 +164,17 @@  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
+ifeq ($(LIBTOOL),)
+$(libqblock-lib-la):
+	@echo "libtool is missing, please install and rerun configure"; exit 1
+else
+$(libqblock-lib-la):
+	$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C libqblock V="$(V)" TARGET_DIR="$*/" $(libqblock-lib-la),)
+endif
+###########################################################################
+
 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  $@")
 
@@ -227,7 +238,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/Makefile.objs b/Makefile.objs
index 4412757..8a4c9fc 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -248,3 +248,9 @@  nested-vars += \
 	common-obj-y \
 	extra-obj-y
 dummy := $(call unnest-vars)
+
+#############################################################################
+# libqblock
+
+libqblock-lib-la = libqblock.la
+libqblock-lib-path = libqblock
diff --git a/libqblock/Makefile b/libqblock/Makefile
new file mode 100644
index 0000000..bf7abcc
--- /dev/null
+++ b/libqblock/Makefile
@@ -0,0 +1,64 @@ 
+###########################################################################
+# 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-1)
+
+#library objects
+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
+
+libqblock-y=libqblock.o libqblock-error.o
+libqblock-lib-y=$(patsubst %.o,%.lo,$(libqblock-y))
+
+QEMU_OBJS=$(tools-obj-y) $(block-obj-y)
+QEMU_OBJS_FILTERED=$(filter %.o,$(QEMU_OBJS))
+QEMU_OBJS_LIB=$(patsubst %.o, %.lo,$(QEMU_OBJS_FILTERED))
+
+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)
+
+#################################################################
+# Runtime rules
+#################################################################
+clean:
+	rm -f *.lo *.o *.d *.la libqblock-test trace.c trace.c-timestamp
+	rm -rf .libs block trace
+
+all: libqblock-test
+	@true
+
+help:
+	@echo type make libqblock-test at root dirtory, libtool is required
+
+#make dir block at runtime which would hold the output of block/*.c
+block:
+	@mkdir block
+
+ifeq ($(LIBTOOL),)
+$(libqblock-lib-la):
+	@echo "libtool is missing, please install and rerun configure"; exit 1
+else
+$(libqblock-lib-la): $(libqblock-lib-y) $(QEMU_OBJS_LIB)
+	$(call quiet-command,$(LIBTOOL) --mode=link --quiet --tag=CC $(CC) -rpath $(libdir) -o $@ $^ $(LIBS),"  lt LINK $@")
+endif
+
+.PHONY: libqblock.la