Skip to content

Instantly share code, notes, and snippets.

@lucasw
Last active November 18, 2020 01:07
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save lucasw/7997efdad0b0c467ffac75e35b716c33 to your computer and use it in GitHub Desktop.
gcc 68000 cross compiler

http://darkdust.net/writings/megadrive/crosscompiler

https://gcc.gnu.org/svn.html

https://www.gnu.org/software/binutils/

svn checkout svn://gcc.gnu.org/svn/gcc/trunk gcc

That is taking too long, get a snapshot instead.

wget http://www.netgull.com/gcc/snapshots/7-20170504/gcc-7-20170504.tar.bz2
git clone git://sourceware.org/git/binutils-gdb.git

(Why is one git and the other svn?)

binutils

mkdir build_binutils
cd build_binutils
../binutils-gdb/configure --target=m68k-coff --
=$HOME/other/install
...
*** Configuration m68k-unknown-coff is obsolete.
*** Specify --enable-obsolete to build it anyway.
*** Support will be REMOVED in the next major release of BINUTILS,
*** unless a maintainer comes forward.
../binutils-gdb/configure --target=m68k-coff --prefix=$HOME/other/install --enable-obsolete
make
...
Setting warning flags = -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wstack-usage=262144 -Werror
checking whether byte ordering is bigendian... no
This target is no longer supported in gas

So this version is not going to work. What is the latest version that will work?

2.23 is mentioned http://daveho.github.io/2012/10/26/m68k-elf-cross-compiler.html

git checkout remotes/origin/binutils-2_23-branch
cd build_binutils
../binutils-gdb/configure --target=m68k-coff --prefix=$HOME/other/install --enable-languages=c --program-prefix=m68k-coff-
make

../../../binutils-gdb/bfd/doc/bfd.texinfo:325: unknown command `colophon'
../../../binutils-gdb/bfd/doc/bfd.texinfo:336: unknown command `cygnus'

sudo apt-get install libgmp-dev

That didn't fix it.

http://trac.clfs.org/ticket/926

cd binutils-gdb
sed -i -e 's/@colophon/@@colophon/' \
       -e 's/doc@cygnus.com/doc@@cygnus.com/' bfd/doc/bfd.texinfo
cd ../build_binutils
make
In file included from ../../binutils-gdb/bfd/opncls.c:26:0:
../../binutils-gdb/bfd/opncls.c: In function ‘bfd_fopen’:
./bfd.h:529:65: error: right-hand operand of comma expression has no effect [-Werror=unused-value]
 #define bfd_set_cacheable(abfd,bool) (((abfd)->cacheable = bool), TRUE)
                                                                 ^
../../binutils-gdb/bfd/opncls.c:261:5: note: in expansion of macro ‘bfd_set_cacheable’
     bfd_set_cacheable (nbfd, TRUE);
     ^
cc1: all warnings being treated as errors

Make warnings warnings next.

make CFLAGS="-Os -w"
...
This target is no longer supported in gas

https://cygwin.com/ml/binutils/2010-02/msg00089.html Go back to 2.16

git checkout   remotes/origin/binutils-2_16-branch
...
make

built!

make install
...
./elf.texi:1: warning: @section missing argument
../../../binutils-gdb/bfd/doc/bfdt.texi:313: raising the section level of @subsubsection which is too low
./init.texi:5: raising the section level of @subsubsection which is too low
../../../binutils-gdb/bfd/doc/archive.texi:54: raising the section level of @subsubsection which is too low
...
Makefile:360: recipe for target '../../../binutils-gdb/bfd/doc/bfd.info' failed
...

failed!

http://blog.kempj.co.uk/2015/09/binutils-errors-compiling-oe/

"The error is due to an incompatibility between older versions of binutils and newer versions of texinfo. "

Replaced every subsubsection with subsection that generated a 'raising the section level' error.

