Use common objects for qemu-img and qemu-nbd
Right now, we sprinkle #if defined(QEMU_IMG) && defined(QEMU_NBD) all over the
code. It's ugly and causes us to have to build multiple object files for
linking against qemu and the tools.
This patch introduces a new file, qemu-tool.c which contains enough for
qemu-img, qemu-nbd, and QEMU to all share the same objects.
This also required getting qemu-nbd to be a bit more Windows friendly. I also
changed the Windows block-raw to use normal IO instead of overlapping IO since
we don't actually do AIO yet on Windows. I changed the various #if 0's to
#if WIN32_AIO to make it easier for someone to eventually fix AIO on Windows.
After this patch, there are no longer any #ifdef's related to qemu-img and
qemu-nbd.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5226 c046a42c-6fe2-441c-8c8c-71466251a162
diff --git a/Makefile b/Makefile
index 708941c..7bb2bf2 100644
--- a/Makefile
+++ b/Makefile
@@ -28,6 +28,10 @@
LIBS+=-lsocket -lnsl -lresolv
endif
+ifdef CONFIG_WIN32
+LIBS+=-lwinmm -lws2_32 -liphlpapi
+endif
+
all: $(TOOLS) $(DOCS) recurse-all
SUBDIR_RULES=$(patsubst %,subdir-%, $(TARGET_DIRS))
@@ -46,9 +50,17 @@
BLOCK_OBJS=cutils.o qemu-malloc.o
BLOCK_OBJS+=block-cow.o block-qcow.o aes.o block-vmdk.o block-cloop.o
BLOCK_OBJS+=block-dmg.o block-bochs.o block-vpc.o block-vvfat.o
-BLOCK_OBJS+=block-qcow2.o block-parallels.o
-ifndef CONFIG_WIN32
-BLOCK_OBJS+=block-nbd.o
+BLOCK_OBJS+=block-qcow2.o block-parallels.o block-nbd.o
+BLOCK_OBJS+=nbd.o block.o
+
+ifdef CONFIG_WIN32
+BLOCK_OBJS += block-raw-win32.o
+else
+BLOCK_OBJS += block-raw-posix.o
+endif
+
+ifdef CONFIG_AIO
+BLOCK_OBJS += compatfd.o
endif
######################################################################
@@ -59,11 +71,6 @@
OBJS=$(BLOCK_OBJS)
OBJS+=readline.o console.o
-OBJS+=block.o
-
-ifndef CONFIG_WIN32
-OBJS+=nbd.o
-endif
OBJS+=irq.o
OBJS+=i2c.o smbus.o smbus_eeprom.o max7310.o max111x.o wm8750.o
@@ -173,33 +180,15 @@
rm -f $@
$(AR) rcs $@ $(USER_OBJS)
-QEMU_IMG_BLOCK_OBJS = $(BLOCK_OBJS)
-ifdef CONFIG_WIN32
-QEMU_IMG_BLOCK_OBJS += qemu-img-block-raw-win32.o
-else
-QEMU_IMG_BLOCK_OBJS += nbd.o qemu-img-block-raw-posix.o
-endif
-
-ifdef CONFIG_AIO
-QEMU_IMG_BLOCK_OBJS += compatfd.o
-endif
-
######################################################################
-qemu-img$(EXESUF): qemu-img.o qemu-img-block.o $(QEMU_IMG_BLOCK_OBJS)
+qemu-img$(EXESUF): qemu-img.o qemu-tool.o osdep.o $(BLOCK_OBJS)
$(CC) $(LDFLAGS) -o $@ $^ -lz $(LIBS)
-qemu-img-%.o: %.c
- $(CC) $(CFLAGS) $(CPPFLAGS) -DQEMU_IMG -c -o $@ $<
-
%.o: %.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
-qemu-nbd-%.o: %.c
- $(CC) $(CFLAGS) $(CPPFLAGS) -DQEMU_NBD -c -o $@ $<
-
-qemu-nbd$(EXESUF): qemu-nbd.o qemu-nbd-nbd.o qemu-img-block.o \
- osdep.o qemu-nbd-block-raw-posix.o compatfd.o $(BLOCK_OBJS)
+qemu-nbd$(EXESUF): qemu-nbd.o qemu-tool.o osdep.o $(BLOCK_OBJS)
$(CC) $(LDFLAGS) -o $@ $^ -lz $(LIBS)
# dyngen host tool