summaryrefslogtreecommitdiffstats
path: root/rules/Rules.make
blob: fcbc59b51887c75abb3fb01a0790d4d7d9688830 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
# -*-makefile-*-
PASSIVEFTP	= --passive-ftp
SUDO		= sudo
PTXUSER		= $(shell echo $$USER)
GNU_BUILD	= $(shell $(TOPDIR)/scripts/config.guess)
GNU_HOST	= $(shell echo $(GNU_BUILD) | sed s/-[a-zA-Z0-9_]*-/-host-/)
HOSTCC		= gcc
HOSTCC_ENV	= CC=$(HOSTCC)
CROSSSTRIP	= PATH=$(CROSS_PATH) $(PTXCONF_GNU_TARGET)-strip
CROSS_STRIP	= $(CROSSSTRIP)
DOT		= dot
DEP_OUTPUT	= depend.out
DEP_TREE_PS	= deptree.ps

#
# some convenience functions
#

ifneq (y, $(PTXCONF_CROSSTOOL))
compilercheck =								\
	echo -n "compiler check...";					\
	which $(PTXCONF_GNU_TARGET)-gcc > /dev/null 2>&1 || {		\
		echo; echo;						\
		echo "No compiler installed!";				\
		echo "Specified: $(PTXCONF_GNU_TARGET)-gcc";		\
		echo;							\
		exit -1;						\
	};								\
	if [ "$(PTXCONF_CROSSCHAIN_CHECK)" != `$(PTXCONF_GNU_TARGET)-gcc -dumpversion` ]; then	\
		echo; echo;						\
		echo "Please use the specified compiler!";		\
		echo;							\
		echo "Specified: $(PTXCONF_CROSSCHAIN_CHECK)";		\
		echo "Found:     "`$(PTXCONF_GNU_TARGET)-gcc -dumpversion`;\
		echo;							\
		exit -1;						\
	fi;								\
	echo "ok";
else
compilercheck =								\
	echo > /dev/null;
endif

check_prog_exists = 				\
	@if [ ! -x `which $(1)` ]; then		\
		echo "$(1) not found";		\
		echo "please install $(1)"; 	\
		exit -1;			\
	fi;

check_prog_version = 				\
	@if [ `$(1) -V | head -n 1 |		\
	awk '{gsub ("[a-zA-Z]",""); if ($$1 != $(2)) print "false"; else print "true"}'` == "false" ]; then \
		echo "need $(1) version $(2)";	\
		echo "please install";		\
		exit -1;			\
	fi;

#
# print out header information and check if we have the right compiler
#
targetinfo = 						\
	echo;						\
	TG=`echo $(1) | sed -e "s,/.*/,,g"`; 		\
	LINE=`echo target: $$TG |sed -e "s/./-/g"`;	\
	echo $$LINE;					\
	echo target: $$TG;				\
	echo $$LINE;					\
	echo;						\
	if [ `echo $$TG | grep "\.compile"` ]; then	\
		$(call compilercheck)			\
	fi;						\
	if [ `echo $$TG | grep "\.prepare"` ]; then	\
		$(call compilercheck)			\
	fi;						\
	echo $@ : $^ | sed -e "s@$(TOPDIR)@@g" -e "s@/src/@@g" -e "s@/state/@@g" >> $(DEP_OUTPUT)


#
# extract the given source to builddir
#
# $1 = filename to extract
# $2 = dir into extract
#
# if $2 is not given, it is extracted to the BUILDDIR
#
extract =							\
	PACKET="$(strip $(1))";					\
	if [ "$$PACKET" = "" ]; then				\
		echo;						\
		echo Error: empty parameter to \"extract\(\)\";	\
		echo;						\
		exit -1;					\
	fi;							\
	DEST="$(strip $(2))";					\
	DEST=$${DEST:-$(BUILDDIR)};				\
	case "$$PACKET" in					\
	*gz)							\
		EXTRACT=$(GZIP)					\
		;;						\
	*bz2)							\
		EXTRACT=$(BZIP2)				\
		;;						\
	*)							\
		echo;						\
		echo Unknown format, cannot extract!;		\
		echo;						\
		exit -1;					\
		;;						\
	esac;							\
	[ -d $$DEST ] || mkdir -p $$DEST;			\
	echo $$(basename $$PACKET) >> state/packetlist; 			\
	$$EXTRACT -dc $$PACKET | $(TAR) -C $$DEST -xf -	;	

