Commits

Alex Hixon  committed 4d4b1f9

Add make rules target, rename UCODEDIR to UCODE_PATH, general cleanup of Makefile

Added the ability to generate a udev rules file based off the template
located in the contrib/ directory. If built, this will also be installed
when running the 'install' target.

The loader tool is now installed into the PREFIX/sbin directory, rather
than PREFIX/bin.

Removed the hard coded list of firmware files; generate them from
listing the ucode directory and using xargs to separate them with spaces.

Also, pass across the microcode path to the compiler from the Makefile
rather than keep one copy in the Makefile and another in config.h.

  • Participants
  • Parent commits 806f4e1

Comments (0)

Files changed (2)

 INSTALL=install
 
 # FW data
-FIRMWARE="r5u87x-05ca-1803.fw" "r5u87x-05ca-1810.fw" "r5u87x-05ca-1812.fw" "r5u87x-05ca-1830.fw" "r5u87x-05ca-1832.fw" "r5u87x-05ca-1833.fw" "r5u87x-05ca-1834.fw" "r5u87x-05ca-1835.fw" "r5u87x-05ca-1836.fw" "r5u87x-05ca-1837.fw" "r5u87x-05ca-1839.fw" "r5u87x-05ca-183a.fw" "r5u87x-05ca-183b.fw" "r5u87x-05ca-183e.fw" "r5u87x-05ca-1841.fw" "r5u87x-05ca-1870_1.fw" "r5u87x-05ca-1870.fw"
+FIRMWARE_NAMESPEC="r5u87x-%vid%-%pid%.fw"
+FIRMWARE=`ls ucode | xargs`
 
-# Modification to filenames
+# Install names
 LOADER_INSTALL=r5u87x-loader
+UDEV_INSTALL=/etc/udev/rules.d/
 
 # Directories
 PREFIX=/usr
-INSTALL_PATH=$(DESTDIR)/$(PREFIX)
-bindir=/bin
+INSTALL_PATH=$(DESTDIR)$(PREFIX)
+sbindir=/sbin
 libdir=/lib
-FIRMWARE_DIR=$(INSTALL_PATH)$(libdir)/r5u87x/ucode/
+FIRMWARE_DIR=$(INSTALL_PATH)$(libdir)/r5u87x/ucode
+
+# For rules and make targets -------------------------------------------------|
+RULESFILE=90-r5u87x-loader.rules
 
 # Automake targets -----------------------------------------------------------|
 
 .c.o:
-	$(CC) -g -Wall -DHAVE_CONFIG_H $(CFLAGS) $(INCS) -c $*.c $*.h
+	$(CC) -g -Wall -DHAVE_CONFIG_H -DUCODE_PATH=\"$(FIRMWARE_DIR)/$(FIRMWARE_NAMESPEC)\" $(CFLAGS) $(INCS) -c $*.c $*.h
 
 all: loader
 
 clean:
 	rm -fr *.o loader
 	rm -fr *.gch loader
-	#rm *~
+	if [ -f contrib/$(RULESFILE) ]; then \
+	    rm -f contrib/$(RULESFILE); \
+    fi
 
-install:	all
-	./mkinstalldirs $(INSTALL_PATH)$(bindir)
-	$(INSTALL) -m 0755 loader $(INSTALL_PATH)$(bindir)/$(LOADER_INSTALL)
-	./mkinstalldirs $(FIRMWARE_DIR)
+install: all
+	$(INSTALL) -d $(INSTALL_PATH)$(bindir)
+	$(INSTALL) -m 0755 loader $(INSTALL_PATH)$(sbindir)/$(LOADER_INSTALL)
+	$(INSTALL) -d $(FIRMWARE_DIR)
 	@for fw in $(FIRMWARE); do \
-	    echo "$(INSTALL) -m 0666 ucode/$$fw $(FIRMWARE_DIR)$$fw" ; \
-	    $(INSTALL) -m 0666 ucode/$$fw $(FIRMWARE_DIR)$$fw || exit 1 ; \
-    done
+		echo "$(INSTALL) -m 0644 ucode/$$fw $(FIRMWARE_DIR)/$$fw" ; \
+		$(INSTALL) -m 0644 ucode/$$fw $(FIRMWARE_DIR)/$$fw || exit 1 ; \
+	done
+	
+	## If we have the rules file generated, install it while we're here
+	if [ -f contrib/$(RULESFILE) ]; then \
+		$(INSTALL) -m 0644 $(RULESFILE) $(UDEV_INSTALL); \
+	fi
 
 uninstall:
-	rm -fv $(INSTALL_PATH)$(bindir)/$(LOADER_INSTALL)
+	rm -fv $(INSTALL_PATH)$(sbindir)/$(LOADER_INSTALL)
 	rm -rfv $(INSTALL_PATH)$(libdir)/r5u87x
+
+contrib/$(RULESFILE):
+	cat contrib/$(RULESFILE).in | awk 'BEGIN{P=1;}/^###BEGINTEMPLATE###/{P=0;} {if (P) print;}' | grep -v '^###' >$@
+	for sedline in `ls ucode | sed 's/^r5u87x-\([0-9a-zA-Z]\+\)-\([0-9a-zA-Z]\+\)\.fw$$/s\/#VENDORID#\/\1\/g;s\/#PRODUCTID#\/\2\/g/p;d'`; do \
+		cat contrib/$(RULESFILE).in | awk 'BEGIN{P=0;}/^###BEGINTEMPLATE###/{P=1;}/^###ENDTEMPLATE###/{P=0;} {if (P) print;}' | grep -v '^###' | sed "$$sedline" >>$@; \
+		done >>$(RULESFILE)
+	cat contrib/$(RULESFILE).in | awk 'BEGIN{P=0;}/^###ENDTEMPLATE###/{P=1;} {if (P) print;}' | grep -v '^###' >>$@
+
+rules: contrib/$(RULESFILE)
     
     loader_msg ("Found camera: %04x:%04x\n", dev->descriptor.idVendor,
         dev->descriptor.idProduct);
-    //loader_msg ("Firmware       : %s\n\n", firmware);
+    //loader_msg ("Firmware: %s\n\n", firmware);
     
     // Open the firmware file
-    if ((fd = g_open (firmware, O_RDONLY)) == -1) {
-        #ifdef UCODEDIR
-        firmware = usb_id_printf (UCODEDIR, dev);
+    if ((fd = g_open (firmware, O_RDONLY)) != -1) {
+        #ifdef UCODE_PATH
+        firmware = usb_id_printf (UCODE_PATH, dev);
         //loader_msg ("Trying %s\n", firmware);
         if ((fd = g_open (firmware, O_RDONLY)) == -1) {
             loader_error ("Failed to open %s. Does it exist?\n", firmware);