Blame doc/README.Mac

Packit d28291
The contents of this file are old and pertain to pre-MacOSX versions.
Packit d28291
You probably really wanted README.darwin.
Packit d28291
Packit d28291
---------------------------------------------
Packit d28291
Packit d28291
Patrick Beard's Notes for building GC v4.12 with CodeWarrior Pro 2:
Packit d28291
----------------------------------------------------------------------------
Packit d28291
The current build environment for the collector is CodeWarrior Pro 2.
Packit d28291
Projects for CodeWarrior Pro 2 (and for quite a few older versions)
Packit d28291
are distributed in the file Mac_projects.sit.hqx. The project file
Packit d28291
:Mac_projects:gc.prj builds static library versions of the collector.
Packit d28291
:Mac_projects:gctest.prj builds the GC test suite.
Packit d28291
Packit d28291
Configuring the collector is still done by editing the file
Packit d28291
:extra:Mac_files:MacOS_config.h.
Packit d28291
Packit d28291
Lars Farm's suggestions on building the collector:
Packit d28291
----------------------------------------------------------------------------
Packit d28291
Garbage Collection on MacOS - a manual 'MakeFile'
Packit d28291
-------------------------------------------------
Packit d28291
Packit d28291
Project files and IDE's are great on the Macintosh, but they do have
Packit d28291
problems when used as distribution media. This note tries to provide
Packit d28291
porting instructions in pure TEXT form to avoid those problems. A manual
Packit d28291
'makefile' if you like.
Packit d28291
Packit d28291
    GC version:     4.12a2
Packit d28291
    Codewarrior:    CWPro1
Packit d28291
    date:           18 July 1997
Packit d28291
Packit d28291
The notes may or may not apply to earlier or later versions of the
Packit d28291
GC/CWPro. Actually, they do apply to earlier versions of both except that
Packit d28291
until recently a project could only build one target so each target was a
Packit d28291
separate project. The notes will most likely apply to future versions too.
Packit d28291
Possibly with minor tweaks.
Packit d28291
Packit d28291
This is just to record my experiences. These notes do not mean I now
Packit d28291
provide a supported port of the GC to MacOS. It works for me. If it works
Packit d28291
for you, great. If it doesn't, sorry, try again...;-) Still, if you find
Packit d28291
errors, please let me know.
Packit d28291
Packit d28291
Packit d28291
Porting to MacOS is a bit more complex than it first seems. Which MacOS?
Packit d28291
68K/PowerPC? Which compiler? Each supports both 68K and PowerPC and offer a
Packit d28291
large number of (unique to each environment) compiler settings. Each
Packit d28291
combination of compiler/68K/PPC/settings require a unique combination of
Packit d28291
standard libraries. And the IDE's does not select them for you. They don't
Packit d28291
even check that the library is built with compatible setting and this is
Packit d28291
the major source of problems when porting the GC (and otherwise too).
Packit d28291
Packit d28291
You will have to make choices when you configure the GC. I've made some
Packit d28291
choices here, but there are other combinations of settings and #defines
Packit d28291
that work too.
Packit d28291
Packit d28291
As for target settings the major obstacles may be:
Packit d28291
- 68K Processor: check "4-byte Ints".
Packit d28291
- PPC Processor: uncheck "Store Static Data in TOC".
Packit d28291
Packit d28291
What you need to do:
Packit d28291
1) Build the GC as a library
Packit d28291
2) Test that the library works with 'test.c'.
Packit d28291
3) Test that the C++ interface 'gc_cpp.cc/h' works with 'test_cpp.cc'.
Packit d28291
Packit d28291
== 1. The Libraries ==
Packit d28291
Packit d28291
I made one project with four targets (68K/PPC tempmem or appheap). One target
Packit d28291
will suffice if you're able to decide which one you want. I wasn't...
Packit d28291
Packit d28291
Codewarrior allows a large number of compiler/linker settings. I used these:
Packit d28291
Packit d28291
Settings shared by all targets:
Packit d28291
------------------------------
Packit d28291
o Access Paths:
Packit d28291
  - User Paths:   the GC folder
Packit d28291
  - System Paths: {Compiler}:Metrowerks Standard Library:
Packit d28291
                  {Compiler}:MacOS Support:Headers:
Packit d28291
                  {Compiler}:MacOS Support:MacHeaders:
Packit d28291
o C/C++ language:
Packit d28291
  - inlining: normal
Packit d28291
  - direct to SOM: off
Packit d28291
  - enable/check: exceptions, RTTI, bool (and if you like pool strings)
Packit d28291
Packit d28291
PowerPC target settings
Packit d28291
-----------------------
Packit d28291
o Target Settings:
Packit d28291
  - name of target