#
# download the given URL
#
# $1 = URL of the packet
# $2 = source dir
# 
get =								\
	URL="$(strip $(1))";					\
	if [ "$$URL" = "" ]; then				\
		echo;						\
		echo Error: empty parameter to \"get\(\)\";	\
		echo;						\
		exit -1;					\
	fi;							\
	[ "$$(expr match $$URL http://)" != "0" ] && URLTYPE="http"; \
	[ "$$(expr match $$URL ftp://)" != "0" ] && URLTYPE="ftp";   \
	[ "$$(expr match $$URL file://)" != "0" ] && URLTYPE="file"; \
	SRC="$(strip $(2))";					\
	SRC=$${SRC:-$(SRCDIR)};					\
	[ -d $$SRC ] || mkdir -p $$SRC;				\
	case $$URLTYPE in 					\
	http)							\
		$(WGET) -P $$SRC $(PASSIVEFTP) $$URL;		\
		[ $$? -eq 0 ] || {				\
			echo;					\
			echo "Could not get packet via http!";	\
			echo "URL: $$URL";			\
			echo;					\
			exit -1;				\
			};					\
		;;						\
	ftp)							\
		$(WGET) -P $$SRC $(PASSIVEFTP) $$URL;		\
		[ $$? -eq 0 ] || {				\
			echo;					\
			echo "Could not get packet via ftp!";	\
			echo "URL: $$URL";			\
			echo;					\
			exit -1;				\
			};					\
		;;						\
	file)							\
		FILE="$$(echo $$URL | sed s-file://-/-g)";	\
		cp -av $$FILE $$SRC;				\
		[ $$? -eq 0 ] || {				\
			echo;					\
			echo "Could not copy packet!";		\
			echo "File: $$FILE";			\
			echo;					\
			exit -1;				\
			};					\
		;;						\
	*)							\
		echo;						\
		echo "Unknown URL Type!";			\
		echo "URL: $$URL";				\
		echo;						\
		exit -1;					\
		;;						\
	esac;								
#
# download the given URL
#
# $1 = name of the package the patch has to be applied to 
# $2 = URL of the patch; this may either point to a single unified diff
#      or to a directory containing a 'patcher' like patch series
# $3 = patch name; the patch is stored in $(TOPDIR)/feature-patches/$3
# 
get_feature_patch =						\
	FP_PARENT="$(strip $(1))";				\
	FP_URL="$(strip $(2))";					\
	FP_NAME="$(strip $(3))";				\
	if [ -f $(TOPDIR)/feature-patches/$$FP_NAME/$$FP_FILE ]; then	\
		echo "patch already downloaded, skipping...";	\
		exit 0;						\
	fi;							\
	if [ "$$FP_URL" == "" ] && [ "$$FP_NAME" == "" ]; then	\
		echo "patch not set, silently dropping";	\
		exit 0;						\
	fi;							\
	if [ "$$FP_URL" == "" ] || [ "$$FP_NAME" == "" ]; then	\
		echo;						\
		echo "Error: empty feature patch name or URL";	\
		echo;						\
		exit -1;					\
	fi;							\
	FP_DIR="$(TOPDIR)/feature-patches/$$FP_NAME";		\
	[ -d $$FP_DIR ] || mkdir -p $$FP_DIR;			\
	[ "$$(expr match $$FP_URL http://)" != "0" ] && FP_URLTYPE="http"; \
        [ "$$(expr match $$FP_URL ftp://)" != "0" ] && FP_URLTYPE="ftp";   \
        [ "$$(expr match $$FP_URL file://)" != "0" ] && FP_URLTYPE="file"; \
	case $$FP_URLTYPE in                                    \
        http)                                                   \
                $(WGET) -r -np -nd -nH --cut-dirs=0 -P $$FP_DIR $(PASSIVEFTP) $$FP_URL; \
		[ $$? -eq 0 ] || {                              \
                        echo;                                   \
                        echo "Could not get feature patch via http!";  \
                        echo "URL: $$URL";                      \
                        echo;                                   \
                        exit -1;                                \
                        };                                      \
                ;;                                              \
        ftp)                                                    \
                $(WGET) -r -np -nd -nH --cut-dirs=0 -P $$FP_DIR $(PASSIVEFTP) $$FP_URL; \
		[ $$? -eq 0 ] || {                              \
                        echo;                                   \
                        echo "Could not get feature patch via ftp!";   \
                        echo "URL: $$URL";                      \
                        echo;                                   \
                        exit -1;                                \
                        };                                      \
                ;;                                              \
        file)                                                   \
                FP_FILE="$$(echo $$FP_URL | sed s-file://-/-g)";\
                cp -av $$FP_FILE $$FP_DIR;                      \
                [ $$? -eq 0 ] || {                              \
                        echo;                                   \
                        echo "Could not copy feature patch!";   \
                        echo "File: $$FILE";                    \
                        echo;                                   \
                        exit -1;                                \
                        };                                      \
                ;;                                              \
        *)                                                      \
                echo;                                           \
                echo "Unknown URL Type for feature patch!";     \
                echo "URL: $$URL";                              \
                echo;                                           \
                exit -1;                                        \
                ;;                                              \
        esac;
