From: corey@milton.u.washington.edu (Corey Satten)
Newsgroups: comp.sys.3b1
Subject: checkout cross-compiling for 3b1
Date: 14 Apr 92 03:24:41 GMT
Reply-To: corey@cac.washington.edu
Organization: University of Washington, Seattle

: ----- cut here ----- cut here ----- cut here ----- cut here -----
: This is a "shell archive".  Save everything after the cut mark
: in a file called thisstuff, then feed it to sh by typing sh thisstuff.
: SHAR archive format.  Archive created Mon Apr 13 20:13:04 PDT 1992
echo x - READ_ME
echo '-rw-r--r--  1 corey       4854 Apr 13 20:13 READ_ME    (as sent)'
sed 's/^-//' >READ_ME <<'+FUNKY+STUFF+'
-
-
- Sorry this is rather rough, I have been delaying posting it in hopes of
- cleaning it up, but now I think I'd better just post asis.  If you don't
- understand how to take it the rest of the way, I'm sorry.  Hopefully
- someone else will like the idea and run with it.
-
- There has been recent discussion in this group about cross-compiling to
- .o files with the GNU compiler/assembler and this is great (although I
- can't get it to work -- the cross assembled .o files are reported to have
- invalid relocation bits when I try to link them on a 3b1).  However, here
- is another way of using fast machines to help with porting software to
- slow ones (such as the 3b1).
-
- In my experience, most of the pain in porting something big to something
- slow is the repeated iterating with the slow compiler/linker.  If something
- would simply compile the first time, unattended, it wouldn't be so terrible
- to just walk away and let it happen.
-
- In this posting, I propose a way of using gcc on a fast/modern workstation
- to do all but the final iteration of that cycle -- including the linking.
-
- The first thing to notice is that a native gcc on a workstation already
- has the necessary command-line options to disassociate itself from the
- native /usr/include files and #defines and to examine instead a tree of
- 3b1 include files:
-
- gcc -nostdinc -nostdlib -I. -I- -I/3b1/include -Dmc68k -Umc68000 -Dunix etc.
-
- Thus, check-out compiling as far as .o files, comes essentially for free
- if you have gcc on a workstation.
-
- The next observation is that as long as we aren't going to run the
- cross-compiled binary on the workstation anyway, it doesn't matter what
- library code we link with, as long as it has the same topology as the 3b1
- library (so we can debug the link phase and resolve the undefined
- references).  It turns out to be quite easy to make a fake 3b1 library
- from the name-lists of the 3b1 libraries.  The fake library need only
- define and reference the same symbols in the same files as the real 3b1
- libraries.
-
- These fake libraries can be linked on the workstation and theoretically,
- once a successful link is achieved on the workstation, the source should
- compile and link without hitch on the 3b1.
-
- I used the following tools (enclosed) to make my fake libraries for a NeXT:
-
-         nx              - a script to run nm and postprocess the coff format
-                           output into something like v7/BSD format nm output.
-                           This gets used on the 3b1 to make *.t files from
-                           *.o and *.a files.
-
- < *.t files are then uploaded to the workstation >
-
-         symtab-to-c     - a perl script to take a bunch of lib.t files
-                           (table of contents files in nx output format)
-                           and turn them into subdirectories of *.c files
-                           each directory named after the *.a library file
-                           the *.t file represents.
-
-         c-to-ar         - a shell script to compile all the *.c files
-                           into .o files and ar them into fake libraries.
-                           (note, it moves the final *.a files into .. since
-                           there are directories in . named *.a.  (As I
-                           said, it needs cleaning up.)
-
- The libraries you get at this point are complete as far as the 3b1 is
- concerned, but don't have any of the internal (compiler support) routines
- your native gcc may need to do floating point or whatnot.  You can either
- ignore any unresolved references they generate, or generate another fake
- library to resolve them, or copy them from your workstation's native
- library if you can find them.  So far, I've just ignored them.
-
- Unless you want to change the scripts, I think you need to run
-     symtab-to-c *.t
- from a subdirectory of where you eventually want the fake libraries to
- live.  It creates a bunch of *.a subdirs which eventually get removed
- after the libraries are built by
-     c-to-ar
- I didn't put a lot of energy into making this pretty, I just did it one
- day to see how it worked and quit when I got the libraries.  Therefore,
- you are encouraged to read and understand what the scripts are doing before
- you run them.
-
- Once you have the fake libraries, it's just a matter of using a script
- to invoke gcc with the fake libraries.  My script is called ccc, (checkout
- c compiler).
-
- One other thing to note:
-
- There is a boolean in symtab-to-c which somewhat works around NeXT's
- linker's unwillingness to handle bss symbols the way most linkers do.
- The workaround moves them into the data segment.  NeXT has since informed
- me that ranlib -c might eliminate the problem but I haven't tried it yet.
- Set NeXTbug = 1 to use the workaround.
-
- Happy compiling.
-
- Corey Satten, corey@cac.washington.edu
+FUNKY+STUFF+
chmod u=rw,g=r,o=r READ_ME
ls -l READ_ME
echo x - c-to-ar
echo '-rwxr-xr-x  1 corey        268 Mar  3 14:31 c-to-ar    (as sent)'
sed 's/^-//' >c-to-ar <<'+FUNKY+STUFF+'
-#!/bin/sh
-
-for d in *.a; do (cd $d && cc -c -pipe *.c); done
-for d in *.a; do (cd $d && ar q $d *.o); done
-(cd libc.a && ar d libc.a fakcu.o)
-(cd libc.a&&echo '_end(){}'>end.c&&cc -c end.c&&ar q libc.a end.o&&rm end.[co])
-ranlib *.a/*.a
-mv *.a/*.a ..
-rm -rf *.a *.a.c
+FUNKY+STUFF+
chmod u=rwx,g=rx,o=rx c-to-ar
ls -l c-to-ar
echo x - ccc
echo '-rwxr-xr-x  1 corey        655 Apr 13 11:10 ccc    (as sent)'
sed 's/^-//' >ccc <<'+FUNKY+STUFF+'
-#!/bin/sh
-#
-# NeXT CC as 3b1 checkout C compiler - requires faked libraries
-#
-# probable uses:
-#	$0 [flags] files.c -lc_s
-#	$0 [flags] files.c -lc -ltermcap -lc
-
-ROOT=/3b1
-LIBS=$ROOT/xlib
-DEFS="-Dmc68k -Umc68000 -UNeXT -Dunix -U__MACH__"
-
-for i in $*; do
-    case "$i" in
-	-[csE])	nlink=1;;
-	-lc*)	libs=1;;
-    esac
-done
-
-case "$nlink/$libs" in
-    1*)  cc $DEFS -pipe -nostdinc -nostdlib -I. -I- -I$ROOT/include \
-	   -L$LIBS "$@" ;;
-    /1)  cc $DEFS -pipe -nostdinc -nostdlib -I. -I- -I$ROOT/include \
-	   -L$LIBS $LIBS/crt0.o "$@" ;;
-    /)   cc $DEFS -pipe -nostdinc -nostdlib -I. -I- -I$ROOT/include \
-	   -L$LIBS $LIBS/crt0s.o "$@" -lc_s;;
-esac
-
-
-
+FUNKY+STUFF+
chmod u=rwx,g=rx,o=rx ccc
ls -l ccc
echo x - nx
echo '-rwxr-xr-x  1 corey       1174 Mar  2 13:31 nx    (as sent)'
sed 's/^-//' >nx <<'+FUNKY+STUFF+'
-: '
-: A postprocessor for common object format nm output which is:
-:   1 - sortable
-:   2 - grepable for a symbol to file mapping
-:   3 - less cluttered and more aligned with the unix philosophy
-:
-: Usage: nx options files
-:	options passed directly to nm
-:
-: This program is hereby officially introduced into the public domain.
-:	Corey Satten,  fluke!corey,  Feb. 20, 1986
-: '
-
-STANDARD_NM=/bin/nm
-FLAGS=-e
-for i in $* ;do
-    case "$i" in
-	-*) FLAGS="$FLAGS $i"; shift;;
-	*)  break;;
-	esac
-    done
-for FILE in $* ;do
-    $STANDARD_NM $FLAGS $FILE |
-    /bin/sed -n '
-    1 {
-	h
-	s|.*|'"$FILE"'|
-	x
-	}
-    /^Symbols from \([^:]*\):$/ {
-	s//\1/
-	h
-	b noprint
-	}
-    /|static|/ {
-	/|\.text/s/^\([^|]*\)|\([^|]*\).*/\1 t \2/
-	/|\.data/s/^\([^|]*\)|\([^|]*\).*/\1 d \2/
-	/|\.bss/ s/^\([^|]*\)|\([^|]*\).*/\1 b \2/
-	t print
-	s/^\([^|]*\)|\([^|]*\).*/\1 U \2/
-	t print
-	}
-    /|extern|/ {
-	/|\.text/s/^\([^|]*\)|\([^|]*\).*/\1 T \2/
-	/|\.data/s/^\([^|]*\)|\([^|]*\).*/\1 D \2/
-	/|\.bss/ s/^\([^|]*\)|\([^|]*\).*/\1 B \2/
-	s/^\([^|]*\)|\([ 0]*\)|.*/\1 U \2/
-	s/^\([^|]*\)|\([^|]*\).*/\1 C \2/
-	t print
-	}
-
-    b noprint
-    : print
-    G; s/\n/  /; p
-    : noprint
-    '
-    done
+FUNKY+STUFF+
chmod u=rwx,g=rx,o=rx nx
ls -l nx
echo x - symtab-to-c
echo '-rwxr-xr-x  1 corey       1882 Apr 13 11:16 symtab-to-c    (as sent)'
sed 's/^-//' >symtab-to-c <<'+FUNKY+STUFF+'
-
-#! /usr/local/bin/perl
-eval 'exec perl -S $0 ${1+"$@"} ;' unless 1;
-#
-# Convert nx output from COFF libraries and .o files to C syntax
-# which can be re-compiled and re-ar'd on a different host for
-# purposes of doing checkout linking only.
-#
-# Usage: symtab-to-c *.t
-#
-# Results in lots of *.a subdirs; each with one .c file for each .o file
-# in the original archive.  You should then:
-#
-#    sh -c 'for d in *.a; do (cd $d && cc -c *.c); done'
-#    sh -c 'for d in *.a; do (cd $d && ar q $d *.o); done'
-#    ranlib *.a/*.a
-#
-# Corey Satten, corey@cac.washington.edu, 3/1/92
-
-# define NeXTbug on NeXT 2.1 because common symbols in libs aren't right
-$NeXTbug = 0;
-
-while (<>) {
-    ($sym, $typ, $val, $member) = split(" ");
-    if ($member ne $omember) {
-	do emit();			# emit refs,defs for this .o file
-	if ($omember) {close(OFILE);}
-	@ref = @com = @def = ();
-	$omember = $member;
-	if ($member =~ /(.*)\[(.+)\.o\]/) {
-	    $dir = $1; $file = $2;	# get next archive/member name
-	    }
-	else {
-	    $dir = "."; $file=$member;	# or just filename is not archive
-	    }
-	mkdir($dir, 0755) if (! -d $dir);
-	open(OFILE, ">$dir/$file.c");
-	}
-    if ($typ eq "U")        {push(@ref, $sym);}	# global refs
-    elsif ($typ eq "C")     {push(@com, $sym);}	# global commons
-    elsif ($typ !~ /[tdb]/) {push(@def, $sym);}	# global defines
-    }
-do emit();
-
-sub emit {
-	for ($i=0; $i<=$#com; ++$i) {	# commons become int name;
-	    printf OFILE ("int %s%s;\n", $com[$i], $NeXTbug ? "=0" : "");
-	    }
-	for ($i=0; $i<$#def; ++$i) {	# all-1 defs become name(){};
-	    printf OFILE ("%s(){};\n", $def[$i]);
-	    }
-	# last def becomes name(){	   				     #}
-	printf OFILE ("%s(){\n", $#def>=0 ? $def[$#def] : "static dummy");   #}
-	for ($i=0; $i<=$#ref; ++$i) {	# and all the refs: name();
-	    printf OFILE ("\t%s();\n", $ref[$i]);
-	    }
-	printf OFILE ("}\n");		# finally close brace		     #{
-	}
+FUNKY+STUFF+
chmod u=rwx,g=rx,o=rx symtab-to-c
ls -l symtab-to-c
exit 0
Xref: sparky comp.sys.3b1:1981 comp.sys.att:1272 comp.unix.wizards:2175