wjj@SUN-VALLEY.STANFORD.EDU (Warren Jasper) (05/28/90)
Archive-name: gnu-cross-compiler/25-May-90 Original-posting-by: wjj@SUN-VALLEY.STANFORD.EDU (Warren Jasper) Original-subject: gcc as a cross-compiler Reposted-by: emv@math.lsa.umich.edu (Edward Vielmetti) [Reposted from gnu.gcc. Comments on this service to emv@math.lsa.umich.edu (Edward Vielmetti).] I have received a few requests for making gcc into a cross compiler from the Sun4 (Host) to a Motorola 680X0 (Target) single-board computer. We use gcc to generate code that we compile on a SPARCStation to run on our real time MVME 147 boards (68030 SBC). Here is a step by step procedure for doing this. Note: I am trying to finish up my PhD dissertation, and I don't have a lot of time to help people with this. If you can not get this to work, please do NOT ask me for help. Sorry, but I have to finish up. 1) You will need to get the latest copies of gcc (1.37.1), gas(1.35) and gld. 2) Make sure you have a working gcc compiler. Ours is in /local/bin. 3) Copy the scripts Makefile.cross and cross-config.gcc into the main gcc directory. e.g. /usr/local/src/gcc/gcc.1.37.1. 4) type "cross-config.gcc sun4-os4 sun3-os4". This will set up the correct symbolic links for you. 5) Edit Makefile.cross if you need to change directory paths. 6) Type make -f Makefile.cross Note: If you get an error making gnulib{2}, don't worry about it. There is no good way that I know of on how to make a cross compiled version of this. Best to copy a version made on a Sun3 into DESTDIR. Unless you use long long, you don't need gnulib2 anyway. This should make the cross-compiler. Now for the cross assembler and loader. 7) Copy Makefile.gas into the gas directory and type make -f Makefile.gas 8) Copy Makefile.gld into the gld directory. Type make -f Makefile.gld Warning: There were some problems with earlier versions of gld. I think that they were fixed. If not, get the latest ld from the g++ distribution. I think our bug fixes were incorporated, but I'm not sure. If gld does not cross load, send me mail and I'll see what I can do. 9) Copy your version of gcc into /usr/local/lib/sun4. In this directory should be: gcc-as gcc-sun3-as gcc gcc-sun3-gcc gcc-cc1 gcc-sun3-cc1 gcc-cpp gcc-sun3-cpp gcc-gnublib gcc-sun3-gnulib <-- you have to make this on a Sun3 gcc-sun3-ld copy gcc and gld (scripts at the end of this file) into /usr/local/bin. 10) gld does not do dynamic loading. You don't want this anyway for your target processor. Also, ld does not know how to get to the C libraries such as libC.a. Don't worry about this either, since you will be using the ld -r option anyway. Also, don't forget to include the file math-68881.h if your SBC has the math chip. This file goes into ./gcc-include. 11) To compile normally, just type gcc foo.c To cross compile: gcc -sun3 -c cross_foo.c gld -sun3 -r -o cross_foo cross_foo.o Good Luck !! Warren Jasper Stanford University ______________________________________________________________________ Makefile.cross: # Makefile for GNU C cross-compiler. # Written by Warren J. Jasper Stanford Univerity 1989 #Make sure you have a working gcc on your host machine in directory BINDIR #Run cross-config.gcc to set up the backend files. BINDIR = /local/bin HOST_ARCH = sun4 TARGET_ARCH = sun3 PROGRAMS = gcc cpp cc1 EXECUTABLES = $(PROGRAMS:%=gcc-$(TARGET_ARCH)-%) DESTDIR = /usr/local/lib/$(HOST_ARCH) INSTALL_OPTIONS = -m 751 -g bin -s $(PROGRAMS): $(MAKE) CC=$(BINDIR)/gcc CFLAGS="-g -O" install : $(PROGRAMS) install $(INSTALL_OPTIONS) gcc $(DESTDIR)/gcc-$(TARGET_ARCH)-gcc install $(INSTALL_OPTIONS) cpp $(DESTDIR)/gcc-$(TARGET_ARCH)-cpp install $(INSTALL_OPTIONS) cc1 $(DESTDIR)/gcc-$(TARGET_ARCH)-cc1 clean: $(MAKE) clean ________________________________________________________________________ cross-config.gcc: #!/bin/sh # Cross-Configuration script for GNU CC version 1.37.1 # Modified by Warren J. Jasper Stanford Univerity 1990 #GNU CC 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 1, or (at your option) #any later version. #GNU CC 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 GNU CC; see the file COPYING. If not, write to #the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. # # Shell script to create proper links to machine-dependent files in # preparation for cross-compiling gcc. # # Usage: cross-config.gcc [vint] Host_Machine Target_Machine # # If cross-config.gcc succeeds, it leaves its status in config.status. # If cross-config.gcc fails after disturbing the status quo, # config.status is removed. # progname=$0 remove=/bin/rm hard_link=ln symbolic_link='ln -s' #for Test #remove="echo rm" #hard_link="echo ln" #symbolic_link="echo ln -s" case $# in 3) vint=on shift ;; *) ;; esac case $# in 2) Host_Machine=$1 shift Target_Machine=$1 case $Host_Machine in sun4 | sun-4 | sun4-os3 | sun-4-os3) host_cpu_type=sparc configuration_file=xm-sparc.h ;; sun3 | sun-3 | sun3-os3 | sun-3-os3) host_cpu_type=m68k configuration_file=xm-m68k.h ;; sun3-nfp | sun-3-nfp | sun3-nfp-os3 | sun-3-nfp-os3) host_cpu_type=m68k configuration_file=xm-m68k.h ;; sun2 | sun-2 | sun2-os3 | sun-2-os3) host_cpu_type=m68k configuration_file=xm-m68k.h ;; sun386 | sun386i | roadrunner) host_cpu_type=i386 configuration_file=xm-sun386i.h ;; sun4-os4 | sun-4-os4) host_cpu_type=sparc configuration_file=xm-sparc.h ;; sun3-os4 | sun-3-os4) host_cpu_type=m68k configuration_file=xm-m68k.h ;; sun3-nfp-os4 | sun-3-nfp-os4) host_cpu_type=m68k configuration_file=xm-68k.h ;; sun3-fpa-os4 | sun-3-fpa-os4) host_cpu_type=m68k configuration_file=xm-68k.h ;; sun2-os4 |sun-2-os4) host_cpu_type=m68k configuration_file=xm-sunos4.h ;; esac case $Target_Machine in sun4 | sun-4 | sun4-os3 | sun-4-os3) target_cpu_type=sparc target_machine=tm-sun4os3.h ;; sun3 | sun-3 | sun3-os3 | sun-3-os3) target_cpu_type=m68k target_machine=tm-sun3os3.h ;; sun3-nfp | sun-3-nfp | sun3-nfp-os3 | sun-3-nfp-os3) target_cpu_type=m68k target_machine=tm-sun3os3nf.h ;; sun2 | sun-2 | sun2-os3 | sun-2-os3) target_cpu_type=m68k target_machine=tm-sun2.h ;; sun386 | sun386i | roadrunner) target_cpu_type=i386 target_machine=tm-sun386i.h ;; sun4-os4 | sun-4-os4) target_cpu_type=sparc target_machine=tm-sparc.h ;; sun3-os4 | sun-3-os4) target_cpu_type=m68k target_machine=tm-sun3.h ;; sun3-nfp-os4 | sun-3-nfp-os4) target_cpu_type=m68k target_machine=tm-sun3-nfp.h ;; sun2-os4 |sun-2-os4) target_cpu_type=m68k target_machine=tm-sun2.h ;; esac # if cpu_type is not set, define cpu_type to machine. # host_cpu_type=${host_cpu_type-$Host_Machine} configuration_file=${configuration_file-xm-$host_cpu_type.h} target_machine=${target_machine-tm-$Target_Machine.h} machine_description=${target_cpu_type}.md aux_output=${aux_output-out-$target_cpu_type.c} if [ xx${vint} = xx ] then files="$configuration_file $target_machine $machine_description $aux_output" links="config.h tm.h md aux-output.c" else files="$configuration_file tm-vmc.h $target_machine $machine_description $aux_output" links="config.h tm.h tm-pre.h md aux-output.c" fi while [ -n "$files" ] do # set file to car of files, files to cdr of files set $files; file=$1; shift; files=$* set $links; link=$1; shift; links=$* if [ ! -r config/$file ] then echo "$progname: cannot create a link \`$link'," echo "since the file \`config/$file' does not exist." exit 1 fi $remove -f $link rm -f config.status # Make a symlink if possible, otherwise try a hard link $symbolic_link config/$file $link 2>/dev/null || $hard_link config/$file $link if [ ! -r $link ] then echo "$progname: unable to link \`$link' to \`config/$file'." exit 1 fi echo "Linked \`$link' to \`config/$file'." done if [ xx${vint} = xx ] then echo "Links are now set up for use with a $Host_Machine"\ "to cross compile on a $Target_Machine." \ | tee config.status else echo "Links are now set up for use with a $Host_Machine (vint) "\ "to cross compile on a $Ttarget_Machine (vint)." \ | tee config.status fi exit 0 ;; *) echo "Usage: $progname Host_Machine Target_Machine" echo -n "Where \`Host_Machine' is something like " echo "sun4-os4" echo -n "And \`Target_Machine' is something like " echo "sun3-os4" if [ -r config.status ] then cat config.status fi exit 1 ;; esac ________________________________________________________________________ Makefile.gas: # # Makefile for building gas cross assembler # # Specify the host and target architectures HOST_ARCH = sun4 TARGET_ARCH = sun3 # Set up Sun compatible cross-compilation options CROSS_COMPILE_FLAGS = -DSUN3=3 -DTARGET=SUN3 # Generate name of execuatable EXECUTABLE = gcc-$(TARGET_ARCH)-as # Generate path to executable TARGET_DIR = $(HOST_ARCH) DESTDIR = /usr/local/lib/$(TARGET_DIR) INSTALL_OPTIONS = -m 751 -g bin -s CC = gcc CFLAGS = -O -g $(CROSS_COMPILE_FLAGS) $(EXECUTABLE) : ln -s m-sun3.h m68k.h make a68 mv a68 $@ install : $(EXECUTABLE) install $(INSTALL_OPTIONS) $(EXECUTABLE) $(DESTDIR) _______________________________________________________________________ Makefile.gld # # Makefile for building gld cross loader # # Specify the host and target architectures HOST_ARCH = sun4 TARGET_ARCH = sun3 # Set up Sun compatible cross-compilation options CROSS_COMPILE_FLAGS = -DSUN3=3 -DTARGET=SUN3 # Generate name of execuatable EXECUTABLE = gcc-$(TARGET_ARCH)-ld # Generate path to executable TARGET_DIR = $(HOST_ARCH) DESTDIR = /usr/local/lib/$(TARGET_DIR) INSTALL_OPTIONS = -m 751 -g bin -s CC = gcc CFLAGS = -O -g $(CROSS_COMPILE_FLAGS) $(EXECUTABLE) : gld.c $(CC) $(CFLAGS) -o $@ $? install : $(EXECUTABLE) install $(INSTALL_OPTIONS) $(EXECUTABLE) $(DESTDIR) ______________________________________________________________________ gcc: #! /bin/csh -f # # Name: # gcc front-end driver script for GNU C compiler # # gcc [ -target_arch ] [ gcc_options ] files # # Description: # Provides support for Sun compatible cross-compilation via the # -TARGET_ARCH command line option. # # Files: # /local/lib/ARCH/gcc Files used for native compilation # /local/lib/ARCH/gcc-cpp # /local/lib/ARCH/gcc-cc1 # /local/lib/ARCH/gcc-as # /local/lib/ARCH/gcc-ld # # /local/lib/sun4/gcc-sun3-gcc Files used for cross compilation # /local/lib/sun4/gcc-sun3-cpp # /local/lib/sun4/gcc-sun3-cc1 # /local/lib/sun4/gcc-sun3-as # /local/lib/sun4/gcc-sun3-ld # # Written by: Marc Ullman & Stan Schneider, Stanford Nov 3, 1989 # # Revision History: # Ver. 1.01, Warren Jasper, Stanford University Jan 10, 1989 # Include 68881 for cross compilation. #__________________________________________________________________________ #begin set target = "" set argumemts = ( ) while ( $#argv > 0 ) if ( "$argv[1]" =~ -sun* ) then set target = $argv[1] else set argumemts = ( $argumemts $argv[1] ) endif shift end #while if ( "$target" == "-sun3" && `arch` == "sun4" ) then exec /local/lib/$ARCH/gcc-sun3-gcc \ -B/local/lib/$ARCH/gcc-sun3- \ -m68020 -m68881 -D__HAVE_68881__ $argumemts else exec /local/lib/$ARCH/gcc $argumemts endif #end. _______________________________________________________________________ gld: #! /bin/csh -f # NAME # gld - Front-end driver script for GNU link/loader. # # DESCRIPTION: # Provides support for cross-compilation via the -TARGET_ARCH # command line option. # # FILES: # /usr/bin/ld Files used for native compilation # # /local/lib/sun4/gcc-sun3-ld Files used for cross compilation # # WRITTEN: # Marc Ullman, Stan Schneider Dec. 25, 1989 # set target = FALSE set params while ( $#argv > 0 ) if ( "$argv[1]" =~ -sun* ) then set target = $argv[1] else set params = ($params $argv[1] ) endif shift end #while if ($target == "-sun3" && `arch` == "sun4") then exec /local/lib/$ARCH/gcc-sun3-ld $params else exec ld $params endif