#
# download patches from Pengutronix' patch repository
# 
# $1 = packet name = identifier for patch subdir
# 
# the wget options:
# ----------------
# -r -l1		recursive 1 level
# -nH --cutdirs=3	remove hostname and next 3 dirs from URL, when saving
#			so "http://www.pengutronix.de/software/ptxdist-cvs/patches/glibc-2.2.5/*"
#			becomes "glibc-2.2.5/*"
#
get_patches =											\
	PACKET_NAME="$(strip $(1))";								\
	if [ "$$PACKET_NAME" = "" ]; then							\
		echo;										\
		echo Error: empty parameter to \"get_pachtes\(\)\";				\
		echo;										\
		exit -1;									\
	fi;											\
	if [ "$(EXTRAVERSION)" = "-cvs" ]; then							\
		PATCH_TREE=cvs;									\
	else											\
		PATCH_TREE=$(FULLVERSION);							\
	fi;											\
	echo "checking if $(PATCHDIR) exists..."; 						\
	if [ ! -d $(PATCHDIR) ]; then								\
		mkdir -p $(PATCHDIR);								\
	fi;											\
	echo "removing old patches..."; 							\
	if [ -d $(PATCHDIR)/$$PACKET_NAME ]; then						\
		rm -fr $(PATCHDIR)/$$PACKET_NAME;						\
	fi;											\
	echo "checking for local or net patches...";						\
	if [ -d $(PATCHDIR)-local ]; then							\
		echo "Copying Local patches from patches-local/"$$PACKET_NAME;			\
		if [ -d "$(PATCHDIR)-local/$$PACKET_NAME" ]; then 				\
			echo "patch found";							\
			cp -vr $(PATCHDIR)-local/$$PACKET_NAME $(PATCHDIR);			\
		else										\
			echo "no patch available";						\
		fi;										\
	else											\
		echo "copying network patches from Pengutronix server"; 				\
		$(WGET) -r -l 1 -nH --cut-dirs=3 -A.diff -A.patch -A.gz -A.bz2 -q -P $(PATCHDIR)	\
			$(PASSIVEFTP) $(PTXPATCH_URL)-$$PATCH_TREE/$$PACKET_NAME/generic/;		\
		[ $$? -eq 0 ] || {									\
			echo;										\
			echo "Could not get patch!";							\
			echo "URL: $(PTXPATCH_URL)-$$PATCH_TREE/$$PACKET_NAME/generic/";		\
			echo;										\
			exit -1;									\
		};											\
		$(WGET) -r -l 1 -nH --cut-dirs=3 -A.diff -A.patch -A.gz -A.bz2 -q -P $(PATCHDIR)	\
			$(PASSIVEFTP) $(PTXPATCH_URL)-$$PATCH_TREE/$$PACKET_NAME/$(PTXCONF_ARCH)/;	\
		[ $$? -eq 0 ] || {									\
			echo;										\
			echo "Could not get patch!";							\
			echo "URL: $(PTXPATCH_URL)-$$PATCH_TREE/$$PACKET_NAME/$(PTXCONF_ARCH)/ ";	\
			echo;										\
			exit -1;									\
		};											\
		true;											\
	fi;

