1d228e3790deac08edf981a5e29efe2b36d22604
[fw/sdcc] / device / lib / pic / Makefile.subdir
1 ###########################################################
2 ### Makefile.subdir for the SDCC/PIC14 Library
3 ###
4 ### Copyright (C) 2005 by Raphael Neider <rneider@web.de>
5 ###
6 ### The library is currently maintained by
7 ###     Raphael Neider <rneider@web.de>
8 ###
9 ### This file may be distributed under the terms of the the
10 ### GNU General Public License (GPL). See GPL for details.
11 ###
12 ### $Id$
13 ###
14
15 include $(topsrcdir)/Makefile.common
16
17 SUBDIRS ?= 
18 MKLIB   ?= 
19
20 # fallback: if builddir is not specified via the command line...
21 builddir ?= build/$(patsubst $(shell cd $(topsrcdir); pwd)/%,%,$(CURDIR))
22
23 C_SRC   ?= $(wildcard *.c)
24 S_SRC   ?= $(wildcard *.S)
25 OBJS    ?= $(addprefix $(topsrcdir)/$(builddir)/,$(C_SRC:.c=.o) $(S_SRC:.S=.o))
26 LIB_O   ?= $(OBJS)
27
28 ifneq (,$(strip $(MKLIB)))
29 LIB_LIB = $(topsrcdir)/$(builddir)/$(MKLIB)
30 TARGETS ?= $(LIB_LIB)
31 else
32 LIB_LIB = 
33 #TARGETS ?= $(OBJS)
34 endif
35
36 .PHONY : all install clean clean-intermediate
37
38 all : install
39
40 ifneq (,$(strip $(TARGETS)))
41 # usually install $(LIB_LIB) or $(OBJS), race condition in "[ -d x ] || mkdir x"
42 install : recurse $(OBJS) $(LIB_LIB)
43         @[ -d "$(topsrcdir)/$(installdir)" ] || ( $(MKDIR) "$(topsrcdir)/$(installdir)" || true );
44 ifndef SILENT
45         @echo "[INSTALL] $(patsubst $(topsrcdir)/$(builddir)/%,%,$(TARGETS))";
46 endif
47         $(Q)$(CP) $(TARGETS) "$(topsrcdir)/$(installdir)"
48 else
49 # used in subdirs like libc/ctype whose files
50 # are contained in a parent's library
51 install : recurse $(OBJS) $(LIB_LIB)
52 endif
53
54 clean : recurse
55         @-echo "dummy" > .dummy
56         $(Q)-$(RM) .dummy $(foreach suf,asm d p lst hex cod sym,$(OBJS:.o=.$(suf)))
57         @-echo "dummy" > .dummy
58         $(Q)-$(RM) .dummy $(OBJS) $(LIB_LIB)
59         $(Q)-$(RM) $(TARGETS)
60         $(Q)-$(RM) $(addprefix $(topsrcdir)/$(installdir)/,$(notdir $(TARGETS)))
61         $(Q)-[ ! -d "$(topsrcdir)/$(builddir)" ] || $(RMDIR) "$(topsrcdir)/$(builddir)"
62
63 clean-intermediate : recurse
64         @-echo "dummy" > .dummy
65         $(Q)-$(RM) .dummy $(foreach suf,p lst hex cod sym,$(OBJS:.o=.$(suf)))
66         
67 include $(topsrcdir)/Makefile.rules