Skip to content

Commit

Permalink
Add udev rules installation on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Christophe Staïesse committed Aug 20, 2017
1 parent 9ac3447 commit 119ac4f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
3 changes: 3 additions & 0 deletions 50_ems_gb_flash.rules
@@ -0,0 +1,3 @@
# EMS USB 64M Gameboy flash cart
SUBSYSTEM=="usb", ACTION=="add", ATTRS{idVendor}=="4670", \
ATTRS{idProduct}=="9394", TAG+="uaccess"
9 changes: 8 additions & 1 deletion Makefile.tmpl
@@ -1,4 +1,5 @@
MENUVARS = menu.gb menucs.gb menuc.gb menus.gb
UDEVRULES = 50_ems_gb_flash.rules

PROG = ems-flasher-real
OBJS = ems.o main.o header.o cmd.o updates.o progress.o flash.o insert.o \
Expand Down Expand Up @@ -69,7 +70,13 @@ menu: FORCE
test: FORCE ems-flasher
cd tests && make test

install: $(PROG) menuvars
install-udevrules:
@if test -n '$(UDEVRULESDIR)'; then \
cp '$(UDEVRULES)' '$(UDEVRULESDIR)' && \
udevadm control --reload-rules; \
fi

install: $(PROG) menuvars install-udevrules
mkdir -p $(BINDIR)
install ems-flasher-real "$(BINDIR)"/ems-flasher
mkdir -p "$(DATADIR)"
Expand Down
31 changes: 26 additions & 5 deletions config.sh
Expand Up @@ -4,20 +4,28 @@ libusb=libusb-1.0
CC=${CC:-cc}
CFLAGS=${CFLAGS:--g -Wall -Werror -pedantic -std=c99}

unset noudevrules
while [ $# -ne 0 ]; do
case $1 in
--prefix) shift; PREFIX=$1;;
--bindir) shift; BINDIR=$1;;
--datadir) shift; DATADIR=$1;;
--mandir) shift; MANDIR=$1;;
--udevrulesdir) shift; UDEVRULESDIR=$1;;
--no-udevrules) noudevrules=1;;
*) cat >&2 << 'EOT'
config.sh [ --prefix PREFIX ] [ --bindir BINDIR ] [ --datadir DATADIR ]
[ --mandir MANDIR ]
[ --mandir MANDIR ] [ --udevrulesdir UDEVRULESDIR ]
[ --no-udevrules ]
Generate config.h and Makefile
--prefix default prefix for the installation directories (/usr/local)
--bindir installation directory of the executables ($PREFIX/bin)
--datadir installation directory of the menu ROMs ($PREFIX/share/ems-flasher)
--mandir installation directory of the manual pages ($PREFIX/share/man)
--prefix default prefix for the installation directories (/usr/local)
--bindir installation directory of the executables ($PREFIX/bin)
--datadir installation directory of the menu ROMs
($PREFIX/share/ems-flasher)
--mandir installation directory of the manual pages ($PREFIX/share/man)
--udevrulesdir installation directory of the udev rules ensuring access to
users to the USB device (/lib/udev/rules.d)
--no-udevrules don't install the udev rules
EOT
exit 1
;;
Expand All @@ -29,13 +37,25 @@ PREFIX=${PREFIX:-/usr/local}
BINDIR=${BINDIR:-$PREFIX/bin}
DATADIR=${DATADIR:-$PREFIX/share/ems-flasher}
MANDIR=${MANDIR:-$PREFIX/share/man}
if [ -z "$noudevrules" ] && [ "$(uname -s)" = "Linux" ]; then
UDEVRULESDIR=${UDEVRULESDIR:-/lib/udev/rules.d}
if ! [ -d "$UDEVRULESDIR" ]; then
echo "Can't find the udev rules directory." \
"Specify it with --udevrulesdir or disable installation" \
"of the udev rules with -no-udevrules" >&2
exit 1
fi
else
unset UDEVRULESDIR
fi

cat <<EOT
CC=$CC
CFLAGS=$CFLAGS
BINDIR=$BINDIR
DATADIR=$DATADIR
MANDIR=$MANDIR
UDEVRULESDIR=$UDEVRULESDIR
EOT

if
Expand Down Expand Up @@ -99,5 +119,6 @@ PTHREAD_LDFLAGS = $pthread_ldflags
BINDIR = $BINDIR
DATADIR = $DATADIR
MANDIR = $MANDIR
UDEVRULESDIR = $UDEVRULESDIR
EOT
cat Makefile.tmpl >>Makefile

0 comments on commit 119ac4f

Please sign in to comment.