Packit d28291
  - MacOS PPC Linker
Packit d28291
o PPC Target
Packit d28291
  - name of library
Packit d28291
o C/C++ language
Packit d28291
  - prefix file as described below
Packit d28291
o PPC Processor
Packit d28291
  - Struct Alignment: PowerPC
Packit d28291
  - uncheck "Store Static Data in TOC" -- important!
Packit d28291
    I don't think the others matter, I use full optimization and it is OK
Packit d28291
o PPC Linker
Packit d28291
  - Factory Settings (SYM file with full paths, faster linking, dead-strip
Packit d28291
    static init, Main: __start)
Packit d28291
Packit d28291
Packit d28291
68K target settings
Packit d28291
-------------------
Packit d28291
o Target Settings:
Packit d28291
  - name of target
Packit d28291
  - MacOS 68K Linker
Packit d28291
o 68K Target
Packit d28291
  - name of library
Packit d28291
  - A5 relative data
Packit d28291
o C/C++ language
Packit d28291
  - prefix file as described below
Packit d28291
o 68K Processor
Packit d28291
  - Code model: smart
Packit d28291
  - Struct alignment: 68K
Packit d28291
  - FP: SANE
Packit d28291
  - enable 4-Byte Ints -- important!
Packit d28291
    I don't think the others matter. I selected...
Packit d28291
  - enable: 68020
Packit d28291
  - enable: global register allocation
Packit d28291
o IR Optimizer
Packit d28291
  - enable: Optimize Space, Optimize Speed
Packit d28291
    I suppose the others would work too, but haven't tried...
Packit d28291
o 68K Linker
Packit d28291
  - Factory Settings (New Style MacsBug, SYM file with full paths,
Packit d28291
    A6 Frames, fast link, Merge compiler glue into segment 1,
Packit d28291
    dead-strip static init)
Packit d28291
Packit d28291
Prefix Files to configure the GC sources
Packit d28291
----------------------------------------
Packit d28291
The Codewarrior equivalent of command-line compilers -DNAME=X is to use
Packit d28291
prefix-files. A TEXT file that is automatically #included before the first byte
Packit d28291
of every source file. I used these:
Packit d28291
Packit d28291
---- ( cut here ) ----  gc_prefix_tempmem.h     -- 68K and PPC -----
Packit d28291
    #include "gc_prefix_common.h"
Packit d28291
    #undef USE_TEMPORARY_MEMORY
Packit d28291
    #define USE_TEMPORARY_MEMORY
Packit d28291
---- ( cut here ) ----  gc_prefix_appmem.h      -- 68K and PPC -----
Packit d28291
    #include "gc_prefix_common.h"
Packit d28291
    #undef USE_TEMPORARY_MEMORY
Packit d28291
//  #define USE_TEMPORARY_MEMORY
Packit d28291
Packit d28291
---- ( cut here ) ----  gc_prefix_common.h      --------------------
Packit d28291
// gc_prefix_common.h
Packit d28291
// ------------------
Packit d28291
// Codewarrior prefix file to configure the GC libraries
Packit d28291
//
Packit d28291
//   prefix files are the Codewarrior equivalent of the
Packit d28291
//   command line option -Dname=x frequently seen in makefiles
Packit d28291
Packit d28291
#if !__MWERKS__
Packit d28291
  #error only tried this with Codewarrior
Packit d28291
#endif
Packit d28291
Packit d28291
#if macintosh
Packit d28291
  #define MSL_USE_PRECOMPILED_HEADERS 0
Packit d28291
  #include <ansi_prefix.mac.h>
Packit d28291
Packit d28291
  //  See list of #defines to configure the library in: 'MakeFile'
Packit d28291
  //  see also README
Packit d28291
Packit d28291
  #define ALL_INTERIOR_POINTERS // follows interior pointers.
Packit d28291
//#define DONT_ADD_BYTE_AT_END  // disables the padding if defined.
Packit d28291
//#define SMALL_CONFIG          // whether to use a smaller heap.
Packit d28291
  #define GC_ATOMIC_UNCOLLECTABLE // GC_malloc_atomic_uncollectable()
Packit d28291
Packit d28291
  // define either or none as per personal preference
Packit d28291
  //   used in malloc.c
Packit d28291
  #define REDIRECT_MALLOC GC_malloc
Packit d28291
//#define REDIRECT_MALLOC GC_malloc_uncollectable
Packit d28291
  // if REDIRECT_MALLOC is #defined make sure that the GC library
Packit d28291
  // is listed before the ANSI/ISO libs in the Codewarrior
Packit d28291
  // 'Link order' panel
Packit d28291
//#define IGNORE_FREE
Packit d28291
Packit d28291
  // mac specific configs
