Allow for separate installation of tools and target-tools, to aid in packaging.

By default everything the tools are installed into /usr/local/bin but this can
be overridden using PREFIX= or BINDIR= on the make invocation.

To enable this it was necessary to split fex2bin and bin2fex out from $(TOOLS)
into $(FEXC_LINKS), because install(1) does not seem to have a mode which
preserves symlinks so it needs to be done separately.

Supports DESTDIR to allow for convenient installation into a staging dir for
distro packaging convenience.

Signed-off-by: Ian Campbell <[email protected]>
---
 Makefile | 38 +++++++++++++++++++++++++++++++-------
 1 file changed, 31 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile
index 67dfafa..c5a2906 100644
--- a/Makefile
+++ b/Makefile
@@ -22,8 +22,10 @@ CFLAGS += -std=c99 -D_POSIX_C_SOURCE=200112L
 CFLAGS += -Iinclude/
 
 # Tools useful on host and target
-TOOLS = sunxi-fexc bin2fex fex2bin sunxi-bootinfo sunxi-fel
-TOOLS += sunxi-nand-part
+TOOLS = sunxi-fexc sunxi-bootinfo sunxi-fel sunxi-nand-part
+
+# Symlinks to sunxi-fexc
+FEXC_LINKS = bin2fex fex2bin
 
 # Tools which are only useful on the target
 TARGET_TOOLS = sunxi-pio
@@ -32,18 +34,40 @@ MISC_TOOLS = phoenix_info
 
 CROSS_COMPILE ?= arm-none-eabi-
 
-.PHONY: all clean tools target-tools
+DESTDIR ?=
+PREFIX  ?= /usr/local
+BINDIR  ?= $(PREFIX)/bin
+
+.PHONY: all clean tools target-tools install install-tools install-target-tools
 
 all: tools target-tools
 
-tools: $(TOOLS)
+tools: $(TOOLS) $(FEXC_LINKS)
 target-tools: $(TARGET_TOOLS)
 
 misc: $(MISC_TOOLS)
 
-clean:
-       @rm -vf $(TOOLS) $(TARGET_TOOLS) $(MISC_TOOLS) *.o *.elf *.sunxi *.bin 
*.nm *.orig
+install: install-tools install-target-tools
+
+install-tools: $(TOOLS)
+       install -d $(DESTDIR)$(BINDIR)
+       @set -ex ; for t in $^ ; do \
+               install -m0755 $$t $(DESTDIR)$(BINDIR)/$$t ; \
+       done
+       @set -ex ; for l in $(FEXC_LINKS) ; do \
+               ln -nfs sunxi-fexc $(DESTDIR)$(BINDIR)/$$l ; \
+       done
 
+install-target-tools: $(TARGET_TOOLS)
+       install -d $(DESTDIR)$(BINDIR)
+       @set -ex ; for t in $^ ; do \
+               install -m0755 $$t $(DESTDIR)$(BINDIR)/$$t ; \
+       done
+
+
+clean:
+       @rm -vf $(TOOLS) $(FEXC_LINKS) $(TARGET_TOOLS) $(MISC_TOOLS)
+       @rm -vf *.o *.elf *.sunxi *.bin *.nm *.orig
 
 $(TOOLS) $(TARGET_TOOLS): Makefile common.h
 
@@ -122,6 +146,6 @@ sunxi-meminfo: meminfo.c
        $(CROSS_COMPILE)gcc -g -O0 -Wall -static -o $@ $^
 
 .gitignore: Makefile
-       @for x in $(TOOLS) $(TARGET_TOOLS) '*.o' '*.swp'; do \
+       @for x in $(TOOLS) $(FEXC_LINKS) $(TARGET_TOOLS) '*.o' '*.swp'; do \
                echo "$$x"; \
        done > $@
-- 
2.5.3

-- 
You received this message because you are subscribed to the Google Groups 
"linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to