chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] Mingw Makefile and Instructions


From: Patrick Brannan
Subject: [Chicken-users] Mingw Makefile and Instructions
Date: Tue, 28 Feb 2006 21:45:12 -0600

I tried to send this a couple of days ago, but apparently the entire message was too big... might have been because of forwards. Anyway, this is how I got chicken 2.3 running with MINGW.

Patrick

=====================================================================
Building Chicken With Mingw and Msys

Chicken Version 2.3

======================================================================
Mingw Setup

Mingw Packages - http://www.mingw.org/download.shtml
      mingw-runtime-3.9.tar.gz
      w32api-3.6.tar.gz      
      gcc-core-3.4.2-20040916-1.tar.gz
      binutils-2.15.91-20040904-1.tar.gz
      mingw-utils-0.3.tar.gz
      gcc-g++-3.4.2-20040916-1.tar.gz [Probably not needed]
      MSYS-1.0.10.exe
      msysDTK-1.0.1.exe

You probably don't need all of the packages listed, but at a minimum
you will need the mingw-runtime, gcc, w32api, and msys packages.  I
installed the others.

*** You have to have sed on the path for make and gunzip on the path for
    chicken-setup.  Either use the unix-utils package from
    http://unxutils.sourceforge.net/ or install the msysDTK.

1. Extract the gz files into C:\mingw.  If you put them anywhere
   else you will need to adjust all paths accordingly

2. Run the msys installer. It will run a script following the install.
   As the script runs you will be prompted for two items:
   - Where is you mingw?  Enter the correct location.
   - Make fstab entries?  Say yes.

3. Do whatever you decided to get sed and gunzip. Just make sure they
   are on the path.

You should be done with mingw setup at this point.


======================================================================
Alternate setup using Dev-C++ Bloodshed Dev-C++
      
      Packages - I used the package updater to get/update win32, gcc,
      and binutils.

      TODO - Finish this. It does work, just set different paths in the batch file.

======================================================================
Set up the path with a batch file

Set your path and start a command prompt using something like this
batch file:

REM Don't use backslashes for anything used in the make file
set MINGW_HOME=C:/mingw
set MINGW_PATH=%MINGW_HOME%/bin;C:/msys/1.0/bin
set CHICKEN_HOME=C:/working/mingw-only/chicken-2.3
set PATH=%CHICKEN_HOME%;%MINGW_PATH%;C:/WINDOWS/system32
set INCLUDE=%CHICKEN_HOME%
set CHICKEN_INCLUDE_PATH=%CHICKEN_HOME%
set CHICKEN_LIB_DIR=%CHICKEN_HOME%
set LIB=%CHICKEN_HOME%;%MINGW_HOME%/lib
REM Must use backslashes or chicken-setup will fail on windows
set CHICKEN_REPOSITORY=C:\working\mingw-only\chicken-2.3\repo
cmd.exe

Now you can just run this batch file to get a working environment.

*** Don't forget sed and gunzip.

I recommend that you eliminate all extraneous path entries.  I ran into
some strange linking issues with some of my standard path entries.


======================================================================
Change these files:

*** csc.scm.in
    Line 105
      remove '-DHAVE_CHICKEN_CONFIG '
    Line 185 should be:
      (define default-library-files '("%staticlibfiles%"))
    Line 529 should be:
      (set! compile-options (cons* "-DC_SHARED" compile-options))

*** chicken.h
    Line 80 should be
      # if defined(__CYGWIN__)


======================================================================
Build chicken.exe, csi.exe, csc.exe, chicken-setup.exe

make -f Makefile.mingw all

Try it out.


======================================================================
Issues and TODO

*** The method that csc.scm uses to obtain tool locations is unusual.
    It would be nice if it used environment variables instead. Maybe
    I don't have the big picture on this. Some things can be passed as
    arguments, but not everything.  In general csc.scm.in needs to be
    fixed to handle MINGW properly.

*** Update the command part of this doc to match the batch file.

*** This probably works with CYGWIN set up for MINGW building.

*** Figure out if all the MINGW packages listed are needed.



======================================================================
Makefile.mingw
======================================================================
CC = gcc
CXX = g++

# If you remove the -DPIC the build works fine. With it the dll will not link.
CFLAGS = -Os -DC_DEFAULT_TARGET_STACK_SIZE=300000 -DC_STACK_GROWS_DOWNWARD=1 \
    -DNO_PIC_NO_DLL -DHAVE_LOADLIBRARY -DHAVE_GETPROCADDRESS -DHAVE_WINDOWS_H \
    -Wno-unused -Wno-uninitialized -I$(CHICKEN_INCLUDE_PATH)

SHARED_LFLAGS = -Os -dll --compat-implib -lchicken -L$(CHICKEN_LIB_DIR) \
    -Wl,-R$(CHICKEN_LIB_DIR)

O = .
S = .
LFLAGS = -L$(CHICKEN_HOME) -L$(MINGW_HOME)/lib
EXTRA_LINK_FLAGS='-Wl,-R$(CHICKEN_HOME),-R$(MINGW_HOME)/lib'
CHICKEN = chicken.exe
STATIC_LIB = libchicken-static.a
CHICKENFLAGS = -optimize-level 2 -debug-level 0 -quiet
WINLIBS = -lws2_32
MORE_LIBS = $(WINLIBS)
MORE_STATIC_LIBS = $(WINLIBS)
DESTDIR = $(CHICKEN_HOME)

# Static objects
OBJS = $O/runtime.o $O/library.o $O/eval.o $O/profiler.o $O/scheduler.o \
    $O/extras.o $O/match-support.o $O/lolevel.o $O/tinyclos.o $O/pregexp.o \
    $O/utils.o $O/tcp.o $O/posixwin.o $O/srfi-1.o $O/srfi-4.o $O/srfi-13.o \
    $O/srfi-14.o $O/srfi-18.o $O/stub.o

# Library objects
LIB_OBJECTS = $O/runtime.o $O/library.o $O/eval.o $O/profiler.o $O/scheduler.o

# Executable objects
CHICKEN_OBJS = $O/chicken.o $O/support.o $O/partition.o $O/easyffi.o $O/compiler.o \
    $O/optimizer.o $O/batch-driver.o $O/c-platform.o $O/c-backend.o

all: chicken-config.h $(STATIC_LIB) $(CHICKEN) csi.exe csc.exe chicken-setup.exe

# Chicken executables
chicken-static.exe: $(CHICKEN_OBJS) $(STATIC_LIB)
    $(CC) $(LFLAGS) -static $(CHICKEN_OBJS) -o$@ -lchicken-static $(WINLIBS)

# Strip after linking because it is so big. Figure this out
chicken.exe: $(CHICKEN_OBJS) libchicken.dll
    $(CC) -o$@ $(CHICKEN_OBJS) $(SHARED_LFLAGS) -lchicken $(WINLIBS)
    strip --strip-unneeded $@

#chicken-setup.exe
chicken-setup.c: chicken-setup.scm parameters.scm $(CHICKEN)
    $(CHICKEN) chicken-setup.scm $(CHICKENFLAGS) -output-file $@

$O/chicken-setup.o: chicken-setup.c chicken.h

chicken-setup.exe: $O/chicken-setup.o libchicken.a $(CHICKEN)
    $(CC) $(SHARED_LFLAGS) $O/chicken-setup.o -o$@ -lchicken $(WINLIBS)

# The static library
$(STATIC_LIB): $(OBJS)
    ar cru $@ $(OBJS)
    ranlib $@

# The Shared library
libchicken.dll: $(OBJS)
    $(CC) -shared $(OBJS) $(WINLIBS) -o libchicken.dll -Wl,--image-base=0x10000000 -Wl,--out-implib,libchicken.a

#CSI
csi.exe: $O/csi.o libchicken.a
    $(CC) $(SHARED_LFLAGS) $O/csi.o -o$@ -lchicken $(WINLIBS)

$O/csi.o: csi.c chicken.h

csi.c: csi.scm build.scm $(CHICKEN)
    $(CHICKEN) csi.scm $(CHICKENFLAGS) -output-file $@ -prologue build.scm

#CSC
# Added a dependency to the static lib so we can build static exes
csc.exe: $O/csc.o libchicken.a
    $(CC) $(SHARED_LFLAGS) csc.o -o$@ -lchicken $(WINLIBS)

$O/csc.o: csc.c chicken.h

csc.c: $O/csc.scm $(CHICKEN)
    $(CHICKEN) csc.scm $(CHICKENFLAGS) -output-file $@

#You need to have sed. Either the gnu for win32 or the msys dtk version will work.
csc.scm: csc.scm.in
    sed_quote_subst='s/\([\\`\\"$\\\\]\)/\\\1/g' ; \
    quoted_cflags=`echo X$(CFLAGS) $(BASE_CPPFLAGS) | sed -e s/^X// -e "$$sed_quote_subst"` ; \
    quoted_cppflags=`echo X$(CPPFLAGS) $(BASE_CPPFLAGS) | sed -e s/^X// -e "$$sed_quote_subst"` ; \
    sed -e "s,%bindir%,$(DESTDIR)," \
        -e "s,%pcc%,$(CC)," \
        -e "s,%cc%,$(CC)," \
        -e "s,%cxx%,$(CXX)," \
        -e "s,%cxxlinker%,$(CXX)," \
        -e "s,%cflags%,$$quoted_cflags," \
        -e "s,%morelibs%,$(MORE_LIBS)," \
        -e "s,%morestaticlibs%,$(MORE_STATIC_LIBS)," \
        -e "s,%CHICKEN_HOME%,$(CHICKEN_HOME)," \
        -e "s,%includedir%,$(INCLUDE)," \
        -e "s,%libdir%,$(CHICKEN_LIB_DIR),g" \
        -e "s,%staticlibfiles%,$(CHICKEN_LIB_DIR)/$(STATIC_LIB),g" \
        -e "s,%optlibs%,#f," \
      <$(S)/csc.scm.in >csc.scm

# Not using this right now since we aren't setting it up properly
chicken-config.h: chicken-config.h.in
    cp -f chicken-config.h.in chicken-config.h

%.o: %.c
    $(CC) -c $(CFLAGS) -DPIC $< -o $@

# Objects for statically linked library
$(LIB_OBJECTS): chicken.h
    $(CC) $(CFLAGS) -DPIC -DC_BUILDING_LIBCHICKEN -c $*.c -o$@

.PHONY : clean
clean:
    rm -f $O/*.o $O/*.obj *.a *.exe *.exp *.dll *.RES csi.c csc.c \
    chicken-profile.c chicken-setup.c csc.scm chicken-config.h
reply via email to

[Prev in Thread] Current Thread [Next in Thread]