1 #-----------------------------------------------------------------------------
2 # Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # See LICENSE.txt for the text of the license.
15 #-----------------------------------------------------------------------------
16 # This Makefile might have been called from various subdirs, trying to find our Makefile.defs
17 ifeq ($(DEFSBEENHERE),)
18 -include Makefile.defs
20 ifeq ($(DEFSBEENHERE),)
21 -include ../Makefile.defs
23 ifeq ($(DEFSBEENHERE),)
24 -include ../../Makefile.defs
26 ifeq ($(DEFSBEENHERE),)
27 -include ../../../Makefile.defs
29 ifeq ($(DEFSBEENHERE),)
30 $(error Can't find Makefile.defs)
33 CFLAGS ?= $(DEFCFLAGS)
34 CFLAGS += $(MYDEFS) $(MYCFLAGS) $(MYINCLUDES)
35 CXXFLAGS ?= $(DEFCXXFLAGS)
36 CXXFLAGS += $(MYDEFS) $(MYCXXFLAGS) $(MYINCLUDES)
37 LDFLAGS ?= $(DEFLDFLAGS)
38 LDFLAGS += $(MYLDFLAGS)
41 vpath %.c $(MYSRCPATHS)
43 # Flags to generate temporary dependency files
44 DEPFLAGS = -MT $@ -MMD -MP -MF $(OBJDIR)/$*.Td
45 # make temporary to final dependency files after successful compilation
46 POSTCOMPILE = $(MV) -f $(OBJDIR)/$*.Td $(OBJDIR)/$*.d && $(TOUCH) $@
51 MYOBJS ?= $(MYSRCS:%.c=$(OBJDIR)/%.o)
52 MYCXXOBJS ?= $(MYCXXSRCS:%.cpp=$(OBJDIR)/%.o)
53 CLEAN = $(foreach bin,$(MYLIBS) $(BINS) $(LIB_A),$(BINDIR)/$(bin))
55 all: $(foreach bin,$(MYLIBS) $(BINS) $(LIB_A),$(BINDIR)/$(bin))
59 $(Q)$(RMDIR) $(OBJDIR)
60 ifneq (,$(MYCLEANOLDPATH))
61 $(Q)$(RM) $(foreach f,$(CLEAN),$(MYCLEANOLDPATH)/$(f))
62 $(Q)$(RMDIR) $(MYCLEANOLDPATH)/$(OBJDIR)
63 $(Q)$(RMDIR_SOFT) $(MYCLEANOLDPATH) 2>/dev/null || true
67 ifneq (,$(INSTALLTOOLS))
68 $(info [@] Installing $(BINS) to $(DESTDIR)$(PREFIX)...)
69 $(Q)$(INSTALLSUDO) $(MKDIR) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLTOOLSRELPATH)
70 $(Q)$(INSTALLSUDO) $(CP) $(INSTALLTOOLS) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLTOOLSRELPATH)
75 ifneq (,$(INSTALLTOOLS))
76 $(info [@] Uninstalling $(BINS) from $(DESTDIR)$(PREFIX)...)
77 $(Q)$(INSTALLSUDO) $(RM) $(foreach tool,$(INSTALLTOOLS),$(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLTOOLSRELPATH)$(PATHSEP)$(notdir $(tool)))
81 .PHONY: all clean install uninstall
83 $(BINDIR)/$(LIB_A): $(MYOBJS) $(MYCXXOBJS)
84 $(info [=] AR $(notdir $@))
85 $(Q)$(AR) $@ $(MYOBJS) $(MYCXXOBJS)
88 $(BINDIR)/% : $(OBJDIR)/%.o $(MYOBJS) $(MYCXXOBJS) $(MYLIBS)
89 $(info [=] CXX $(notdir $@))
90 $(Q)$(CXX) $(LDFLAGS) $(MYOBJS) $(MYCXXOBJS) $< -o $@ $(MYLIBS) $(MYLDLIBS)
93 $(OBJDIR)/%.o : %.c $(OBJDIR)/%.d | $(OBJDIR)
95 $(Q)$(CC) $(DEPFLAGS) $(CFLAGS) -c -o $@ $<
99 $(OBJDIR)/%.o : %.cpp $(OBJDIR)/%.d | $(OBJDIR)
101 $(Q)$(CXX) $(DEPFLAGS) $(CXXFLAGS) -c -o $@ $<
105 $(Q)$(MKDIR) $(OBJDIR)
107 DEPENDENCY_FILES = $(MYOBJS:%.o=%.d) $(MYCXXOBJS:%.o=%.d) $(BINS:%=$(OBJDIR)/%.d)
109 $(DEPENDENCY_FILES): ;
110 .PRECIOUS: $(DEPENDENCY_FILES)
112 -include $(DEPENDENCY_FILES)