Packit d28291
//#define USE_TEMPORARY_MEMORY    // use Macintosh temporary memory.
Packit d28291
//#define SHARED_LIBRARY_BUILD    // build for use in a shared library.
Packit d28291
Packit d28291
#else
Packit d28291
  // could build Win32 here too, or in the future
Packit d28291
  // Rhapsody PPC-mach, Rhapsody PPC-MacOS,
Packit d28291
  // Rhapsody Intel-mach, Rhapsody Intel-Win32,...
Packit d28291
  // ... ugh this will get messy ...
Packit d28291
#endif
Packit d28291
Packit d28291
// make sure ints are at least 32-bit
Packit d28291
// ( could be set to 16-bit by compiler settings (68K) )
Packit d28291
Packit d28291
struct gc_private_assert_intsize_{ char x[ sizeof(int)>=4 ? 1 : 0 ]; };
Packit d28291
Packit d28291
#if __powerc
Packit d28291
  #if __option(toc_data)
Packit d28291
    #error turn off "store static data in TOC" when using GC
Packit d28291
    //     ... or find a way to add TOC to the root set...(?)
Packit d28291
  #endif
Packit d28291
#endif
Packit d28291
---- ( cut here ) ----  end of gc_prefix_common.h  -----------------
Packit d28291
Packit d28291
Files to  build the GC libraries:
Packit d28291
--------------------------------
Packit d28291
    allchblk.c
Packit d28291
    alloc.c
Packit d28291
    blacklst.c
Packit d28291
    checksums.c
Packit d28291
    dbg_mlc.c
Packit d28291
    finalize.c
Packit d28291
    headers.c
Packit d28291
    mach_dep.c
Packit d28291
    MacOS.c    -- contains MacOS code
Packit d28291
    malloc.c
Packit d28291
    mallocx.c
Packit d28291
    mark.c
Packit d28291
    mark_rts.c
Packit d28291
    misc.c
Packit d28291
    new_hblk.c
Packit d28291
    obj_map.c
Packit d28291
    os_dep.c   -- contains MacOS code
Packit d28291
    ptr_chck.c
Packit d28291
    reclaim.c
Packit d28291
    stubborn.c
Packit d28291
    typd_mlc.c
Packit d28291
    gc++.cc    -- this is 'gc_cpp.cc' with less 'inline' and
Packit d28291
               -- throw std::bad_alloc when out of memory
Packit d28291
               -- gc_cpp.cc works just fine too
Packit d28291
Packit d28291
== 2. Test that the library works with 'test.c' ==
Packit d28291
Packit d28291
The test app is just an ordinary ANSI-C console app. Make sure settings
Packit d28291
match the library you're testing.
Packit d28291
Packit d28291
Files
Packit d28291
-----
Packit d28291
    test.c
Packit d28291
    the GC library to test        -- link order before ANSI libs
Packit d28291
    suitable Mac+ANSI libraries
Packit d28291
Packit d28291
prefix:
Packit d28291
------
Packit d28291
---- ( cut here ) ----  gc_prefix_testlib.h     -- all libs -----
Packit d28291
#define MSL_USE_PRECOMPILED_HEADERS 0
Packit d28291
#include <ansi_prefix.mac.h>
Packit d28291
#undef NDEBUG
Packit d28291
Packit d28291
#define ALL_INTERIOR_POINTERS   /* for GC_priv.h */
Packit d28291
---- ( cut here ) ----
Packit d28291
Packit d28291
== 3. Test that the C++ interface 'gc_cpp.cc/h' works with 'test_cpp.cc' ==
Packit d28291
Packit d28291
The test app is just an ordinary ANSI-C console app. Make sure settings match
Packit d28291
the library you're testing.
Packit d28291
Packit d28291
Files
Packit d28291
-----
Packit d28291
    test_cpp.cc
Packit d28291
    the GC library to test        -- link order before ANSI libs
Packit d28291
    suitable Mac+ANSI libraries
