# Adding a compile rule to mkmf.rb

**URL:** <https://www.ruby-forum.com/t/adding-a-compile-rule-to-mkmf-rb/54543>\
**Category:** Ruby\
**Created:** [March 8, 2006, 4:07am UTC](https://www.ruby-forum.com/t/adding-a-compile-rule-to-mkmf-rb/54543 "2006-03-08T04:07:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gerardo\_SSGSSS\_mez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c37758/32.png) [@Gerardo\_SSGSSS\_mez](https://www.ruby-forum.com/u/Gerardo_SSGSSS_mez)\
**Post date:** [March 8, 2006, 4:07am UTC](https://www.ruby-forum.com/t/adding-a-compile-rule-to-mkmf-rb/54543/1 "2006-03-08T04:07:29Z")

</div>

I want to write an extconf.rb file for a Ruby extension. The problem  
is that my source file has a suffix that is not any of the expected by  
mkmf.rb: ec. The suffixes expected are:

SRC\_EXT = [“c”, “cc”, “m”, “cxx”, “cpp”, “C”]

I could add the suffix:

SRC\_EXT \<\< “ec”

and even define my own COMPILE\_EC rule:

COMPILE\_EC = ‘$(ESQL) $(CFLAGS) -c $\<’

but how can I extend create\_makefile to use this rule, without  
modifying mkmf.rb?

–  
Gerardo S.  
“Between individuals, as between nations, respect for the rights of  
others is peace” - Don Benito Juárez

> **[Santana's Tech Notes](http://santanatechnotes.blogspot.com/)**
>
> Small notes about technical related stuff I do, mainly OpenBSD and Ruby

---

<div class="post-metadata">

**Author:** ![Gerardo\_SSGSSS\_mez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c37758/32.png) [@Gerardo\_SSGSSS\_mez](https://www.ruby-forum.com/u/Gerardo_SSGSSS_mez)\
**Post date:** [March 8, 2006, 4:20am UTC](https://www.ruby-forum.com/t/adding-a-compile-rule-to-mkmf-rb/54543/2 "2006-03-08T04:20:01Z")

</div>

On Mar 7, 2006, at 10:04 PM, Gerardo S. Gómez Garrido wrote:

> and even define my own COMPILE\_EC rule:  
> [http://santanatechnotes.blogspot.com/](http://santanatechnotes.blogspot.com/)

I don’t think you can :(. I just looked at mkmf, and it looks like  
the only way to make an extension for ruby as far as mkmf is  
concerned with C or C++. mkmf doesn’t really look for anything  
dynamically, those constants seem to be more to save typing than  
anything else. ☹ It’s too bad, it would be neat if mkmf was  
extendable in this manner.

---

<div class="post-metadata">

**Author:** ![Gerardo\_SSGSSS\_mez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c37758/32.png) [@Gerardo\_SSGSSS\_mez](https://www.ruby-forum.com/u/Gerardo_SSGSSS_mez)\
**Post date:** [March 8, 2006, 9:23pm UTC](https://www.ruby-forum.com/t/adding-a-compile-rule-to-mkmf-rb/54543/3 "2006-03-08T21:23:48Z")

</div>

Don’t know how you could extend mkmf.rb as you describe, but you could  
take the approach that SWIG offers. In the installation of SWIG,  
you’ll find Makefile.swig and extconf.rb skeletons (in  
/usr/share/swig/1.3.25/ruby/ for my installation).

Makefile.swig has rules for creating the SWIG wrapper (generates a C or  
C++ source file wrapper using swig) and also for creating the Makefile  
(using ruby,mkmf.rb, and your extconf.rb). Your extconf.rb will  
typically check for your library, etc., so that it will be linked into  
your extension.

[from Makefile.swig]

# File : Makefile.swig

# Makefile for a SWIG module. Use this file if you are

# producing a Ruby extension for general use or distribution.

# 

# 1. Prepare extconf.rb.

# 2. Modify this file as appropriate.

# 3. Type ‘make -f Makefile.swig’ to generate wrapper code and

Makefile.

# 4. Type ‘make’ to build your extension.

# 5. Type ‘make install’ to install your extension.

Perhaps you could create an appropriate Makefile.whatever and an  
extconf.rb that will create your extension.

Good luck!
