]> Zhao Yanbai Git Server - kernel.git/commitdiff
修改Makefile使之能在MacOS Apple Silicon的Docker Linux下编译
authoracevest <zhaoyanbai@126.com>
Sat, 5 Feb 2022 04:11:35 +0000 (04:11 +0000)
committeracevest <zhaoyanbai@126.com>
Sat, 5 Feb 2022 04:11:35 +0000 (04:11 +0000)
bin/Makefile

index 4b76644056318319f5971e37de90edd8aeabf2b4..013ad00ba71ef3a2db34eee2c3045007bb065cf2 100644 (file)
@@ -1,4 +1,30 @@
-CC = gcc
+OS := $(shell uname -s)
+CPU_ARCH := $(shell uname -p)
+
+CC                     = gcc
+LD                     = ld
+ifeq ($(OS), Darwin)
+       # MacOS下安装i686-elf-*的方法: brew install i686-elf-binutils
+       # Apple Silicon
+       ifeq ($(CPU_ARCH), arm)
+               CC              = i686-elf-gcc
+               LD              = i686-elf-ld
+       # Intel MacOS
+       else ifeq ($(CPU_ARCH), i386)
+               CC              = i686-elf-gcc
+               LD              = i686-elf-ld
+       endif
+else ifeq ($(OS), Linux)
+       # Apple Silicon Docker Linux
+       ifeq ($(CPU_ARCH), aarch64)
+               CC              = x86_64-linux-gnu-gcc
+               LD              = x86_64-linux-gnu-ld
+       endif
+endif
+
+
+
+CFLAGS = -g -c -fno-builtin -m32 -DBUILDER='"$(shell whoami)"' 
 LDFLAG = -e _start
 CFLAGS = -m32 -c -I../include -fno-builtin
 LIBC_DIRS = ../lib
@@ -9,11 +35,11 @@ BINS := shell hello
 all:$(BINS)
 
 shell: shell.o
-       gcc $(CFLAGS) shell.c -o shell.o
-       ld  -m elf_i386 ${LIBC_OBJS} shell.o -o shell
+       $(CC) $(CFLAGS) shell.c -o shell.o
+       $(LD)  -m elf_i386 ${LIBC_OBJS} shell.o -o shell
 hello: hello.o
-       gcc $(CFLAGS) hello.c -o hello.o
-       ld  -m elf_i386 $(LIBC_OBJS) hello.o -o hello
+       $(CC) $(CFLAGS) hello.c -o hello.o
+       $(LD)  -m elf_i386 $(LIBC_OBJS) hello.o -o hello
 
 
 .PHONY:clean