#
# returns an options from the .config file
#
# $1 = regex, that's applied to the .config file
#      format: 's/foo/bar/'
#
# $2 = default option, this value is returned if the regex outputs nothing
#
get_option =										\
	$(shell										\
		REGEX="$(strip $(1))";							\
		DEFAULT="$(strip $(2))";						\
		if [ -f $(TOPDIR)/.config ]; then					\
			VALUE=`cat $(TOPDIR)/.config | sed -n -e "$${REGEX}p"`;		\
		fi;									\
		echo $${VALUE:-$$DEFAULT}						\
	)

#
# returns an options from the .config file
#
# $1 = regex, that's applied to the .config file
#      format: 's/foo/bar/'
# $2 = command that get in STDIN the output from the regex magic
#      should return something in STDOUT
#
get_option_ext =									\
	$(shell										\
		REGEX="$(strip $(1))";							\
		if [ -f $(TOPDIR)/.config ]; then					\
			cat $(TOPDIR)/.config | sed -n -e "$${REGEX}p" | $(2);		\
		fi;									\
	)


#
# cleanup the given directory or file
#
clean =								\
	DIR="$(strip $(1))";					\
	if [ -e $$DIR ]; then					\
		rm -rf $$DIR;					\
	fi

# 	if [ "$$DIR" = "" ]; then				\
# 		echo;						\
# 		echo Error: empty parameter to \"clean\(\)\";	\
# 		echo;						\
# 		exit -1;					\
# 	fi;							\


#
# find latest config
#
latestconfig = `find $(TOPDIR)/config -name $(1)* -print | sort | tail -1`


#
# enables a define, removes /* */
#
# (often found in .c or .h files)
#
# $1 = file
# $2 = parameter
#
enable_c =											\
	FILENAME="$(strip $(1))";								\
	PARAMETER="$(strip $(2))";								\
	perl -p -i -e										\
		"s,^\s*(\/\*)?\s*(\#\s*define\s+$$PARAMETER)\s*(\*\/)?$$,\$$2\n,"		\
		$$FILENAME

#
# disables a define with, adds /* */
#
# (often found in .c or .h files)
#
# $1 = file
# $2 = parameter
#
disable_c =											\
	FILENAME="$(strip $(1))";								\
	PARAMETER="$(strip $(2))";								\
	perl -p -i -e										\
		"s,^\s*(\/\*)?\s*(\#\s*define\s+$$PARAMETER)\s*(\*\/)?$$,\/\*\$$2\*\/\n,"	\
		$$FILENAME

#
# enabled something, removes #
#
# often found in shell scripts, Makefiles
#
# $1 = file
# $2 = parameter
#
enable_sh =						\
	FILENAME="$(strip $(1))";			\
	PARAMETER="$(strip $(2))";			\
	perl -p -i -e					\
		"s,^\s*(\#)?\s*($$PARAMETER),\$$2,"	\
		$$FILENAME

#
# disables a comment, adds #
#
# often found in shell scripts, Makefiles
#
# $1 = file
# $2 = parameter
#
disable_sh =						\
	FILENAME="$(strip $(1))";			\
	PARAMETER="$(strip $(2))";			\
	perl -p -i -e					\
		"s,^\s*(\#)?\s*($$PARAMETER),\#\$$2,"	\
		$$FILENAME

#
# go into a directory and apply all patches from there into a sourcetree
#
# $1 = $(PACKET_NAME) -> identifier
# $2 = path to source tree 
#      if this parameter is omitted, the path will be derived
#      from the packet name
#
patchin =									\
	PACKET_NAME="$(strip $(1))";						\
	if [ "$$PACKET_NAME" = "" ]; then					\
		echo;								\
		echo Error: empty parameter to \"patchin\(\)\";			\
		echo;								\
		exit -1;							\
	fi;									\
	PACKET_DIR="$(strip $(2))";						\
	PACKET_DIR=$${PACKET_DIR:-$(BUILDDIR)/$$PACKET_NAME};			\
	for PATCH_NAME in							\
	    $(TOPDIR)/patches/$$PACKET_NAME/generic/*.diff			\
	    $(TOPDIR)/patches/$$PACKET_NAME/generic/*.patch			\
	    $(TOPDIR)/patches/$$PACKET_NAME/generic/*.gz			\
	    $(TOPDIR)/patches/$$PACKET_NAME/generic/*.bz2			\
	    $(TOPDIR)/patches/$$PACKET_NAME/$(PTXCONF_ARCH)/*.diff		\
	    $(TOPDIR)/patches/$$PACKET_NAME/$(PTXCONF_ARCH)/*.patch		\
	    $(TOPDIR)/patches/$$PACKET_NAME/$(PTXCONF_ARCH)/*.gz		\
	    $(TOPDIR)/patches/$$PACKET_NAME/$(PTXCONF_ARCH)/*.bz2;		\
	    do									\
		if [ -f $$PATCH_NAME ]; then					\
			case `basename $$PATCH_NAME` in				\
			*.gz)							\
				CAT=$(ZCAT)					\
				;;						\
			*.bz2)							\
				CAT=$(BZCAT)					\
				;;						\
			*.diff|diff*|*.patch|patch*)				\
				CAT=$(CAT)					\
				;;						\
			*)							\
				echo;						\
				echo Unknown patch format, cannot apply!;	\
				echo;						\
				exit -1;					\
				;;						\
			esac;							\
			echo "patchin' $$PATCH_NAME ...";			\
			$$CAT $$PATCH_NAME | $(PATCH) -Np1 -d $$PACKET_DIR || exit -1;	\
		fi;								\
	    done

