
ROOT =		hotplug
PREFIX =	diet
VERSION =	0.1
INSTALL_DIR =	/usr/local/bin
INCLUDE_DIR =	.
RELEASE_NAME =	$(PREFIX)$(ROOT)-$(VERSION)

# override this one on the make command line, as it's probably wrong
KERNEL_INCLUDE_DIR = /usr/local/linux

# get the kernel version from the include file so we can determine where
# the map files are
KERNEL_VERSION = $(shell grep UTS_RELEASE $(KERNEL_INCLUDE_DIR)/linux/version.h | cut -f 2 -d \" )


all: $(ROOT)

# Comment out this line to build with diet libc
#DIET = diet

# Controls if debugging is enabled or not
#DEBUG = y

CC = $(DIET) gcc

OBJS =	hotplug.o	\
	usb.o		\
	logging.o	\
	util.o

# header files automatically generated
GEN_HEADERS =	usb_modules.h	\
		pci_modules.h	\
		hotplug_version.h

# other files we want in the release tarball
OTHERFILES =	Makefile	\
		README


ifeq ($(DEBUG),y)
  # options for development
  DEBUG_FLAGS = -g -DDEBUG
endif

CFLAGS := -O2 -Wall -D_GNU_SOURCE
CFLAGS += $(DEBUG_FLAGS)
CFLAGS += -I$(INCLUDE_DIR)


# Rules on how to create the generated header files
usb_modules.h:
	perl convert_usb.pl < /lib/modules/$(KERNEL_VERSION)/modules.usbmap > $@

pci_modules.h:
	perl convert_pci.pl < /lib/modules/$(KERNEL_VERSION)/modules.pcimap > $@

hotplug_version.h:
	@echo \#define HOTPLUG_VERSION \"$(VERSION)\" > $@



$(ROOT): $(GEN_HEADERS) $(OBJS)
	$(CC) -o $(ROOT) $(OBJS)

clean:
	-rm -f *.o *~ *# *.a core $(ROOT) $(GEN_HEADERS)

release: $(SOURCES) $(DOCS) $(OTHERFILES)
	@echo
	@echo "->Note: The version for now is hacked into Makefile as"
	@echo "->" $(VERSION)
	@echo
	@echo "->copying all release files to the directory " $(RELEASE_NAME)
	@echo
	-rm -rf $(RELEASE_NAME)
	-mkdir $(RELEASE_NAME)
	cp *.c $(RELEASE_NAME)
	-cp *.h $(RELEASE_NAME)
	-cp *.pl $(RELEASE_NAME)
	cp $(OTHERFILES) $(RELEASE_NAME)
	tar -c $(RELEASE_NAME) | gzip -9 > $(RELEASE_NAME).tar.gz
	@echo "->removing the temporary directory " $(RELEASE_NAME)
	rm -rf $(RELEASE_NAME)

