Skip to content

Commit

Permalink
Makefile: Add an install rule
Browse files Browse the repository at this point in the history
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 <ijc@hellion.org.uk>
Acked-by: Peter Korsgaard <peter@korsgaard.com>
  • Loading branch information
ijc authored and ssvb committed Oct 23, 2015
1 parent bf4ec9a commit 0f69187
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions Makefile
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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 > $@

0 comments on commit 0f69187

Please sign in to comment.