Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
# -*- mode: mak; tabs: 8; -*-
2
#
3
##############################################################################
4
# Compat for older (embedded) makefiles
5
##############################################################################
6
#
7
 
8
SCM_ROOT	= $(GBE_ROOT)
9
SCM_TYPE	= $(GBE_TYPE)
10
SCM_BIN 	= $(GBE_BIN)
11
SCM_PLATFORM	= $(GBE_PLATFORM)
12
 
13
#
14
###############################################################################
15
# Common definitions extracted from OPTIONS
16
##############################################################################
17
#
18
CC_PRE      := @
19
XX_PRE      := @
20
AA_PRE      := @
21
 
241 dpurdie 22
SHOWARGS    := NONE
227 dpurdie 23
 
241 dpurdie 24
USE_FILTER  := 1
25
LEAVETMP    :=
26
SHOWENV     :=
27
 
227 dpurdie 28
ifdef OPTIONS
29
 
30
ifneq "$(findstring args,$(OPTIONS))" ""        # Show arguments (default)
241 dpurdie 31
CC_PRE :=
32
XX_PRE :=
33
SHOWARGS := ARGS
227 dpurdie 34
endif
35
 
36
ifneq "$(findstring noargs,$(OPTIONS))" ""      # Show no arguments
241 dpurdie 37
CC_PRE := @
38
XX_PRE := @
39
SHOWARGS := NONE
227 dpurdie 40
endif
41
 
42
ifneq "$(findstring allargs,$(OPTIONS))" ""     #  Show ALL arguments
43
AA_PRE :=
241 dpurdie 44
SHOWARGS := ALL
227 dpurdie 45
endif
46
 
47
ifneq "$(findstring filter,$(OPTIONS))" ""      # Use filter (Default)
241 dpurdie 48
USE_FILTER := 1
227 dpurdie 49
endif
50
 
51
ifneq "$(findstring nofilter,$(OPTIONS))" ""    # Don't use filter
241 dpurdie 52
USE_FILTER  :=
227 dpurdie 53
endif
54
 
55
ifneq "$(findstring leavetmp,$(OPTIONS))" ""    # Leave temp files
241 dpurdie 56
LEAVETMP := 1
227 dpurdie 57
endif
58
 
59
ifneq "$(findstring noleavetmp,$(OPTIONS))" ""  # Don't leave temp files (Default)
241 dpurdie 60
LEAVETMP :=
227 dpurdie 61
endif
62
 
63
ifneq "$(findstring showenv,$(OPTIONS))" ""     # Display env before commands
241 dpurdie 64
SHOWENV := 1
227 dpurdie 65
endif
66
 
67
ifneq "$(findstring noshowenv,$(OPTIONS))" ""   # Don't display env before commands
241 dpurdie 68
SHOWENV :=
227 dpurdie 69
endif
70
 
71
endif
72
 
73
#
74
###############################################################################
75
# Brain hurts stuff... $(space) becomes a macro containing 1 space
76
# other aren't so bad.  These are used to make argument lists is a few 
77
# places where we have to translate from a space seperated list to a 
78
# something else seperated list (or vicky verka).
79
###############################################################################
80
#
81
comma		:= ,
82
plus		:= +
83
semicolon	:= ;
84
empty		:= 
85
space		:= $(empty) $(empty)
86
spacealt	:= %20
87
 
88
#
89
###############################################################################
90
# A little macro used within each of the rules for translating a file from 
91
# one type to another to print the environment if the variable SHOWENV has 
92
# been defined.
93
###############################################################################
94
#
95
ifdef SHOWENV
96
define show_environment
245 dpurdie 97
		$(printenv)
227 dpurdie 98
endef
99
else
100
define show_environment
101
endef
102
endif
103
 
104
#
105
###############################################################################
106
# Verbose versions of specific commands
107
###############################################################################
108
#
109
 
110
ifdef VERBOSE
111
GBE_RM		=$(rm)
112
GBE_RMDIR	=$(rmdir)
113
else
114
GBE_RM		=@$(rm)
115
GBE_RMDIR	=@$(rmdir)
116
endif
117
 
118
#
119
###############################################################################
120
# Support macros
121
###############################################################################
122
#
123
 
124
#.. Remove files contained within the specified list
125
#
126
#   Usage:      $(call RmFiles,VARIABLE_NAME)
127
#
128
define RmFiles
129
	@(if [ "$(GBE_VERBOSE)" -gt 0 ]; then \
130
		echo Removing $($(1)); fi; \
131
	CHOWNS=; \
132
	RMS=; \
133
	for file in $($(1)); do \
134
		if [ -f $$file -o -h $$file ]; then \
135
			if [ ! -w $$file ]; then \
136
				CHOWNS="$$CHOWNS $$file"; \
137
			fi; \
138
			RMS="$$RMS $$file"; \
139
		fi; \
140
	done; \
141
	if [ -n "$$RMS" ]; then \
142
		if [ -n "$$CHOWNS" ]; then \
143
			$(chmod) -f +w $$CHOWNS; \
144
		fi; \
145
		$(rm) -f $$RMS; \
146
	fi);