#
# apply a patch
#
# $1 = the name of the patch to apply
# $2 = apply patch to that directory
#
patch_apply =								\
	PATCH_NAME="$(strip $(1))";					\
	if [ "$$PATCH_NAME" = "" ]; then				\
		echo;							\
		echo Error: empty parameter to \"patch_apply\(\)\";	\
		echo;							\
		exit -1;						\
	fi;								\
	PACKET_DIR="$(strip $(2))";					\
	if [ -f $$PATCH_NAME ]; then					\
		case `basename $$PATCH_NAME` in				\
		*.gz)							\
			CAT=$(ZCAT)					\
			;;						\
		*.bz2)							\
			CAT=$(BZCAT)					\
			;;						\
		*.diff|diff*|*.patch|patch*)				\
			CAT=$(CAT)					\
			;;						\
		*)							\
			echo;						\
			echo Unknown patch format, cannot apply!;	\
			echo;						\
			exit -1;					\
			;;						\
		esac;							\
		echo "patchin' $$PATCH_NAME ...";			\
		$$CAT $$PATCH_NAME | $(PATCH) -Np1 -d $$PACKET_DIR || exit -1;	\
	fi;								\
	true;

#
# go into a directory, look for either a 'series' file and apply all 
# patches listed there into a sourcetree, or, if no 'series' file
# exists, apply the patches as they come
#
# $1 = $(FP_TARGET): path to source tree where the feature patch is
#      to be applied  
#
# $2 = $(FP_NAME): name of the patch to be applied; patches usually live 
#      in $(TOPDIR)/feature-patches/$(FP_NAME). Patches without a name 
#      are silently ignored. 
#
feature_patchin =								\
	FP_TARGET="$(strip $(1))";						\
	FP_NAME="$(strip $(2))";						\
	if [ "x$$FP_TARGET" = "x" ]; then					\
		echo;								\
		echo "Error: you didn't specify a feature patch target dir!";	\
		echo "Error: feature_patchin needs this as parameter 2";	\
		echo;								\
		exit -1;							\
	fi;									\
	if [ "x$$FP_NAME" = "x" ]; then						\
		echo "No patch name specified, dropping.";			\
		exit 0;								\
	fi;									\
	FP_DIR=$(TOPDIR)/feature-patches/$$FP_NAME;				\
	if [ -f $$FP_DIR/series ]; then						\
		for PATCH_NAME in `cat $$FP_DIR/series`; do			\
			echo "patchin' $$PATCH_NAME ...";			\
			cat $$FP_DIR/$$PATCH_NAME.patch | 			\
			     $(PATCH) -Np1 -d $$FP_TARGET || exit -1; 		\
		done;								\
	else									\
		echo "feature-patchin' in $$FP_DIR...";				\
		cd $$FP_DIR && for PATCH_NAME in 				\
			$$(find . -name "*patch*")				\
			$$(find . -name "*diff*"); do				\
			PATCH_NAME_BASE=`basename $$PATCH_NAME`;		\
			echo "basename=$$PATCH_NAME_BASE";			\
			case $$PATCH_NAME_BASE in				\
			*.gz)							\
				echo "patch is gzip compressed";		\
				CAT=$(ZCAT);					\
				;;						\
			*.bz2)							\
				echo "patch is bzip2 compressed";		\
				CAT=$(BZCAT);					\
				;;						\
			*)							\
				echo "patch is uncompressed";			\
				CAT=$(CAT)					\
				;;						\
			esac;							\
			echo "patchin' $$PATCH_NAME ...";			\
			if [ ! -e $$PATCH_NAME ]; then 				\
				echo "Error: patch $$PATCH_NAME doesn't exist!";\
				exit -1; 					\
			fi; 							\
			$$CAT $$PATCH_NAME | $(PATCH) -Np1 -d $$FP_TARGET;	\
			if [ $$? -ne 0 ]; then					\
				echo "Error: feature_patchin failed!";		\
				exit -1;					\
			fi;							\
		done;								\
	fi;									\

