Skip to content

Commit 2015a8d

Browse files
authored
Merge pull request #2616 from ghaerr/macos_arm
[build] Fix build problems on macOS ARM machines
2 parents 5184807 + bc17a82 commit 2015a8d

6 files changed

Lines changed: 55 additions & 15 deletions

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
echo $PATH
5454
5555
- name: build
56-
run: ./build.sh auto allimages
56+
run: ./build.sh auto ext allimages
5757

5858
- name: upload
5959
uses: actions/upload-artifact@v4

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
ifndef TOPDIR
3-
$(error TOPDIR is not defined; did you mean to run './build.sh' instead?)
3+
$(error TOPDIR is not defined; run '. ./env.sh' then './build.sh' to build toolchain)
44
endif
55

66
include $(TOPDIR)/Make.defs

build.sh

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
#!/usr/bin/env bash
22

3-
# This build script is called in main.yml by GitHub Continuous Integration
4-
# Full build (including the cross tool chain)
5-
6-
# Arguments:
7-
# - 'auto' : continuous integration context
3+
# ELKS System Builder
4+
# This build script is also called in main.yml for GitHub Continuous Integration
5+
#
6+
# Usage: ./build.sh [auto [[ext] [[[allimages]]]]]
7+
# <no args>: user build: build cross-compiler, menuconfig kernel and standard apps
8+
# auto github CI build:: just IBM PC, 8018X, NECV25 kernel and standard apps
9+
# ext also build external apps (requires OpenWatcom C installed)
10+
# allimages also build all floppy and HD disk images
11+
#
12+
# After building the system once, the following can be used to rebuild the system:
13+
# $ make clean
14+
# $ make
15+
# $ ./buildext.sh all # optionally build specified external apps (OpenWatcom reqd)
16+
# $ ./qemu.sh
17+
#
818
set -e
919

1020
SCRIPTDIR="$(dirname "$0")"
@@ -63,12 +73,14 @@ if [ "$1" != "auto" ]; then
6373
echo "Building all..."
6474
make -j1 all || clean_exit 5
6575

66-
echo "Building external applications..."
67-
./buildext.sh all || clean_exit 51
76+
if [ "$2" = "ext" ]; then
77+
echo "Building external applications..."
78+
./buildext.sh all || clean_exit 51
79+
fi
6880

6981
# Possibly build all images
7082

71-
if [ "$2" = "allimages" ]; then
83+
if [ "$3" = "allimages" ]; then
7284
echo "Building FD images..."
7385
cd image
7486
make -j1 images-minix images-fat || clean_exit 6

elks/tools/mtools/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ all: mtools-4.0.23/Makefile
5151

5252
mtools-4.0.23/Makefile:
5353
cd mtools-4.0.23; ./configure --disable-floppyd; cd ..
54+
case `uname -s` in Darwin) \
55+
sed -i.bak 's/^#define HAVE_STAT64 1//' mtools-4.0.23/config.h && \
56+
rm -f mtools-4.0.23/config.h.bak ;; esac
5457

5558
clean:
5659
make -C mtools-4.0.23 clean

qemu.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ ACCEL_V9="-accel tcg,one-insn-per-tb=on"
130130
ACCEL_HVF="-accel hvf"
131131

132132
ACCEL=$ACCEL_SSTP
133-
if [[ `$QEMU -version` =~ "version 9" ]]; then
133+
if [[ `$QEMU -version` =~ "version 9" || `$QEMU -version` =~ "version 10" ]]; then
134134
ACCEL=$ACCEL_V9
135135
fi
136136
if [[ $QEMU =~ "x86_64" && $UNAME =~ "Darwin" && $UNAME =~ "x86_64" ]]; then

tools/Makefile

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ BUILDDIR=$(CROSSDIR)/build
2323

2424
# BINUTILS for IA16
2525

26-
BINUTILS_VER=cc5f1a9d7437051c3aae6ec16fca27c3b2d31f6c
26+
BINUTILS_VER=69e12ea2c125ff830580abbe4699d35ba002148b
2727
BINUTILS_DIST=binutils-ia16-$(BINUTILS_VER)
2828

2929
$(DISTDIR)/$(BINUTILS_DIST).tar.gz:
@@ -45,6 +45,13 @@ $(BUILDDIR)/.binutils.src: $(DISTDIR)/$(BINUTILS_DIST).tar.gz
4545
cd $(BUILDDIR) && tar -xzf $(DISTDIR)/$(BINUTILS_DIST).tar.gz
4646
rm -rf $(BUILDDIR)/binutils-src
4747
cd $(BUILDDIR) && mv $(BINUTILS_DIST) binutils-src
48+
case `uname -s` in Darwin) \
49+
cd $(BUILDDIR)/binutils-src/zlib && \
50+
sed -i.bak 's/defined(MACOS) || defined(TARGET_OS_MAC)/defined(MACOS)/' zutil.h && \
51+
rm -f zutil.h.bak ;; esac
52+
cd $(BUILDDIR)/binutils-src/bfd && \
53+
sed -i.bak 's/development=.*/development=false/' development.sh && \
54+
rm -f development.sh.bak
4855
touch $(BUILDDIR)/.binutils.src
4956