../../../binutils-gdb/gas/doc/c-arc.texi:52: unknown command `ta'

Added another @ in front of @ta.

cannot open gasver.texi or /gasver.texi: No such file or directory

Don't think this is a major problem.

../../../binutils-gdb/gas/doc/as.texinfo:3637: @itemx must follow @item
...
../../../binutils-gdb/gas/doc/c-arc.texi:215: command @bullet not accepting argument in brace should not be on @table line
...
../../../binutils-gdb/gas/doc/c-tic54x.texi:112: @code expected braces
...

https://dev.openwrt.org/ticket/13039

"I manually downgraded to texinfo-4.13a"

Try installing old texinfo to other/install

http://ftp.gnu.org/gnu/texinfo/texinfo-4.13a.tar.gz

Or just disable documentation generation, though would like to look at it eventually.

make install MAKEINFO=false

or set MAKEINFO = missing in the build dir makefiles? That isn't working.

What about --disable-doc?

../binutils-gdb/configure --target=m68k-coff --prefix=$HOME/other/install --enable-languages=c --program-prefix=m68k-coff- --disable-doc

"You should be able to pass MAKEINFO=/bin/false to configure to make it explicit that makeinfo is not available on your machine."

Also it looks like I do have some binutils binaries installed, despite the docs causing make install to fail.

bin/m68k-coff-objcopy
bin/m68k-coff-strings
bin/m68k-coff-strip
bin/m68k-coff-objdump
bin/m68k-coff-readelf
bin/m68k-coff-ar
bin/m68k-coff-c++filt
bin/m68k-coff-addr2line
bin/m68k-coff-nm
bin/m68k-coff-ranlib
bin/m68k-coff-size
m68k-coff
m68k-coff/bin
...

It looks like setting MAKEINFO = false in the top-level Makefile in the build_binutils also works?

GCC

Try latest then go backwards.

../gcc-7-20170504/configure --prefix=$HOME/other/install --target=m68k-coff --enable-languages=c --program-prefix=m68k-coff-
checking for the correct version of mpfr.h... no
configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
...
sudo apt-get install libmpfr-dev libmpc-dev

configure now works, but not make:

*** Configuration m68k-unknown-coff not supported

4.4.2 instead? (saw this on a webpage about cross compiling) Try 4.9.4 first - nope not supported.

../gcc-4.4.2/configure --prefix=$HOME/other/install --target=m68k-coff --enable-languages=c --program-prefix=m68k-coff- --enable-obsolete
make
...
toplev.c:536:1: error: redefinition of ‘floor_log2’

http://stackoverflow.com/questions/34569458/error-occurred-compiling-gcc-from-source-code

CC = gcc -fgnu89-inline
CXX = g++ -fgnu89-inline

This

...
attribs.o: In function `floor_log2':
/home/lucasw/other/retro/68000/build_gcc/gcc/../../gcc-4.4.2/gcc/toplev.h:192: multiple definition of `floor_log2'
c-lang.o:/home/lucasw/other/retro/68000/build_gcc/gcc/../../gcc-4.4.2/gcc/toplev.h:192: first defined here
attribs.o: In function `exact_log2':
...

https://bugzilla.redhat.com/show_bug.cgi?id=476370

https://gcc.gnu.org/ml/gcc-patches/2009-06/msg01234.html

How about commenting out the ../gcc-4.4.2/gcc/toplev.h definitions?

/*
extern inline int
floor_log2 (unsigned HOST_WIDE_INT x)
{
  return x ? HOST_BITS_PER_WIDE_INT - 1 - (int) CLZ_HWI (x) : -1;
}

extern inline int
exact_log2 (unsigned HOST_WIDE_INT x)
{
  return x == (x & -x) && x ? (int) CTZ_HWI (x) : -1;
}
*/

Now another texinfo error:

../../gcc-4.4.2/gcc/doc/cppopts.texi:761: @itemx must follow @item

Set MAKEINFO = false in build_gcc/Makefile and build_gcc/gcc/Makefile, and BUILD_INFO = (make it blank) in the gcc makefile also.

This looks more serious:

checking for m68k-coff-gcc... /home/lucasw/other/retro/68000/build_gcc/./gcc/xgcc -B/home/lucasw/other/retro/68000/build_gcc/./gcc/ -B/home/lucasw/other/install/m68k-coff/bin/ -B/home/lucasw/other/install/m68k-coff/lib/ -isystem /home/lucasw/other/install/m68k-coff/include -isystem /home/lucasw/other/install/m68k-coff/sys-include  -mcpu=51qe
checking for suffix of object files... configure: error: in `/home/lucasw/other/retro/68000/build_gcc/m68k-coff/m51qe/libgcc':
configure: error: cannot compute suffix of object files: cannot compile
Makefile:11146: recipe for target 'configure-target-libgcc' failed

https://gcc.gnu.org/wiki/FAQ#Configuration_fails_with_.27.27configure:_error:_cannot_compute_suffix_of_object_files:_cannot_compile.27.27._What_is_the_problem.3F

Error: unrecognized architecture specification `cpu=51qe'
Error: unrecognized option -mcpu=51qe
configure:2614: $? = 1
configure: failed program was:
| /* confdefs.h.  */
|
| #define PACKAGE_NAME "GNU C Runtime Library"
| #define PACKAGE_TARNAME "libgcc"
| #define PACKAGE_VERSION "1.0"
| #define PACKAGE_STRING "GNU C Runtime Library 1.0"
| #define PACKAGE_BUGREPORT ""
| /* end confdefs.h.  */
|
| int
| main ()
| {
|
|   ;
|   return 0;
| }
configure:2627: error: in `/home/lucasw/other/retro/68000/build_gcc/m68k-coff/m51qe/libgcc':
configure:2630: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details.

What is 51qe?

It looks like a more modern embedded board, just disable it for now.

m68k-coff/libgcc/Makefile has a line MULTIDIRS = ... 51qe ..., remove it from there.

4.4.2/libgcc/../include  -DHAVE_CC_TLS -o _double.o -MT _double.o -MD -MP -MF _double.dep -DL_double -xassembler-with-cpp \
  -c ../../../../gcc-4.4.2/libgcc/../gcc/config/m68k/lb1sf68.asm
../../../../gcc-4.4.2/libgcc/../gcc/config/m68k/lb1sf68.asm: Assembler messages:
../../../../gcc-4.4.2/libgcc/../gcc/config/m68k/lb1sf68.asm:669: Error: unknown pseudo-op: `.hidden'
Makefile:350: recipe for target '_double.o' failed
make[4]: *** [_double.o] Error 1
make[4]: Leaving directory '/home/lucasw/other/retro/68000/build_gcc/m68k-coff/m68000/libgcc'

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=18804

Links to patches are now broken. The log message is "Use implementation instead of declaration for test function", should be able to find that.

http://stackoverflow.com/questions/43822748/view-old-changes-to-gcc-cvs-repository

https://gcc.gnu.org/viewvc/gcc?view=revision&revision=91732

Don't see the file mklibgcc.in

Maybe give up on compiling gcc and try another way for 68000 c/asm.

Ubuntu repo

gcc-m68k-linux-gnu exists, where does that come from?

sudo apt-get install gcc-m68k-linux-gnu
...
The following additional packages will be installed:
  binutils-m68k-linux-gnu cpp-5-m68k-linux-gnu cpp-m68k-linux-gnu gcc-5-cross-base-ports
  gcc-5-m68k-linux-gnu gcc-5-m68k-linux-gnu-base libatomic1-m68k-cross libc6-dev-m68k-cross
  libc6-m68k-cross libgcc-5-dev-m68k-cross libgcc2-m68k-cross libgomp1-m68k-cross
  linux-libc-dev-m68k-cross
Suggested packages:
  binutils-doc gcc-5-locales cpp-doc gcc-5-doc libgcc2-dbg-m68k-cross libgomp1-dbg-m68k-cross
  libitm1-dbg-m68k-cross libatomic1-dbg-m68k-cross libasan2-dbg-m68k-cross
  liblsan0-dbg-m68k-cross libtsan0-dbg-m68k-cross libubsan0-dbg-m68k-cross
  libcilkrts5-dbg-m68k-cross libmpx0-dbg-m68k-cross libquadmath0-dbg-m68k-cross bison
  gdb-m68k-linux-gnu gcc-doc
The following packages will be REMOVED:
  g++-multilib gcc-multilib
The following NEW packages will be installed:
  binutils-m68k-linux-gnu cpp-5-m68k-linux-gnu cpp-m68k-linux-gnu gcc-5-cross-base-ports
  gcc-5-m68k-linux-gnu gcc-5-m68k-linux-gnu-base gcc-m68k-linux-gnu libatomic1-m68k-cross
  libc6-dev-m68k-cross libc6-m68k-cross libgcc-5-dev-m68k-cross libgcc2-m68k-cross
  libgomp1-m68k-cross linux-libc-dev-m68k-cross