#
# Install function with user/group ownership and permissions via fakeroot
#
# $1 = UID
# $2 = GID
# $3 = permissions (octal)
# $4 = source (for files); directory (for directories)
# $5 = destination (for files); empty (for directories). Prefixed with $(ROOTDIR)
#
copy_root = 									\
	@OWN=`echo $(1) | sed -e 's/[[:space:]]//g'`;				\
	GRP=`echo $(2) | sed -e 's/[[:space:]]//g'`;				\
	PER=`echo $(3) | sed -e 's/[[:space:]]//g'`;				\
	SRC=`echo $(4) | sed -e 's/[[:space:]]//g'`;				\
	DST=`echo $(5) | sed -e 's/[[:space:]]//g'`;				\
	if [ -z "$(5)" ]; then									 \
		echo "copy_root dir=$$SRC owner=$$OWN group=$$GRP permissions=$$PER"; 		 \
		install -d $(ROOTDIR)/$$SRC;							 \
		echo "$$SRC:$$OWN:$$GRP:$$PER" >> $(TOPDIR)/permissions;			 \
	else											 \
		echo "copy_root src=$$SRC dst=$$DST owner=$$OWN group=$$GRP permissions=$$PER";  \
		install $$SRC $(ROOTDIR)/$$DST;							 \
		echo "$$DST:$$OWN:$$GRP:$$PER" >> $(TOPDIR)/permissions;			 \
	fi;

#
# Link function: consistent syntax for soft links
# 
# $1 = source
# $2 = destination
#
link_root =									\
	@SRC=`echo $(1) | sed -e 's/[[:space:]]//g'`;				\
	DST=`echo $(2) | sed -e 's/[[:space:]]//g'`;				\
	echo "link_root src=$$SRC dst=$$DST "; 					\
	ln -sf $$SRC $(ROOTDIR)$$DST

#
# CFLAGS // CXXFLAGS
#
# the TARGET_CFLAGS and TARGET_CXXFLAGS are included from the architecture
# depended config file that is specified in .config
#
# the option in the .config is called 'TARGET_CONFIG_FILE'
#
#
TARGET_CFLAGS		+= $(PTXCONF_TARGET_EXTRA_CFLAGS)
TARGET_CXXFLAGS		+= $(PTXCONF_TARGET_EXTRA_CXXFLAGS)
TARGET_CPPFLAGS		+= $(PTXCONF_TARGET_EXTRA_CPPFLAGS)
TARGET_LDFLAGS		+= $(PTXCONF_TARGET_EXTRA_LDFLAGS)

#
# if we use an external crosschain set include and lib dirs correctly
#
ifndef $(PTXCONF_CROSSTOOL)
TARGET_CFLAGS		+= -idirafter$(PTXCONF_PREFIX)/$(PTXCONF_GNU_TARGET)/include
TARGET_CXXFLAGS		+= -idirafter$(PTXCONF_PREFIX)/$(PTXCONF_GNU_TARGET)/include
TARGET_CPPFLAGS		+= -idirafter$(PTXCONF_PREFIX)/$(PTXCONF_GNU_TARGET)/include
TARGET_LDFLAGS		+= -L$(PTXCONF_PREFIX)/$(PTXCONF_GNU_TARGET)/lib
endif