147
endef
148
 
149
#.. Install/uninstall the specified file
150
#
151
#   Usage:      $(call InstallFile,dest,file,path,fmode)
152
#               $(call UninstallFile,file)
153
#
154
define InstallFile
155
    $(call CopyFile,installing,$1,$2,$3,$4)
156
endef
157
 
158
define UninstallFile
159
    $(call UncopyFile,uninstalling,$1)
160
endef
161
 
162
#.. Package/Unpackage the specified file
163
#
164
#   Usage:      $(call PackageFile,dest,file,path,fmode)
165
#               $(call UnpackageFile,file)
166
#
167
define PackageFile
168
    $(call CopyFile,packaging,$1,$2,$3,$4)
169
endef
170
 
171
define UnpackageFile
172
    $(call UncopyFile,unpackaging,$1)
173
endef
174
 
175
#.. Generic Copy/Remove the specified file
176
#
177
#   Usage:      $(call CopyFile,Text,dest,file,path,fmode)
178
#               $(call UncopyFile,Text,file)
179
#
257 dpurdie 180
#   Notes:
181
#       dest, file and path
182
#	May have spaces in them
183
#		These will have been escaped with a '\' which will
184
#		need to be removed. The '\ ' is required to keep make
185
#		happy elsewhere.
249 dpurdie 186
#
257 dpurdie 187
#	May have '$' in them which we will need to escape
249 dpurdie 188
#
257 dpurdie 189
#       Windows copy has limitations.
190
#		Abs path length must < 260
191
#		Passing a relative path does not solve the problem
192
#		Moreover, if the relative path contains one or more ../
193
#		sequences, then the 'cp' command creates a complete path
194
#		before removing the zzz/.. sequences - and this must not exceed
195
#		259 characters.
196
#
197
#		At the moment we get the most out of the windows 'cp' by
198
#		passing it a clean absolute pathname, but there is still
199
#		a limit of ~259 characters. This affects many programs, not just
200
#		cp but make, rm, chmod ...
201
#
202
#
203
#	Nice Macros
204
#	AbsName	- convert a '\ ' pathname into an absolute path with plain spaces
205
#                 and $ escaped with a \.
206
#		  In the process 'spaces' need to be replaced with something to
207
#		  keep abspath from splitting on space.
208
#	NiceName - convert a '\ ' pathname into an string with plain spaces
209
#                 and $ escaped with a \.
210
#
211
AbsName = $(subst $$,\$$,$(subst $(spacealt),$(space),$(abspath $(subst \$(space),$(spacealt),$1))))
212
NiceName = $(subst $$,\$$,$(subst \$(space),$(space),$1))
213
 
227 dpurdie 214
define CopyFile
257 dpurdie 215
	(\
216
        udest="$(call NiceName,$2)"; \
217
        dest="$(call AbsName,$2)"; \
218
        file="$(call NiceName,$3)"; \
219
        path="$(call AbsName,$4)"; \
249 dpurdie 220
        fmode="$(5)"; \
257 dpurdie 221
	echo "------ $1 $$udest"; \
227 dpurdie 222
        if [ ! -f "$$file" ] ; then echo "$1 source file not found: $$file" ; exit 1; fi;\
223
	if [ ! -d "$$path" ] ; then $(mkdir) -p "$$path"; fi; \
224
	if [ -f "$$dest" -a ! -w "$$dest" ]; then $(chmod) -f +w "$$dest"; fi; \
225
	$(rm) -f "$$dest"; \
226
        $(cp) "$$file" "$$dest" ;\
227
        if [ $$? -gt 0 ] ; then echo "$1 copy error" ; exit 1; fi ;\
228
        $(if $(5),$(chmod) -f $$fmode "$$dest") ; \
229
        if [ ! -f "$$dest" ] ; then echo "$1 file not found after copy: $$dest" ; exit 1; fi; \
230
        );
231
endef
232
 
233
define UncopyFile
257 dpurdie 234
	$(AA_PRE)(\
235
        udest="$(call NiceName,$2)"; \
236
        file="$(call AbsName,$2)"; \
237
	echo "------ $1 $$udest"; \
227 dpurdie 238
	if [ -f "$$file" ]; then \
239
		if [ ! -w "$$file" ]; then $(chmod) -f +w "$$file"; fi; \
240
		$(rm) -f "$$file"; \
241
	fi);
242
endef
243
 
244
##