From 4fdb5a2f4bb8b4fd5f1499e138eff364ad594e1f Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 21:55:13 +0200 Subject: [PATCH] make install: half way --- Makefile | 31 ++++++++++++++++++++++--------- Makefile.host | 14 ++++++++++++-- armsrc/Makefile | 30 ++++++++++++++++-------------- bootrom/Makefile | 25 ++++++++++++++----------- client/Makefile | 25 +++++++++++++++++++++++-- common_arm/Makefile.common | 9 +++++---- fpga/Makefile | 16 ++++++++-------- recovery/Makefile | 18 ++++++++++-------- tools/mfkey/Makefile | 1 + tools/nonce2key/Makefile | 1 + 10 files changed, 112 insertions(+), 58 deletions(-) diff --git a/Makefile b/Makefile index 3f288f504..f74932ccc 100644 --- a/Makefile +++ b/Makefile @@ -4,35 +4,48 @@ ifneq ($(V),1) endif # To see full command lines, use make V=1 -COPY=cp +CP = cp -a GZIP=gzip +MKDIR = mkdir -p +RM = rm -f +RMDIR = rm -rf -include Makefile.platform -include .Makefile.options.cache include common_arm/Makefile.hal +# preserve relative DESTDIR path for subdir makes +ifneq (,$(DESTDIR)) + # realpath needs the directory to exist + $(shell $(MKDIR) $(DESTDIR)) + MYDESTDIR:=$(realpath $(DESTDIR)) + ifeq (,$(MYDESTDIR)) + $(error Can't create $(DESTDIR)) + endif +endif + all clean install uninstall: %: client/% bootrom/% armsrc/% recovery/% mfkey/% nonce2key/% fpga_compress/% mfkey/%: FORCE $(info [*] MAKE $@) - $(Q)$(MAKE) --no-print-directory -C tools/mfkey $(patsubst mfkey/%,%,$@) + $(Q)$(MAKE) --no-print-directory -C tools/mfkey $(patsubst mfkey/%,%,$@) DESTDIR=$(MYDESTDIR) nonce2key/%: FORCE $(info [*] MAKE $@) - $(Q)$(MAKE) --no-print-directory -C tools/nonce2key $(patsubst nonce2key/%,%,$@) + $(Q)$(MAKE) --no-print-directory -C tools/nonce2key $(patsubst nonce2key/%,%,$@) DESTDIR=$(MYDESTDIR) fpga_compress/%: FORCE $(info [*] MAKE $@) - $(Q)$(MAKE) --no-print-directory -C tools/fpga_compress $(patsubst fpga_compress/%,%,$@) + $(Q)$(MAKE) --no-print-directory -C tools/fpga_compress $(patsubst fpga_compress/%,%,$@) DESTDIR=$(MYDESTDIR) bootrom/%: FORCE cleanifplatformchanged $(info [*] MAKE $@) - $(Q)$(MAKE) --no-print-directory -C bootrom $(patsubst bootrom/%,%,$@) + $(Q)$(MAKE) --no-print-directory -C bootrom $(patsubst bootrom/%,%,$@) DESTDIR=$(MYDESTDIR) armsrc/%: FORCE cleanifplatformchanged fpga_compress/% $(info [*] MAKE $@) - $(Q)$(MAKE) --no-print-directory -C armsrc $(patsubst armsrc/%,%,$@) + $(Q)$(MAKE) --no-print-directory -C armsrc $(patsubst armsrc/%,%,$@) DESTDIR=$(MYDESTDIR) client/%: FORCE $(info [*] MAKE $@) - $(Q)$(MAKE) --no-print-directory -C client $(patsubst client/%,%,$@) + $(Q)$(MAKE) --no-print-directory -C client $(patsubst client/%,%,$@) DESTDIR=$(MYDESTDIR) recovery/%: FORCE cleanifplatformchanged bootrom/% armsrc/% $(info [*] MAKE $@) - $(Q)$(MAKE) --no-print-directory -C recovery $(patsubst recovery/%,%,$@) + $(Q)$(MAKE) --no-print-directory -C recovery $(patsubst recovery/%,%,$@) DESTDIR=$(MYDESTDIR) FORCE: # Dummy target to force remake in the subdirectories, even if files exist (this Makefile doesn't know about the prerequisites) .PHONY: all clean install uninstall help _test bootrom fullimage recovery client mfkey nonce2key style checks FORCE udev accessrights cleanifplatformchanged @@ -77,7 +90,7 @@ nonce2key: nonce2key/all fpga_compress: fpga_compress/all newtarbin: - $(DELETE) proxmark3-$(platform)-bin.tar proxmark3-$(platform)-bin.tar.gz + $(RM) proxmark3-$(platform)-bin.tar proxmark3-$(platform)-bin.tar.gz @touch proxmark3-$(platform)-bin.tar tarbin: newtarbin client/tarbin armsrc/tarbin bootrom/tarbin diff --git a/Makefile.host b/Makefile.host index 8e76caa50..861e697fb 100644 --- a/Makefile.host +++ b/Makefile.host @@ -4,6 +4,9 @@ ifneq ($(V),1) endif # To see full command lines, use make V=1 +INSTALLBINRELPATH = /bin/ +INSTALLTOOLSRELPATH = /share/proxmark3/tools/ + CC = gcc LD = gcc RM = rm -f @@ -49,11 +52,18 @@ clean: $(Q)$(RMDIR) $(OBJDIR) install: all - $(info [@] Installing $(BINS) $(LIB_A) to $(PREFIX)) +ifneq (,$(INSTALLTOOLS)) + $(info [@] Installing $(BINS) to $(DESTDIR)$(PREFIX)...) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLTOOLSRELPATH) + $(Q)$(CP) $(INSTALLTOOLS) $(DESTDIR)$(PREFIX)$(INSTALLTOOLSRELPATH) +endif @true uninstall: - $(info [@] Uninstalling $(BINS) $(LIB_A) from $(PREFIX)) +ifneq (,$(INSTALLTOOLS)) + $(info [@] Uninstalling $(BINS) from $(DESTDIR)$(PREFIX)...) + $(Q)$(RM) $(foreach tool,$(INSTALLTOOLS),$(DESTDIR)$(PREFIX)$(INSTALLTOOLSRELPATH)$(notdir $(tool))) +endif @true .PHONY: all clean install uninstall diff --git a/armsrc/Makefile b/armsrc/Makefile index 6e67913e4..8cbe03dab 100644 --- a/armsrc/Makefile +++ b/armsrc/Makefile @@ -134,6 +134,7 @@ include ../common_arm/Makefile.common COMMON_FLAGS = -Os +INSTALLFW = $(OBJDIR)/fullimage.elf OBJS = $(OBJDIR)/fullimage.s19 FPGA_COMPRESSOR = ../tools/fpga_compress/fpga_compress @@ -144,7 +145,7 @@ all: $(OBJS) # version.c should be remade on every time fullimage.stage1.elf should be remade version.c: default_version.c $(OBJDIR)/fpga_version_info.o $(OBJDIR)/fpga_all.o $(THUMBOBJ) $(ARMOBJ) $(info [-] GEN $@) - $(Q)sh ../tools/mkversion.sh > $@ || perl ../tools/mkversion.pl > $@ || $(COPY) $^ $@ + $(Q)sh ../tools/mkversion.sh > $@ || perl ../tools/mkversion.pl > $@ || $(CP) $^ $@ fpga_version_info.c: $(FPGA_BITSTREAMS) | $(FPGA_COMPRESSOR) $(info [-] GEN $@) @@ -203,23 +204,24 @@ tarbin: $(OBJS) $(Q)$(TAR) $(TARFLAGS) ../proxmark3-$(platform)-bin.tar $(OBJS:%=armsrc/%) $(OBJS:%.s19=armsrc/%.elf) clean: - $(Q)$(DELETE) $(DEPENDENCY_FILES) - $(Q)$(DELETE) $(OBJDIR)$(PATHSEP)*.o - $(Q)$(DELETE) $(OBJDIR)$(PATHSEP)*.elf - $(Q)$(DELETE) $(OBJDIR)$(PATHSEP)*.s19 - $(Q)$(DELETE) $(OBJDIR)$(PATHSEP)*.map - $(Q)$(DELETE) $(OBJDIR)$(PATHSEP)*.d - $(Q)$(DELETE) $(OBJDIR)$(PATHSEP)*.z - $(Q)$(DELETE) $(OBJDIR)$(PATHSEP)*.bin - $(Q)$(DELETE) version.c + $(Q)$(RM) $(DEPENDENCY_FILES) + $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.o + $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.elf + $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.s19 + $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.map + $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.d + $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.z + $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.bin + $(Q)$(RM) version.c install: all - $(info [@] Installing fullimage to $(PREFIX)) - @true + $(info [@] Installing fullimage to $(DESTDIR)$(PREFIX)...) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH) + $(Q)$(CP) $(INSTALLFW) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH) uninstall: - $(info [@] Uninstalling fullimage from $(PREFIX)) - @true + $(info [@] Uninstalling fullimage from $(DESTDIR)$(PREFIX)...) + $(Q)$(RM) $(foreach fw,$(INSTALLFW),$(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH)$(notdir $(fw))) .PHONY: all clean help install uninstall help: diff --git a/bootrom/Makefile b/bootrom/Makefile index 179678b92..0d3f081d9 100644 --- a/bootrom/Makefile +++ b/bootrom/Makefile @@ -31,12 +31,14 @@ APP_CFLAGS += -fno-stack-protector -fno-pie # Do not move this inclusion before the definition of {THUMB,ASM,ARM}SRC include ../common_arm/Makefile.common +INSTALLFW = $(OBJDIR)/bootrom.elf + OBJS = $(OBJDIR)/bootrom.s19 # version.c should be remade on every compilation version.c: default_version.c $(info [=] GEN $@) - $(Q)sh ../tools/mkversion.sh > $@ || perl ../tools/mkversion.pl > $@ || $(COPY) $^ $@ + $(Q)sh ../tools/mkversion.sh > $@ || perl ../tools/mkversion.pl > $@ || $(CP) $^ $@ all: $(OBJS) @@ -49,20 +51,21 @@ $(OBJDIR)/bootrom.elf: $(VERSIONOBJ) $(ASMOBJ) $(ARMOBJ) $(THUMBOBJ) $(Q)$(CC) $(LDFLAGS) -Wl,-T,ldscript-flash,-Map,$(patsubst %.elf,%.map,$@) -o $@ $^ $(LIBS) clean: - $(Q)$(DELETE) $(OBJDIR)$(PATHSEP)*.o - $(Q)$(DELETE) $(OBJDIR)$(PATHSEP)*.elf - $(Q)$(DELETE) $(OBJDIR)$(PATHSEP)*.s19 - $(Q)$(DELETE) $(OBJDIR)$(PATHSEP)*.map - $(Q)$(DELETE) $(OBJDIR)$(PATHSEP)*.d - $(Q)$(DELETE) version.c + $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.o + $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.elf + $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.s19 + $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.map + $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.d + $(Q)$(RM) version.c install: all - $(info [@] Installing bootrom to $(PREFIX)) - @true + $(info [@] Installing bootrom to $(DESTDIR)$(PREFIX)...) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH) + $(Q)$(CP) $(INSTALLFW) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH) uninstall: - $(info [@] Uninstalling bootrom from $(PREFIX)) - @true + $(info [@] Uninstalling bootrom from $(DESTDIR)$(PREFIX)...) + $(Q)$(RM) $(foreach fw,$(INSTALLFW),$(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH)$(notdir $(fw))) .PHONY: all clean help install help: diff --git a/client/Makefile b/client/Makefile index 42e617e1f..a8232f7e9 100644 --- a/client/Makefile +++ b/client/Makefile @@ -15,6 +15,12 @@ ifneq ($(V),1) endif # To see full command lines, use make V=1 +INSTALLBINRELPATH = /bin/ +INSTALLSHARERELPATH = /share/proxmark3/ +#TODO INSTALLBIN = proxmark3 proxmark3-flasher +INSTALLBIN = proxmark3 flasher +INSTALLSHARE = lualibs luascripts resources dictionaries + CC = gcc CXX = g++ LD = g++ @@ -27,6 +33,7 @@ MKDIR = mkdir -p MV = mv TOUCH = touch FALSE = false +CP=cp -a platform = $(shell uname) ROOT_DIR:=$(dir $(realpath $(lastword $(MAKEFILE_LIST)))) @@ -335,11 +342,25 @@ clean: $(Q)$(MAKE) --no-print-directory -C $(REVENGPATH) clean install: all - $(info [@] Installing client to $(PREFIX)) + $(info [@] Installing client to $(DESTDIR)$(PREFIX)...) +ifneq (,$(INSTALLBIN)) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH) + $(Q)$(CP) $(INSTALLBIN) $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH) +endif +ifneq (,$(INSTALLSHARE)) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLSHARERELPATH) + $(Q)$(CP) $(INSTALLSHARE) $(DESTDIR)$(PREFIX)$(INSTALLSHARERELPATH) +endif @true uninstall: - $(info [@] Uninstalling client from $(PREFIX)) + $(info [@] Uninstalling client from $(DESTDIR)$(PREFIX)...) +ifneq (,$(INSTALLBIN)) + $(Q)$(RM) $(foreach tool,$(INSTALLBIN),$(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH)$(notdir $(tool))) +endif +ifneq (,$(INSTALLSHARE)) + $(Q)$(RMDIR) $(foreach tool,$(INSTALLSHARE),$(DESTDIR)$(PREFIX)$(INSTALLSHARERELPATH)$(notdir $(tool))) +endif @true tarbin: $(BINS) diff --git a/common_arm/Makefile.common b/common_arm/Makefile.common index 011f020f8..5af77bcf7 100644 --- a/common_arm/Makefile.common +++ b/common_arm/Makefile.common @@ -25,6 +25,7 @@ all: platform = $(shell uname) PREFIX?=/usr/local +INSTALLFWRELPATH = /share/proxmark3/firmware/ CROSS ?= arm-none-eabi- CC = $(CROSS)gcc @@ -40,10 +41,10 @@ INCLUDE = -I../include -I../common_arm -I../common_fpga -I../common -I. TAR=tar TARFLAGS = -C .. -rvf - -DELETE=rm -rf -MOVE=mv -COPY=cp +RM=rm -f +RMDIR=rm -rf +CP=cp -a +MKDIR=mkdir -p PATHSEP=/ DETECTED_OS=$(platform) diff --git a/fpga/Makefile b/fpga/Makefile index b28c27db9..06cdec2ee 100644 --- a/fpga/Makefile +++ b/fpga/Makefile @@ -1,36 +1,36 @@ all: fpga_lf.bit fpga_hf.bit clean: - $(Q)$(DELETE) *.bgn *.drc *.ncd *.ngd *_par.xrpt *-placed.* *-placed_pad.* *_usage.xml xst_hf.srp xst_lf.srp - $(Q)$(DELETE) *.map *.ngc *.xrpt *.pcf *.rbt *_auto_* *.bld *.mrp *.ngm *.unroutes *_summary.xml netlist.lst xst + $(Q)$(RM) *.bgn *.drc *.ncd *.ngd *_par.xrpt *-placed.* *-placed_pad.* *_usage.xml xst_hf.srp xst_lf.srp + $(Q)$(RM) *.map *.ngc *.xrpt *.pcf *.rbt *_auto_* *.bld *.mrp *.ngm *.unroutes *_summary.xml netlist.lst xst fpga_hf.ngc: fpga_hf.v fpga.ucf xst_hf.scr util.v hi_simulate.v hi_read_tx.v hi_read_rx_xcorr.v hi_iso14443a.v hi_sniffer.v hi_flite.v - $(Q)$(DELETE) $@ + $(Q)$(RM) $@ $(info [-] XST $@) $(Q)$(XILINX_TOOLS_PREFIX)xst -ifn xst_hf.scr fpga_lf.ngc: fpga_lf.v fpga.ucf xst_lf.scr util.v clk_divider.v lo_edge_detect.v lo_read.v lo_passthru.v lp20khz_1MSa_iir_filter.v min_max_tracker.v lf_edge_detect.v - $(Q)$(DELETE) $@ + $(Q)$(RM) $@ $(info [-] XST $@) $(Q)$(XILINX_TOOLS_PREFIX)xst -ifn xst_lf.scr %.ngd: %.ngc - $(Q)$(DELETE) $@ + $(Q)$(RM) $@ $(info [-] NGD $@) $(Q)$(XILINX_TOOLS_PREFIX)ngdbuild -aul -p xc2s30-5-vq100 -nt timestamp -uc fpga.ucf $< $@ %.ncd: %.ngd - $(Q)$(DELETE) $@ + $(Q)$(RM) $@ $(info [-] MAP $@) $(Q)$(XILINX_TOOLS_PREFIX)map -p xc2s30-5-vq100 $< %-placed.ncd: %.ncd - $(Q)$(DELETE) $@ + $(Q)$(RM) $@ $(info [-] PAR $@) $(Q)$(XILINX_TOOLS_PREFIX)par $< $@ %.bit: %-placed.ncd - $(Q)$(DELETE) $@ $*.drc $*.rbt + $(Q)$(RM) $@ $*.drc $*.rbt $(info [=] BITGEN $@) $(Q)$(XILINX_TOOLS_PREFIX)bitgen $< $@ diff --git a/recovery/Makefile b/recovery/Makefile index 60b62cfe1..fd10020bf 100644 --- a/recovery/Makefile +++ b/recovery/Makefile @@ -1,6 +1,7 @@ include ../common_arm/Makefile.common -BINS = bootrom.bin fullimage.bin proxmark3_recovery.bin +INSTALLFW = proxmark3_recovery.bin +BINS = bootrom.bin fullimage.bin $(INSTALLFW) all: $(BINS) @@ -17,14 +18,15 @@ proxmark3_recovery.bin: bootrom.bin fullimage.bin $(Q)cat bootrom.bin fullimage.bin > $@ clean: - $(Q)rm -f $(BINS) + $(Q)$(RM) $(BINS) install: all - $(info [@] Installing recovery to $(PREFIX)) - @true + $(info [@] Installing recovery to $(DESTDIR)$(PREFIX)...) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH) + $(Q)$(CP) $(INSTALLFW) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH) -uninstall: all - $(info [@] Uninstalling recovery from $(PREFIX)) - @true +uninstall: + $(info [@] Uninstalling recovery from $(DESTDIR)$(PREFIX)...) + $(Q)$(RM) $(foreach fw,$(INSTALLFW),$(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH)$(notdir $(fw))) -PHONY: all clean install uninstall +.PHONY: all clean install uninstall diff --git a/tools/mfkey/Makefile b/tools/mfkey/Makefile index 27fa95aa0..a7b006f6e 100644 --- a/tools/mfkey/Makefile +++ b/tools/mfkey/Makefile @@ -5,6 +5,7 @@ MYCFLAGS = -std=c99 -D_ISOC99_SOURCE MYDEFS = BINS = mfkey32 mfkey32v2 mfkey64 +INSTALLTOOLS = $(BINS) include ../../Makefile.host diff --git a/tools/nonce2key/Makefile b/tools/nonce2key/Makefile index 8b5d05278..77dc18099 100644 --- a/tools/nonce2key/Makefile +++ b/tools/nonce2key/Makefile @@ -5,6 +5,7 @@ MYCFLAGS = -std=c99 -D_ISOC99_SOURCE MYDEFS = BINS = nonce2key +INSTALLTOOLS = $(BINS) include ../../Makefile.host