この記事は「Qiita Advent Calendar 2019 DSLで自作ビルドツールを作ろう」の24日目の記事です。
24日目 EmacsプロジェクトをRumyでコンパイルしてみる試行 ~ひたすらルールファイルを書く~
前回に引き続き、ひたすらMakefileをRumyファイルに移していきます。deps.mk
ファイルは各ファイルのオブジェクトに対する依存関係を記述しているので、これをひたすらコピーしていきます。
build.rb
make_cpp_target "atimer.o", ["atimer.c", "atimer.h", "syssignal.h", "systime.h", "lisp.h", "blockinput.h", "globals.h", "../lib/unistd.h", "msdos.h", config_h] make_cpp_target "bidi.o", ["bidi.c", "buffer.h", "character.h", "dispextern.h", "msdos.h", "lisp.h", "globals.h", config_h] ...
依存関係を記述していくのが面倒なので、make_cpp_target
というラッパーを用意しました。
def make_cpp_target(target, depend_list) make_target target do executes ["#{CC} #{ALL_CFLAGS} -c #{name.sub(".o", ".c")}"] depends [depend_list, "globals.h"] end end
いちいちexecute
のコマンドを書くのが面倒くさいので、もう専用のmake_cpp_target
とう関数を用意してしまったわけです。これでひたすらオブジェクトファイルの依存関係を記述していきます。
依存関係についてもひたすら外部Makeルールを記述していきます。このあたりはRubyで柔軟性があるので、自由に依存関係を記述していきます。
make_target "globals.h" do depends ["gl-stamp"] end make_target "gl-stamp" do depends [libsrc + "/make-docfile" + EXEEXT, GLOBAL_SOURCES] executes ["#{libsrc}/make-docfile -d #{srcdir} -g #{obj.join(' ').to_s} > globals.tmp"] executes ["#{top_srcdir}/build-aux/move-if-change globals.tmp globals.h"] executes ["echo timestamp > #{name}"] end
さて、ひたすら長いRumyルールファイルを記述したので、さっそくビルドしてみます。いろいろ苦労したのですが、無事にビルドしてemacs
をビルドすることができました。どうにかこうにか、Makeと同じことができるようになったわけです。
rumy
... gcc -Demacs -I. -I. -I../lib -I../lib -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/includ e/libpng16 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/p11-kit-1 -g3 -O2 -c ftfont.c gcc -Demacs -I. -I. -I../lib -I../lib -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/includ e/libpng16 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/p11-kit-1 -g3 -O2 -c xftfont.c [DEBUG] : ==== Execute Target gl-stamp ==== [DEBUG] : ==== Execute Target gl-stamp ==== Target Execution Skipped [DEBUG] : ==== Execute Target gl-stamp ==== [DEBUG] : ==== Execute Target globals.h ==== ...
ビルドが完了しました!
./src/emacs