42 $(info TARGET=$(TARGET)) |
42 $(info TARGET=$(TARGET)) |
43 $(info HOST=$(HOST)) |
43 $(info HOST=$(HOST)) |
44 $(info BUILD=$(BUILD)) |
44 $(info BUILD=$(BUILD)) |
45 |
45 |
46 ARCH := $(word 1,$(subst -, ,$(TARGET))) |
46 ARCH := $(word 1,$(subst -, ,$(TARGET))) |
|
47 $(info ARCH=$(ARCH)) |
47 |
48 |
48 ########################################################################################## |
49 ########################################################################################## |
49 # Define external dependencies |
50 # Define external dependencies |
50 |
51 |
51 # Latest that could be made to work. |
52 # Latest that could be made to work. |
52 gcc_ver := gcc-4.9.2 |
53 GCC_VER := 7.3.0 |
53 binutils_ver := binutils-2.25 |
54 ifeq ($(GCC_VER), 7.3.0) |
54 ccache_ver := ccache-3.2.1 |
55 gcc_ver := gcc-7.3.0 |
55 mpfr_ver := mpfr-3.0.1 |
56 binutils_ver := binutils-2.30 |
56 gmp_ver := gmp-4.3.2 |
57 ccache_ver := ccache-3.3.6 |
57 mpc_ver := mpc-1.0.1 |
58 mpfr_ver := mpfr-3.1.5 |
58 |
59 gmp_ver := gmp-6.1.2 |
59 GCC := http://ftp.gnu.org/pub/gnu/gcc/$(gcc_ver)/$(gcc_ver).tar.bz2 |
60 mpc_ver := mpc-1.0.3 |
60 BINUTILS := http://ftp.gnu.org/pub/gnu/binutils/$(binutils_ver).tar.bz2 |
61 gdb_ver := gdb-8.1 |
61 CCACHE := http://samba.org/ftp/ccache/$(ccache_ver).tar.gz |
62 else ifeq ($(GCC_VER), 4.9.2) |
|
63 gcc_ver := gcc-4.9.2 |
|
64 binutils_ver := binutils-2.25 |
|
65 ccache_ver := ccache-3.2.1 |
|
66 mpfr_ver := mpfr-3.0.1 |
|
67 gmp_ver := gmp-4.3.2 |
|
68 mpc_ver := mpc-1.0.1 |
|
69 gdb_ver := gdb-7.12.1 |
|
70 else |
|
71 $(error Unsupported GCC version) |
|
72 endif |
|
73 |
|
74 GCC := http://ftp.gnu.org/pub/gnu/gcc/$(gcc_ver)/$(gcc_ver).tar.xz |
|
75 BINUTILS := http://ftp.gnu.org/pub/gnu/binutils/$(binutils_ver).tar.xz |
|
76 CCACHE := https://samba.org/ftp/ccache/$(ccache_ver).tar.xz |
62 MPFR := http://www.mpfr.org/${mpfr_ver}/${mpfr_ver}.tar.bz2 |
77 MPFR := http://www.mpfr.org/${mpfr_ver}/${mpfr_ver}.tar.bz2 |
63 GMP := http://ftp.gnu.org/pub/gnu/gmp/${gmp_ver}.tar.bz2 |
78 GMP := http://ftp.gnu.org/pub/gnu/gmp/${gmp_ver}.tar.bz2 |
64 MPC := http://www.multiprecision.org/mpc/download/${mpc_ver}.tar.gz |
79 MPC := http://ftp.gnu.org/pub/gnu/mpc/${mpc_ver}.tar.gz |
|
80 GDB := http://ftp.gnu.org/gnu/gdb/${gdb_ver}.tar.xz |
|
81 |
|
82 OEL_URL := http://yum.oracle.com/repo/OracleLinux/OL6/4/base/$(ARCH)/ |
65 |
83 |
66 # RPMs in OEL6.4 |
84 # RPMs in OEL6.4 |
67 LINUX_VERSION := OEL6.4 |
85 LINUX_VERSION := OEL6.4 |
68 RPM_LIST := \ |
86 RPM_LIST := \ |
69 kernel-headers \ |
87 kernel-headers \ |
83 libXdmcp libXdmcp-devel \ |
101 libXdmcp libXdmcp-devel \ |
84 libXau libXau-devel \ |
102 libXau libXau-devel \ |
85 libgcc \ |
103 libgcc \ |
86 zlib zlib-devel \ |
104 zlib zlib-devel \ |
87 libffi libffi-devel \ |
105 libffi libffi-devel \ |
88 fontconfig fontconfig-devel |
106 fontconfig fontconfig-devel \ |
|
107 systemtap-sdt-devel \ |
|
108 # |
|
109 |
|
110 ########################################################################################## |
|
111 # Define common directories and files |
|
112 |
|
113 # Ensure we have 32-bit libs also for x64. We enable mixed-mode. |
|
114 ifeq (x86_64,$(ARCH)) |
|
115 LIBDIRS := lib64 lib |
|
116 CFLAGS_lib := -m32 |
|
117 else |
|
118 LIBDIRS := lib |
|
119 endif |
|
120 |
|
121 # Define directories |
|
122 RESULT := $(OUTPUT_ROOT)/result |
|
123 BUILDDIR := $(OUTPUT_ROOT)/$(HOST)/$(TARGET) |
|
124 PREFIX := $(RESULT)/$(HOST) |
|
125 TARGETDIR := $(PREFIX)/$(TARGET) |
|
126 SYSROOT := $(TARGETDIR)/sysroot |
|
127 DOWNLOAD := $(OUTPUT_ROOT)/download |
|
128 DOWNLOAD_RPMS := $(DOWNLOAD)/rpms |
|
129 SRCDIR := $(OUTPUT_ROOT)/src |
|
130 |
|
131 # Marker file for unpacking rpms |
|
132 rpms := $(SYSROOT)/rpms_unpacked |
|
133 |
|
134 # Need to patch libs that are linker scripts to use non-absolute paths |
|
135 libs := $(SYSROOT)/libs_patched |
|
136 |
|
137 ################################################################################ |
|
138 # Download RPMs |
|
139 download-rpms: |
|
140 mkdir -p $(DOWNLOAD_RPMS) |
|
141 # Only run this if rpm dir is empty. |
|
142 ifeq ($(wildcard $(DOWNLOAD_RPMS)/*.rpm), ) |
|
143 cd $(DOWNLOAD_RPMS) && \ |
|
144 wget -r -np -nd $(patsubst %, -A "*%*.rpm", $(RPM_LIST)) $(OEL_URL) |
|
145 endif |
|
146 |
|
147 ########################################################################################## |
|
148 # Unpack source packages |
|
149 |
|
150 # Generate downloading + unpacking of sources. |
|
151 define Download |
|
152 $(1)_DIR = $(abspath $(SRCDIR)/$(basename $(basename $(notdir $($(1)))))) |
|
153 $(1)_CFG = $$($(1)_DIR)/configure |
|
154 $(1)_FILE = $(DOWNLOAD)/$(notdir $($(1))) |
|
155 |
|
156 $$($(1)_CFG) : $$($(1)_FILE) |
|
157 mkdir -p $$(SRCDIR) |
|
158 tar -C $$(SRCDIR) -xf $$< |
|
159 $$(foreach p,$$(abspath $$(wildcard $$(notdir $$($(1)_DIR)).patch)), \ |
|
160 echo PATCHING $$(p) ; \ |
|
161 patch -d $$($(1)_DIR) -p1 -i $$(p) ; \ |
|
162 ) |
|
163 touch $$@ |
|
164 |
|
165 $$($(1)_FILE) : |
|
166 wget -P $(DOWNLOAD) $$($(1)) |
|
167 endef |
|
168 |
|
169 # Download and unpack all source packages |
|
170 $(foreach p,GCC BINUTILS CCACHE MPFR GMP MPC GDB,$(eval $(call Download,$(p)))) |
|
171 |
|
172 ########################################################################################## |
|
173 # Unpack RPMS |
89 |
174 |
90 ifeq ($(ARCH),x86_64) |
175 ifeq ($(ARCH),x86_64) |
91 RPM_DIR ?= $(RPM_DIR_x86_64) |
|
92 RPM_ARCHS := x86_64 noarch |
176 RPM_ARCHS := x86_64 noarch |
93 ifeq ($(BUILD),$(HOST)) |
177 ifeq ($(BUILD),$(HOST)) |
94 ifeq ($(TARGET),$(HOST)) |
178 ifeq ($(TARGET),$(HOST)) |
95 # When building the native compiler for x86_64, enable mixed mode. |
179 # When building the native compiler for x86_64, enable mixed mode. |
96 RPM_ARCHS += i386 i686 |
180 RPM_ARCHS += i386 i686 |
97 endif |
181 endif |
98 endif |
182 endif |
|
183 else ifeq ($(ARCH),i686)) |
|
184 RPM_ARCHS := i386 i686 |
99 else |
185 else |
100 RPM_DIR ?= $(RPM_DIR_i686) |
186 RPM_ARCHS := $(ARCH) |
101 RPM_ARCHS := i386 i686 |
187 endif |
102 endif |
188 |
103 |
189 RPM_FILE_LIST := $(sort $(foreach a, $(RPM_ARCHS), \ |
104 # Sort to remove duplicates |
190 $(wildcard $(patsubst %,$(DOWNLOAD_RPMS)/%*$a.rpm,$(RPM_LIST))) \ |
105 RPM_FILE_LIST := $(sort $(foreach a,$(RPM_ARCHS),$(wildcard $(patsubst %,$(RPM_DIR)/%*$a.rpm,$(RPM_LIST))))) |
191 )) |
106 |
|
107 #$(info RPM_FILE_LIST $(RPM_FILE_LIST)) |
|
108 |
|
109 ifeq ($(RPM_FILE_LIST),) |
|
110 $(error Found no RPMs, RPM_DIR must point to list of directories to search for RPMs) |
|
111 endif |
|
112 |
|
113 ########################################################################################## |
|
114 # Define common directories and files |
|
115 |
|
116 # Ensure we have 32-bit libs also for x64. We enable mixed-mode. |
|
117 ifeq (x86_64,$(ARCH)) |
|
118 LIBDIRS := lib64 lib |
|
119 CFLAGS_lib := -m32 |
|
120 else |
|
121 LIBDIRS := lib |
|
122 endif |
|
123 |
|
124 # Define directories |
|
125 RESULT := $(OUTPUTDIR)/result |
|
126 BUILDDIR := $(OUTPUTDIR)/$(HOST)/$(TARGET) |
|
127 PREFIX := $(RESULT)/$(HOST) |
|
128 TARGETDIR := $(PREFIX)/$(TARGET) |
|
129 SYSROOT := $(TARGETDIR)/sysroot |
|
130 DOWNLOAD := $(OUTPUTDIR)/download |
|
131 SRCDIR := $(OUTPUTDIR)/src |
|
132 |
|
133 # Marker file for unpacking rpms |
|
134 rpms := $(SYSROOT)/rpms_unpacked |
|
135 |
|
136 # Need to patch libs that are linker scripts to use non-absolute paths |
|
137 libs := $(SYSROOT)/libs_patched |
|
138 |
|
139 ########################################################################################## |
|
140 # Unpack source packages |
|
141 |
|
142 # Generate downloading + unpacking of sources. |
|
143 define Download |
|
144 $(1)_DIR = $(abspath $(SRCDIR)/$(basename $(basename $(notdir $($(1)))))) |
|
145 $(1)_CFG = $$($(1)_DIR)/configure |
|
146 $(1)_FILE = $(DOWNLOAD)/$(notdir $($(1))) |
|
147 |
|
148 $$($(1)_CFG) : $$($(1)_FILE) |
|
149 mkdir -p $$(SRCDIR) |
|
150 tar -C $$(SRCDIR) -x$$(if $$(findstring .gz, $$<),z,j)f $$< |
|
151 $$(foreach p,$$(abspath $$(wildcard $$(notdir $$($(1)_DIR)).patch)), \ |
|
152 echo PATCHING $$(p) ; \ |
|
153 patch -d $$($(1)_DIR) -p1 -i $$(p) ; \ |
|
154 ) |
|
155 touch $$@ |
|
156 |
|
157 $$($(1)_FILE) : |
|
158 wget -P $(DOWNLOAD) $$($(1)) |
|
159 endef |
|
160 |
|
161 # Download and unpack all source packages |
|
162 $(foreach p,GCC BINUTILS CCACHE MPFR GMP MPC,$(eval $(call Download,$(p)))) |
|
163 |
|
164 ########################################################################################## |
|
165 # Unpack RPMS |
|
166 |
192 |
167 # Note. For building linux you should install rpm2cpio. |
193 # Note. For building linux you should install rpm2cpio. |
168 define unrpm |
194 define unrpm |
169 $(SYSROOT)/$(notdir $(1)).unpacked \ |
195 $(SYSROOT)/$(notdir $(1)).unpacked : $(1) |
170 : $(1) |
|
171 $$(rpms) : $(SYSROOT)/$(notdir $(1)).unpacked |
196 $$(rpms) : $(SYSROOT)/$(notdir $(1)).unpacked |
172 endef |
197 endef |
173 |
198 |
174 %.unpacked : |
199 %.unpacked : |
175 $(info Unpacking target rpms and libraries from $<) |
200 $(info Unpacking target rpms and libraries from $<) |
208 @touch $@ |
233 @touch $@ |
209 |
234 |
210 ########################################################################################## |
235 ########################################################################################## |
211 # Create links for ffi header files so that they become visible by default when using the |
236 # Create links for ffi header files so that they become visible by default when using the |
212 # devkit. |
237 # devkit. |
213 |
238 ifeq ($(ARCH), x86_64) |
214 $(SYSROOT)/usr/include/ffi.h: $(rpms) |
239 $(SYSROOT)/usr/include/ffi.h: $(rpms) |
215 cd $(@D) && rm $(@F) && ln -s ../lib/libffi-*/include/$(@F) . |
240 cd $(@D) && rm -f $(@F) && ln -s ../lib/libffi-*/include/$(@F) . |
216 |
241 |
217 $(SYSROOT)/usr/include/ffitarget.h: $(rpms) |
242 $(SYSROOT)/usr/include/ffitarget.h: $(rpms) |
218 cd $(@D) && rm $(@F) && ln -s ../lib/libffi-*/include/$(@F) . |
243 cd $(@D) && rm -f $(@F) && ln -s ../lib/libffi-*/include/$(@F) . |
219 |
244 |
220 SYSROOT_LINKS += $(SYSROOT)/usr/include/ffi.h $(SYSROOT)/usr/include/ffitarget.h |
245 SYSROOT_LINKS += $(SYSROOT)/usr/include/ffi.h $(SYSROOT)/usr/include/ffitarget.h |
|
246 endif |
221 |
247 |
222 ########################################################################################## |
248 ########################################################################################## |
223 |
249 |
224 # Define marker files for each source package to be compiled |
250 # Define marker files for each source package to be compiled |
225 $(foreach t,binutils mpfr gmp mpc gcc ccache,$(eval $(t) = $(TARGETDIR)/$($(t)_ver).done)) |
251 $(foreach t,binutils mpfr gmp mpc gcc ccache gdb,$(eval $(t) = $(TARGETDIR)/$($(t)_ver).done)) |
226 |
252 |
227 ########################################################################################## |
253 ########################################################################################## |
228 |
254 |
229 # Default base config |
255 # Default base config |
230 CONFIG = --target=$(TARGET) \ |
256 CONFIG = --target=$(TARGET) \ |
484 echo '# devkit' >> $@ |
530 echo '# devkit' >> $@ |
485 echo '' >> $@ |
531 echo '' >> $@ |
486 echo 'DEVKIT_NAME="$(gcc_ver) - $(LINUX_VERSION)"' >> $@ |
532 echo 'DEVKIT_NAME="$(gcc_ver) - $(LINUX_VERSION)"' >> $@ |
487 echo 'DEVKIT_TOOLCHAIN_PATH="$$DEVKIT_ROOT/bin"' >> $@ |
533 echo 'DEVKIT_TOOLCHAIN_PATH="$$DEVKIT_ROOT/bin"' >> $@ |
488 echo 'DEVKIT_SYSROOT="$$DEVKIT_ROOT/$$host/sysroot"' >> $@ |
534 echo 'DEVKIT_SYSROOT="$$DEVKIT_ROOT/$$host/sysroot"' >> $@ |
|
535 echo 'DEVKIT_EXTRA_PATH="$$DEVKIT_ROOT/bin"' >> $@ |
|
536 |
|
537 ########################################################################################## |
|
538 # Copy these makefiles into the root of the kit |
|
539 $(PREFIX)/Makefile: ./Makefile |
|
540 rm -rf $@ |
|
541 cp $< $@ |
|
542 |
|
543 $(PREFIX)/Tools.gmk: ./Tools.gmk |
|
544 rm -rf $@ |
|
545 cp $< $@ |
|
546 |
|
547 THESE_MAKEFILES := $(PREFIX)/Makefile $(PREFIX)/Tools.gmk |
489 |
548 |
490 ########################################################################################## |
549 ########################################################################################## |
491 |
550 |
492 ifeq ($(TARGET), $(HOST)) |
551 ifeq ($(TARGET), $(HOST)) |
|
552 # To build with dtrace support, the build needs access to the dtrace executable from the |
|
553 # sysroot. Generally we don't want to add binaries in the sysroot to the path, but |
|
554 # luckily this seems to execute well enough on a different host Linux distro, so symlink |
|
555 # it into the main bin dir. |
|
556 $(PREFIX)/bin/dtrace: |
|
557 @echo 'Creating dtrace soft link' |
|
558 ln -s ../$(HOST)/sysroot/usr/bin/dtrace $@ |
|
559 |
493 $(PREFIX)/bin/%: |
560 $(PREFIX)/bin/%: |
494 @echo 'Creating missing $* soft link' |
561 @echo 'Creating missing $* soft link' |
495 ln -s $(TARGET)-$* $@ |
562 ln -s $(TARGET)-$* $@ |
496 |
563 |
497 missing-links := $(addprefix $(PREFIX)/bin/, \ |
564 missing-links := $(addprefix $(PREFIX)/bin/, \ |
498 addr2line ar as c++ c++filt elfedit g++ gcc gprof ld nm objcopy ranlib readelf \ |
565 addr2line ar as c++ c++filt elfedit g++ gcc gprof ld nm objcopy ranlib readelf \ |
499 size strings strip) |
566 size strings strip ld.bfd ld.gold dtrace) |
500 endif |
567 endif |
501 |
568 |
502 ########################################################################################## |
569 ########################################################################################## |
503 |
570 |
504 bfdlib : $(bfdlib) |
571 bfdlib : $(bfdlib) |
505 binutils : $(binutils) |
572 binutils : $(binutils) |
506 rpms : $(rpms) |
573 rpms : $(rpms) |
507 libs : $(libs) |
574 libs : $(libs) |
508 sysroot : rpms libs |
575 sysroot : rpms libs |
509 gcc : sysroot $(gcc) $(gccpatch) |
576 gcc : sysroot $(gcc) $(gccpatch) |
510 all : binutils gcc bfdlib $(PREFIX)/devkit.info $(missing-links) $(SYSROOT_LINKS) |
577 gdb : $(gdb) |
|
578 all : binutils gcc bfdlib $(PREFIX)/devkit.info $(missing-links) $(SYSROOT_LINKS) \ |
|
579 $(THESE_MAKEFILES) gdb |
511 |
580 |
512 # this is only built for host. so separate. |
581 # this is only built for host. so separate. |
513 ccache : $(ccache) |
582 ccache : $(ccache) |
514 |
583 |
515 # Force target |
584 # Force target |