PROGS	= 	node_handler \
		tdump \
		ibm_vpd_render \
		adapter_pci_legacy

DATAS	= 	scsivpd.conf pci.ids ide_mf.map

GEN	= 	adapter_pci_legacy_class.c lsvpd_lib_dir.h

INSTALL = 	/usr/bin/install -c
INSTALL_PROG =	$(INSTALL) -m 755
INSTALL_DATA =	$(INSTALL) -m 644

# -I$$PWD is so compiles of files in src/test/ will find includes in src/.
#CFLAGS 	=	-g -O -fstrict-aliasing -Werror -Wstrict-aliasing=2 -Wall -Wuninitialized -I$$PWD
CFLAGS 	=	-g -O -Wall -Wuninitialized -I$$PWD

# libsgutils are statically linked, but libc is dynamic.
LDLIBS	=	-Xlinker -Bstatic -lsgutils -Xlinker -Bdynamic

all:		$(PROGS)

util.o:		util.c util.h

growbuf.o:	growbuf.c growbuf.h

vpd.o:		vpd.c growbuf.h

tdump:		tdump.o util.o

tdump.o:	tdump.c util.h

######################################################################

dlist.o:	dlist.c dlist.h

sysfs_attr.o:	sysfs_attr.c libsysfs.h \
		sysfs.h dlist.h

sysfs_bus.o:	sysfs_bus.c libsysfs.h \
		sysfs.h dlist.h

sysfs_class.o:	sysfs_class.c libsysfs.h \
		sysfs.h dlist.h

sysfs_device.o:	sysfs_device.c libsysfs.h \
		sysfs.h dlist.h

sysfs_driver.o:	sysfs_driver.c libsysfs.h \
		sysfs.h dlist.h

sysfs_module.o:	sysfs_module.c libsysfs.h \
		sysfs.h dlist.h

sysfs_utils.o:	sysfs_utils.c libsysfs.h \
		sysfs.h dlist.h



######################################################################

node.o:			node.c node.h \
			init.h \
			util.h vpd.h

lsvpd.o:		lsvpd.c lsvpd.h \
			lsvpd_lib_dir.h init.h util.h

lsvpd_lib_dir.o:	lsvpd_lib_dir.c lsvpd_lib_dir.h \
			init.h

lsvpd_lib_dir.h:	lsvpd_lib_dir.h.in
	        	sed -e "s%@libdir@%$(libdir)%g" $< > $@

sysfs.o:		sysfs.c sysfs.h \
			init.h

device_tree.o:		device_tree.c device_tree.h \
			init.h util.h

proc_scsi.o:		proc_scsi.c proc_scsi.h \
			init.h

######################################################################

device.o:		device.c device.h \
			init.h node.h \
			util.h vpd.h

device_sysfs.o:		device_sysfs.c device.h \
			device_scsi.h device_ide.h \
			sysfs.h \
			node.h init.h lsvpd.h util.h vpd.h

device_ide.o:		device_ide.c device_ide.h \
			node.h device.h

device_scsi.o:		device_scsi.c device_scsi.h \
			node.h device.h \
			lsvpd.h init.h

device_ide_proc.o:	device_ide_proc.c \
			node.h device_ide.h device.h \
			lsvpd.h util.h vpd.h \
			lsvpd_lib_dir.h init.h

device_scsi_sg.o:	device_scsi_sg.c \
			node.h device.h device_scsi.h \
			lsvpd.h util.h vpd.h \
			lsvpd_lib_dir.h init.h

device_scsi_sg_map.o:	device_scsi_sg_map.c \
			node.h device.h device_scsi.h \
			lsvpd.h util.h vpd.h \
			lsvpd_lib_dir.h init.h

# The order here is *very* important because init() functions are
# called in link order.
INITIAL_MODULES	=	node.o lsvpd.o \
			sysfs.o proc_scsi.o device_tree.o \
			dlist.o sysfs_attr.o sysfs_bus.o \
			sysfs_class.o \
			sysfs_device.o sysfs_driver.o \
			sysfs_module.o sysfs_utils.o

DEVICE_MODULES	=	device.o \
			device_ide.o device_scsi.o \
			device_ide_proc.o \
			device_scsi_sg_map.o \
			device_scsi_sg.o \
			device_sysfs.o

ADAPTER_MODULES =	adapter.o \
			adapter_pci.o \
			adapter_pci_lookup.o \
			adapter_pci_vpd_capabilities.o \
			adapter_pci_vpd_generic.o \
			adapter_pci_vpd_parse.o \
			adapter_sysfs.o \
			adapter_device_tree.o

