#=----------------------------------------------------------------------------=# # OS/K CROSS COMPILER BUILDER # # # # Desc: Project Makefile # # # # # # Copyright © 2018-2020 The OS/K Team # # # # This file is part of OS/K. # # # # OS/K is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # any later version. # # # # OS/K is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY# without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with OS/K. If not, see . # #=----------------------------------------------------------------------------=# .PHONY: retrieve compile showenv deflate clean cross-cc .DEFAULT_GOAL := cross-cc ## VERSIONS ------------------------------------------------------------------ # GCC_NAME =gcc-10.1.0 BINUTILS_NAME =binutils-2.34 # GCC 10.1.0 GCC_SOURCES = https://ftp.gnu.org/gnu/gcc/$(GCC_NAME)/$(GCC_NAME).tar.xz # BINUTILS 2.34 BINUTILS_SOURCES = https://ftp.gnu.org/gnu/binutils/$(BINUTILS_NAME).tar.xz ## VARIABLES ----------------------------------------------------------------- # #ENV export NTHREADS := $(shell nproc) export PREFIX := $(shell pwd)/cross-cc export TARGET := x86_64-elf export PATH := $(PREFIX)/bin:$(PATH) export XZ_DEFAULTS := -T $(NTHREADS) GCCTARNAME = gcc.tar.xz BINUTILSTARNAME = binutils.tar.xz GCCDIRNAME = gcc-src BINUTILSDIRNAME = binutils-src # Color codes CL='\033[0;32m' CL2='\033[1;36m' CL3='\033[0m' NC='\033[1;37m' ## RECIPES ------------------------------------------------------------------- # showenv: @echo Installation path prefix : $(PREFIX) @echo Installation path : $(PATH) @echo Target : $(TARGET) @echo Thread number : $(NTHREADS) $(GCCTARNAME): @echo ${CL2}[$@] ${NC}Downloading GCC sources...${CL3} @wget $(GCC_SOURCES) -O $(GCCTARNAME) -q -c --show-progress @echo ${CL2}[$@] ${CL}Success.${CL3} $(BINUTILSTARNAME): @echo ${CL2}[$@] ${NC}Downloading BINUTILS sources...${CL3} @wget $(BINUTILS_SOURCES) -O $(BINUTILSTARNAME) -q -c --show-progress @echo ${CL2}[$@] ${CL}Success.${CL3} ./build-binutils: $(BINUTILSTARNAME) @echo ${CL2}[$@] ${NC}Deflate $(BINUTILS_NAME) sources...${CL3} @tar -xaf $(BINUTILSTARNAME) --skip-old-files @echo ${CL2}[$@] ${CL}Success.${CL3} @echo ${CL2}[$@] ${NC}Configuring $(BINUTILS_NAME)...${CL3} @mkdir -p build-binutils cd build-binutils && ../$(BINUTILS_NAME)/configure --target=$(TARGET) --prefix="$(PREFIX)" --with-sysroot --disable-nls --disable-werror @echo ${CL2}[$@] ${CL}Success.${CL3} $(PREFIX)/bin/x86_64-elf-objcopy: ./build-binutils @echo ${CL2}[$@] ${NC}Compiling $(BINUTILS_NAME)...${CL3} cd build-binutils && make -j $(NTHREADS) @echo ${CL2}[$@] ${NC}Compiling $(BINUTILS_NAME)...${CL3} @mkdir -p cross-cc cd build-binutils && make install -j $(NTHREADS) @echo ${CL2}[$@] ${CL}Success.${CL3} ./build-gcc: $(GCCTARNAME) @echo ${CL2}[$@] ${NC}Deflate $(GCC_NAME) sources...${CL3} @tar -xaf $(GCCTARNAME) --skip-old-files @echo ${CL2}[$@] ${CL}Success.${CL3} @echo ${CL2}[$@] ${NC}Configuring $(GCC_NAME)...${CL3} @cp multilib.opt $(GCC_NAME)/gcc/config/i386/t-x86_64-elf @patch $(GCC_NAME)/gcc/config.gcc < patch-red-zone.diff @mkdir -p build-gcc cd build-gcc && ../$(GCC_NAME)/configure --target=$(TARGET) --prefix="$(PREFIX)" --disable-nls --enable-languages=c,c++ --without-headers @echo ${CL2}[$@] ${CL}Success.${CL3} $(PREFIX)/bin/x86_64-elf-gcc: $(PREFIX)/bin/x86_64-elf-objcopy ./build-gcc @echo ${CL2}[$@] ${NC}Compiling $(GCC_NAME)...${CL3} cd build-gcc && make all-gcc -j $(NTHREADS) cd build-gcc && make all-target-libgcc -j $(NTHREADS) @mkdir -p cross-cc cd build-gcc && make install-gcc -j $(NTHREADS) cd build-gcc && make install-target-libgcc -j $(NTHREADS) @echo ${CL2}[$@] ${CL}The cross compiler has been successfully compiled.${CL3} @echo It is located in the cross-cc subdirectory. clean: @mkdir -p build-gcc build-binutils @rm -rf build-gcc @rm -rf build-binutils @rm -rf cross-cc -@rm -rf $(GCC_NAME)/gcc/config/i386/t-x86_64-elf -@echo ${CL2}[$@] ${CL}Success.${CL3} remove_all: @rm -rf *gcc* @rm -rf *bin* @echo ${CL2}[$@] ${CL}Success.${CL3} cross-cc: $(PREFIX)/bin/x86_64-elf-gcc