From: Guillaume Marcais Date: 2003-08-31T08:51:33+09:00 Subject: mkmf & swig --=-9wNtCSvI3DsIsm3gOD1N Content-Type: text/plain Content-Transfer-Encoding: 7bit As I started to play with SWIG, I did a quick modification of mkmf so it supports SWIG (see attached diff). An extconf.rb file would look like: require 'mkmf' use_swig create_makefile('example') Then, the usual: $ ruby extconf.rb $ make should do. In addition, there is a 'swig' rule to trigger swig ("make swig"). So that one can generate the C files and distribute a tarball that doesn't require SWIG. "make distclean" gets ride of the C files generated by swig. That's it. It is fairly simple and has plenty of shortcomings. For example, it doesn't support C++ source file. Is it of interest to anybody? Should mkmf in the standard distribution supports SWIG and other tools (like Racc)? Guillaume. --=-9wNtCSvI3DsIsm3gOD1N Content-Disposition: attachment; filename=mkmf.diff Content-Transfer-Encoding: quoted-printable Content-Type: text/x-diff; charset=ISO-8859-1 --- mkmf.rb Tue Jul 22 12:30:05 2003 +++ mkmf-swig.rb Sat Aug 30 19:23:50 2003 @@ -9,6 +9,7 @@ ORIG_LIBPATH =3D ENV['LIB'] =20 SRC_EXT =3D ["c", "cc", "m", "cxx", "cpp", "C"] +ADD_SUFFIXES =3D [] $static =3D $config_h =3D nil =20 unless defined? $configure_args @@ -103,6 +104,11 @@ end end =20 +def use_swig(swig =3D "swig", swig_flags =3D "-ruby") + CONFIG["SWIG"] =3D with_config("swig", swig) + CONFIG["SWIG_FLAGS"] =3D with_config("swig-flags", swig_flags) +end + def rm_f(*files) FileUtils.rm_f(Dir[files.join("\0")]) end @@ -580,6 +586,8 @@ MAKEDIRS =3D $(RUBY) -r ftools -e 'File::makedirs(*ARGV)' INSTALL_PROG =3D $(RUBY) -r ftools -e 'File::install(ARGV[0], ARGV[1], 075= 5, true)' INSTALL_DATA =3D $(RUBY) -r ftools -e 'File::install(ARGV[0], ARGV[1], 064= 4, true)' +#{"\nSWIG =3D " + CONFIG["SWIG"] if CONFIG["SWIG"]} +#{"SWIG_FLAGS =3D " + CONFIG["SWIG_FLAGS"] if CONFIG["SWIG_FLAGS"]} =20 #### End of system configuration section. #### =20 @@ -627,6 +635,13 @@ for f in Dir[File.join(srcdir, "*.{#{SRC_EXT.join(%q{,})}}")] $objs.push(File.basename(f, ".*") << "." << $OBJEXT) end + if CONFIG["SWIG"] + $swig_objs =3D [] + for f in Dir[File.join(srcdir, "*.i")] + $swig_objs.push(File.basename(f, ".*") << "_wrap." << $OBJEXT) + end + $objs +=3D $swig_objs + end else for i in $objs i.sub!(/\.o\z/, ".#{$OBJEXT}") @@ -668,6 +683,14 @@ dllib =3D target ? "$(TARGET).#{$static ? $LIBEXT : CONFIG['DLEXT']}" : = "" mfile =3D open("Makefile", "wb") mfile.print configuration(srcdir) + + if CONFIG["SWIG"] + mfile.print %{ +SWIG_SRC =3D #{$swig_objs.collect { |x| x.gsub(/\.#{$OBJEXT}$/, ".c")}} +} + $distcleanfiles << "$(SWIG_SRC)" + end + mfile.print %{ LIBPATH =3D #{libpath} DEFFILE =3D #{deffile} @@ -735,7 +758,9 @@ =20 return unless target =20 - mfile.print ".SUFFIXES: .#{SRC_EXT.join(' .')} .#{$OBJEXT}\n" + ADD_SUFFIXES << "i" if CONFIG["SWIG"] + + mfile.print ".SUFFIXES: .#{(SRC_EXT+ADD_SUFFIXES).join(' .')} .#{$OBJEXT= }\n" mfile.print "\n" =20 %w[cc cpp cxx C].each do |ext| @@ -751,6 +776,11 @@ end end =20 + if CONFIG["SWIG"] + mfile.print("$(SWIG_SRC): %_wrap.c: %.i\n\t$(SWIG) $(SWIG_FLAGS) $<\n\= n") + end + + mfile.print "$(DLLIB): $(OBJS)\n\t" mfile.print "@-$(RM) $@\n\t" mfile.print "@-$(RM) $(TARGET).lib\n\t" if $mswin @@ -810,6 +840,9 @@ $distcleanfiles =3D [] =20 dir_config("opt") + + config["SWIG"] =3D nil + config["SWIG_FLAGS"] =3D nil end =20 init_mkmf --=-9wNtCSvI3DsIsm3gOD1N--