RN rnmake  3.0.0
Extras.mk
Go to the documentation of this file.
1 ################################################################################
2 #
3 # Extras.mk
4 #
5 ifdef RNMAKE_DOXY
6 /*!
7 \file
8 
9 \brief Optional extras that the including package makefiles may include.
10 
11 Include this file in the local make file (usually near the bottom).
12 
13 \pkgsynopsis
14 RN Make System
15 
16 \pkgfile{Extras.mk}
17 
18 \pkgauthor{Robin Knight,robin.knight@roadnarrows.com}
19 
20 \pkgcopyright{2018,RoadNarrows LLC,http://www.roadnarrows.com}
21 
22 \license{MIT}
23 
24 \EulaBegin
25 \EulaEnd
26 
27 \cond RNMAKE_DOXY
28  */
29 endif
30 #
31 ################################################################################
32 
33 _EXTRAS_MK = 1
34 
35 # $(call copySrcDst,src,dst)
36 # Template to a copy source file to destination file. The file is copied iff
37 # the destination does not exists or if the source is newer.
38 define copySrcDst
39  @if [ "$(1)" != "" ]; \
40  then \
41  if [ ! -f "$(2)" -o "$(1)" -nt "$(2)" ]; \
42  then \
43  d=$$(dirname $(2)); \
44  test -d $$d || $(MKDIR) $$d; \
45  printf " $(1)\n"; \
46  $(CP) $(1) $(2); \
47  fi; \
48  fi
49 endef
50 
51 # $(call copySrcDir,srcfile...,dir)
52 # Template to copy source files to the destination directory. Each source
53 # file is copied iff the destination file does not exists or if the source is
54 # newer. Subdirectories of the destination directory are created as needed.
55 #
56 # Examples:
57 # $(call copySrcDir,foo bar,egg) -->
58 # egg/foo egg/bar
59 # $(call copySrcDir,lode of/the/bride,mother) -->
60 # mother/lode mother/of/the/bride
61 define copySrcDir
62  @if [ "$(1)" != "" ]; \
63  then \
64  flist="$(wildcard $(1))"; \
65  for src in $${flist}; \
66  do \
67  dst=$(2)/$${src}; \
68  if [ ! -f "$${dst}" -o "$${src}" -nt "$${dst}" ]; \
69  then \
70  d=$$(dirname $${dst}); \
71  test -d $${d} || $(MKDIR) $${d}; \
72  printf " $${src}\n"; \
73  $(CP) $${src} $${dst}; \
74  fi; \
75  done; \
76  fi
77 endef
78 
79 # $(call copySrcDirRel,srcfile...,dir[,prefix])
80 # Template to copy source files to the destination directory. Each source
81 # file is copied iff the destination file does not exists or if the source is
82 # newer. Subdirectories of the destination directory are created as needed.
83 # If the prefix paramter is specified, string up to prefix is stripped off
84 # the source files prior to copying. Otherwise the common directory part
85 # between the target and source are removed.
86 #
87 # Example 1:
88 # srcfiles = share/etc/rules.d/my.rules share/etc/ld.so.conf.d/my.conf
89 # etcdir = /path/to/mypkg/dist/dist.arch/etc
90 # $(call copySrcDirRel,$(srcfiles),$(etcdir) -->
91 # /path/to/mypkg/dist/dist.arch/etc/rules.d/my.rules
92 # /path/to/mypkg/dist/dist.arch/etc/ld.so.conf.d/my.conf
93 # Example 2:
94 # srcfile = share/lib/cmake/mypkg-config.cmake
95 # libdir = /path/to/mypkg/dist/dist.arch/lib
96 # $(call copySrcDirRel,$(srcfile),$(libdir)) -->
97 # /path/to/mypkg/dist/dist.arch/lib/cmake/mypkg-config.cmake
98 # Example 3:
99 # srcfiles = share/theroad share/food/cake
100 # sharedir = /path/to/mypkg/dist/dist.arch/share/mypkg-x.y.z
101 # $(call copySrcDirRel,$(srcfiles),$(sharedir),share) -->
102 # /path/to/mypkg/dist/dist.arch/share/mypkg-x.y.z/theroad
103 # /path/to/mypkg/dist/dist.arch/share/mypkg-x.y.z/food/cake
104 define copySrcDirRel
105  @if [ "$(1)" != "" ]; \
106  then \
107  dstbase=$(notdir $(2)); \
108  flist="$(wildcard $(addprefix $(RNMAKE_PKG_ROOT)/,$(1)))"; \
109  for src in $${flist}; \
110  do \
111  if [ -z "$(3)" ]; \
112  then \
113  dst=$(2)/$${src##*$${dstbase}/}; \
114  else \
115  dst=$(2)/$${src##*$(3)/}; \
116  fi; \
117  if [ ! -f "$${dst}" -o "$${src}" -nt "$${dst}" ]; \
118  then \
119  dstdir=$$(dirname $${dst}); \
120  test -d $${dstdir} || $(MKDIR) $${dstdir}; \
121  printf " $${src}\n"; \
122  $(CP) $${src} $${dst}; \
123  fi; \
124  done; \
125  fi
126 endef
127 
128 # $(call copySrcDirRel,srcfile...,dir,prefix)
129 # Three argument version.
130 #
131 # Template to copy source files to the destination directory. Each source
132 # file is copied iff the destination file does not exists or if the source is
133 # newer. Subdirectories of the destination directory are created as needed.
134 #
135 #define copySrcDirRel
136 # $(info rdk: here 3: '$(3)')
137 # @if [ "$(1)" != "" ]; \
138 # then \
139 # flist="$(wildcard $(addprefix $(RNMAKE_PKG_ROOT)/,$(1)))"; \
140 # for src in $${flist}; \
141 # do \
142 # dst=$(2)/$${src##*$(3)/}; \
143 # if [ ! -f "$${dst}" -o "$${src}" -nt "$${dst}" ]; \
144 # then \
145 # dstdir=$$(dirname $${dst}); \
146 # test -d $${dstdir} || $(MKDIR) $${dstdir}; \
147 # printf " $${src}\n"; \
148 # $(CP) $${src} $${dst}; \
149 # fi; \
150 # done; \
151 # fi
152 #endef
153 
154 
155 ifdef RNMAKE_DOXY
156 /*! \endcond RNMAKE_DOXY */
157 endif