#
# crossenvironment
#
CROSS_ENV_AR		= AR=$(PTXCONF_GNU_TARGET)-ar
CROSS_ENV_AS		= AS=$(PTXCONF_GNU_TARGET)-as
CROSS_ENV_LD		= LD=$(PTXCONF_GNU_TARGET)-ld
CROSS_ENV_NM		= NM=$(PTXCONF_GNU_TARGET)-nm
CROSS_ENV_CC		= CC=$(PTXCONF_GNU_TARGET)-gcc
CROSS_ENV_CC_FOR_BUILD	= CC_FOR_BUILD=$(HOSTCC)
CROSS_ENV_CXX		= CXX=$(PTXCONF_GNU_TARGET)-g++
CROSS_ENV_OBJCOPY	= OBJCOPY=$(PTXCONF_GNU_TARGET)-objcopy
CROSS_ENV_OBJDUMP	= OBJDUMP=$(PTXCONF_GNU_TARGET)-objdump
CROSS_ENV_RANLIB	= RANLIB=$(PTXCONF_GNU_TARGET)-ranlib
CROSS_ENV_STRIP		= STRIP=$(PTXCONF_GNU_TARGET)-strip
ifneq ('','$(strip $(subst ",,$(TARGET_CFLAGS)))')
CROSS_ENV_CFLAGS	= CFLAGS='$(strip $(subst ",,$(TARGET_CFLAGS)))'
endif
ifneq ('','$(strip $(subst ",,$(TARGET_CXXFLAGS)))')
CROSS_ENV_CXXFLAGS	= CXXFLAGS='$(strip $(subst ",,$(TARGET_CXXFLAGS)))'
endif
ifneq ('','$(strip $(subst ",,$(TARGET_CPPFLAGS)))')
CROSS_ENV_CPPFLAGS	= CPPFLAGS='$(strip $(subst ",,$(TARGET_CPPFLAGS)))'
endif
ifneq ('','$(strip $(subst ",,$(TARGET_LDFLAGS)))')
CROSS_ENV_LDFLAGS	= LDFLAGS='$(strip $(subst ",,$(TARGET_LDFLAGS)))'
endif

CROSS_ENV := \
	$(CROSS_ENV_AR) \
	$(CROSS_ENV_AS) \
	$(CROSS_ENV_CXX) \
	$(CROSS_ENV_CC) \
	$(CROSS_ENV_CC_FOR_BUILD) \
	$(CROSS_ENV_LD) \
	$(CROSS_ENV_NM) \
	$(CROSS_ENV_OBJCOPY) \
	$(CROSS_ENV_OBJDUMP) \
	$(CROSS_ENV_RANLIB) \
	$(CROSS_ENV_STRIP) \
	$(CROSS_ENV_CFLAGS) \
	$(CROSS_ENV_CPPFLAGS) \
	$(CROSS_ENV_LDFLAGS) \
	$(CROSS_ENV_CXXFLAGS) \
	ac_cv_func_getpgrp_void=yes \
	ac_cv_func_setpgrp_void=yes \
	ac_cv_sizeof_long_long=8 \
	ac_cv_func_memcmp_clean=yes \
	ac_cv_func_setvbuf_reversed=no \
	ac_cv_func_getrlimit=yes


#
# CROSS_LIB_DIR	= the libs for the target system are installed into this dir
#
CROSS_LIB_DIR		= $(PTXCONF_PREFIX)/$(PTXCONF_GNU_TARGET)

#
# Use the masquerading method of invoking distcc if enabled
#
#
ifdef PTXCONF_XCHAIN-DISTCC
# FIXME: should also allow use of DISTCC for native stuff
DISTCC_PATH_COLON     = $(PTXCONF_PREFIX)/lib/distcc/bin:
endif

#
# prepare the search path
#
CROSS_PATH		= $(DISTCC_PATH_COLON)$(PTXCONF_PREFIX)/bin:$$PATH

#
# same as PTXCONF_GNU_TARGET, but w/o -linux
# e.g. i486 instead of i486-linux
#
SHORT_TARGET		:= `echo $(PTXCONF_GNU_TARGET) |  perl -i -p -e 's/(.*?)-.*/$$1/'`

#
# change this if you have some wired configuration :)
#
SH		:= /bin/sh
WGET		:= wget
MAKE		:= make
PATCH		:= patch
TAR		:= tar
GZIP		:= gzip
ZCAT		:= zcat
BZIP2		:= bzip2
BZCAT		:= bzcat
CAT		:= cat
RM		:= rm
MKDIR		:= mkdir
CD		:= cd
MV		:= mv
CP		:= cp
LN		:= ln
PERL		:= perl
GREP		:= grep
INSTALL		:= install

# vim: syntax=make