XEN_ROOT = $(CURDIR)/../../..
include $(XEN_ROOT)/tools/Rules.mk

OBJS-y += libxlu_cfg_y.o
OBJS-y += libxlu_cfg_l.o
OBJS-y += libxlu_cfg.o
OBJS-y += libxlu_disk_l.o
OBJS-y += libxlu_disk.o
OBJS-y += libxlu_vif.o
OBJS-y += libxlu_pci.o

CFLAGS += -Wno-format-zero-length -Wmissing-declarations -Wformat-nonliteral
CFLAGS += $(CFLAGS_libxenctrl)

CFLAGS += $(PTHREAD_CFLAGS)
LDFLAGS += $(PTHREAD_LDFLAGS)

ifeq ($(FLEX),)
%.c %.h:: %.l
	$(warning Flex is needed to rebuild some libxl parsers and \
		  scanners, please install it and rerun configure)
endif

ifeq ($(BISON),)
%.c %.h:: %.y
	$(warning Bison is needed to rebuild some libxl parsers and \
		  scanners, please install it and rerun configure)
endif

AUTOINCS = libxlu_cfg_y.h libxlu_cfg_l.h libxlu_disk_l.h

LIBHEADER := libxlutil.h
PKG_CONFIG_NAME := Xlutil
PKG_CONFIG_DESC := The xl utility library for Xen hypervisor

NO_HEADERS_CHK := y

include $(XEN_ROOT)/tools/libs/libs.mk

$(OBJS-y) $(PIC_OBJS): $(AUTOINCS)

# Adding the .c conterparts of the headers generated by flex/bison as
# prerequisite of all objects.
# This is to tell make that if only the .c file is out-of-date but not the
# header, it should still wait for the .c file to be rebuilt.
# Otherwise, make doesn't considered "%.c %.h" as grouped targets, and will run
# the flex/bison rules in parallel of CC rules which only need the header.
$(OBJS-y) $(PIC_OBJS): libxlu_cfg_l.c libxlu_cfg_y.c libxlu_disk_l.c

%.c %.h:: %.y
	@rm -f $*.[ch]
	$(BISON) --output=$*.c $<

%.c %.h:: %.l
	@rm -f $*.[ch]
	$(FLEX) --header-file=$*.h --outfile=$*.c $<
