Opened 12 years ago

Last modified 9 years ago

#9543 closed defect

Enable cephes on FreeBSD — at Version 16

Reported by: pjeremy Owned by: pjeremy
Priority: major Milestone: sage-5.6
Component: porting: BSD Keywords: cephes spkg cygwin freebsd
Cc: mhansen, jpflori Merged in:
Authors: Peter Jeremy, Jean-Pierre Flori Reviewers: Stephen Montgomery-Smith
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by kcrisman)

FreeBSD does not currently have a full C99 libm and therefore also needs cephes. The attached patch enables cephes on FreeBSD, enables error checking and renames the long double gamma() functions in line with C99. The latter two components are applicable to Cygwin as well as FreeBSD.

A number of areas still need work - in particular some of the cephes self tests have been removed and some of the other self tests fail (at least some of the failures reflect bugs in cephes). Suitable self-tests and a spkg-check script need to be developed. It's possible mpfr could be used as a reference library.

Spkg at http://boxen.math.washington.edu/home/jpflori/cephes-2.8.p0.spkg

Change History (16)

comment:1 Changed 12 years ago by pjeremy

  • Description modified (diff)

comment:2 Changed 12 years ago by mhansen

I made an spkg at http://sage.math.washington.edu/home/mhansen/cephes-2.8.p0.spkg , but I get the following build error on Cygwin:

 /usr/lib/gcc/i686-pc-cygwin/4.3.4/collect2.exe -tsaware --wrap _Znwj --wrap _Znaj --wrap _ZdlPv --wrap _ZdaPv --wrap _ZnwjRKSt9nothrow_t --wrap _ZnajRKSt9nothrow_t --wrap _ZdlPvRKSt9nothrow_t --wrap _ZdaPvRKSt9nothrow_t -Bdynamic --dll-search-prefix=cyg -u ___register_frame_info -u ___deregister_frame_info -o mtst.exe /usr/lib/gcc/i686-pc-cygwin/4.3.4/../../../crt0.o /usr/lib/gcc/i686-pc-cygwin/4.3.4/crtbegin.o -L/home/mhansen/sage-4.5.3.alpha2/local/lib -L/home/mhansen/sage-4.5.3.alpha2/local/lib -L/usr/lib/gcc/i686-pc-cygwin/4.3.4 -L/usr/lib/gcc/i686-pc-cygwin/4.3.4 -L/usr/lib/gcc/i686-pc-cygwin/4.3.4/../../.. mtst.o cmplx.o clog.o cgamma.o stubs.o -lm -lgcc_s -lgcc -lgcc_eh -lcygwin -luser32 -lkernel32 -ladvapi32 -lshell32 -lgcc_s -lgcc -lgcc_eh /usr/lib/gcc/i686-pc-cygwin/4.3.4/crtend.o
gcc  -I. -g -O2 -Wall   -c -o cvect.o cvect.c
cvect.c: In function ‘main’:
cvect.c:130: warning: implicit declaration of function ‘memcmp’
cvect.c:223: warning: implicit declaration of function ‘exit’
cvect.c:223: warning: incompatible implicit declaration of built-in function ‘exit’
gcc -o cvect cvect.o clog.o cmplx.o stubs.o -lm
gcc  -I. -g -O2 -Wall -c dccalc.c
gcc -o dccalc dccalc.o libmc.a stubs.o -lm
gcc  -I. -g -O2 -Wall   -c -o mtstf.o mtstf.c
gcc -o mtstf mtstf.o cmplxf.o clogf.o cgammaf.o stubs.o -lm
make: *** No rule to make target `whitebxf.c', needed by `whitebxf.o'.  Stop.

comment:3 Changed 12 years ago by pjeremy

The patches I added do not affect the build on Cygwin and I get exactly the same failure when building cephes-2.8.spkg (without any of my patches) on Cygwin. As I noted in my initial description, some of the cephes self-tests have been removed - whitebxf.c being one such.

comment:4 follow-up: Changed 10 years ago by jdemeyer

Note that patches should now be applied by using patch instead of cp.

Also, it would be really nice to make it more uniform: when possible, use the same patches both for Cygwin and for FreeBSD.

comment:5 in reply to: ↑ 4 Changed 10 years ago by kcrisman

Replying to jdemeyer:

Note that patches should now be applied by using patch instead of cp.

Also, it would be really nice to make it more uniform: when possible, use the same patches both for Cygwin and for FreeBSD.

Of course, though with Cygwin development halted for a bit that may not be as crucial.

comment:6 Changed 10 years ago by kcrisman

With respect to this patch right now, according to Stephen Montgomery-Smith, "It caused build errors in other sub-packages." However, it does seem that cephes is needed for ccosh and who knows what else.

comment:8 follow-up: Changed 10 years ago by stephen

I could not get pjeremy's patch to work for FreeBSD. After some searching, I found out that the problem is that his patch attempts to link the cephes functions with /lib/libm.so. This is something that is not meant to work for dynamic libraries. Once a dynamic library has been created, apparently there is no mechanism for merging it with other dynamic libraries.

My solution was to slightly modify pjeremy's patch so that it creates a library libm_complex.so. The following patch should be applied to pjeremy's patch:

--- cephes-2.8	2012-04-14 01:39:13.000000000 +0000
+++ cephes-2.8	2012-04-14 01:38:51.000000000 +0000
@@ -1273,11 +1273,11 @@
 +# Intermediate (ar) libraries
 +LIBS=c9x-complex/libmc.a double/libmd.a ldouble/libml.a single/libmf.a
 +
-+all: libm.so
++all: libm_complex.so
 +
-+install: libm.so complex.h math.h
++install: libm_complex.so complex.h math.h
 +	${INSTALL} -C -m 644 complex.h math.h "${SAGE_LOCAL}/include"
-+	${INSTALL} -C -m 755 libm.so "${SAGE_LOCAL}/lib"
++	${INSTALL} -C -m 755 libm_complex.so "${SAGE_LOCAL}/lib"
 +
 +check:
 +	cd c9x-complex && ${MAKE} "CC=${CC}" check
@@ -1291,7 +1291,7 @@
 +#	TBD
 +
 +clean:
-+	rm -f libm.so syms.c99 syms.libm syms.wanted
++	rm -f libm_complex.so syms.c99 syms.libm syms.wanted
 +	cd c9x-complex && ${MAKE} clean
 +	cd double && ${MAKE} clean
 +	cd ldouble && ${MAKE} clean
@@ -1300,8 +1300,8 @@
 +# FreeBSD includes some but not all of the C99 maths functions.  Build
 +# a "new" libm.so that uses cephes functions to replace the missing ones
 +# (listed in syms.wanted) and then fallback to the base libm.so
-+libm.so: ${LIBS} syms.wanted
-+	${LD} -shared -o $@ $$(sed 's/^/-u /' syms.wanted) -L/usr/lib -lc -lm \
++libm_complex.so: ${LIBS} syms.wanted
++	${LD} -shared -o $@ $$(sed 's/^/-u /' syms.wanted) -L/usr/lib \
 +	   ${LIBS} -lgcc
 +
 +# List of symbols defined in the FreeBSD base libc.so and libm.so

Then I put a script in $SAGE_ROOT/local/bin called "cc" which is a wrapper around the cc I really want to use:

#!/usr/local/bin/bash

# Intersperse a "-lm_complex" before "-lm".

n=0
for i in "$@"; do
  if [ "x$i" = "x-lm" ]; then
    arg[$n]="-lm_complex"
    n=$((n+1))
    arg[$n]="-lm"
  else
    arg[$n]="$i"
  fi
  n=$((n+1))
done

# Some configure scripts invoke the compiler with the argument "-v", and if
# LDFLAGS are added to the arguments, this results in an error which
# ultimately stops the relevant package being built.

# Otherwise LDFLAGS needs to be added so that the linker knows where to find
# the dynamic libraries.

if [ $n = 1 -a "x${arg[0]}" = "x-v" ]; then
  exec /usr/local/bin/gcc46 "${arg[@]}"
else
  exec /usr/local/bin/gcc46 -Wl,-rpath=$SAGE_ROOT/local/lib  -Wl,-rpath=/usr/local/lib/gcc46 "${arg[@]}"
fi

comment:9 in reply to: ↑ 8 ; follow-up: Changed 10 years ago by jdemeyer

Replying to stephen:

I could not get pjeremy's patch to work for FreeBSD. After some searching, I found out that the problem is that his patch attempts to link the cephes functions with /lib/libm.so. This is something that is not meant to work for dynamic libraries.

Are you sure about this? Couldn't you link Cephes's libm against the system -lm (maybe you would have to rename the latter).

I'm willing to experiment with this if somebody could give me access to a FreeBSD box.

comment:10 in reply to: ↑ 9 ; follow-up: Changed 10 years ago by stephen

Replying to jdemeyer:

Replying to stephen:

I could not get pjeremy's patch to work for FreeBSD. After some searching, I found out that the problem is that his patch attempts to link the cephes functions with /lib/libm.so. This is something that is not meant to work for dynamic libraries.

Are you sure about this? Couldn't you link Cephes's libm against the system -lm (maybe you would have to rename the latter).

I'm willing to experiment with this if somebody could give me access to a FreeBSD box.

No I am not sure about this. I received a private email from pjeremy, and did some more investigating. I discovered his patch doesn't work when I use the gcc46 compiler, which comes with the FreeBSD ports system, and is automatically invoked when you use fortran.

Let me think some more about this.

comment:11 in reply to: ↑ 10 Changed 10 years ago by stephen

Replying to stephen:

No I am not sure about this. I received a private email from pjeremy, and did some more investigating. I discovered his patch doesn't work when I use the gcc46 compiler, which comes with the FreeBSD ports system, and is automatically invoked when you use fortran.

Let me think some more about this.

It looks like I found the problem. I was building under a chroot'ed environment. I have discovered that after I perform the

chroot /usr/jail

I need to do

sh /etc/rc.d/ldconfig start

It looks like I only need to do this one time.

Thanks for sticking with me on this guys. It looks like pjeremy's patch works, as is, with no changes.

comment:12 Changed 10 years ago by kcrisman

  • Authors set to Peter Jeremy
  • Reviewers set to Stephen Montgomery-Smith

Great, we just have to make a new spkg for this. Probably we should change to patches instead of entire files copied over, though these are all new files so it's not as big of an issue.

comment:13 Changed 10 years ago by kcrisman

On #13806 this message came up. Relevant? Sorry that we still haven't made an spkg for this...

comment:14 Changed 10 years ago by jpflori

  • Cc jpflori added

comment:15 Changed 10 years ago by jpflori

Spkg cleanup and only targetting FreeBSD at http://boxen.math.washington.edu/home/jpflori/cephes-2.8.p0.spkg

comment:16 Changed 10 years ago by kcrisman

  • Authors changed from Peter Jeremy to Peter Jeremy, Jean-Pierre Flori
  • Description modified (diff)

Trivial error

if [ "$UNAME" != "FreeBSD" ]; then 
    echo "We only install the cephes library on Cygwin and FreeBSD." 
    exit 0 
fi

Anyway, I'm trying this on Cygwin now.

Note: See TracTickets for help on using tickets.