The following patches are for plugin support on FreeBSD, relative to
the latest Hugs beta on haskell.org.

I added a couple of things to configure.in: a check for leading
underscores in symbol names (stolen from ghc) and a check for the
loader which needs to be called separately from gcc.

Someone should verify that these don't break anything else :)  I'll
make a FreeBSD package when there's a final release of Hugs 1.4.

Cheers,
        Simon

-- 
Simon Marlow                                             [EMAIL PROTECTED]
University of Glasgow                       http://www.dcs.gla.ac.uk/~simonm/
finger for PGP public key

diff -cr hugs-old/Install hugs/Install
*** hugs-old/Install    Mon Jul 14 18:31:42 1997
--- hugs/Install        Wed Jul 30 14:06:49 1997
***************
*** 192,197 ****
--- 192,200 ----
       Solaris + /opt/SUNWspro/bin/cc:
        env "DLL_FLAGS=-G" ./configure --with-plugins
  
+      FreeBSD:
+       env "PIC_FLAGS=-fpic" "DLL_FLAGS=-Bshareable -x" ./configure --with-plugins
+ 
       Here's what little we know about building shared object files on
       other machines.  We'd be delighted if you could tell us what changes
       you need to make to the Makefile to build a working Xlib.so file.
diff -cr hugs-old/src/Makefile.in hugs/src/Makefile.in
*** hugs-old/src/Makefile.in    Fri Jul 11 21:47:40 1997
--- hugs/src/Makefile.in        Wed Jul 30 13:53:28 1997
***************
*** 27,35 ****
  CFLAGS                = @CFLAGS@ @DEBUGFLAGS@
  OPTFLAGS      = @OPTFLAGS@
  
! LD            = @CC@
  LDFLAGS       = @LDFLAGS@  @LDDEBUGFLAGS@
  DLL_FLAGS     = @DLL_FLAGS@
  LIBS          = @LIBS@
  
  YACC          = @YACC@
--- 27,36 ----
  CFLAGS                = @CFLAGS@ @DEBUGFLAGS@
  OPTFLAGS      = @OPTFLAGS@
  
! LD            = @LD@
  LDFLAGS       = @LDFLAGS@  @LDDEBUGFLAGS@
  DLL_FLAGS     = @DLL_FLAGS@
+ PIC_FLAGS     = @PIC_FLAGS@
  LIBS          = @LIBS@
  
  YACC          = @YACC@
***************
*** 59,71 ****
  ################################################################
  
  hugs@EXE@     : $(IOBJECTS) @WOBJECTS@ @RC_FILES@
!                 $(LD) $(LDFLAGS) $(IOBJECTS) @WOBJECTS@ $(LIBS) -o hugs@EXE@ 
                  @STRIP@
  
  SERVER_OBJECTS        = server@OBJ@ $(OBJECTS) 
  runhugs@OBJ@  : $(PRELUDE) hugs.c machdep.c timer.c runhugs.c
  runhugs@EXE@  : runhugs@OBJ@ $(SERVER_OBJECTS)
!                 $(LD) $(LDFLAGS) runhugs@OBJ@ $(SERVER_OBJECTS) $(LIBS) -o 
runhugs@EXE@
  
  ################################################################
  # Clean, distclean, veryclean, TAGS
--- 60,72 ----
  ################################################################
  
  hugs@EXE@     : $(IOBJECTS) @WOBJECTS@ @RC_FILES@
!                 $(CC) $(LDFLAGS) $(IOBJECTS) @WOBJECTS@ $(LIBS) -o hugs@EXE@ 
                  @STRIP@
  
  SERVER_OBJECTS        = server@OBJ@ $(OBJECTS) 
  runhugs@OBJ@  : $(PRELUDE) hugs.c machdep.c timer.c runhugs.c
  runhugs@EXE@  : runhugs@OBJ@ $(SERVER_OBJECTS)
!                 $(CC) $(LDFLAGS) runhugs@OBJ@ $(SERVER_OBJECTS) $(LIBS) -o 
runhugs@EXE@
  
  ################################################################
  # Clean, distclean, veryclean, TAGS
diff -cr hugs-old/src/MkXlib.in hugs/src/MkXlib.in
*** hugs-old/src/MkXlib.in      Fri Jul 11 21:47:41 1997
--- hugs/src/MkXlib.in  Wed Jul 30 13:53:48 1997
***************
*** 4,10 ****
                  $(STRUCTC) -I$(PLUGINS) $(PLUGINS)/Xlib.ss -oXlib.ps
                  $(PRIMC) Xlib
  Xlib$(OBJ)    : Xlib.c $(PLUGIN_INCLUDES)
!                 $(CC) $(CFLAGS) $(X_CFLAGS) Xlib.c -c
  Xlib$(DLL)    : Xlib$(OBJ)
                  $(LD) $(DLL_FLAGS) $(LDFLAGS) -o Xlib$(DLL) Xlib$(OBJ) $(X_LIBS)
  
--- 4,10 ----
                  $(STRUCTC) -I$(PLUGINS) $(PLUGINS)/Xlib.ss -oXlib.ps
                  $(PRIMC) Xlib
  Xlib$(OBJ)    : Xlib.c $(PLUGIN_INCLUDES)
!                 $(CC) $(PIC_FLAGS) $(CFLAGS) $(X_CFLAGS) Xlib.c -c
  Xlib$(DLL)    : Xlib$(OBJ)
                  $(LD) $(DLL_FLAGS) $(LDFLAGS) -o Xlib$(DLL) Xlib$(OBJ) $(X_LIBS)
  
***************
*** 26,31 ****
  xhugs$(EXE)   : Xlib$(OBJ) $(IOBJECTS)
                  $(CC) -c $(CFLAGS) $(OPTFLAGS) plugin.c \
                    -DPLUGINS="{\"Xlib\",(InitModuleFun)&initModule},"
!                 $(LD) $(LDFLAGS) $(IOBJECTS) Xlib$(OBJ) $(X_LIBS) $(LIBS) -o 
xhugs$(EXE) 
  
  # End X11 plugin
--- 26,31 ----
  xhugs$(EXE)   : Xlib$(OBJ) $(IOBJECTS)
                  $(CC) -c $(CFLAGS) $(OPTFLAGS) plugin.c \
                    -DPLUGINS="{\"Xlib\",(InitModuleFun)&initModule},"
!                 $(CC) $(LDFLAGS) $(IOBJECTS) Xlib$(OBJ) $(X_LIBS) $(LIBS) -o 
xhugs$(EXE) 
  
  # End X11 plugin
diff -cr hugs-old/src/config.h.in hugs/src/config.h.in
*** hugs-old/src/config.h.in    Mon Jul  7 16:48:34 1997
--- hugs/src/config.h.in        Wed Jul 30 13:40:37 1997
***************
*** 306,309 ****
  /* Define if you have the editline library (-leditline).  */
  #undef HAVE_LIBREADLINE
  
! 
--- 306,310 ----
  /* Define if you have the editline library (-leditline).  */
  #undef HAVE_LIBREADLINE
  
! /* Define if your C compiler inserts underscores before symbol names */
! #undef LEADING_UNDERSCORE
diff -cr hugs-old/src/machdep.c hugs/src/machdep.c
*** hugs-old/src/machdep.c      Sun Jul 20 22:26:11 1997
--- hugs/src/machdep.c  Wed Jul 30 14:02:11 1997
***************
*** 1117,1123 ****
--- 1117,1127 ----
          ERRMSG(0) "Error %s while importing DLL \"%s\"", dlerror(), dll
          EEND;
      }
+ #ifdef LEADING_UNDERSCORE
+     return dlsym(instance,"_initModule");
+ #else
      return dlsym(instance,"initModule");
+ #endif
  }
  
  #elif HAVE_DL_H /* eg HPUX */
diff -cr hugs-old/src/unix/configure hugs/src/unix/configure
*** hugs-old/src/unix/configure Sat Jul 19 23:43:47 1997
--- hugs/src/unix/configure     Wed Jul 30 14:00:48 1997
***************
*** 1838,1844 ****
  for ac_hdr in stdarg.h stdlib.h unistd.h assert.h ctype.h string.h \
    fcntl.h sgtty.h termio.h termios.h signal.h \
    sys/stat.h sys/types.h sys/ioctl.h sys/resource.h sys/param.h \
!   console.h pascal.h Files.h errno.h stat.h
    
  do
  ac_safe=`echo "$ac_hdr" | tr './\055' '___'`
--- 1838,1844 ----
  for ac_hdr in stdarg.h stdlib.h unistd.h assert.h ctype.h string.h \
    fcntl.h sgtty.h termio.h termios.h signal.h \
    sys/stat.h sys/types.h sys/ioctl.h sys/resource.h sys/param.h \
!   console.h pascal.h Files.h errno.h stat.h nlist.h
    
  do
  ac_safe=`echo "$ac_hdr" | tr './\055' '___'`
***************
*** 3349,3354 ****
--- 3349,3421 ----
  fi
  
  
+ # We assume that they _aren't_ there if anything goes wrong.
+ #
+ echo checking for a leading underscore in symbol names
+ if test "$cross_compiling" = yes; then
+   LEADING_UNDERSCORE='YES'
+ else
+ cat > conftest.$ac_ext <<EOF
+ #line 3360 "configure"
+ #include "confdefs.h"
+ #ifdef HAVE_NLIST_H
+ #include <nlist.h>
+ struct nlist xYzzY[] = {{"_xYzzY", 0},{0}};
+ #endif
+ 
+ main(argc, argv)
+ int argc;
+ char **argv;
+ {
+ #ifdef HAVE_NLIST_H
+     if(nlist(argv[0], xYzzY) == 0 && xYzzY[0].n_value != 0)
+         exit(0);
+ #endif
+     exit(1);
+ }
+ EOF
+ { (eval echo configure:3378: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }
+ if test -s conftest && (./conftest; exit) 2>/dev/null; then
+   LEADING_UNDERSCORE='YES'
+ else
+   LEADING_UNDERSCORE='NO'
+ fi
+ fi
+ rm -fr conftest*
+ test -n "$verbose" && echo "    setting LEADING_UNDERSCORE to $LEADING_UNDERSCORE"
+ cat >> confdefs.h <<\EOF
+ #define LEADING_UNDERSCORE 1
+ EOF
+ 
+ 
+ # Extract the first word of "ld", so it can be a program name with args.
+ set dummy ld; ac_word=$2
+ echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
+ if eval "test \"`echo '$''{'ac_cv_prog_LD'+set}'`\" = set"; then
+   echo $ac_n "(cached) $ac_c" 1>&6
+ else
+   if test -n "$LD"; then
+   ac_cv_prog_LD="$LD" # Let the user override the test.
+ else
+   IFS="${IFS=         }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
+   for ac_dir in $PATH; do
+     test -z "$ac_dir" && ac_dir=.
+     if test -f $ac_dir/$ac_word; then
+       ac_cv_prog_LD="ld"
+       break
+     fi
+   done
+   IFS="$ac_save_ifs"
+ fi
+ fi
+ LD="$ac_cv_prog_LD"
+ if test -n "$LD"; then
+   echo "$ac_t""$LD" 1>&6
+ else
+   echo "$ac_t""no" 1>&6
+ fi
+ 
+ 
  
  # Check whether --enable-modules or --disable-modules was given.
  if test "${enable_modules+set}" = set; then
***************
*** 3486,3492 ****
    ac_save_LIBS="$LIBS"
  LIBS="-lreadline -ltermcap $LIBS"
  cat > conftest.$ac_ext <<EOF
! #line 3490 "configure"
  #include "confdefs.h"
  /* Override any gcc2 internal prototype to avoid an error.  */
  /* We use char because int might match the return type of a gcc2
--- 3553,3559 ----
    ac_save_LIBS="$LIBS"
  LIBS="-lreadline -ltermcap $LIBS"
  cat > conftest.$ac_ext <<EOF
! #line 3557 "configure"
  #include "confdefs.h"
  /* Override any gcc2 internal prototype to avoid an error.  */
  /* We use char because int might match the return type of a gcc2
***************
*** 3498,3504 ****
  readline()
  ; return 0; }
  EOF
! if { (eval echo configure:3502: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }; then
    rm -rf conftest*
    eval "ac_cv_lib_$ac_lib_var=yes"
  else
--- 3565,3571 ----
  readline()
  ; return 0; }
  EOF
! if { (eval echo configure:3569: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }; then
    rm -rf conftest*
    eval "ac_cv_lib_$ac_lib_var=yes"
  else
***************
*** 3527,3533 ****
    ac_save_LIBS="$LIBS"
  LIBS="-leditline  $LIBS"
  cat > conftest.$ac_ext <<EOF
! #line 3531 "configure"
  #include "confdefs.h"
  /* Override any gcc2 internal prototype to avoid an error.  */
  /* We use char because int might match the return type of a gcc2
--- 3594,3600 ----
    ac_save_LIBS="$LIBS"
  LIBS="-leditline  $LIBS"
  cat > conftest.$ac_ext <<EOF
! #line 3598 "configure"
  #include "confdefs.h"
  /* Override any gcc2 internal prototype to avoid an error.  */
  /* We use char because int might match the return type of a gcc2
***************
*** 3539,3545 ****
  readline()
  ; return 0; }
  EOF
! if { (eval echo configure:3543: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }; then
    rm -rf conftest*
    eval "ac_cv_lib_$ac_lib_var=yes"
  else
--- 3606,3612 ----
  readline()
  ; return 0; }
  EOF
! if { (eval echo configure:3610: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }; then
    rm -rf conftest*
    eval "ac_cv_lib_$ac_lib_var=yes"
  else
***************
*** 3639,3645 ****
    ac_cv_sizeof_int=4
  else
  cat > conftest.$ac_ext <<EOF
! #line 3643 "configure"
  #include "confdefs.h"
  #include <stdio.h>
  main()
--- 3706,3712 ----
    ac_cv_sizeof_int=4
  else
  cat > conftest.$ac_ext <<EOF
! #line 3710 "configure"
  #include "confdefs.h"
  #include <stdio.h>
  main()
***************
*** 3650,3656 ****
    exit(0);
  }
  EOF
! { (eval echo configure:3654: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }
  if test -s conftest && (./conftest; exit) 2>/dev/null; then
    ac_cv_sizeof_int=`cat conftestval`
  else
--- 3717,3723 ----
    exit(0);
  }
  EOF
! { (eval echo configure:3721: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }
  if test -s conftest && (./conftest; exit) 2>/dev/null; then
    ac_cv_sizeof_int=`cat conftestval`
  else
***************
*** 3673,3679 ****
    ac_cv_sizeof_float=4
  else
  cat > conftest.$ac_ext <<EOF
! #line 3677 "configure"
  #include "confdefs.h"
  #include <stdio.h>
  main()
--- 3740,3746 ----
    ac_cv_sizeof_float=4
  else
  cat > conftest.$ac_ext <<EOF
! #line 3744 "configure"
  #include "confdefs.h"
  #include <stdio.h>
  main()
***************
*** 3684,3690 ****
    exit(0);
  }
  EOF
! { (eval echo configure:3688: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }
  if test -s conftest && (./conftest; exit) 2>/dev/null; then
    ac_cv_sizeof_float=`cat conftestval`
  else
--- 3751,3757 ----
    exit(0);
  }
  EOF
! { (eval echo configure:3755: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }
  if test -s conftest && (./conftest; exit) 2>/dev/null; then
    ac_cv_sizeof_float=`cat conftestval`
  else
***************
*** 3707,3713 ****
    ac_cv_sizeof_double=8
  else
  cat > conftest.$ac_ext <<EOF
! #line 3711 "configure"
  #include "confdefs.h"
  #include <stdio.h>
  main()
--- 3774,3780 ----
    ac_cv_sizeof_double=8
  else
  cat > conftest.$ac_ext <<EOF
! #line 3778 "configure"
  #include "confdefs.h"
  #include <stdio.h>
  main()
***************
*** 3718,3724 ****
    exit(0);
  }
  EOF
! { (eval echo configure:3722: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }
  if test -s conftest && (./conftest; exit) 2>/dev/null; then
    ac_cv_sizeof_double=`cat conftestval`
  else
--- 3785,3791 ----
    exit(0);
  }
  EOF
! { (eval echo configure:3789: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }
  if test -s conftest && (./conftest; exit) 2>/dev/null; then
    ac_cv_sizeof_double=`cat conftestval`
  else
***************
*** 3741,3747 ****
    ac_cv_sizeof_intp=4
  else
  cat > conftest.$ac_ext <<EOF
! #line 3745 "configure"
  #include "confdefs.h"
  #include <stdio.h>
  main()
--- 3808,3814 ----
    ac_cv_sizeof_intp=4
  else
  cat > conftest.$ac_ext <<EOF
! #line 3812 "configure"
  #include "confdefs.h"
  #include <stdio.h>
  main()
***************
*** 3752,3758 ****
    exit(0);
  }
  EOF
! { (eval echo configure:3756: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }
  if test -s conftest && (./conftest; exit) 2>/dev/null; then
    ac_cv_sizeof_intp=`cat conftestval`
  else
--- 3819,3825 ----
    exit(0);
  }
  EOF
! { (eval echo configure:3823: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }
  if test -s conftest && (./conftest; exit) 2>/dev/null; then
    ac_cv_sizeof_intp=`cat conftestval`
  else
***************
*** 3793,3798 ****
--- 3860,3866 ----
  
  
   
+  
  
  
  
***************
*** 4087,4095 ****
--- 4155,4165 ----
  s%@X_LIBS@%$X_LIBS%g
  s%@X_EXTRA_LIBS@%$X_EXTRA_LIBS%g
  s%@ALLOCA@%$ALLOCA%g
+ s%@LD@%$LD%g
  s%@OPTFLAGS@%$OPTFLAGS%g
  s%@DEBUGFLAGS@%$DEBUGFLAGS%g
  s%@LDDEBUGFLAGS@%$LDDEBUGFLAGS%g
+ s%@PIC_FLAGS@%$PIC_FLAGS%g
  s%@DLL_FLAGS@%$DLL_FLAGS%g
  /@MkXlib@/r $MkXlib
  s%@MkXlib@%%g
diff -cr hugs-old/src/unix/configure.in hugs/src/unix/configure.in
*** hugs-old/src/unix/configure.in      Sat Jul 19 23:43:49 1997
--- hugs/src/unix/configure.in  Wed Jul 30 14:00:39 1997
***************
*** 49,55 ****
    stdarg.h stdlib.h unistd.h assert.h ctype.h string.h \
    fcntl.h sgtty.h termio.h termios.h signal.h \
    sys/stat.h sys/types.h sys/ioctl.h sys/resource.h sys/param.h \
!   console.h pascal.h Files.h errno.h stat.h
    )
  
  AC_HEADER_TIME
--- 49,55 ----
    stdarg.h stdlib.h unistd.h assert.h ctype.h string.h \
    fcntl.h sgtty.h termio.h termios.h signal.h \
    sys/stat.h sys/types.h sys/ioctl.h sys/resource.h sys/param.h \
!   console.h pascal.h Files.h errno.h stat.h nlist.h
    )
  
  AC_HEADER_TIME
***************
*** 189,194 ****
--- 189,219 ----
  
  AC_PROG_GCC_TRADITIONAL
  
+ dnl ** check for leading underscores in symbol names
+ # We assume that they _aren't_ there if anything goes wrong.
+ #
+ echo checking for a leading underscore in symbol names
+ AC_TRY_RUN(
+ [#ifdef HAVE_NLIST_H
+ #include <nlist.h>
+ struct nlist xYzzY[] = {{"_xYzzY", 0},{0}};
+ #endif
+ 
+ main(argc, argv)
+ int argc;
+ char **argv;
+ {
+ #ifdef HAVE_NLIST_H
+     if(nlist(argv[0], xYzzY) == 0 && xYzzY[0].n_value != 0)
+         exit(0);
+ #endif
+     exit(1);
+ }], LEADING_UNDERSCORE='YES', LEADING_UNDERSCORE='NO', LEADING_UNDERSCORE='YES')
+ test -n "$verbose" && echo "    setting LEADING_UNDERSCORE to $LEADING_UNDERSCORE"
+ AC_DEFINE(LEADING_UNDERSCORE)
+ 
+ AC_CHECK_PROG(LD,ld,ld)
+ 
  dnl ################################################################
  dnl Check Configuration options
  dnl ################################################################
***************
*** 349,354 ****
--- 374,380 ----
  dnl 
  dnl fi
  
+ AC_SUBST(PIC_FLAGS) 
  AC_SUBST(DLL_FLAGS) 
  
  

Reply via email to