5057
$(BUILDDIR)/.binutils.build: $(BUILDDIR)/.binutils.src
@@ -99,7 +106,7 @@ $(DISTDIR)/$(MPC_DIST).tar.gz:
99106

100107
# GCC for IA16
101108

102-
GCC_VER=43408af9d4127b884ab39dcff6a829e86008e587
109+
GCC_VER=ca893320926dc93552390b892a202e9373d040c0
103110
GCC_DIST=gcc-ia16-$(GCC_VER)
104111

105112
$(DISTDIR)/$(GCC_DIST).tar.gz:
@@ -130,12 +137,30 @@ $(BUILDDIR)/.gcc.src: $(DISTDIR)/$(GCC_DIST).tar.gz \
130137
cd $(BUILDDIR)/gcc-src && ln -s $(MPFR_DIST) mpfr
131138
cd $(BUILDDIR)/gcc-src && tar -xzf $(DISTDIR)/$(MPC_DIST).tar.gz
132139
cd $(BUILDDIR)/gcc-src && ln -s $(MPC_DIST) mpc
140+
case `uname -s` in Darwin) \
141+
cd $(BUILDDIR)/gcc-src/zlib && \
142+
sed -i.bak 's/defined(MACOS) || defined(TARGET_OS_MAC)/defined(MACOS)/' zutil.h && \
143+
rm -f zutil.h.bak ;; esac
144+
cd $(BUILDDIR)/gcc-src/gcc && \
145+
sed -i.bak 's/heapb->min->compare (heapa->min)/heapb->m_min->compare (heapa->m_min)/' fibonacci_heap.h && \
146+
rm -f fibonacci_heap.h.bak
147+
case `uname -s`-`uname -m` in Darwin-arm64) \
148+
cd $(BUILDDIR)/gcc-src/gcc/config && \
149+
sed -i.bak 's/aligned (4096)/aligned (16384)/' host-darwin.c && \
150+
rm -f host-darwin.c.bak && \
151+
cd $(BUILDDIR)/gcc-src/gcc && \
152+
awk '/i\[34567\]86-\*-darwin\* \| x86_64-\*-darwin\*\)/{print " aarch64-*-darwin* | arm-*-darwin*)"; print " out_host_hook_obj=\"$${out_host_hook_obj} host-aarch64-darwin.o\""; print " host_xmake_file=\"$${host_xmake_file} aarch64/x-darwin\""; print " ;;"} {print}' config.host > config.host.tmp && \
153+
mv config.host.tmp config.host && \
154+
printf 'host-aarch64-darwin.o : $$(srcdir)/config/aarch64/host-aarch64-darwin.c\n\t$$(COMPILE) $$<\n\t$$(POSTCOMPILE)\n' \
155+
> $(BUILDDIR)/gcc-src/gcc/config/aarch64/x-darwin && \
156+
printf '/* aarch64-darwin host-specific hook definitions. */\n#include "config.h"\n#include "system.h"\n#include "coretypes.h"\n#include "hosthooks.h"\n#include "hosthooks-def.h"\n#include "config/host-darwin.h"\nconst struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER;\n' \
157+
> $(BUILDDIR)/gcc-src/gcc/config/aarch64/host-aarch64-darwin.c ;; esac
133158
touch $(BUILDDIR)/.gcc.src
134159

135160
$(BUILDDIR)/.gcc.build: $(BUILDDIR)/.gcc.src $(BUILDDIR)/.binutils.build
136161
cd $(BUILDDIR) && rm -rf gcc-build
137162
mkdir $(BUILDDIR)/gcc-build
138-
cd $(BUILDDIR)/gcc-build && ../gcc-src/configure --target=ia16-elf --prefix="$(CROSSDIR)" --without-headers --enable-languages=c --disable-libssp --without-isl
163+
cd $(BUILDDIR)/gcc-build && LC_ALL=C ../gcc-src/configure --target=ia16-elf --prefix="$(CROSSDIR)" --without-headers --enable-languages=c --disable-libssp --without-isl --disable-nls
139164
# If there are any obsolete multilib directories (which are no longer
140165
# used) in the installation directory, remove them, so that they do
141166
# not clutter up the installation directory. This is a bit of a hack.
@@ -145,7 +170,7 @@ $(BUILDDIR)/.gcc.build: $(BUILDDIR)/.gcc.src $(BUILDDIR)/.binutils.build
145170
$(CROSSDIR)/lib/gcc/ia16-elf/6.3.0/regparmcall/size \
146171
$(CROSSDIR)/lib/gcc/ia16-elf/6.3.0/regparmcall/any_186/size
147172
# Now build.
148-
$(MAKE) -C $(BUILDDIR)/gcc-build $(PARALLEL)
173+
LC_ALL=C $(MAKE) -C $(BUILDDIR)/gcc-build $(PARALLEL)
149174
touch $(BUILDDIR)/.gcc.build
150175

151176
$(CROSSDIR)/.gcc.install: $(BUILDDIR)/.gcc.build

0 commit comments

Comments
 (0)