home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1393 < prev    next >
Encoding:
Text File  |  1990-12-28  |  12.5 KB  |  487 lines

  1. Newsgroups: alt.sources
  2. From: wjj@SUN-VALLEY.STANFORD.EDU (Warren Jasper)
  3. Subject: [gcc] gcc as a cross-compiler
  4. Message-ID: <1990May27.190430.27196@math.lsa.umich.edu>
  5. Date: Sun, 27 May 90 19:04:30 GMT
  6.  
  7. Archive-name: gnu-cross-compiler/25-May-90
  8. Original-posting-by: wjj@SUN-VALLEY.STANFORD.EDU (Warren Jasper)
  9. Original-subject: gcc as a cross-compiler
  10. Reposted-by: emv@math.lsa.umich.edu (Edward Vielmetti)
  11.  
  12. [Reposted from gnu.gcc.
  13. Comments on this service to emv@math.lsa.umich.edu (Edward Vielmetti).]
  14.  
  15.  
  16. I have received a few requests for making gcc into a cross compiler
  17. from the Sun4 (Host) to a Motorola 680X0 (Target) single-board
  18. computer.  We use gcc to generate code that we compile on a
  19. SPARCStation to run on our real time MVME 147 boards (68030 SBC).
  20. Here is a step by step procedure for doing this.
  21.  
  22. Note: I am trying to finish up my PhD dissertation, and I don't have a
  23. lot of time to help people with this.  If you can not get this to
  24. work, please do NOT ask me for help.  Sorry, but I have to finish up.
  25.  
  26. 1) You will need to get the latest copies of gcc (1.37.1), gas(1.35) and gld.
  27. 2) Make sure you have a working gcc compiler. Ours is in /local/bin.
  28. 3) Copy the scripts Makefile.cross and cross-config.gcc into
  29.    the main gcc directory. e.g. /usr/local/src/gcc/gcc.1.37.1.
  30. 4) type "cross-config.gcc sun4-os4 sun3-os4". This will set up the
  31.    correct symbolic links for you.
  32. 5) Edit Makefile.cross if you need to change directory paths.
  33. 6) Type make -f Makefile.cross  
  34.    Note: If you get an error making gnulib{2}, don't worry about it.
  35.    There is no good way that I know of on how to make a cross compiled
  36.    version of this.  Best to copy a version made on a Sun3 into 
  37.    DESTDIR.  Unless you use long long, you don't need gnulib2 anyway.
  38.    This should make the cross-compiler.
  39.  
  40. Now for the cross assembler and loader.
  41.  
  42. 7) Copy Makefile.gas into the gas directory and type
  43.    make -f Makefile.gas
  44. 8) Copy Makefile.gld into the gld directory. Type
  45.    make -f Makefile.gld
  46.    Warning: There were some problems with earlier versions of gld.  I think
  47.    that they were fixed. If not, get the latest ld from the g++ distribution.
  48.    I think our bug fixes were incorporated, but I'm not sure.  If gld does not
  49.    cross load, send me mail and I'll see what I can do.
  50.  
  51. 9) Copy your version of gcc into /usr/local/lib/sun4.  In this directory
  52.    should be:
  53.  
  54.    gcc-as        gcc-sun3-as
  55.    gcc           gcc-sun3-gcc
  56.    gcc-cc1       gcc-sun3-cc1
  57.    gcc-cpp       gcc-sun3-cpp
  58.    gcc-gnublib   gcc-sun3-gnulib <-- you have to make this on a Sun3
  59.                  gcc-sun3-ld
  60.  
  61.  
  62. copy gcc and gld (scripts at the end of this file) into /usr/local/bin.
  63.  
  64. 10) gld does not do dynamic loading.  You don't want this anyway for
  65.     your target  processor.  Also, ld does not know how to get to the 
  66.     C libraries such as libC.a.  Don't worry about this either, since
  67.     you will be using the ld -r option anyway.
  68.  
  69.     Also, don't forget to include the file math-68881.h if your
  70.     SBC has the math chip.  This file goes into ./gcc-include.
  71.  
  72. 11) To compile normally, just type
  73.  
  74.            gcc foo.c
  75.     To cross compile:
  76.         gcc -sun3 -c cross_foo.c 
  77.                 gld -sun3 -r -o cross_foo cross_foo.o
  78.    
  79. Good Luck !!
  80.  
  81.         
  82. Warren Jasper
  83. Stanford University
  84.  
  85. ______________________________________________________________________
  86. Makefile.cross:
  87.  
  88. # Makefile for GNU C cross-compiler.
  89. # Written by Warren J. Jasper  Stanford Univerity 1989
  90.  
  91. #Make sure you have a working gcc on your host machine in directory BINDIR
  92. #Run cross-config.gcc to set up the backend files.
  93.  
  94. BINDIR = /local/bin
  95. HOST_ARCH = sun4
  96. TARGET_ARCH = sun3
  97. PROGRAMS = gcc cpp cc1
  98. EXECUTABLES = $(PROGRAMS:%=gcc-$(TARGET_ARCH)-%)
  99.  
  100. DESTDIR = /usr/local/lib/$(HOST_ARCH)
  101. INSTALL_OPTIONS = -m 751 -g bin -s
  102.  
  103. $(PROGRAMS):
  104.     $(MAKE) CC=$(BINDIR)/gcc CFLAGS="-g -O"
  105.  
  106. install : $(PROGRAMS)
  107.     install $(INSTALL_OPTIONS) gcc $(DESTDIR)/gcc-$(TARGET_ARCH)-gcc
  108.     install $(INSTALL_OPTIONS) cpp $(DESTDIR)/gcc-$(TARGET_ARCH)-cpp
  109.     install $(INSTALL_OPTIONS) cc1 $(DESTDIR)/gcc-$(TARGET_ARCH)-cc1
  110.  
  111. clean:
  112.     $(MAKE) clean
  113.  
  114. ________________________________________________________________________
  115. cross-config.gcc:
  116.  
  117. #!/bin/sh
  118. # Cross-Configuration script for GNU CC version 1.37.1
  119. #  Modified by Warren J. Jasper  Stanford Univerity  1990
  120.  
  121.  
  122. #GNU CC is free software; you can redistribute it and/or modify
  123. #it under the terms of the GNU General Public License as published by
  124. #the Free Software Foundation; either version 1, or (at your option)
  125. #any later version.
  126.  
  127. #GNU CC is distributed in the hope that it will be useful,
  128. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  129. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  130. #GNU General Public License for more details.
  131.  
  132. #You should have received a copy of the GNU General Public License
  133. #along with GNU CC; see the file COPYING.  If not, write to
  134. #the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  135.  
  136. #
  137. # Shell script to create proper links to machine-dependent files in
  138. # preparation for cross-compiling gcc.
  139. #
  140. # Usage: cross-config.gcc [vint] Host_Machine Target_Machine
  141. #
  142. # If cross-config.gcc succeeds, it leaves its status in config.status.
  143. # If cross-config.gcc fails after disturbing the status quo,
  144. # config.status is removed.
  145. #
  146.  
  147. progname=$0
  148.  
  149. remove=/bin/rm
  150. hard_link=ln
  151. symbolic_link='ln -s'
  152.  
  153. #for Test
  154. #remove="echo rm"
  155. #hard_link="echo ln"
  156. #symbolic_link="echo ln -s"
  157.  
  158. case $# in
  159. 3)
  160.     vint=on
  161.     shift
  162.     ;;
  163. *)
  164.     ;;
  165. esac
  166.  
  167. case $# in
  168. 2)
  169.     Host_Machine=$1
  170.     shift
  171.     Target_Machine=$1
  172.  
  173.     case $Host_Machine in
  174.     sun4 | sun-4 | sun4-os3 | sun-4-os3)
  175.         host_cpu_type=sparc
  176.         configuration_file=xm-sparc.h
  177.         ;;
  178.     sun3 | sun-3 | sun3-os3 | sun-3-os3)
  179.         host_cpu_type=m68k
  180.         configuration_file=xm-m68k.h
  181.         ;;
  182.     sun3-nfp | sun-3-nfp | sun3-nfp-os3 | sun-3-nfp-os3)
  183.         host_cpu_type=m68k
  184.         configuration_file=xm-m68k.h
  185.         ;;
  186.     sun2 | sun-2 | sun2-os3 | sun-2-os3)
  187.         host_cpu_type=m68k
  188.         configuration_file=xm-m68k.h
  189.         ;;
  190.     sun386 | sun386i | roadrunner)
  191.         host_cpu_type=i386
  192.         configuration_file=xm-sun386i.h
  193.         ;;
  194.     sun4-os4 | sun-4-os4)
  195.         host_cpu_type=sparc
  196.         configuration_file=xm-sparc.h
  197.         ;;
  198.     sun3-os4 | sun-3-os4)
  199.         host_cpu_type=m68k
  200.         configuration_file=xm-m68k.h
  201.         ;;
  202.     sun3-nfp-os4 | sun-3-nfp-os4)
  203.         host_cpu_type=m68k
  204.         configuration_file=xm-68k.h
  205.         ;;
  206.     sun3-fpa-os4 | sun-3-fpa-os4)
  207.         host_cpu_type=m68k
  208.         configuration_file=xm-68k.h
  209.         ;;
  210.     sun2-os4 |sun-2-os4)
  211.         host_cpu_type=m68k
  212.         configuration_file=xm-sunos4.h
  213.         ;;
  214.     esac
  215.  
  216.     case $Target_Machine in
  217.     sun4 | sun-4 | sun4-os3 | sun-4-os3)
  218.         target_cpu_type=sparc
  219.         target_machine=tm-sun4os3.h
  220.         ;;
  221.     sun3 | sun-3 | sun3-os3 | sun-3-os3)
  222.         target_cpu_type=m68k
  223.         target_machine=tm-sun3os3.h
  224.         ;;
  225.     sun3-nfp | sun-3-nfp | sun3-nfp-os3 | sun-3-nfp-os3)
  226.         target_cpu_type=m68k
  227.         target_machine=tm-sun3os3nf.h
  228.         ;;
  229.     sun2 | sun-2 | sun2-os3 | sun-2-os3)
  230.         target_cpu_type=m68k
  231.         target_machine=tm-sun2.h
  232.         ;;
  233.     sun386 | sun386i | roadrunner)
  234.         target_cpu_type=i386
  235.         target_machine=tm-sun386i.h
  236.         ;;
  237.     sun4-os4 | sun-4-os4)
  238.         target_cpu_type=sparc
  239.         target_machine=tm-sparc.h
  240.         ;;
  241.     sun3-os4 | sun-3-os4)
  242.         target_cpu_type=m68k
  243.         target_machine=tm-sun3.h
  244.         ;;
  245.     sun3-nfp-os4 | sun-3-nfp-os4)
  246.         target_cpu_type=m68k
  247.         target_machine=tm-sun3-nfp.h
  248.         ;;
  249.     sun2-os4 |sun-2-os4)
  250.         target_cpu_type=m68k
  251.         target_machine=tm-sun2.h
  252.         ;;
  253.     esac
  254.  
  255.  
  256.         # if cpu_type is not set, define cpu_type to machine.
  257.         #
  258.     host_cpu_type=${host_cpu_type-$Host_Machine}
  259.     configuration_file=${configuration_file-xm-$host_cpu_type.h}
  260.     target_machine=${target_machine-tm-$Target_Machine.h}
  261.     machine_description=${target_cpu_type}.md
  262.     aux_output=${aux_output-out-$target_cpu_type.c}
  263.  
  264.     if [ xx${vint} = xx ]
  265.     then
  266.         files="$configuration_file $target_machine
  267.             $machine_description $aux_output"
  268.         links="config.h tm.h md aux-output.c"
  269.     else
  270.         files="$configuration_file tm-vmc.h $target_machine
  271.             $machine_description $aux_output"
  272.         links="config.h tm.h tm-pre.h md aux-output.c"
  273.     fi
  274.  
  275.     while [ -n "$files" ]
  276.     do
  277.         # set file to car of files, files to cdr of files
  278.         set $files; file=$1; shift; files=$*
  279.         set $links; link=$1; shift; links=$*
  280.  
  281.         if [ ! -r config/$file ]
  282.         then
  283.             echo "$progname: cannot create a link \`$link',"
  284.             echo "since the file \`config/$file' does not exist."
  285.             exit 1
  286.         fi
  287.  
  288.         $remove -f $link
  289.         rm -f config.status
  290.         # Make a symlink if possible, otherwise try a hard link
  291.         $symbolic_link config/$file $link 2>/dev/null || $hard_link config/$file $link
  292.  
  293.         if [ ! -r $link ]
  294.         then
  295.             echo "$progname: unable to link \`$link' to \`config/$file'."
  296.             exit 1
  297.         fi
  298.         echo "Linked \`$link' to \`config/$file'."
  299.     done
  300.  
  301.     if [ xx${vint} = xx ]
  302.     then
  303.       echo "Links are now set up for use with a $Host_Machine"\
  304.            "to cross compile on a $Target_Machine." \
  305.             | tee config.status
  306.     else
  307.       echo "Links are now set up for use with a $Host_Machine (vint) "\
  308.            "to cross compile on a $Ttarget_Machine (vint)." \
  309.             | tee config.status
  310.     fi
  311.     exit 0
  312.  
  313.     ;;
  314. *)
  315.     echo "Usage: $progname Host_Machine Target_Machine"
  316.     echo -n "Where \`Host_Machine' is something like "
  317.     echo "sun4-os4"
  318.     echo -n "And \`Target_Machine' is something like "
  319.     echo "sun3-os4"
  320.     if [ -r config.status ]
  321.     then
  322.         cat config.status
  323.     fi
  324.     exit 1
  325.     ;;
  326. esac
  327.  
  328. ________________________________________________________________________
  329. Makefile.gas:
  330.  
  331. #
  332. # Makefile for building gas cross assembler
  333. #
  334.  
  335. # Specify the host and target architectures
  336. HOST_ARCH = sun4
  337. TARGET_ARCH = sun3
  338.  
  339. # Set up Sun compatible cross-compilation options
  340. CROSS_COMPILE_FLAGS = -DSUN3=3 -DTARGET=SUN3
  341.  
  342. # Generate name of execuatable
  343. EXECUTABLE = gcc-$(TARGET_ARCH)-as
  344.  
  345. # Generate path to executable
  346. TARGET_DIR = $(HOST_ARCH)
  347. DESTDIR = /usr/local/lib/$(TARGET_DIR)
  348.  
  349. INSTALL_OPTIONS = -m 751 -g bin -s
  350.  
  351. CC = gcc
  352. CFLAGS = -O -g $(CROSS_COMPILE_FLAGS)
  353.  
  354. $(EXECUTABLE) :
  355.     ln -s m-sun3.h m68k.h
  356.     make a68
  357.     mv a68 $@
  358.  
  359. install : $(EXECUTABLE)
  360.     install $(INSTALL_OPTIONS) $(EXECUTABLE) $(DESTDIR)
  361. _______________________________________________________________________
  362. Makefile.gld
  363.  
  364. #
  365. # Makefile for building gld cross loader
  366. #
  367.  
  368. # Specify the host and target architectures
  369. HOST_ARCH = sun4
  370. TARGET_ARCH = sun3
  371.  
  372. # Set up Sun compatible cross-compilation options
  373. CROSS_COMPILE_FLAGS = -DSUN3=3 -DTARGET=SUN3
  374.  
  375. # Generate name of execuatable
  376. EXECUTABLE = gcc-$(TARGET_ARCH)-ld
  377.  
  378. # Generate path to executable
  379. TARGET_DIR = $(HOST_ARCH)
  380. DESTDIR = /usr/local/lib/$(TARGET_DIR)
  381.  
  382. INSTALL_OPTIONS = -m 751 -g bin -s
  383.  
  384. CC = gcc
  385. CFLAGS = -O -g $(CROSS_COMPILE_FLAGS)
  386.  
  387. $(EXECUTABLE) : gld.c
  388.     $(CC) $(CFLAGS) -o $@ $?
  389.  
  390. install : $(EXECUTABLE)
  391.     install $(INSTALL_OPTIONS) $(EXECUTABLE) $(DESTDIR)
  392. ______________________________________________________________________
  393. gcc:
  394.  
  395. #! /bin/csh -f
  396. #
  397. #   Name:
  398. #    gcc    front-end driver script for GNU C compiler
  399. #
  400. #    gcc  [ -target_arch ] [ gcc_options ]  files
  401. #
  402. #   Description:
  403. #    Provides support for Sun compatible cross-compilation via the
  404. #    -TARGET_ARCH command line option.
  405. #
  406. #   Files:
  407. #    /local/lib/ARCH/gcc        Files used for native compilation
  408. #    /local/lib/ARCH/gcc-cpp
  409. #    /local/lib/ARCH/gcc-cc1
  410. #    /local/lib/ARCH/gcc-as
  411. #    /local/lib/ARCH/gcc-ld
  412. #
  413. #    /local/lib/sun4/gcc-sun3-gcc    Files used for cross compilation
  414. #    /local/lib/sun4/gcc-sun3-cpp
  415. #    /local/lib/sun4/gcc-sun3-cc1
  416. #    /local/lib/sun4/gcc-sun3-as
  417. #    /local/lib/sun4/gcc-sun3-ld
  418. #
  419. #   Written by:    Marc Ullman & Stan Schneider, Stanford    Nov  3, 1989
  420. #
  421. #   Revision History:
  422. #   Ver. 1.01,    Warren Jasper, Stanford    University    Jan 10, 1989
  423. #    Include 68881 for cross compilation.
  424. #__________________________________________________________________________
  425.  
  426.  
  427. #begin
  428.     set target      = ""
  429.     set argumemts = ( )
  430.  
  431.     while ( $#argv > 0  )
  432.     if ( "$argv[1]" =~ -sun* ) then
  433.         set target = $argv[1]
  434.     else
  435.         set argumemts = ( $argumemts $argv[1] )
  436.     endif
  437.     shift
  438.     end #while
  439.  
  440.     if ( "$target" == "-sun3"  &&  `arch` == "sun4" ) then
  441.     exec /local/lib/$ARCH/gcc-sun3-gcc \
  442.         -B/local/lib/$ARCH/gcc-sun3- \
  443.         -m68020 -m68881 -D__HAVE_68881__ $argumemts
  444.     else
  445.     exec /local/lib/$ARCH/gcc  $argumemts
  446.     endif
  447. #end.
  448.  
  449. _______________________________________________________________________
  450. gld:
  451.  
  452.  
  453. #! /bin/csh -f
  454. # NAME
  455. #    gld - Front-end driver script for GNU link/loader.
  456. #
  457. # DESCRIPTION:
  458. #    Provides support for cross-compilation via the -TARGET_ARCH
  459. #    command line option.
  460. #
  461. # FILES:
  462. #    /usr/bin/ld            Files used for native compilation
  463. #
  464. #    /local/lib/sun4/gcc-sun3-ld    Files used for cross compilation
  465. #
  466. # WRITTEN:
  467. #    Marc Ullman, Stan Schneider            Dec. 25, 1989
  468. #
  469.  
  470.     set target     = FALSE
  471.     set params
  472.  
  473.     while ( $#argv > 0  )
  474.     if ( "$argv[1]" =~ -sun* ) then
  475.         set target = $argv[1]
  476.     else
  477.         set params = ($params $argv[1] )
  478.     endif
  479.     shift
  480.     end #while
  481.  
  482. if ($target == "-sun3" && `arch` == "sun4") then
  483.     exec /local/lib/$ARCH/gcc-sun3-ld  $params
  484. else
  485.     exec ld $params
  486. endif
  487.