UTIL_MODULES	=	util.o lsvpd_lib_dir.o vpd.o growbuf.o

node_handler:		node_handler.o \
			$(INITIAL_MODULES) \
			$(DEVICE_MODULES) \
			$(ADAPTER_MODULES) \
			$(UTIL_MODULES)

node_handler.o:		node_handler.c \
			util.h vpd.h node.h init.h

######################################################################

ibm_vpd_render:		ibm_vpd_render.o adapter_pci_vpd_parse.o \
			util.o growbuf.o vpd.o
ibm_vpd_render.o:	ibm_vpd_render.c adapter_pci_vpd_parse.h \
			util.h growbuf.h vpd.h

######################################################################

adapter.o:		adapter.c adapter.h \
			node.h vpd.h

adapter_pci.o:		adapter_pci.c adapter_pci.h \
			adapter.h adapter_pci_vpd_capabilities.h \
			adapter_pci_vpd_parse.h adapter_pci_lookup.h \
			lsvpd.h lsvpd_lib_dir.h \
			node.h vpd.h util.h

adapter_pci_lookup.o:	adapter_pci_lookup.c adapter_pci_lookup.h \
			util.h

adapter_pci_vpd_capabilities.o: \
			adapter_pci_vpd_capabilities.c \
			adapter_pci_vpd_capabilities.h \
			growbuf.h

adapter_pci_vpd_generic.o: \
			adapter_pci_vpd_generic.c adapter_pci_vpd_generic.h \
			growbuf.h

adapter_pci_vpd_parse.o: \
			adapter_pci_vpd_parse.c adapter_pci_vpd_parse.h \
			growbuf.h util.h vpd.h

adapter_sysfs.o:	adapter_sysfs.c \
			init.h sysfs.h

adapter_device_tree.o:	adapter_device_tree.c \
			adapter_pci.h adapter.h \
			init.h sysfs.h device_tree.h util.h

adapter_pci_legacy:	adapter_pci_legacy.o \
			adapter_pci_legacy_ide.o \
			adapter_pci_legacy_scsi.o \
			adapter_pci_legacy_ethernet.o \
			adapter_pci_legacy_proc.o \
			adapter_pci_legacy_class.o \
			util.o

adapter_pci_legacy.o:	adapter_pci_legacy.c adapter_pci_legacy.h \
			adapter_pci_legacy_ide.h \
			adapter_pci_legacy_scsi.h \
			adapter_pci_legacy_ethernet.h \
			adapter_pci_legacy_proc.h util.h

adapter_pci_legacy_ethernet.o:	\
			adapter_pci_legacy_ethernet.c \
			adapter_pci_legacy_ethernet.h \
			adapter_pci_legacy.h \
			util.h
adapter_pci_legacy_scsi.o:	\
			adapter_pci_legacy_scsi.c adapter_pci_legacy_scsi.h \
			adapter_pci_legacy.h util.h
adapter_pci_legacy_ide.o:	\
			adapter_pci_legacy_ide.c adapter_pci_legacy_ide.h \
			adapter_pci_legacy.h util.h

adapter_pci_legacy_proc.o:	\
			adapter_pci_legacy_proc.c adapter_pci_legacy_proc.h \
			util.h
adapter_pci_legacy_class.c:	\
			pci.ids GEN_ADAPTER_PCI_LEGACY_CLASS
			./GEN_ADAPTER_PCI_LEGACY_CLASS < $< > $@

######################################################################

install:	all
	@ for f in $(PROGS) ; do \
		$(INSTALL_PROG) $$f $(DESTDIR)$(libdir) ;\
	done
	@ for f in $(DATAS) ; do \
		$(INSTALL_DATA) $$f $(DESTDIR)$(libdir) ;\
	done

######################################################################

#TEST_PROGS	=	test/test_growbuf test/test_growbuf.out \
			#test/test_vpd

#test_progs:		$(TEST_PROGS)

#test/test_growbuf:	test/test_growbuf.o growbuf.o

#test/test_vpd:		test/test_vpd.o \
			#vpd.o util.o growbuf.o

#test_runs:		test_run_growbuf

#test_run_growbuf:	test/test_growbuf
			#test/test_growbuf < test/test_growbuf.c > test/test_growbuf.out
			#diff -u test/test_growbuf.c test/test_growbuf.out

######################################################################

clean:
	rm -f $(PROGS) $(GEN) *.o $(TEST_PROGS) test/*.o *~