Packit d28291
Packit d28291
prefix:
Packit d28291
------
Packit d28291
same as for test.c
Packit d28291
Packit d28291
For convenience I used one test-project with several targets so that all
Packit d28291
test apps are build at once. Two for each library to test: test.c and
Packit d28291
gc_app.cc. When I was satisfied that the libraries were OK. I put the
Packit d28291
libraries + gc.h + the c++ interface-file in a folder that I then put into
Packit d28291
the MSL hierarchy so that I don't have to alter access-paths in projects
Packit d28291
that use the GC.
Packit d28291
Packit d28291
After that, just add the proper GC library to your project and the GC is in
Packit d28291
action! malloc will call GC_malloc and free GC_free, new/delete too. You
Packit d28291
don't have to call free or delete. You may have to be a bit cautious about
Packit d28291
delete if you're freeing other resources than RAM. See gc_cpp.h. You can
Packit d28291
also keep coding as always with delete/free. That works too. If you want,
Packit d28291
include "gc.h" and tweak its use a bit.
Packit d28291
Packit d28291
== Symantec SPM ==
Packit d28291
Packit d28291
It has been a while since I tried the GC in SPM, but I think that the above
Packit d28291
instructions should be sufficient to guide you through in SPM too. SPM
Packit d28291
needs to know where the global data is. Use the files 'datastart.c' and
Packit d28291
'dataend.c'. Put 'datastart.c' at the top of your project and 'dataend.c'
Packit d28291
at the bottom  of your project so that all data is surrounded. This is not
Packit d28291
needed in Codewarrior because it provides intrinsic variables
Packit d28291
__datastart__, __data_end__ that wraps all globals.
Packit d28291
Packit d28291
== Source Changes (GC 4.12a2) ==
Packit d28291
Packit d28291
Very few. Just one tiny in the GC, not strictly needed.
Packit d28291
- test_cpp.cc
Packit d28291
  made the first lines of main() look like this:
Packit d28291
  ------------
Packit d28291
  int main( int argc, char* argv[] ) {
Packit d28291
  #endif
Packit d28291
  #if macintosh                             // MacOS
Packit d28291
    char* argv_[] = {"test_cpp","10"};      //   doesn't
Packit d28291
    argv=argv_;                             //     have a
Packit d28291
    argc = sizeof(argv_)/sizeof(argv_[0]);  //       commandline
Packit d28291
  #endif                                    //
Packit d28291
Packit d28291
  int i, iters, n;
Packit d28291
  # ifndef __GNUC__
Packit d28291
   alloc dummy_to_fool_the_compiler_into_doing_things_it_currently_cant_handle;
Packit d28291
  ------------
Packit d28291
Packit d28291
- config.h [now gcconfig.h]
Packit d28291
  __MWERKS__ does not have to mean MACOS. You can use Codewarrior to
Packit d28291
  build a Win32 or BeOS library and soon a Rhapsody library. You may
Packit d28291
  have to change that #if...
Packit d28291
Packit d28291
Packit d28291
Packit d28291
   It worked for me, hope it works for you.
Packit d28291
Packit d28291
   Lars Farm
Packit d28291
----------------------------------------------------------------------------
Packit d28291
Packit d28291
Packit d28291
Patrick Beard's instructions (may be dated):
Packit d28291
Packit d28291
v4.3 of the collector now runs under Symantec C++/THINK C v7.0.4, and
Packit d28291
Metrowerks C/C++ v4.5 both 68K and PowerPC. Project files are provided
Packit d28291
to build and test the collector under both development systems.
Packit d28291
Packit d28291
Configuration
Packit d28291
-------------
Packit d28291
Packit d28291
To configure the collector, under both development systems, a prefix file
Packit d28291
is used to set preprocessor directives. This file is called "MacOS_config.h".
Packit d28291
Packit d28291
Testing
Packit d28291
-------
Packit d28291
Packit d28291
To test the collector (always a good idea), build one of the gctest projects,
Packit d28291
gctest. (Symantec C++/THINK C), mw/gctest.68K, or mw/gctest.PPC.  The
Packit d28291
test will ask you how many times to run; 1 should be sufficient.
Packit d28291
Packit d28291
Building
Packit d28291
--------
Packit d28291
Packit d28291
For your convenience project files for the major Macintosh development
Packit d28291
systems are provided.
Packit d28291
Packit d28291
For Symantec C++/THINK C, you must build the two projects gclib-1 and
Packit d28291
gclib-2. It has to be split up because the collector has more than 32k
Packit d28291
of static data and no library can have more than this in the Symantec
Packit d28291
environment. (Future versions will probably fix this.)
Packit d28291
Packit d28291
For Metrowerks C/C++ 4.5 you build gc.68K/PPC and the result will
Packit d28291
be a library called gc.68K.lib/gc.PPC.lib.
Packit d28291
Packit d28291
Using
Packit d28291
-----
Packit d28291
Packit d28291
Under Symantec C++/THINK C, you can just add the gclib-1 and gclib-2
Packit d28291
projects to your own project. Under Metrowerks, you add gc.68K.lib or
Packit d28291
gc.PPC.lib and two additional files. You add the files called datastart.c
Packit d28291
and dataend.c to your project, bracketing all files that use the collector.
Packit d28291
See mw/gctest for an example.
Packit d28291
Packit d28291
Include the projects/libraries you built above into your own project,
Packit d28291
#include "gc.h", and call GC_malloc. You don't have to call GC_free.
Packit d28291
Packit d28291
Patrick C. Beard