From e165121e120d9a6a13293ef743c630b4ec1dbce4 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 10 May 2014 22:35:00 +1200 Subject: Makefile options for portability --- Makefile | 34 +++++++++++++++++++++++----------- trayfreq.c | 2 +- trayfreq_set.c | 11 +---------- trayfreq_set_interface.c | 8 ++++---- 4 files changed, 29 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index f54ac26..3a1a2db 100644 --- a/Makefile +++ b/Makefile @@ -3,11 +3,22 @@ MAKE = make CC = gcc INSTALL_PATH=/ +PREFIX=/usr +BINDIR=$(PREFIX)/bin +SUDO=/usr/bin/sudo +TRAYFREQ_SET=$(BINDIR)/trayfreq-set +LOCALE_DIR=$(PREFIX)/share/locale/ ifdef DEBUG EXTRA_CFLAGS+=-DDEBUG endif +EXTRA_CFLAGS+= -DPREFIX=\"$(PREFIX)\" \ + -DBINDIR=\"$(BINDIR)\" \ + -DSUDO=\"$(SUDO)\" \ + -DTRAYFREQ_SET=\"$(TRAYFREQ_SET)\" \ + -DLOCALE_DIR=\"$(LOCALE_DIR)\" + DEPS = bat_tray.h \ bool.h \ @@ -119,18 +130,19 @@ clean: ######################################################################## # Install entire suite install: - mkdir -p $(INSTALL_PATH)/usr/share/trayfreq/ - mkdir -p $(INSTALL_PATH)/usr/share/locale/fr/LC_MESSAGES/ - mkdir -p $(INSTALL_PATH)/etc/ + mkdir -p $(PREFIX)/share/trayfreq/ + mkdir -p $(LOCALE_DIR)/fr/LC_MESSAGES/ + mkdir -p $(PREFIX)/etc/ + + cp data/*.png $(PREFIX)/share/trayfreq/ + cp lc/fr.mo $(LOCALE_DIR)/fr/LC_MESSAGES/trayfreq.mo - cp data/*.png $(INSTALL_PATH)/usr/share/trayfreq/ - cp lc/fr.mo $(INSTALL_PATH)/usr/share/locale/fr/LC_MESSAGES/trayfreq.mo + install -Dm 644 data/trayfreq.conf $(PREFIX)/etc/trayfreq.conf + install -Dm 644 data/trayfreq.desktop $(PREFIX)/etc/xdg/autostart/trayfreq.desktop - install -Dm 644 data/trayfreq.conf $(INSTALL_PATH)/etc/trayfreq.conf - install -Dm 644 data/trayfreq.desktop $(INSTALL_PATH)/etc/xdg/autostart/trayfreq.desktop - install -Dm 755 trayfreq $(INSTALL_PATH)/usr/bin/trayfreq - install -Dm 755 trayfreq-set $(INSTALL_PATH)/usr/bin/trayfreq-set + install -Dm 755 trayfreq $(BINDIR)/trayfreq + install -Dm 755 trayfreq-set $(BINDIR)/trayfreq-set - ln -s /usr/share/licenses/common/GLPv3/license.txt $(INSTALL_PATH)/usr/share/trayfreq/LICENCE - ln -s ../../../etc/trayfreq.conf $(INSTALL_PATH)/usr/share/trayfreq/trayfreq.conf + ln -s ../licenses/common/GLPv3/license.txt $(PREFIX)/share/trayfreq/LICENCE + ln -s ../../../etc/trayfreq.conf $(PREFIX)/share/trayfreq/trayfreq.conf ######################################################################## diff --git a/trayfreq.c b/trayfreq.c index 8ef3572..282ccd5 100644 --- a/trayfreq.c +++ b/trayfreq.c @@ -37,7 +37,7 @@ int main(int argc, char** argv) { setlocale(LC_ALL, ""); - bindtextdomain("trayfreq","/usr/share/locale"); + bindtextdomain("trayfreq",LOCALE_DIR); textdomain("trayfreq"); debug("Set gettext up\n"); diff --git a/trayfreq_set.c b/trayfreq_set.c index 785b93b..2b8f1d2 100644 --- a/trayfreq_set.c +++ b/trayfreq_set.c @@ -17,8 +17,6 @@ ************************************************************************/ -// : move a lot of this to a .h - #include #include #include @@ -41,8 +39,6 @@ typedef struct { char *frequency; } argument_summary; -// - char write_str_to_file(const char *file, const char *data, const char *core) { FILE *fd; @@ -115,12 +111,7 @@ void get_argument_summary(int argc, char **argv, argument_summary *argsum) int main(int argc, char *argv[]) { setlocale(LC_ALL,""); - - - // TO DO: Not portable - bindtextdomain("trayfreq","/usr/share/locale"); - - // TO DO: Needs to be #defined + bindtextdomain("trayfreq",LOCALE_DIR); textdomain("trayfreq"); debug("Set gettext up\n"); diff --git a/trayfreq_set_interface.c b/trayfreq_set_interface.c index fc847e6..d16c160 100644 --- a/trayfreq_set_interface.c +++ b/trayfreq_set_interface.c @@ -28,9 +28,9 @@ void si_gov(char* gov, int core) char cmd[256]; if (_DEFAULT_USE_SUDO) { - sprintf(cmd, "sudo trayfreq-set -g %s -c %i",gov,core); + sprintf(cmd, SUDO" "TRAYFREQ_SET" -g %s -c %i",gov,core); } else { - sprintf(cmd, "trayfreq-set -g %s -c %i",gov,core); + sprintf(cmd, TRAYFREQ_SET" -g %s -c %i",gov,core); } debug("Running '%s'\n",cmd); system(cmd); @@ -41,9 +41,9 @@ void si_freq(int freq, int core) char cmd[256]; if (_DEFAULT_USE_SUDO) { - sprintf(cmd, "sudo trayfreq-set -f %i -c %i",freq,core); + sprintf(cmd, SUDO" "TRAYFREQ_SET" -f %i -c %i",freq,core); } else { - sprintf(cmd, "trayfreq-set -f %i -c %i",freq,core); + sprintf(cmd, TRAYFREQ_SET" -f %i -c %i",freq,core); } debug("Running '%s'\n",cmd); system(cmd); -- cgit v1.1