summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 2e2d75edc4dc9a46bbc00d1d7fe85a38ebcdb966 (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
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
###################################################################
# Makefile to generate a GNU GCC compiler (64-Bit) collection
#
#	- linux based mingw multilib cross compiler
#	- windows gcc multilib native compiler
#	- linux gcc multilib native compiler
#
#	all compiler including GDB 7.12
#
#	Languages:	C, C++, Fortran, Obj-C
#	Multilib:	-m32, -m64
#
# host
# 
#     The system that is going to run the software once it is built. Once the software
#     has been built, it will execute on this particular system.
# 
# build
# 
#     The system where the build process is being executed. For most uses this
#     would be the same as the host system, but in case of cross-compilation
#     the two obviously differ.
# 
# target
# 
#     The system against which the software being built will run on. This only exists, or rather
#     has a meaning, when the software being built may interact specifically with a
#     system that differs from the one it's being executed on (our host). This is the case
#     for compilers, debuggers, profilers and analyzers and other tools in general.
#
# Build order:
#
#  linux hosted nativ compiler -> linux hosted mingw cross compiler -> windows hosted nativ compiler
#
#

include versions.mk.inc

ifeq ($(BUILD_NUMBER),)
VERSION_SUITE		= $(SUITE)-unofficial
else
VERSION_SUITE		= $(SUITE)-$(BUILD_NUMBER)
endif

TOP			= $(shell readlink -f .)
ARCH 			= x86-linux64
ARCH64			= x86_64-linux-gnu
ARCH32			= i686-linux-gnu

GCC_PKGVERSION		= "TechSAT GCC-Suite v$(VERSION_SUITE)"

XGCC_TARGET64		= x86_64-w64-mingw32
XGCC_TARGET32		= i686-w64-mingw32

SOURCE_DIR 		= $(shell readlink -f $(PWD)/SOURCES)
PATCHES_DIR 		= $(shell readlink -f $(PWD)/PATCHES)
UNPACK_DIR		= $(PWD)/unpack.$(ARCH)
BUILD_DIR		= $(PWD)/build.$(ARCH)
INST_BASE		= $(PWD)/inst.$(ARCH)

SUITEDIR		= /opt/dev-tools/gcc-suite

INSTALLDIR		?= $(TOP)

INST_BASE_LINUX		= $(INSTALLDIR)/inst.x86-linux64

XGCC_INST_DIR		= $(INST_BASE_LINUX)/mingw64
XGCC_PREFIX		= $(XGCC_TARGET64)-
XGCC_BINPATH		= $(XGCC_INST_DIR)/bin
XGCC32			= "$(XGCC_BINPATH)/$(XGCC_PREFIX)gcc -m32 -static-libgcc"
XGCC64			= "$(XGCC_BINPATH)/$(XGCC_PREFIX)gcc -m64 -static-libgcc"
XGPP32			= "$(XGCC_BINPATH)/$(XGCC_PREFIX)g++ -m32 -static-libgcc -static-libstdc++"
XGPP64			= "$(XGCC_BINPATH)/$(XGCC_PREFIX)g++ -m64 -static-libgcc -static-libstdc++"

GCC_BINPATH		= $(INST_BASE)/gcc/bin
GCC32			= "$(GCC_BINPATH)/gcc -m32 -static-libgcc"
GXX32			= "$(GCC_BINPATH)/g++ -m32 -static-libgcc -static-libstdc++"
GCC64			= "$(GCC_BINPATH)/gcc -m32 -static-libgcc"
GXX64			= "$(GCC_BINPATH)/g++ -m32 -static-libgcc -static-libstdc++"
GCC			= "$(GCC_BINPATH)/gcc -static-libgcc"
GXX			= "$(GCC_BINPATH)/g++ -static-libgcc -static-libstdc++"


WINGCC_ROOTNAME		= gcc
WINGCC_INST_DIR		= $(INST_BASE)/$(WINGCC_ROOTNAME)
WINGCC_SYSROOT		= $(INST_BASE)/$(WINGCC_ROOTNAME)

SIMPLE_ARCHIVE_NAMES	= 0

LANGUAGES		= c,c++

SOURCE_PACKAGES 	= \
	$(SOURCE_DIR)/binutils-$(VERSION_BINUTILS).tar.bz2	\
	$(SOURCE_DIR)/gcc-$(VERSION_GCC).tar.gz		\
	$(SOURCE_DIR)/gdb-$(VERSION_GDB).tar.gz		\
	$(SOURCE_DIR)/gmp-$(VERSION_GMP).tar.lz			\
	$(SOURCE_DIR)/isl-$(VERSION_ISL).tar.bz2			\
	$(SOURCE_DIR)/mingw-w64-v$(VERSION_MINGW).tar.bz2	\
	$(SOURCE_DIR)/mpc-$(VERSION_MPC).tar.gz			\
	$(SOURCE_DIR)/mpfr-$(VERSION_MPFR).tar.bz2		\
	$(SOURCE_DIR)/zlib-$(VERSION_ZLIB).tar.gz		\
	$(SOURCE_DIR)/bzip2-$(VERSION_BZ2).tar.gz			

#JOBS	= -j4
JOBS	=

$(SOURCE_DIR)/binutils-$(VERSION_BINUTILS).tar.bz2: _download_prepare
	wget -c https://ftp.gnu.org/gnu/binutils/binutils-$(VERSION_BINUTILS).tar.bz2 -O \
		$(SOURCE_DIR)/binutils-$(VERSION_BINUTILS).tar.bz2 2>&1 
$(SOURCE_DIR)/gcc-$(VERSION_GCC).tar.gz:
	wget -c https://ftp.gnu.org/gnu/gcc/gcc-$(VERSION_GCC)/gcc-$(VERSION_GCC).tar.gz -O \
		$(SOURCE_DIR)/gcc-$(VERSION_GCC).tar.gz
$(SOURCE_DIR)/gmp-$(VERSION_GMP).tar.lz:
	wget -c https://gmplib.org/download/gmp/gmp-$(VERSION_GMP).tar.lz -O \
		$(SOURCE_DIR)/gmp-$(VERSION_GMP).tar.lz
$(SOURCE_DIR)/mingw-w64-v$(VERSION_MINGW).tar.bz2:
	wget -c https://vorboss.dl.sourceforge.net/project/mingw-w64/mingw-w64/mingw-w64-release/mingw-w64-v$(VERSION_MINGW).tar.bz2 -O \
		$(SOURCE_DIR)/mingw-w64-v$(VERSION_MINGW).tar.bz2
$(SOURCE_DIR)/mpc-$(VERSION_MPC).tar.gz:
	wget -c ftp://ftp.gnu.org/gnu/mpc/mpc-$(VERSION_MPC).tar.gz -O \
		$(SOURCE_DIR)/mpc-$(VERSION_MPC).tar.gz
$(SOURCE_DIR)/mpfr-$(VERSION_MPFR).tar.bz2:
	wget -c http://www.mpfr.org/mpfr-current/mpfr-$(VERSION_MPFR).tar.bz2 -O \
		$(SOURCE_DIR)/mpfr-$(VERSION_MPFR).tar.bz2
$(SOURCE_DIR)/zlib-$(VERSION_ZLIB).tar.gz:
	wget -c https://www.zlib.net/zlib-$(VERSION_ZLIB).tar.gz -O \
		$(SOURCE_DIR)/zlib-$(VERSION_ZLIB).tar.gz
$(SOURCE_DIR)/bzip2-$(VERSION_BZ2).tar.gz:
	wget -c ftp://sourceware.org/pub/bzip2/bzip2-$(VERSION_BZ2).tar.gz -O \
		$(SOURCE_DIR)/bzip2-$(VERSION_BZ2).tar.gz
$(SOURCE_DIR)/gdb-$(VERSION_GDB).tar.gz:
	wget -c ftp://sourceware.org/pub/gdb/releases/gdb-$(VERSION_GDB).tar.gz -O \
		$(SOURCE_DIR)/gdb-$(VERSION_GDB).tar.gz
#$(SOURCE_DIR)/isl-$(VERSION_ISL).tar.bz2:
#	wget -c "ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-$(VERSION_ISL).tar.bz2" -O \
#		$(SOURCE_DIR)/isl-$(VERSION_ISL).tar.bz2
$(SOURCE_DIR)/isl-$(VERSION_ISL).tar.bz2:
	wget -c "http://isl.gforge.inria.fr/isl-$(VERSION_ISL).tar.bz2" -O \
		$(SOURCE_DIR)/isl-$(VERSION_ISL).tar.bz2

download: $(SOURCE_PACKAGES)

_download_prepare:
	mkdir -p $(SOURCE_DIR)

all: 	lingcc-all xgcc-all wingcc-all fullclean
ifneq ($(LOCAL_INST_PATH),)
	mkdir -p $(LOCAL_INST_PATH)
	mkdir -p $(LOCAL_INST_PATH)/../x86-mingw64
	cd $(LOCAL_INST_PATH); \
	tar -zxf $(PWD)/gcc-suite-$(VERSION_SUITE)-gcc-$(VERSION_GCC)-x86-linux64.tgz 
	cd $(LOCAL_INST_PATH); \
	tar -zxf $(PWD)/gcc-suite-$(VERSION_SUITE)-xgcc-$(VERSION_GCC)-$(VERSION_MINGW)-x86-linux64.tgz
	cd $(LOCAL_INST_PATH)/../x86-mingw64; \
	unzip -o $(PWD)/gcc-suite-$(VERSION_SUITE)-gcc-$(VERSION_GCC)-$(VERSION_MINGW)-x86-mingw64.zip
endif

prepare:
	mkdir -p $(UNPACK_DIR)
	tar -zxf $(SOURCE_DIR)/gcc-$(VERSION_GCC).tar.gz -C $(UNPACK_DIR)/
	# Patches from https://gcc-mcf.lhmouse.com/ ...
	cd $(UNPACK_DIR)/gcc-$(VERSION_GCC) && \
		patch -p1 <  $(PATCHES_DIR)/0002-Relocate-libintl.patch && \
		patch -p1 <  $(PATCHES_DIR)/0004-Windows-Use-not-in-progpath-and-leave-case-as-is.patch && \
		patch -p1 <  $(PATCHES_DIR)/0006-Windows-New-feature-to-allow-overriding.patch && \
		patch -p1 <  $(PATCHES_DIR)/0008-Prettify-linking-no-undefined.patch && \
		patch -p1 <  $(PATCHES_DIR)/0010-Fix-using-large-PCH.gcc10.patch
	tar -zxf $(SOURCE_DIR)/gdb-$(VERSION_GDB).tar.gz -C $(UNPACK_DIR)/
	cd $(UNPACK_DIR)/gdb-$(VERSION_GDB) && \
		patch -p1 <  $(PATCHES_DIR)/0004-Windows-Use-not-in-progpath-and-leave-case-as-is.patch
	tar -jxf $(SOURCE_DIR)/binutils-$(VERSION_BINUTILS).tar.bz2 -C $(UNPACK_DIR)/
	cd $(UNPACK_DIR)/binutils-$(VERSION_BINUTILS) && \
		patch -p1 <  $(PATCHES_DIR)/0004-Windows-Use-not-in-progpath-and-leave-case-as-is.patch
	tar -jxf $(SOURCE_DIR)/mingw-w64-v$(VERSION_MINGW).tar.bz2 -C $(UNPACK_DIR)/
	#cd $(UNPACK_DIR)/mingw-w64-v$(VERSION_MINGW)/mingw-w64-tools/widl && \
	#    patch -p0 < $(PATCHES_DIR)/mingw-tools-widl-realloc.patch
	tar -jxf $(SOURCE_DIR)/mpfr-$(VERSION_MPFR).tar.bz2 -C $(UNPACK_DIR)/
	tar -jxf $(SOURCE_DIR)/isl-$(VERSION_ISL).tar.bz2 -C $(UNPACK_DIR)/
	tar -zxf $(SOURCE_DIR)/mpc-$(VERSION_MPC).tar.gz -C $(UNPACK_DIR)/
	tar --lzip -xf $(SOURCE_DIR)/gmp-$(VERSION_GMP).tar.lz -C $(UNPACK_DIR)/
	tar -zxf $(SOURCE_DIR)/zlib-$(VERSION_ZLIB).tar.gz -C $(UNPACK_DIR)/
	tar -zxf $(SOURCE_DIR)/bzip2-$(VERSION_BZ2).tar.gz -C $(UNPACK_DIR)/
	#
	rm -Rf $(UNPACK_DIR)/gcc-$(VERSION_GCC)/gmp
	mv $(UNPACK_DIR)/gmp-$(VERSION_GMP) $(UNPACK_DIR)/gcc-$(VERSION_GCC)/gmp
	rm -Rf $(UNPACK_DIR)/gcc-$(VERSION_GCC)/mpc
	mv $(UNPACK_DIR)/mpc-$(VERSION_MPC) $(UNPACK_DIR)/gcc-$(VERSION_GCC)/mpc
	rm -Rf $(UNPACK_DIR)/gcc-$(VERSION_GCC)/mpfr
	mv $(UNPACK_DIR)/mpfr-$(VERSION_MPFR) $(UNPACK_DIR)/gcc-$(VERSION_GCC)/mpfr
	rm -Rf $(UNPACK_DIR)/gcc-$(VERSION_GCC)/isl
	mv $(UNPACK_DIR)/isl-$(VERSION_ISL) $(UNPACK_DIR)/gcc-$(VERSION_GCC)/isl

build-common:
	mkdir -p $(BUILD_DIR)

##############################################################################
# Nativ Multilib Linux Compiler (64 -Bit)
##############################################################################
lingcc-all:
	make ARCH=x86-linux64 clean
	make ARCH=x86-linux64 prepare
	#
	make ARCH=x86-linux64 lingcc-binutils
	make ARCH=x86-linux64 lingcc-gcc
	make ARCH=x86-linux64 lingcc-finish
	make ARCH=x86-linux64 lingcc-gdb
	make ARCH=x86-linux64 lingcc-pack

lingcc-binutils:
	mkdir -p $(BUILD_DIR)/binutils
	cd $(BUILD_DIR)/binutils ;\
		LDLAGS="-static-libgcc -static-libstdc++" \
		$(UNPACK_DIR)/binutils-$(VERSION_BINUTILS)/configure \
			--with-pkgversion=$(GCC_PKGVERSION) \
			--prefix=$(INST_BASE)/gcc \
			--disable-nls \
			--enable-deterministic-archives \
			--with-gcc \
			--with-gnu-ld \
			--with-gnu-as \
			--disable-werror \
			--enable-targets=$(ARCH64),$(ARCH32) && \
		make $(JOBS) && make $(JOBS) install-strip


lingcc-gcc:
	mkdir -p $(BUILD_DIR)/gcc
	cd $(BUILD_DIR)/gcc && \
	LDLAGS="-static-libgcc -static-libstdc++" \
	$(UNPACK_DIR)/gcc-$(VERSION_GCC)/configure \
		--with-pkgversion=$(GCC_PKGVERSION) \
		--prefix=$(INST_BASE)/gcc \
		--build=$(ARCH64) \
		--host=$(ARCH64) \
		--target=$(ARCH64) \
		--disable-nls \
		--enable-multilib \
		--with-arch-32=i686 \
		--with-tune=generic\
		--enable-checking=release \
		--enable-languages=$(LANGUAGES) \
		--without-included-gettext \
		--enable-threads=posix \
		--enable-shared \
		--enable-static \
		--with-tune-64=core2 \
		--disable-werror \
		--disable-symvers \
		--enable-threads=posix \
		--disable-sjlj-exceptions \
		--with-dwarf2 \
		--with-arch-directory=lib64 \
		--enable-libstdcxx-time=yes \
		--enable-libstdcxx-debug \
		--enable-linker-build-id \
		--enable-nls \
		--enable-plugin \
		--enable-gnu-unique-object \
		--disable-vtable-verify \
		--enable-clocale=gnu \
		&& \
	make $(JOBS) all && \
	make $(JOBS) install-strip

lingcc-finish:
	for f in `find $(INST_BASE)/gcc -type f -executable -exec file -i '{}' \; | grep 'x-executable; charset=binary' | cut -d: -f1`; do \
			strip $$f ;\
	done;
	rm -Rf $(INST_BASE)/gcc/share
	find $(INST_BASE)/gcc -type f -name "*.py" | xargs rm -f

lingcc-gdb: 
	rm -Rf $(BUILD_DIR)/lingdb 
	mkdir -p $(BUILD_DIR)/lingdb
	cd $(BUILD_DIR)/lingdb && \
	export PATH=$(INST_BASE)/gcc/bin:$(PATH) && \
	CFLAGS="-g -O2" \
	LDLAGS="-static-libgcc -static-libstdc++" \
	CXXFLAGS="-g -O2 -fpermissive" \
	$(UNPACK_DIR)/gdb-$(VERSION_GDB)/configure \
		--prefix=$(INST_BASE)/gcc \
		--target=$(ARCH64) \
		--host=$(ARCH64) \
		--with-python=no \
		--build=$(ARCH64) && \
	make $(JOBS) && make $(JOBS) install

lingcc-pack:
	rm -Rf  $(INST_BASE)/gcc/share
ifneq ($(SIMPLE_ARCHIVE_NAMES),0)
	cd $(INST_BASE) && \
		tar -zcf $(PWD)/gcc-suite-gcc-x86-linux64.tgz ./gcc
else
	cd $(INST_BASE) && \
		tar -zcf $(PWD)/gcc-suite-$(VERSION_SUITE)-gcc-$(VERSION_GCC)-x86-linux64.tgz ./gcc
endif
		

##############################################################################
# Linux based MinGW multilib cross compiler
##############################################################################
xgcc-all:
	make clean
	make prepare
	#
	make build-common
	make xgcc-build-binutils
	make xgcc-mingw-pass1
	make xgcc-gcc-pass1
	make xgcc-mingw-pass2
	make xgcc-pthread
	make xgcc-gcc-pass2
	make xgcc-finish
	make xgcc-gdb
	make xgcc-zlib
	make xgcc-bzip2
	make xgcc-reimp
	make xgcc-genpeimg
	make xgcc-gendef
	make xgcc-pack

xgcc-build-binutils:
	mkdir -p $(BUILD_DIR)/binutils
	cd $(BUILD_DIR)/binutils ;\
	    	PATH=$(INST_BASE)/gcc/bin:$(PATH) \
		LDLAGS="-static-libgcc -static-libstdc++" \
		CFLAGS="-O2 -pipe" \
		CXXFLAGS="-O2 -pipe" \
		$(UNPACK_DIR)/binutils-$(VERSION_BINUTILS)/configure \
			--with-pkgversion=$(GCC_PKGVERSION) \
			--prefix=$(XGCC_INST_DIR) \
			--disable-nls \
			--enable-deterministic-archives \
			--with-gcc \
			--with-gnu-ld \
			--with-gnu-as \
			--disable-werror \
			--enable-targets=$(XGCC_TARGET64),$(XGCC_TARGET32) \
			--host=$(ARCH64) \
			--build=$(ARCH64) \
			--target=$(XGCC_TARGET64) ;\
		make $(JOBS) ;\
		make $(JOBS) install-strip
	cd $(XGCC_INST_DIR)/bin && ln -s x86_64-w64-mingw32-windres windres

xgcc-mingw-pass1: 
	mkdir -p $(BUILD_DIR)/mingw
	cd $(BUILD_DIR)/mingw ;\
	PATH=$(INST_BASE)/gcc/bin:$(PATH) \
	LDLAGS="-static-libgcc -static-libstdc++" \
	CFLAGS="-O2 -pipe" \
	CXXFLAGS="-O2 -pipe" \
	$(UNPACK_DIR)/mingw-w64-v$(VERSION_MINGW)/mingw-w64-headers/configure \
		--prefix=$(XGCC_INST_DIR)/$(XGCC_TARGET64) \
		--host=$(XGCC_TARGET64) ;\
	make $(JOBS) install
	cd $(XGCC_INST_DIR) && rm -f mingw && ln -s $(XGCC_TARGET64) mingw
	cd $(XGCC_INST_DIR)/$(XGCC_TARGET64) && mkdir -p lib32
	cd $(XGCC_INST_DIR)/$(XGCC_TARGET64) && rm -f lib64 && ln -s lib lib64

xgcc-pthread: xgcc-pthread-32 xgcc-pthread-64

xgcc-pthread-64:
	mkdir -p $(BUILD_DIR)/winpthreads-64
	cd $(BUILD_DIR)/winpthreads-64 && \
	export PATH=$(XGCC_INST_DIR)/bin:$(PATH) && \
	LDLAGS="-static-libgcc -static-libstdc++" \
	CFLAGS="-O2 -pipe" \
	CXXFLAGS="-O2 -pipe" \
	$(UNPACK_DIR)/mingw-w64-v$(VERSION_MINGW)/mingw-w64-libraries/winpthreads/configure \
		--prefix=$(XGCC_INST_DIR)/$(XGCC_TARGET64) \
		--host=$(XGCC_TARGET64) && \
	make $(JOBS) clean && \
	make $(JOBS) && \
	make $(JOBS) install 
	mv -f $(XGCC_INST_DIR)/$(XGCC_TARGET64)/bin/libwinpthread-1.dll \
		$(XGCC_INST_DIR)/$(XGCC_TARGET64)/lib

xgcc-pthread-32:
	rm -Rf $(BUILD_DIR)/winpthreads-32
	mkdir -p $(BUILD_DIR)/winpthreads-32
	cd $(BUILD_DIR)/winpthreads-32 && \
	export PATH=$(XGCC_INST_DIR)/bin:$(PATH) && \
	LDLAGS="-m32 -static-libgcc -static-libstdc++" \
	CFLAGS="-m32 -O2 -pipe" \
	CXXFLAGS="-m32 -O2 -pipe" \
	CC='x86_64-w64-mingw32-gcc -m32' \
        CCAS='x86_64-w64-mingw32-gcc -m32' \
        DLLTOOL='x86_64-w64-mingw32-dlltool -m i386' \
        RC='x86_64-w64-mingw32-windres -F pe-i386' \
	$(UNPACK_DIR)/mingw-w64-v$(VERSION_MINGW)/mingw-w64-libraries/winpthreads/configure \
		--prefix=$(XGCC_INST_DIR)/$(XGCC_TARGET64) \
		--libdir=$(XGCC_INST_DIR)/$(XGCC_TARGET64)/lib32 \
		--host=$(XGCC_TARGET64) && \
	make $(JOBS) clean && \
	make $(JOBS) && \
	make $(JOBS) install
	mv -f $(XGCC_INST_DIR)/$(XGCC_TARGET64)/bin/libwinpthread-1.dll \
		$(XGCC_INST_DIR)/$(XGCC_TARGET64)/lib32


xgcc-gcc-pass1: 
	mkdir -p $(BUILD_DIR)/gcc
	cd $(BUILD_DIR)/gcc && \
	PATH=$(INST_BASE)/gcc/bin:$(PATH) \
	LDLAGS="-static-libgcc -static-libstdc++" \
	CFLAGS="-O2 -pipe" \
	CXXFLAGS="-O2 -pipe" \
	$(UNPACK_DIR)/gcc-$(VERSION_GCC)/configure \
		--with-pkgversion=$(GCC_PKGVERSION) \
		--prefix=$(XGCC_INST_DIR) \
		--with-sysroot=$(XGCC_INST_DIR) \
		--disable-nls \
		--host=$(ARCH64) \
		--build=$(ARCH64) \
		--target=$(XGCC_TARGET64) \
		--enable-languages=$(LANGUAGES) \
		--disable-win32-registry \
		--with-gcc \
		--with-gnu-ld \
		--with-gnu-as \
		--without-x \
		--enable-shared \
		--enable-static \
		--disable-werror \
		--with-tune-64=core2 \
		--enable-threads=posix \
		--disable-sjlj-exceptions \
		--with-dwarf2 \
		--enable-multilib \
		--enable-64bit \
		--enable-clocale=gnu \
		--enable-version-specific-runtime-libs \
		--enable-fully-dynamic-string && \
	make $(JOBS) all-gcc && \
	make $(JOBS) install-gcc

xgcc-mingw-pass2: 
	cd $(BUILD_DIR)/mingw && \
	LDLAGS="-static-libgcc -static-libstdc++" \
	CFLAGS="-O2 -pipe" \
	CXXFLAGS="-O2 -pipe" \
	export PATH=$(XGCC_INST_DIR)/bin:$(PATH); \
	$(UNPACK_DIR)/mingw-w64-v$(VERSION_MINGW)/configure \
		--prefix=$(XGCC_INST_DIR)/$(XGCC_TARGET64) \
		--host=$(XGCC_TARGET64) \
		--disable-nls \
		--enable-sdk=all \
		--enable-idl \
		--enable-secure-api \
		--enable-lib64 \
		--enable-lib32 && \
	make $(JOBS) && \
	make $(JOBS) install

xgcc-gcc-pass2: 
	export PATH=$(XGCC_INST_DIR)/bin:$(PATH) && \
	cd $(BUILD_DIR)/gcc && \
	    make $(JOBS) && \
	    make $(JOBS) install


xgcc-finish:
	cd $(XGCC_INST_DIR) && rm -f mingw 
	for f in `find $(XGCC_INST_DIR) -type f -executable -exec file -i '{}' \; | grep 'x-executable; charset=binary' | cut -d: -f1`; do \
			$(XGCC_INST_DIR)/bin/$(XGCC_TARGET64)-strip $$f ;\
	done;
	rm -Rf $(XGCC_INST_DIR)/share
	find $(XGCC_INST_DIR) -type f -name "*.py" | xargs rm -f
	cp -f $(SOURCE_DIR)/mingw.gcc.specs \
		$(XGCC_INST_DIR)/lib/gcc/$(XGCC_TARGET64)/$(VERSION_GCC)/specs
	cp -f $(SOURCE_DIR)/dll2a \
		$(XGCC_INST_DIR)/bin/$(XGCC_TARGET64)-dll2a
	chmod a+x $(XGCC_INST_DIR)/bin/$(XGCC_TARGET64)-dll2a
	sed -i -e 's/__LIB32__/lib\/gcc\/$(XGCC_TARGET64)\/lib32/g' \
		$(XGCC_INST_DIR)/lib/gcc/$(XGCC_TARGET64)/$(VERSION_GCC)/specs
	sed -i -e 's/__LIB64__/lib\/gcc\/$(XGCC_TARGET64)\/lib/g' \
		$(XGCC_INST_DIR)/lib/gcc/$(XGCC_TARGET64)/$(VERSION_GCC)/specs
	cat $(XGCC_INST_DIR)/lib/gcc/$(XGCC_TARGET64)/$(VERSION_GCC)/specs \
		$(SOURCE_DIR)/gcc.msvcr90.spec > \
		$(XGCC_INST_DIR)/lib/gcc/$(XGCC_TARGET64)/$(VERSION_GCC)/msvcr90
	cat $(XGCC_INST_DIR)/lib/gcc/$(XGCC_TARGET64)/$(VERSION_GCC)/specs \
		$(SOURCE_DIR)/gcc.msvcr100.spec > \
		$(XGCC_INST_DIR)/lib/gcc/$(XGCC_TARGET64)/$(VERSION_GCC)/msvcr100
	cat $(XGCC_INST_DIR)/lib/gcc/$(XGCC_TARGET64)/$(VERSION_GCC)/specs \
		$(SOURCE_DIR)/gcc.msvcr110.spec > \
		$(XGCC_INST_DIR)/lib/gcc/$(XGCC_TARGET64)/$(VERSION_GCC)/msvcr110
	cd $(XGCC_INST_DIR)/x86_64-w64-mingw32/include && \
		ln -s windows.h Windows.h

xgcc-gdb: 
	rm -rf $(BUILD_DIR)/gdb && mkdir -p $(BUILD_DIR)/gdb
	cd $(BUILD_DIR)/gdb && \
	export PATH=$(XGCC_BINPATH):$(INST_BASE)/gcc/bin:$(PATH) && \
	LDLAGS="-static-libgcc -static-libstdc++" \
	CFLAGS="-O2 -pipe" \
	CXXFLAGS="-O2 -pipe -fpermissive" \
	$(UNPACK_DIR)/gdb-$(VERSION_GDB)/configure \
		--prefix=$(XGCC_INST_DIR) \
		--target=$(XGCC_TARGET64) \
		--with-python=no \
		--build=$(ARCH64) \
		--host=$(ARCH64) && \
	make $(JOBS) && make $(JOBS) install
		
xgcc-reimp:
	rm -Rf $(BUILD_DIR)/reimp
	cd $(BUILD_DIR)/ && \
	tar -zxf $(SOURCE_DIR)/reimp.tar.gz
	cd $(BUILD_DIR)/reimp/src && \
		make X=""
	cp -f $(BUILD_DIR)/reimp/src/reimp $(XGCC_INST_DIR)/bin/$(XGCC_TARGET64)-reimp

xgcc-genpeimg:
	rm -Rf $(BUILD_DIR)/genpeimg
	mkdir -p $(BUILD_DIR)/genpeimg
	cd $(BUILD_DIR)/ && \
	export PATH=$(GCC_BINPATH):$(PATH) && \
	cd $(BUILD_DIR)/genpeimg && \
	CC=$(GCC) CXX=$(GXX) \
	    LDLAGS="-static-libgcc" \
	    CFLAGS="-pipe -Werror=implicit-fallthrough=0" \
		$(UNPACK_DIR)/mingw-w64-v$(VERSION_MINGW)/mingw-w64-tools/genpeimg/configure \
		--prefix=$(XGCC_INST_DIR) \
		--target=$(XGCC_TARGET64) \
		--build=$(ARCH64) \
		--host=$(ARCH64) && \
	make && \
	make install
	cp -f $(BUILD_DIR)/genpeimg/genpeimg $(XGCC_INST_DIR)/bin/$(XGCC_TARGET64)-genpeimg

xgcc-gendef:
	rm -Rf $(BUILD_DIR)/gendef
	mkdir -p $(BUILD_DIR)/gendef
	export PATH=$(GCC_BINPATH):$(PATH) && \
	CC=$(GCC) CXX=$(GXX) \
	cd $(BUILD_DIR)/gendef && \
	    CFLAGS="-pipe -Werror=implicit-fallthrough=0" \
	    LDLAGS="-static-libgcc" \
		$(UNPACK_DIR)/mingw-w64-v$(VERSION_MINGW)/mingw-w64-tools/gendef/configure \
		--prefix=$(XGCC_INST_DIR) \
		--target=$(XGCC_TARGET64) \
		--build=$(ARCH64) \
		--host=$(ARCH64) && \
	make && \
	make install
	cp -f $(BUILD_DIR)/gendef/gendef $(XGCC_INST_DIR)/bin/$(XGCC_TARGET64)-gendef

xgcc-zlib:
	mkdir -p $(BUILD_DIR)
	cd $(BUILD_DIR) && rm -Rf zlib-$(VERSION_ZLIB)
	cd $(BUILD_DIR) && tar -zxf $(SOURCE_DIR)/zlib-$(VERSION_ZLIB).tar.gz
	cd $(BUILD_DIR)/zlib-$(VERSION_ZLIB) && patch -p1 < $(PATCHES_DIR)/zlib_ranlib.patch
	cd $(BUILD_DIR)/zlib-$(VERSION_ZLIB) && \
	export PATH=$(XGCC_INST_DIR)/bin:$(PATH) && \
	CC=$(XGCC64) \
	AR=$(XGCC_BINPATH)/$(XGCC_PREFIX)ar \
	RANLIB=$(XGCC_BINPATH)/$(XGCC_PREFIX)ranlib \
	./configure \
		--prefix=$(XGCC_INST_DIR)/$(XGCC_TARGET64) --static && \
	make clean && make 
	cd $(BUILD_DIR)/zlib-$(VERSION_ZLIB) && \
	cp -f libz.a $(XGCC_INST_DIR)/$(XGCC_TARGET64)/lib && \
	cp -f zlib.h zconf.h $(XGCC_INST_DIR)/$(XGCC_TARGET64)/include
	chmod 644  $(XGCC_INST_DIR)/$(XGCC_TARGET64)/lib/libz.a
	chmod 644 $(XGCC_INST_DIR)/$(XGCC_TARGET64)/include/zlib.h 
	chmod 644 $(XGCC_INST_DIR)/$(XGCC_TARGET64)/include/zconf.h
	#
	cd $(BUILD_DIR)/zlib-$(VERSION_ZLIB) && \
	export PATH=$(XGCC_INST_DIR)/bin:$(PATH) && \
	CC=$(XGCC32) \
	AR=$(XGCC_BINPATH)/$(XGCC_PREFIX)ar \
	RANLIB=$(XGCC_BINPATH)/$(XGCC_PREFIX)ranlib \
	./configure \
		--prefix=$(XGCC_INST_DIR)/$(XGCC_TARGET64) --static && \
	make clean && make 
	cd $(BUILD_DIR)/zlib-$(VERSION_ZLIB) && \
	cp -f libz.a $(XGCC_INST_DIR)/$(XGCC_TARGET64)/lib32 && \
	chmod 644  $(XGCC_INST_DIR)/$(XGCC_TARGET64)/lib32/libz.a

xgcc-bzip2:
	mkdir -p $(BUILD_DIR)
	cd $(UNPACK_DIR)/bzip2-$(VERSION_BZ2) && \
	export PATH=$(XGCC_BINPATH):$(PATH) && \
	make \
		CC=$(XGCC64) \
		PREFIX=$(XGCC_INST_DIR)/$(XGCC_TARGET64) clean libbz2.a
	cd $(UNPACK_DIR)/bzip2-$(VERSION_BZ2) && \
		cp -f bzlib.h $(XGCC_INST_DIR)/$(XGCC_TARGET64)/include && \
		cp -f libbz2.a $(XGCC_INST_DIR)/$(XGCC_TARGET64)/lib
	chmod 644 $(XGCC_INST_DIR)/$(XGCC_TARGET64)/include/bzlib.h
	chmod 644 $(XGCC_INST_DIR)/$(XGCC_TARGET64)/lib/libbz2.a
	#	
	cd $(UNPACK_DIR)/bzip2-$(VERSION_BZ2) && \
	export PATH=$(XGCC_BINPATH)/bin:$(PATH) && \
	make \
		CC=$(XGCC32) \
		PREFIX=$(XGCC_INST_DIR)/$(XGCC_TARGET64) clean libbz2.a
	cd $(UNPACK_DIR)/bzip2-$(VERSION_BZ2) && \
		cp -f libbz2.a $(XGCC_INST_DIR)/$(XGCC_TARGET64)/lib32
	chmod 644 $(XGCC_INST_DIR)/$(XGCC_TARGET64)/lib/libbz2.a

xgcc-pack:
	rm -Rf $(XGCC_INST_DIR)/share
ifneq ($(SIMPLE_ARCHIVE_NAMES),0)
	cd $(INST_BASE_LINUX) && \
		tar -zcf $(PWD)/gcc-suite-xgcc-x86-linux64.tgz ./mingw64
else
	cd $(INST_BASE_LINUX) && \
		tar -zcf $(PWD)/gcc-suite-$(VERSION_SUITE)-xgcc-$(VERSION_GCC)-$(VERSION_MINGW)-x86-linux64.tgz ./mingw64
endif

##############################################################################
# Nativ Multilib Windows Compiler (64 -Bit)
##############################################################################
wingcc-all:
	make ARCH=x86-mingw64 clean
	make ARCH=x86-mingw64 prepare
	#
	make ARCH=x86-mingw64 wingcc-binutils
	make ARCH=x86-mingw64 wingcc-mingw
	make ARCH=x86-mingw64 wingcc-pthread
	make ARCH=x86-mingw64 wingcc-gcc
	make ARCH=x86-mingw64 wingcc-finish
	make ARCH=x86-mingw64 wingcc-zlib
	make ARCH=x86-mingw64 wingcc-bzip2
	make ARCH=x86-mingw64 wingcc-mingw-tools
	make ARCH=x86-mingw64 wingcc-reimp
	make ARCH=x86-mingw64 wingcc-gmake
	make ARCH=x86-mingw64 wingcc-gdb
	make ARCH=x86-mingw64 wingcc-pack

wingcc-binutils:
	mkdir -p $(BUILD_DIR)/binutils
	cd $(BUILD_DIR)/binutils ;\
	    export PATH=$(XGCC_BINPATH):$(PATH) && \
		CC=$(XGCC64) CXX=$(XGPP64) \
		LDLAGS="-static-libgcc -static-libstdc++" \
		$(UNPACK_DIR)/binutils-$(VERSION_BINUTILS)/configure \
			--with-pkgversion=$(GCC_PKGVERSION) \
			--prefix=$(WINGCC_INST_DIR) \
			--disable-nls \
			--enable-deterministic-archives \
			--with-gcc \
			--with-gnu-ld \
			--with-gnu-as \
			--enable-static \
			--disable-werror \
			--disable-rpath \
			--enable-targets=$(XGCC_TARGET64),$(XGCC_TARGET32) \
			--host=$(XGCC_TARGET64) \
			--target=$(XGCC_TARGET64) &&\
		make $(JOBS) && make $(JOBS) install

wingcc-mingw:
	rm -Rf $(BUILD_DIR)/mingw && mkdir -p $(BUILD_DIR)/mingw
	cd $(BUILD_DIR)/mingw && \
	export PATH=$(XGCC_BINPATH):$(PATH) && \
	CC=$(XGCC64) CXX=$(XGPP64) \
	LDLAGS="-static-libgcc -static-libstdc++" \
	$(UNPACK_DIR)/mingw-w64-v$(VERSION_MINGW)/configure \
		--prefix=$(WINGCC_INST_DIR)/$(XGCC_TARGET64) \
		--host=$(XGCC_TARGET64) \
		--disable-nls \
		--enable-sdk=all \
		--enable-idl \
		--enable-secure-api \
		--enable-lib64 \
		--enable-lib32 && \
	make $(JOBS) && \
	make $(JOBS) install
	cd $(WINGCC_INST_DIR) && rm -f mingw && ln -s $(XGCC_TARGET64) mingw

wingcc-pthread: wingcc-pthread-32 wingcc-pthread-64 

wingcc-pthread-32:
	rm -Rf $(BUILD_DIR)/winpthreads-32 && mkdir -p $(BUILD_DIR)/winpthreads-32
	cd $(BUILD_DIR)/winpthreads-32 && \
	export PATH=$(XGCC_BINPATH):$(PATH) && \
	LDLAGS="-m32 -static-libgcc -static-libstdc++" \
	CFLAGS="-m32 -O2 -pipe" \
	CXXFLAGS="-m32 -O2 -pipe" \
	CC='x86_64-w64-mingw32-gcc -m32' \
        CCAS='x86_64-w64-mingw32-gcc -m32' \
        DLLTOOL='x86_64-w64-mingw32-dlltool -m i386' \
        RC='x86_64-w64-mingw32-windres -F pe-i386' \
	$(UNPACK_DIR)/mingw-w64-v$(VERSION_MINGW)/mingw-w64-libraries/winpthreads/configure \
		--prefix=$(WINGCC_INST_DIR)/$(XGCC_TARGET64) \
		--host=$(XGCC_TARGET64) && \
	make $(JOBS) && \
	make $(JOBS) install
	cp -f $(WINGCC_INST_DIR)/$(XGCC_TARGET64)/bin/libwinpthread-1.dll \
		$(WINGCC_INST_DIR)/$(XGCC_TARGET64)/lib32

wingcc-pthread-64:
	rm -Rf $(BUILD_DIR)/winpthreads-64 && mkdir -p $(BUILD_DIR)/winpthreads-64
	cd $(BUILD_DIR)/winpthreads-64 && \
	export PATH=$(XGCC_BINPATH):$(PATH) && \
	LDLAGS="-static-libgcc -static-libstdc++" \
	CC=$(XGCC64) CXX=$(XGPP64) \
	$(UNPACK_DIR)/mingw-w64-v$(VERSION_MINGW)/mingw-w64-libraries/winpthreads/configure \
		--prefix=$(WINGCC_INST_DIR)/$(XGCC_TARGET64) \
		--host=$(XGCC_TARGET64) && \
	make $(JOBS) && \
	make $(JOBS) install
	cp -f $(WINGCC_INST_DIR)/$(XGCC_TARGET64)/bin/libwinpthread-1.dll \
		$(WINGCC_INST_DIR)/$(XGCC_TARGET64)/lib

wingcc-gcc:
	rm -Rf $(BUILD_DIR)/gcc && mkdir -p $(BUILD_DIR)/gcc
	cd $(BUILD_DIR)/gcc && \
	export PATH=$(XGCC_BINPATH):$(PATH) && \
	CC=$(XGCC64) CXX=$(XGPP64) \
	LDLAGS="-static-libgcc -static-libstdc++" \
	$(UNPACK_DIR)/gcc-$(VERSION_GCC)/configure \
		--with-pkgversion=$(GCC_PKGVERSION) \
		--prefix=$(WINGCC_INST_DIR) \
		--with-sysroot=$(WINGCC_INST_DIR) \
		--disable-nls \
		--host=$(XGCC_TARGET64) \
		--target=$(XGCC_TARGET64) \
		--build=$(ARCH64) \
		--enable-languages=$(LANGUAGES) \
		--disable-win32-registry \
		--with-gcc \
		--with-gnu-ld \
		--with-gnu-as \
		--without-x \
		--enable-shared \
		--with-tune-64=core2 \
		--disable-werror \
		--disable-symvers \
		--enable-threads=posix \
		--disable-sjlj-exceptions \
		--with-dwarf2 \
		--enable-multilib \
		--enable-64bit \
		--enable-clocale=gnu \
		--enable-version-specific-runtime-libs \
		--enable-fully-dynamic-string && \
	make CFLAGS="-O2 -Wshadow -Wexpansion-to-defined" $(JOBS) all && \
	make $(JOBS) install-strip

wingcc-finish:
	cd $(WINGCC_INST_DIR)/bin && \
	    mkdir -p ../tmp; \
	    mv $(XGCC_TARGET64)-*.exe ../tmp ; \
	    for f in *.exe; do \
		    cp -f $$f $(XGCC_TARGET64)-`basename $$f` > /dev/null 2>&1 ;\
	    done; \
	    mv ../tmp/* . ;\
	    rm -Rf ../tmp ;
	find $(WINGCC_INST_DIR) -type f -name "*.py" | xargs rm -f
	cd $(WINGCC_INST_DIR) && rm -Rf share 
	cd $(WINGCC_INST_DIR) && rm -f mingw 
	cd $(WINGCC_INST_DIR) ;\
		find . -type f -name "*.exe" | xargs $(XGCC_BINPATH)/$(XGCC_PREFIX)strip; true
	#
	cp -f $(SOURCE_DIR)/mingw.gcc.specs \
		$(WINGCC_INST_DIR)/lib/gcc/$(XGCC_TARGET64)/$(VERSION_GCC)/specs
	sed -i -e 's/__LIB32__/lib\/gcc\/$(XGCC_TARGET64)\/lib32/g' \
		$(WINGCC_INST_DIR)/lib/gcc/$(XGCC_TARGET64)/$(VERSION_GCC)/specs
	sed -i -e 's/__LIB64__/lib\/gcc\/$(XGCC_TARGET64)\/lib/g' \
		$(WINGCC_INST_DIR)/lib/gcc/$(XGCC_TARGET64)/$(VERSION_GCC)/specs
	cat $(WINGCC_INST_DIR)/lib/gcc/$(XGCC_TARGET64)/$(VERSION_GCC)/specs \
		$(SOURCE_DIR)/gcc.msvcr90.spec > \
		$(WINGCC_INST_DIR)/lib/gcc/$(XGCC_TARGET64)/$(VERSION_GCC)/msvcr90
	cat $(WINGCC_INST_DIR)/lib/gcc/$(XGCC_TARGET64)/$(VERSION_GCC)/specs \
		$(SOURCE_DIR)/gcc.msvcr100.spec > \
		$(WINGCC_INST_DIR)/lib/gcc/$(XGCC_TARGET64)/$(VERSION_GCC)/msvcr100
	cat $(WINGCC_INST_DIR)/lib/gcc/$(XGCC_TARGET64)/$(VERSION_GCC)/specs \
		$(SOURCE_DIR)/gcc.msvcr110.spec > \
		$(WINGCC_INST_DIR)/lib/gcc/$(XGCC_TARGET64)/$(VERSION_GCC)/msvcr110
	cd $(WINGCC_INST_DIR)/lib/gcc/$(XGCC_TARGET64)/$(VERSION_GCC) && \
	    cp -f ../../x86_64-w64-mingw32/lib/libgcc_s.a .
	cd $(WINGCC_INST_DIR)/lib/gcc/$(XGCC_TARGET64)/$(VERSION_GCC)/32 && \
	    cp -f ../../../x86_64-w64-mingw32/lib32/libgcc_s.a .
		
wingcc-reimp:
	rm -Rf $(BUILD_DIR)/reimp
	cd $(BUILD_DIR)/ && \
	tar -zxf $(SOURCE_DIR)/reimp.tar.gz
	export PATH=$(XGCC_BINPATH):$(PATH) && \
	cd $(BUILD_DIR)/reimp/src && \
		make CC=$(XGCC_TARGET64)-gcc
	cp -f $(BUILD_DIR)/reimp/src/reimp.exe $(WINGCC_INST_DIR)/bin/reimp.exe
	cp -f $(BUILD_DIR)/reimp/src/reimp.exe $(WINGCC_INST_DIR)/bin/$(XGCC_TARGET64)-reimp.exe

wingcc-gmake:
	rm -Rf $(BUILD_DIR)/make-4.2
	cd $(BUILD_DIR)/ && \
	tar -jxf $(SOURCE_DIR)/make-4.2.tar.bz2
	cd $(BUILD_DIR)/make-4.2 && \
	export PATH=$(XGCC_BINPATH):$(PATH) && \
	LDLAGS="-static-libgcc -static-libstdc++" \
	CC=$(XGCC64) CXX=$(XGPP64) \
		./configure \
			CFLAGS="-I../glob" \
			--host=$(XGCC_TARGET64) \
			--prefix=$(WINGCC_INST_DIR) \
			--host=$(XGCC_TARGET64) && \
	make && make install
	cp -f $(WINGCC_INST_DIR)/bin/make.exe $(WINGCC_INST_DIR)/bin/$(XGCC_TARGET64)-make.exe

wingcc-mingw-tools: wingcc-genpeimg wingcc-gendef wingcc-genidl wingcc-genlib wingcc-widl

wingcc-genpeimg:
	rm -Rf $(BUILD_DIR)/genpeimg
	mkdir -p  $(BUILD_DIR)/genpeimg
	cd $(BUILD_DIR)/genpeimg && \
	export PATH=$(XGCC_BINPATH):$(PATH) && \
	CC=$(XGCC64) CXX=$(XGPP64) genpeimg_CFLAGS="" CFLAGS="-O3 -g -Werror=implicit-fallthrough=0"\
		$(UNPACK_DIR)/mingw-w64-v$(VERSION_MINGW)/mingw-w64-tools/genpeimg/configure \
			--host=$(XGCC_TARGET64) && \
	make
	cp -f $(BUILD_DIR)/genpeimg/genpeimg.exe \
		$(WINGCC_INST_DIR)/bin/$(XGCC_TARGET64)-genpeimg.exe

wingcc-gendef:
	rm -Rf $(BUILD_DIR)/gendef
	mkdir -p $(BUILD_DIR)/gendef && \
	cd $(BUILD_DIR)/gendef && \
	export PATH=$(XGCC_BINPATH):$(PATH) && \
	CC=$(XGCC64) CXX=$(XGPP64) genpeimg_CFLAGS="" CFLAGS="-O3 -g -Wno-error=cast-function-type -Werror=implicit-fallthrough=0"\
		$(UNPACK_DIR)/mingw-w64-v$(VERSION_MINGW)/mingw-w64-tools/gendef/configure \
			--host=$(XGCC_TARGET64) && \
	make
	cp -f $(BUILD_DIR)/gendef/gendef.exe $(WINGCC_INST_DIR)/bin/$(XGCC_TARGET64)-gendef.exe

wingcc-genidl:
	rm -Rf $(BUILD_DIR)/genidl
	mkdir -p $(BUILD_DIR)/genidl
	cd $(BUILD_DIR)/genidl && \
	export PATH=$(XGCC_BINPATH):$(PATH) && \
	CC=$(XGCC64) CXX=$(XGPP64) CFLAGS="-O3 -g -Wno-error=cast-function-type -Werror=implicit-fallthrough=0"\
		$(UNPACK_DIR)/mingw-w64-v$(VERSION_MINGW)/mingw-w64-tools/genidl/configure \
			--prefix=$(WINGCC_INST_DIR) \
			--host=$(XGCC_TARGET64) && \
	make && \
	make install 

wingcc-genlib:
	rm -Rf $(BUILD_DIR)/genlib
	mkdir -p $(BUILD_DIR)/genlib
	cd $(BUILD_DIR)/genlib && \
	export PATH=$(XGCC_BINPATH):$(PATH) && \
	CC=$(XGCC64) CXX=$(XGPP64) CFLAGS="-O3 -g -Wno-error=cast-function-type -Werror=implicit-fallthrough=0"\
		$(UNPACK_DIR)/mingw-w64-v$(VERSION_MINGW)/mingw-w64-tools/genlib/configure \
			--prefix=$(WINGCC_INST_DIR) \
			--host=$(XGCC_TARGET64) && \
	make && \
	make install 

wingcc-widl:
	cd $(UNPACK_DIR)/mingw-w64-v$(VERSION_MINGW)/mingw-w64-tools/widl && \
	    autoconf
	rm -Rf $(BUILD_DIR)/widl
	mkdir -p $(BUILD_DIR)/widl
	cd $(BUILD_DIR)/widl && \
	export PATH=$(XGCC_BINPATH):$(PATH) && \
	ac_cv_func_malloc_0_nonnull=yes CC=$(XGCC64) CXX=$(XGPP64) CFLAGS="-O3 -g -Wno-error=cast-function-type -Werror=implicit-fallthrough=0"\
		$(UNPACK_DIR)/mingw-w64-v$(VERSION_MINGW)/mingw-w64-tools/widl/configure \
			--prefix=$(WINGCC_INST_DIR) \
			--host=$(XGCC_TARGET64) && \
	make && \
	make install 

wingcc-zlib:
	mkdir -p $(BUILD_DIR)
	cd $(BUILD_DIR) && rm -Rf zlib-$(VERSION_ZLIB)
	cd $(BUILD_DIR) && tar -zxf $(SOURCE_DIR)/zlib-$(VERSION_ZLIB).tar.gz
	cd $(BUILD_DIR)/zlib-$(VERSION_ZLIB) && patch -p1 < $(PATCHES_DIR)/zlib_ranlib.patch
	cd $(BUILD_DIR)/zlib-$(VERSION_ZLIB) && \
	export PATH=$(XGCC_BINPATH):$(PATH) && \
	CC=$(XGCC64) \
	AR=$(XGCC_BINPATH)/$(XGCC_PREFIX)ar \
	RANLIB=$(XGCC_BINPATH)/$(XGCC_PREFIX)ranlib \
	./configure \
		--prefix=$(WINGCC_INST_DIR)/$(XGCC_TARGET64) --static && \
	make clean && make 
	#
	cd $(BUILD_DIR)/zlib-$(VERSION_ZLIB) && \
	    cp -f libz.a $(WINGCC_INST_DIR)/$(XGCC_TARGET64)/lib && \
	    cp -f zlib.h zconf.h $(WINGCC_INST_DIR)/$(XGCC_TARGET64)/include
	#
	chmod 644 $(WINGCC_INST_DIR)/$(XGCC_TARGET64)/lib/libz.a
	chmod 644 $(WINGCC_INST_DIR)/$(XGCC_TARGET64)/include/zlib.h 
	chmod 644 $(WINGCC_INST_DIR)/$(XGCC_TARGET64)/include/zconf.h
	#
	cd $(BUILD_DIR)/zlib-$(VERSION_ZLIB) && \
	export PATH=$(XGCC_BINPATH):$(PATH) && \
	CC=$(XGCC32) \
	AR=$(XGCC_BINPATH)/$(XGCC_PREFIX)ar \
	RANLIB=$(XGCC_BINPATH)/$(XGCC_PREFIX)ranlib \
	./configure \
		--prefix=$(WINGCC_INST_DIR)/$(XGCC_TARGET64) --static && \
	make clean && make 
	cd $(BUILD_DIR)/zlib-$(VERSION_ZLIB) && \
	cp -f libz.a $(WINGCC_INST_DIR)/$(XGCC_TARGET64)/lib32 && \
	chmod 644  $(WINGCC_INST_DIR)/$(XGCC_TARGET64)/lib32/libz.a

wingcc-bzip2:
	cd $(UNPACK_DIR)/bzip2-$(VERSION_BZ2) && \
	export PATH=$(XGCC_BINPATH):$(PATH) && \
	make \
		CC=$(XGCC64) \
		PREFIX=$(WINGCC_INST_DIR)/$(XGCC_TARGET64) libbz2.a
	cd $(UNPACK_DIR)/bzip2-$(VERSION_BZ2) && \
		cp -f bzlib.h $(WINGCC_INST_DIR)/$(XGCC_TARGET64)/include && \
		cp -f libbz2.a $(WINGCC_INST_DIR)/$(XGCC_TARGET64)/lib
	chmod 644 $(WINGCC_INST_DIR)/$(XGCC_TARGET64)/include/bzlib.h
	chmod 644 $(WINGCC_INST_DIR)/$(XGCC_TARGET64)/lib/libbz2.a
	#	
	cd $(UNPACK_DIR)/bzip2-$(VERSION_BZ2) && \
	export PATH=$(XGCC_BINPATH)/bin:$(PATH) && \
	make \
		CC=$(XGCC32) \
		PREFIX=$(WINGCC_INST_DIR)/$(XGCC_TARGET64) libbz2.a
	cd $(UNPACK_DIR)/bzip2-$(VERSION_BZ2) && \
		cp -f libbz2.a $(WINGCC_INST_DIR)/$(XGCC_TARGET64)/lib32
	chmod 644 $(WINGCC_INST_DIR)/$(XGCC_TARGET64)/lib/libbz2.a

wingcc-gdb: 
	rm -Rf $(BUILD_DIR)/gdb && mkdir -p $(BUILD_DIR)/gdb
	cd $(BUILD_DIR)/gdb && \
	export PATH=$(XGCC_BINPATH):$(PATH) && \
	CC=$(XGCC64) CXX=$(XGPP64) \
	CXXFLAGS="-g -O2 -fpermissive" \
	CFLAGS="-g -O2" \
	$(UNPACK_DIR)/gdb-$(VERSION_GDB)/configure \
		--prefix=$(WINGCC_INST_DIR) \
		--target=$(XGCC_TARGET64) \
		--with-python=no \
		--host=$(XGCC_TARGET64) \
		--build=$(ARCH64) && \
	make $(JOBS) && make $(JOBS) install
	cp -f $(WINGCC_INST_DIR)/bin/gdb.exe \
		$(WINGCC_INST_DIR)/bin/$(XGCC_TARGET64)-gdb.exe
	cp -f $(WINGCC_INST_DIR)/bin/gdbserver.exe \
		$(WINGCC_INST_DIR)/bin/$(XGCC_TARGET64)-gdbserver.exe
wingcc-pack:
	rm -Rf $(WINGCC_INST_DIR)/share
ifneq ($(SIMPLE_ARCHIVE_NAMES),0)
	cd $(INST_BASE) && \
		zip -qr $(PWD)/gcc-suite-gcc-x86-mingw64.zip ./$(WINGCC_ROOTNAME)
else
	cd $(INST_BASE) && \
		zip -qr $(PWD)/gcc-suite-$(VERSION_SUITE)-gcc-$(VERSION_GCC)-$(VERSION_MINGW)-x86-mingw64.zip ./$(WINGCC_ROOTNAME)
endif
# ----------------------------------------------------------------------------
#
distribute: \
    $(PWD)/gcc-suite-$(VERSION_SUITE)-gcc-$(VERSION_GCC)-$(VERSION_MINGW)-x86-mingw64.zip \
    $(PWD)/gcc-suite-$(VERSION_SUITE)-xgcc-$(VERSION_GCC)-$(VERSION_MINGW)-x86-linux64.tgz \
    $(PWD)/gcc-suite-$(VERSION_SUITE)-gcc-$(VERSION_GCC)-x86-linux64.tgz
	mkdir -p $(SUITEDIR)/$(VERSION_SUITE)/x86-linux64
	mkdir -p $(SUITEDIR)/$(VERSION_SUITE)/x86-mingw64
	tar -zxf $(PWD)/gcc-suite-$(VERSION_SUITE)-xgcc-$(VERSION_GCC)-$(VERSION_MINGW)-x86-linux64.tgz \
	    -C $(SUITEDIR)/$(VERSION_SUITE)/x86-linux64/
	tar -zxf $(PWD)/gcc-suite-$(VERSION_SUITE)-gcc-$(VERSION_GCC)-x86-linux64.tgz \
	    -C $(SUITEDIR)/$(VERSION_SUITE)/x86-linux64/
	unzip $(PWD)/gcc-suite-$(VERSION_SUITE)-gcc-$(VERSION_GCC)-$(VERSION_MINGW)-x86-mingw64.zip \
	    -d $(SUITEDIR)/$(VERSION_SUITE)/x86-mingw64/

clean:
	rm -Rf $(UNPACK_DIR)
	rm -Rf $(BUILD_DIR)

fullclean: clean
	rm -Rf inst.*
	rm -Rf build.*
	rm -Rf unpack.*