Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 20-k290.sh → 20-k290.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

case "$1" in
thaw|resume)
/usr/local/sbin/k290_fnkeyctl > /dev/null
@CMAKE_INSTALL_FULL_SBINDIR@/k290_fnkeyctl > /dev/null
;;
*) exit $NA
;;
Expand Down
1 change: 0 additions & 1 deletion 99-k290-config.rules

This file was deleted.

1 change: 1 addition & 0 deletions 99-k290-config.rules.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ATTR{idVendor}=="046d", ATTR{idProduct}=="c31f", RUN+="@CMAKE_INSTALL_FULL_SBINDIR@/k290_fnkeyctl"
43 changes: 43 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
project(k290-fnkeyctl)
cmake_minimum_required(VERSION 2.8.12)

option(INSTALL_UDEV_RULE "Whether to install the udev rule" ON)
option(INSTALL_TO_SYSTEM_UDEV_DIR "Whether to install the udev rule to /usr/lib/udev/rules.d instead of /etc/udev/rules.d" OFF)
option(INSTALL_SYSTEMD_SLEEP_SCRIPT "Whether to install the systemd-sleep script" ON)
option(INSTALL_PM_UTILS_SLEEP_SCRIPT "Whether to install the pm-utils sleep script" ON)

include(GNUInstallDirs)
include(FindPkgConfig)
pkg_search_module(LIBUSB REQUIRED libusb-1.0)

add_executable(k290_fnkeyctl k290_fnkeyctl.cpp)
target_compile_options(k290_fnkeyctl PRIVATE -std=gnu++0x ${LIBUSB_CFLAGS})
target_link_libraries(k290_fnkeyctl PRIVATE ${LIBUSB_LIBRARIES})
target_include_directories(k290_fnkeyctl PRIVATE ${LIBUSB_INCLUDE_DIRS})

install(TARGETS k290_fnkeyctl DESTINATION ${CMAKE_INSTALL_SBINDIR})

if(INSTALL_UDEV_RULE)
configure_file(99-k290-config.rules.in ${CMAKE_CURRENT_BINARY_DIR}/99-k290-config.rules @ONLY)
if(INSTALL_TO_SYSTEM_UDEV_DIR)
set(UDEV_RULES_DIR /usr/lib/udev/rules.d)
else()
set(UDEV_RULES_DIR /etc/udev/rules.d)
endif()
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/99-k290-config.rules DESTINATION ${UDEV_RULES_DIR})
endif()
if(INSTALL_SYSTEMD_SLEEP_SCRIPT)
configure_file(k290-fnkeyctl.sh.in ${CMAKE_CURRENT_BINARY_DIR}/k290-fnkeyctl.sh @ONLY)
if(IS_DIRECTORY /usr/lib/systemd/system-sleep/)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/k290-fnkeyctl.sh DESTINATION /usr/lib/systemd/system-sleep/)
endif()
# some distributions (e.g. Ubuntu) patch systemd to use /lib/systemd/system-sleep/ instead
if(IS_DIRECTORY /lib/systemd/system-sleep/)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/k290-fnkeyctl.sh DESTINATION /lib/systemd/system-sleep/)
endif()
endif()

if(INSTALL_PM_UTILS_SLEEP_SCRIPT)
configure_file(20-k290.sh.in ${CMAKE_CURRENT_BINARY_DIR}/20-k290.sh @ONLY)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/20-k290.sh DESTINATION /etc/pm/sleep.d/)
endif()
6 changes: 2 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/bin/sh
# comment in or out to whatever compiler you prefer
# if you want to use GCC, make sure it's a recent one
g++ -std=gnu++0x k290_fnkeyctl.cpp `pkg-config --libs libusb-1.0` -o k290_fnkeyctl
# clang -std=c++11 -I/usr/include -L/usr/lib k290_fnkeyctl.cpp -lusb-1.0 -lstdc++ -o k290_fnkeyctl
cmake . $@
make
17 changes: 11 additions & 6 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
#!/bin/sh

[ -f ./k290_fnkeyctl ] || ./build.sh || (echo "Could not build" && exit)
INSTALL_UDEV_RULE="OFF"
INSTALL_SYSTEMD_SLEEP_SCRIPT="OFF"
INSTALL_PM_UTILS_SLEEP_SCRIPT="OFF"

install -m 755 -o root k290_fnkeyctl /usr/local/sbin/
if [ -d /etc/udev/rules.d ]; then
install -m 644 -o root 99-k290-config.rules /etc/udev/rules.d/
INSTALL_UDEV_RULE="ON"
fi
if [ -d /usr/lib/systemd/system-sleep/ ]; then
install -m 755 -o root k290-fnkeyctl.sh /usr/lib/systemd/system-sleep/
INSTALL_SYSTEMD_SLEEP_SCRIPT="ON"
fi
if [ -d /etc/pm/sleep.d ]; then
install -m 755 -o root 20-k290.sh /etc/pm/sleep.d/
INSTALL_PM_UTILS_SLEEP_SCRIPT="ON"
fi

[ -f ./k290_fnkeyctl ] || ./build.sh -DINSTALL_UDEV_RULE=$INSTALL_UDEV_RULE \
-DINSTALL_SYSTEMD_SLEEP_SCRIPT=$INSTALL_SYSTEMD_SLEEP_SCRIPT \
-DINSTALL_PM_UTILS_SLEEP_SCRIPT=$INSTALL_PM_UTILS_SLEEP_SCRIPT \
|| (echo "Could not build" && exit)
make install
2 changes: 1 addition & 1 deletion k290-fnkeyctl.sh → k290-fnkeyctl.sh.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
case $1/$2 in
post/*)
/usr/local/sbin/k290_fnkeyctl
@CMAKE_INSTALL_FULL_SBINDIR@/k290_fnkeyctl
;;
esac