...

Now have a ton of m68k tools:

$ m68k-
m68k-coff-addr2line          m68k-linux-gnu-as            m68k-linux-gnu-gcov-tool
m68k-coff-ar                 m68k-linux-gnu-c++filt       m68k-linux-gnu-gcov-tool-5
m68k-coff-as                 m68k-linux-gnu-cpp           m68k-linux-gnu-gprof
m68k-coff-c++filt            m68k-linux-gnu-cpp-5         m68k-linux-gnu-ld
m68k-coff-ld                 m68k-linux-gnu-elfedit       m68k-linux-gnu-ld.bfd
m68k-coff-nm                 m68k-linux-gnu-gcc           m68k-linux-gnu-nm
m68k-coff-objcopy            m68k-linux-gnu-gcc-5         m68k-linux-gnu-objcopy
m68k-coff-objdump            m68k-linux-gnu-gcc-ar        m68k-linux-gnu-objdump
m68k-coff-ranlib             m68k-linux-gnu-gcc-ar-5      m68k-linux-gnu-ranlib
m68k-coff-readelf            m68k-linux-gnu-gcc-nm        m68k-linux-gnu-readelf
m68k-coff-size               m68k-linux-gnu-gcc-nm-5      m68k-linux-gnu-size
m68k-coff-strings            m68k-linux-gnu-gcc-ranlib    m68k-linux-gnu-strings
m68k-coff-strip              m68k-linux-gnu-gcc-ranlib-5  m68k-linux-gnu-strip
m68k-linux-gnu-addr2line     m68k-linux-gnu-gcov          
m68k-linux-gnu-ar            m68k-linux-gnu-gcov-5 
@lucasw
Copy link
Author

lucasw commented May 7, 2017

Sega Genesis / Mega Drive

http://www.bytesizeadventures.com/modern-mega-drive-programming-getting-started/

https://emudocs.org/Genesis/sega2f.htm

http://www.genny4ever.net/index.php?page=tools

https://github.com/kubilus1/gendev

git clone and make - wants sudo, no thanks.
Edit Makefile and delete the sudo, change the install dir to a home dir instead of opt.

GENDEV?=/home/lucasw/other/retro/sega_genesis_mega_drive/gen/
SUDO?=
make -C build-binutils-m68k-elf-2.24 all install DESTDIR= >> /home/lucasw/other/retro/sega_genesis_mega_drive/gendev/work/logs/build-binutils-m68k-elf-2.24.log 2>&1
../gen_gcc/makefile-gen:93: recipe for target 'build-m68k-binutils' failed
make[1]: *** [build-m68k-binutils] Error 2
make[1]: Leaving directory '/home/lucasw/other/retro/sega_genesis_mega_drive/gendev/work'

In gendev/work/logs/build-binutils-m68k-elf-2.24.log

mkdir -p -- /opt/toolchains/gen/m68k-elf /opt/toolchains/gen/m68k-elf
mkdir: cannot create directory ‘/opt/toolchains’: Permission denied
mkdir: cannot create directory ‘/opt/toolchains’: Permission denied

Need to fix TOOLS location in Makefile:

TOOLS+=/home/lucasw/other/retro/sega_genesis_mega_drive/toolchains

also

$(GENDEV):
  if [ -w /home/lucasw/other/retro/sega_genesis_mega_drive ]; then \

Resource: PALETTE font_pal_lib "image/font_lib.png"
--> executing plugin PALETTE...

Make gets a lot further now:

Resource: BIN stop_xgm "sound/stop_xgm.bin"
--> executing plugin BIN...
/home/lucasw/other/retro/sega_genesis_mega_drive/gen//m68k-elf/bin/m68k-elf-gcc  -Dnologo_  -m68000 -Wall -O1 -c -fomit-frame-pointer -Iinc -Ires  -c res/libres.s -o res/libres.o 
make[2]: /home/lucasw/other/retro/sega_genesis_mega_drive/gen//m68k-elf/bin/m68k-elf-gcc: Command not found
Makefile.sgdk_lib:51: recipe for target 'res/libres.o' failed
make[2]: *** [res/libres.o] Error 127
rm res/libres.s
make[2]: Leaving directory '/home/lucasw/other/retro/sega_genesis_mega_drive/gendev/sgdk/sgdk-read-only'
Makefile:56: recipe for target 'sgdk-read-only/libmd.a' failed
make[1]: *** [sgdk-read-only/libmd.a] Error 2
make[1]: Leaving directory '/home/lucasw/other/retro/sega_genesis_mega_drive/gendev/sgdk'
Makefile:66: recipe for target '/home/lucasw/other/retro/sega_genesis_mega_drive/gen//m68k-elf/lib/libmd.a' failed
make: *** [/home/lucasw/other/retro/sega_genesis_mega_drive/gen//m68k-elf/lib/libmd.a] Error 2

The binary is actually in /home/lucasw/other/retro/sega_genesis_mega_drive/toolchains/gen/m68k-elf/bin/

Fix sgdk/sgdk-read-only/Makefile so GENDEV points to the right location (it was getting passed an incorrect GENDEV from elsewhere, would be nice to fix that).

Then:

cd sgdk-read-only/tools/rescomp && \
	patch -u -p0 < ../../../files/rescomp.diff && \
	make -f ../../../files/Makefile.rescomp && cp out/rescomp /home/lucasw/other/retro/sega_genesis_mega_drive/gen//bin/.
patching file inc/tools.h
Reversed (or previously applied) patch detected!  Assume -R? [n] 
Apply anyway? [n] 
Skipping patch.
1 out of 1 hunk ignored -- saving rejects to file src/tools.c.rej
Makefile:32: recipe for target 'tools' failed
make[1]: *** [tools] Error 1
make[1]: Leaving directory '/home/lucasw/other/retro/sega_genesis_mega_drive/gendev/sgdk'
Makefile:66: recipe for target '/home/lucasw/other/retro/sega_genesis_mega_drive/gen//m68k-elf/lib/libmd.a' failed

Try yes next time to the patches?

Running make over requires lengthy recompilation of already compiled binaries.

cd sgdk-read-only && make -f Makefile.sgdk_lib 
make[2]: Entering directory '/home/lucasw/other/retro/sega_genesis_mega_drive/gendev/sgdk/sgdk-read-only'
/home/lucasw/other/retro/sega_genesis_mega_drive/gen//bin/rescomp res/libres.res res/libres.s
rescomp v1.4

Resource: BITMAP logo_lib "image/logo_lib.png" 1
--> executing plugin BITMAP...
Executing /home/lucasw/other/retro/sega_genesis_mega_drive/gen//bin/appack c "pack.in" "pack1.out" -s
===============================================================================
aPLib example                   Copyright (c) 1998-2009 by Joergen Ibsen / Jibz
                                                            All Rights Reserved

                                                  http://www.ibsensoftware.com/
===============================================================================

syntax:

   compress    :  appack c <file> <packed_file>
   decompress  :  appack d <packed_file> <depacked_file>

Makefile.sgdk_lib:54: recipe for target 'res/libres.s' failed
make[2]: *** [res/libres.s] Segmentation fault (core dumped)
make[2]: *** Deleting file 'res/libres.s'
make[2]: Leaving directory '/home/lucasw/other/retro/sega_genesis_mega_drive/gendev/sgdk/sgdk-read-only'
Makefile:56: recipe for target 'sgdk-read-only/libmd.a' failed
make[1]: *** [sgdk-read-only/libmd.a] Error 2
make[1]: Leaving directory '/home/lucasw/other/retro/sega_genesis_mega_drive/gendev/sgdk'
Makefile:66: recipe for target '/home/lucasw/other/retro/sega_genesis_mega_drive/gen//m68k-elf/lib/libmd.a' failed
make: *** [/home/lucasw/other/retro/sega_genesis_mega_drive/gen//m68k-elf/lib/libmd.a] Error 2

@WillSams
Copy link

I had a headache with this a couple of years ago. I've updated my toolchain recently to ensure it works on Windows under Msys2 as well as Linux: https://gist.github.com/WillSams/c4cbf6235b467d8b595693969342237e

I've had no issues other than going through some pain converting ASM68k and NASM targeted code to GNU assembly. =) Currently going through Big Evil Corp's examples, I'll do a proper fork sometime in the coming week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment