Skip to content

Commit

Permalink
Supports static linking of extensions and encodings again.
Browse files Browse the repository at this point in the history
Fixes --with-static-linked-ext.

Patch by Google Inc. [ruby-core:45073].

* Makefile.in (ENCOBJS, EXTOBJS): New variables to specify static
  linked libraries. Also reintroduces extinit.o, introduces encinit.o
  introduces encinit.o

* common.mk: Builds static libraries rather than shared objects if
  specified.

* configure.in (LD): new substitution. 
  Avoids PIE if s

* enc/depend: Supports static linked libraries
  (libencs, libenc, libtrans): New target.

* enc/encinit.c.erb: new template to generate the initialization of
  statically linked encodings.

* enc/make_encmake.rb (--module): new flag to specify whether static
  or dynamic.

* transcode_data.h (TRANS_INIT): New macro to get rid of the name
  collision of encoding initializers and transcoder initializers.

* ext/extmk.rb: Fixes the behavior on $extstatic is true.

* lib/mkmf.rb (clean-static): new target to clean up static linked
  libraries.

* ruby.c (process_options): New initializes statically linked
  encodings here.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35662 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
yugui committed May 16, 2012
1 parent 0923ae5 commit 3fa3f9a
Show file tree
Hide file tree
Showing 31 changed files with 306 additions and 129 deletions.
36 changes: 36 additions & 0 deletions ChangeLog
@@ -1,3 +1,39 @@
Wed May 16 14:19:51 2012 Yuki Yugui Sonoda <yugui@google.com>

Supports static linking of extensions and encodings again.
Fixes --with-static-linked-ext.

Patch by Google Inc. [ruby-core:45073].

* Makefile.in (ENCOBJS, EXTOBJS): New variables to specify static
linked libraries. Also reintroduces extinit.o, introduces encinit.o
introduces encinit.o

* common.mk: Builds static libraries rather than shared objects if
specified.

* configure.in (LD): new substitution.

* enc/depend: Supports static linked libraries
(libencs, libenc, libtrans): New target.

* enc/encinit.c.erb: new template to generate the initialization of
statically linked encodings.

* enc/make_encmake.rb (--module): new flag to specify whether static
or dynamic.

* transcode_data.h (TRANS_INIT): New macro to get rid of the name
collision of encoding initializers and transcoder initializers.

* ext/extmk.rb: Fixes the behavior on $extstatic is true.

* lib/mkmf.rb (clean-static): new target to clean up static linked
libraries.

* ruby.c (process_options): New initializes statically linked
encodings here.

Wed May 16 14:30:43 2012 NAKAMURA Usaku <usa@ruby-lang.org>

* io.c: fixed a merge mistake of r33878, reported by nobu via IRC.
Expand Down
15 changes: 12 additions & 3 deletions Makefile.in
Expand Up @@ -16,6 +16,7 @@ PLATFORM_DIR = @PLATFORM_DIR@

CC = @CC@
CPP = @CPP@
LD = @LD@
YACC = bison
PURIFY =
AUTOCONF = autoconf
Expand Down Expand Up @@ -70,6 +71,8 @@ DLDFLAGS = @LIBRUBY_DLDFLAGS@ $(XLDFLAGS) $(ARCH_FLAG)
SOLIBS = @SOLIBS@
MAINLIBS = @MAINLIBS@
ARCHMINIOBJS = @MINIOBJS@
ENCOBJS = @ENCOBJS@
EXTOBJS = @EXTOBJS@
BUILTIN_ENCOBJS = @BUILTIN_ENCOBJS@
BUILTIN_TRANSSRCS = @BUILTIN_TRANSSRCS@
BUILTIN_TRANSOBJS = @BUILTIN_TRANSOBJS@
Expand Down Expand Up @@ -175,7 +178,7 @@ miniruby$(EXEEXT):
$(PROGRAM):
@$(RM) $@
$(ECHO) linking $@
$(Q) $(PURIFY) $(CC) $(LDFLAGS) $(XLDFLAGS) $(MAINLIBS) $(MAINOBJ) $(EXTOBJS) $(LIBRUBYARG) $(LIBS) $(OUTFLAG)$@
$(Q) $(PURIFY) $(CC) $(LDFLAGS) $(XLDFLAGS) $(MAINLIBS) $(MAINOBJ) $(EXTOBJS) $(ENCOBJS) $(LIBRUBYARG) $(LIBS) $(EXTLIBS) $(OUTFLAG)$@
$(Q) $(POSTLINK)

# We must `rm' the library each time this rule is invoked because "updating" a
Expand All @@ -186,8 +189,9 @@ $(LIBRUBY_A):
$(ECHO) linking static-library $@
$(Q) $(AR) $(ARFLAGS) $@ $(OBJS) $(DMYEXT)
@-$(RANLIB) $@ 2> /dev/null || true
$(ECHO) verifying static-library $@
@$(PURIFY) $(CC) $(XLDFLAGS) $(MAINOBJ) $(LIBRUBY_A) $(MAINLIBS) $(EXTLIBS) $(LIBS) $(OUTFLAG)conftest$(EXEEXT) $(LDFLAGS)
@$(RM) conftest$(EXEEXT)
@$(RM) conftset$(EXEEXT) conftest.c

$(LIBRUBY_SO):
@-$(PRE_LIBRUBY_UPDATE)
Expand Down Expand Up @@ -311,7 +315,8 @@ enc/unicode/name2ctype.h: enc/unicode/name2ctype.kwd
$(Q) $(CPP) $(XCFLAGS) $(CPPFLAGS) $(COUTFLAG)$@ -E $< > $@

clean-local::
$(Q)$(RM) ext/extinit.c ext/extinit.$(OBJEXT) ext/ripper/y.output
$(Q)$(RM) ext/extinit.c ext/extinit.$(OBJEXT) ext/ripper/y.output \
enc/encinit.c enc/encinit.$(OBJEXT)
-$(Q)$(RM) $(pkgconfig_DATA)

distclean-local::
Expand All @@ -335,8 +340,10 @@ clean-ext distclean-ext realclean-ext::
$(RMDIRS) "ext/$$dir" 2> /dev/null || true;; \
esac; \
done
-$(Q)$(RM) ext/extinit.$(OBJEXT)

distclean-ext realclean-ext::
-$(Q)$(RM) ext/extinit.c
-$(Q)$(RMDIR) ext 2> /dev/null || true

clean-extout:
Expand All @@ -362,6 +369,8 @@ ext/extinit.$(OBJEXT): ext/extinit.c $(SETUP)
$(ECHO) compiling $@
$(Q) $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(COUTFLAG)$@ -c ext/extinit.c

enc/encinit.$(OBJEXT): enc/encinit.c $(SETUP)

up::
@$(CHDIR) "$(srcdir)" && LC_TIME=C exec $(VCSUP)

Expand Down
26 changes: 16 additions & 10 deletions common.mk
Expand Up @@ -32,7 +32,6 @@ ID_H_TARGET = -id.h-
DMYEXT = dmyext.$(OBJEXT)
NORMALMAINOBJ = main.$(OBJEXT)
MAINOBJ = $(NORMALMAINOBJ)
EXTOBJS =
DLDOBJS = $(DMYEXT)
MINIOBJS = $(ARCHMINIOBJS) dmyencoding.$(OBJEXT) dmyversion.$(OBJEXT) miniprelude.$(OBJEXT)
ENC_MK = enc.mk
Expand Down Expand Up @@ -141,7 +140,7 @@ COMPILE_PRELUDE = $(MINIRUBY) -I$(srcdir) $(srcdir)/tool/compile_prelude.rb

all: showflags main docs

main: showflags encs exts
main: showflags $(EXTSTATIC:static=lib)encs exts
@$(NULLCMD)

.PHONY: showflags
Expand All @@ -168,12 +167,13 @@ exts: build-ext

EXTS_MK = exts.mk
$(EXTS_MK): $(MKFILES) incs $(PREP) $(RBCONFIG) $(LIBRUBY)
$(ECHO) generating makefile $@
$(Q)$(MINIRUBY) $(srcdir)/ext/extmk.rb --make="$(MAKE)" --command-output=$(EXTS_MK) $(EXTMK_ARGS) configure

configure-ext: $(EXTS_MK)

build-ext: $(EXTS_MK)
$(Q)$(MAKE) -f $(EXTS_MK) $(MFLAGS)
$(Q)$(MAKE) -f $(EXTS_MK) $(MFLAGS) $(EXTSTATIC)

$(MKMAIN_CMD): $(MKFILES) incs $(PREP) $(RBCONFIG) $(LIBRUBY)
$(Q)$(MINIRUBY) $(srcdir)/ext/extmk.rb --make="$(MAKE)" --command-output=$@ $(EXTMK_ARGS)
Expand Down Expand Up @@ -206,7 +206,7 @@ Doxyfile: $(srcdir)/template/Doxyfile.tmpl $(PREP) $(srcdir)/tool/generic_erb.rb
program: showflags $(PROGRAM)
wprogram: showflags $(WPROGRAM)

$(PROGRAM): $(LIBRUBY) $(MAINOBJ) $(OBJS) $(EXTOBJS) $(SETUP) $(PREP)
$(PROGRAM): $(LIBRUBY) $(MAINOBJ) $(OBJS) $(EXTOBJS) $(ENCOBJS) $(SETUP) $(PREP)

$(LIBRUBY_A): $(OBJS) $(MAINOBJ) $(DMYEXT) $(ARCHFILE)

Expand Down Expand Up @@ -519,17 +519,21 @@ test-rubyspec: test-rubyspec-precheck
$(RUNRUBY) $(srcdir)/spec/mspec/bin/mspec run -B $(srcdir)/spec/default.mspec $(MSPECOPT)

encs: enc trans
encs enc trans: showflags $(ENC_MK) $(LIBRUBY) $(PREP)
libencs: libenc libtrans
encs enc trans libencs libenc libtrans: showflags $(ENC_MK) $(LIBRUBY) $(PREP)
$(ECHO) making $@
$(Q) $(MAKE) -f $(ENC_MK) RUBY="$(MINIRUBY)" MINIRUBY="$(MINIRUBY)" $(MFLAGS) $@
$(Q) $(MAKE) -f $(ENC_MK) V="$(V)" \
RUBY="$(MINIRUBY)" MINIRUBY="$(MINIRUBY)" \
$(MFLAGS) $@

enc: {$(VPATH)}encdb.h
trans: {$(VPATH)}transdb.h

libenc enc: {$(VPATH)}encdb.h
libtrans trans: {$(VPATH)}transdb.h

$(ENC_MK): $(srcdir)/enc/make_encmake.rb $(srcdir)/enc/Makefile.in $(srcdir)/enc/depend \
$(srcdir)/lib/mkmf.rb $(RBCONFIG)
$(srcdir)/enc/encinit.c.erb $(srcdir)/lib/mkmf.rb $(RBCONFIG)
$(ECHO) generating $@
$(Q) $(MINIRUBY) $(srcdir)/enc/make_encmake.rb --builtin-encs="$(BUILTIN_ENCOBJS)" --builtin-transes="$(BUILTIN_TRANSOBJS)" $@ $(ENCS)
$(Q) $(MINIRUBY) $(srcdir)/enc/make_encmake.rb --builtin-encs="$(BUILTIN_ENCOBJS)" --builtin-transes="$(BUILTIN_TRANSOBJS)" --module$(EXTSTATIC) $@ $(ENCS)

.PRECIOUS: $(MKFILES)

Expand Down Expand Up @@ -833,6 +837,8 @@ transdb.h: $(PREP) srcs-enc $(srcdir)/tool/generic_erb.rb $(srcdir)/template/tra
$(ECHO) generating $@
$(Q) $(MINIRUBY) $(srcdir)/tool/generic_erb.rb -c -o $@ $(srcdir)/template/transdb.h.tmpl $(srcdir)/enc/trans enc/trans

enc/encinit.c: $(ENC_MK) $(srcdir)/enc/encinit.c.erb

known_errors.inc: $(srcdir)/template/known_errors.inc.tmpl $(srcdir)/defs/known_errors.def
$(ECHO) generating $@
$(Q) $(BASERUBY) $(srcdir)/tool/generic_erb.rb -c -o $@ $(srcdir)/template/known_errors.inc.tmpl $(srcdir)/defs/known_errors.def
Expand Down
39 changes: 24 additions & 15 deletions configure.in
Expand Up @@ -291,6 +291,8 @@ AC_PROG_CC
AC_PROG_CXX
AC_PROG_GCC_TRADITIONAL
AC_SUBST(GCC)
AC_CHECK_TOOL([LD], [ld], [ld])
AC_SUBST(LD)
if test "$GCC" = yes; then
linker_flag=-Wl,
: ${optflags=-O3}
Expand Down Expand Up @@ -2095,7 +2097,7 @@ if test "$with_dln_a_out" != yes; then

AS_CASE(["$target_os"],
[hpux*], [ DLDFLAGS="$DLDFLAGS -E"
: ${LDSHARED='ld -b'}
: ${LDSHARED="$(LD) -b"}
XLDFLAGS="$XLDFLAGS -Wl,-E"
: ${LIBPATHENV=SHLIB_PATH}
if test "$rb_cv_prog_gnu_ld" = no; then
Expand All @@ -2114,17 +2116,17 @@ if test "$with_dln_a_out" != yes; then
: ${LIBPATHENV=LD_LIBRARY_PATH_64}
fi
rb_cv_dlopen=yes],
[sunos*], [ : ${LDSHARED='ld -assert nodefinitions'}
[sunos*], [ : ${LDSHARED="$(LD) -assert nodefinitions"}
rb_cv_dlopen=yes],
[irix*], [ : ${LDSHARED='ld -shared'}
[irix*], [ : ${LDSHARED="$(LD) -shared"}
rb_cv_dlopen=yes],
[sysv4*], [ : ${LDSHARED='ld -G'}
[sysv4*], [ : ${LDSHARED="$(LD) -G"}
rb_cv_dlopen=yes],
[nto-qnx*], [ : ${LDSHARED='$(CC) -shared'}
rb_cv_dlopen=yes],
[esix*|uxpds*], [ : ${LDSHARED="ld -G"}
[esix*|uxpds*], [ : ${LDSHARED="$(LD) -G"}
rb_cv_dlopen=yes],
[osf*], [ : ${LDSHARED="ld -shared -expect_unresolved \"*\""}
[osf*], [ : ${LDSHARED="$(LD) -shared -expect_unresolved \"*\""}
rb_cv_dlopen=yes],
[bsdi3*], [ AS_CASE(["$CC"],
[*shlicc*], [ : ${LDSHARED='$(CC) -r'}
Expand All @@ -2145,7 +2147,7 @@ if test "$with_dln_a_out" != yes; then
LDFLAGS="$LDFLAGS -rdynamic"
DLDFLAGS="$DLDFLAGS "'-Wl,-soname,$(.TARGET)'
else
test "$GCC" = yes && test "$rb_cv_prog_gnu_ld" = yes || LDSHARED="ld -Bshareable"
test "$GCC" = yes && test "$rb_cv_prog_gnu_ld" = yes || LDSHARED="$(LD) -Bshareable"
fi
rb_cv_dlopen=yes],
[openbsd*], [ : ${LDSHARED='$(CC) -shared ${CCDLFLAGS}'}
Expand Down Expand Up @@ -2179,30 +2181,30 @@ if test "$with_dln_a_out" != yes; then
rb_cv_dlopen=yes],
[beos*], [ AS_CASE(["$target_cpu"],
[powerpc*], [
: ${LDSHARED="ld -xms"}
: ${LDSHARED="$(LD) -xms"}
DLDFLAGS="$DLDFLAGS "'-export Init_$(TARGET) -lbe -lroot glue-noinit.a init_term_dyn.o start_dyn.o'
LDFLAGS="$LDFLAGS -L/boot/home/config/lib -lbe -lroot"
],
[i586*], [
: ${LDSHARED="ld -shared"}
: ${LDSHARED="$(LD) -shared"}
DLDFLAGS="$DLDFLAGS -L/boot/develop/lib/x86 -L/boot/home/config/lib \$(topdir)/_APP_ -lbe -lroot"
LDFLAGS="$LDFLAGS -L/boot/develop/lib/x86 -L/boot/home/config/lib -lbe -lroot"
])
: ${LIBPATHENV=LIBRARY_PATH}
rb_cv_dlopen=yes],
[haiku*], [ AS_CASE(["$target_cpu"],
[powerpc*], [
: ${LDSHARED="ld -xms"}
: ${LDSHARED="$(LD) -xms"}
DLDFLAGS="$DLDFLAGS "'-export Init_$(TARGET) -lbe -lroot glue-noinit.a init_term_dyn.o start_dyn.o'
],
[i586*], [
: ${LDSHARED="ld -shared"}
: ${LDSHARED="$(LD) -shared"}
DLDFLAGS="$DLDFLAGS -L/boot/develop/lib/x86 -lbe -lroot"
])
: ${LIBPATHENV=LIBRARY_PATH}
rb_cv_dlopen=yes ],
[nto-qnx*], [ DLDFLAGS="$DLDFLAGS -L/lib -L/usr/lib -L/usr/local/lib"
: ${LDSHARED='ld -Bshareable -x'}
: ${LDSHARED="$(LD) -Bshareable -x"}
LDFLAGS="$LDFLAGS -L/lib -L/usr/lib -L/usr/local/lib"
rb_cv_dlopen=yes],
[cygwin*|mingw*], [
Expand All @@ -2211,12 +2213,12 @@ if test "$with_dln_a_out" != yes; then
DLDFLAGS="${DLDFLAGS} -Wl,--enable-auto-image-base,--enable-auto-import"
: ${LIBPATHENV=""}
rb_cv_dlopen=yes],
[hiuxmpp], [ : ${LDSHARED='ld -r'}],
[hiuxmpp], [ : ${LDSHARED="$(LD) -r"}],
[atheos*], [ : ${LDSHARED='$(CC) -shared'}
rb_cv_dlopen=yes],
[os2-emx*], [ LDFLAGS="$LDFLAGS -Zomf"
],
[ : ${LDSHARED='ld'}])
[ : ${LDSHARED="$(LD)"}])
AC_MSG_RESULT($rb_cv_dlopen)
fi
if test "${LDSHAREDXX}" = ""; then
Expand Down Expand Up @@ -2324,6 +2326,13 @@ AC_SUBST(EXTSTATIC)dnl
AC_ARG_WITH(static-linked-ext,
AS_HELP_STRING([--with-static-linked-ext], [link external modules statically]),
[AS_CASE([$withval],[yes],[STATIC=;EXTSTATIC=static])])
if test x"$EXTSTATIC" = xstatic; then
ENCOBJS='enc/encinit.$(OBJEXT) enc/libenc.a enc/libtrans.a'
EXTOBJS='ext/extinit.$(OBJEXT) ext/libext.a'
AC_DEFINE_UNQUOTED(EXTSTATIC, 1)
fi
AC_SUBST(ENCOBJS)
AC_SUBST(EXTOBJS)

AS_CASE(["$target_os"],
dnl OS/2 environment w/ Autoconf 2.1x for EMX
Expand Down Expand Up @@ -2507,7 +2516,7 @@ AS_CASE("$enable_shared", [yes], [
LIBRUBYARG_SHARED=

# enable PIE if possible
if test "$GCC" = yes; then
if test "$GCC" = yes and -z "$EXTSTATIC"; then
RUBY_TRY_CFLAGS(-fPIE, [pie=yes], [pie=no])
if test "$pie" = yes; then
RUBY_APPEND_OPTION(XCFLAGS, -fPIE)
Expand Down
5 changes: 5 additions & 0 deletions dmyext.c
Expand Up @@ -2,3 +2,8 @@ void
Init_ext(void)
{
}

void
Init_enc()
{
}
3 changes: 3 additions & 0 deletions enc/Makefile.in
Expand Up @@ -20,6 +20,7 @@ ENCSODIR = $(EXTOUT)/$(arch)/enc
TRANSSODIR = $(ENCSODIR)/trans
DLEXT = @DLEXT@
OBJEXT = @OBJEXT@
LIBEXT = @LIBEXT@

BUILTIN_ENCS = ascii.c us_ascii.c\
unicode.c utf_8.c
Expand All @@ -32,7 +33,9 @@ LIBRUBYARG_SHARED = @LIBRUBYARG_SHARED@
LIBRUBYARG_STATIC = $(LIBRUBYARG_SHARED)

empty =
AR = @AR@
CC = @CC@
RANLIB = @RANLIB@
OUTFLAG = @OUTFLAG@$(empty)
COUTFLAG = @COUTFLAG@$(empty)
CFLAGS = $(CCDLFLAGS) @CFLAGS@ @ARCH_FLAG@
Expand Down

0 comments on commit 3fa3f9a

Please sign in to comment.