yamake is makefile generator from YAML

「yaml って Makefile を書くのに向いてるんじゃないか?」で書いたものを試しに作ってみた。


scons がお気に入りなので、Python で書いた*1。今のところ YAML から scons のスクリプトを出力することができるだけ。


これが・・・

project:
  name: hello
  type: executable

src:
  - helloworld.c
  - helloearth.c
  - hellouniverse.c
lib:
  - foo
incdir:
  - contrib/include
libdir:
  - contrib/lib

---
platform: linux
src:
  -  hello_linux.c

---
platform: darwin
src:
  -  hello_darwin.c

---
platform: win32
src:
  -  hello_win32.c


こうなる。

import os

def append_items(target, items):
	for item in items:
		target.append(item)

env = Environment()
platform = env['PLATFORM']

sources = ['helloworld.c','helloearth.c','hellouniverse.c',]
cpppath = ['contrib/include',]
libpath = ['contrib/lib',]
libs = ['foo',]

if os.environ.has_key('CFLAGS'):
	env.Append(CFLAGS = os.environ['CFLAGS'])

if platform == 'posix':
	append_items(sources, ['hello_linux.c',])
	append_items(cpppath, [])
	append_items(libpath, [])
	append_items(libs,    [])
elif platform == 'darwin':
	append_items(sources, ['hello_darwin.c',])
	append_items(cpppath, [])
	append_items(libpath, [])
	append_items(libs,    [])
elif platform == 'win32':
	append_items(sources, ['hello_win32.c',])
	append_items(cpppath, [])
	append_items(libpath, [])
	append_items(libs,    [])

env.Program(
	target = 'hello',
	LIBS = libs,
	LIBPATH = libpath,
	CPPPATH = cpppath,
	source = sources,
	)


ソースコードは割とひどいが、少しずつ整理してオレオレ make 環境を整えていこう。簡単に TODO を書いておく。

  • オプションの強化
    • CPU アーキテクチャを指定できるようにする
    • プラットフォームをもう少し細かく指定できるようにする
    • コンパイルフラグを指定できるようにする?
  • 出力フォーマットの強化
    • Android.mk が出力できるようにする
    • Visual Studio の .vcproj ファイルを出力できるようにする
    • nmake 用のメイクファイルを出力できるようにする

*1:scons は Python