# コマンド設定
CC?= cc
CHMOD?= chmod
ENV?= env
FIND?= find
GREP?= grep
KYUA?= kyua
LS?= ls
MAKE?= make
RM?= rm
SED?= sed
# ディレクトリ設定
.if !defined(TOPDIR)
. if exists(${.CURDIR}/mk/ore.mk)
TOPDIR= ${.CURDIR}
. elif exists(${.CURDIR}/../mk/ore.mk)
TOPDIR= ${.CURDIR:C,/[^/]*$,,}
. elif exists(${.CURDIR}/../../mk/ore.mk)
TOPDIR= ${.CURDIR:C,/[^/]*/[^/]*$,,}
. elif exists(${.CURDIR}/../../../mk/ore.mk)
TOPDIR= ${.CURDIR:C,/[^/]*/[^/]*/[^/]*$,,}
. endif
.endif
WORKPLACE= ${.CURDIR:S,${TOPDIR},,:C,^$,/,}
DIRNAME= ${WORKPLACE:C,${WORKPLACE:C,[^/]*$,,},,}
BINDIR?= ${TOPDIR}/bin
SRCDIR?= ${TOPDIR}/src
TESTDIR?= ${TOPDIR}/tests
# パーミッション設定
BINPERM?= 555
# コンパイルオプション
CFLAGS?= -I. -O2 -pipe
# 対応ターゲット
# TARGET build clean test
# ore/ OK OK OK
# bin/ - - -
# mk/ - - -
# src/ OK OK OK
# bin/ OK OK OK
# */ OK OK OK
# tests/ OK OK OK
# bin/ OK OK OK
# */ OK OK OK
# ビルド・テスト処理
# /
.if ${WORKPLACE} == "/"
build:
cd ${SRCDIR}; ${MAKE} $@
clean:
cd ${SRCDIR}; ${MAKE} $@
test:
cd ${TESTDIR}; ${MAKE} $@
# /src
.elif ${WORKPLACE} == "/src"
build:
cd ${SRCDIR}/bin; ${MAKE} $@
clean:
cd ${SRCDIR}/bin; ${MAKE} $@
test:
cd ${TESTDIR}; ${MAKE} $@
# /src/bin
.elif ${WORKPLACE} == "/src/bin"
TARGETDIRS!= ${FIND} . -type d -maxdepth 1 | ${SED} 's,^[.][/]*,,'
build:
${MAKE} build-recursive
clean:
${MAKE} clean-recursive
test:
cd ${TESTDIR}/bin; ${MAKE} $@
# /src/bin/*
.elif ${WORKPLACE:C,/[^/]*$,,} == "/src/bin"
OBJS!= ${LS} | ${GREP} '[.]c$$' 2> /dev/null | ${SED} 's/.c$$/.o/g'
CLEANFILES?= ${DIRNAME} ${BINDIR}/${DIRNAME} ${OBJS} ${DIRNAME}.core
build: ${DIRNAME}
${DIRNAME}: ${OBJS}
${RM} -f ${BINDIR}/${DIRNAME}
${CC} ${CFLAGS} -o ${BINDIR}/${DIRNAME} ${OBJS}
${CHMOD} ${BINPERM} ${BINDIR}/${DIRNAME}
.c.o:
${CC} ${CFLAGS} -c $< -o $@
clean:
${RM} -f ${CLEANFILES}
test: build
cd ${TESTDIR}/${WORKPLACE:C,^/src/,,}; ${MAKE} $@
# /tests
.elif ${WORKPLACE} == "/tests"
TARGETDIRS!= ${FIND} . -type d -maxdepth 1 | ${SED} 's,^[.][/]*,,'
test:
${ENV} PATH=${BINDIR}:${PATH} ${KYUA} $@
build:
cd ${SRCDIR}; ${MAKE} $@
clean:
cd ${SRCDIR}; ${MAKE} $@
# /tests/bin
.elif ${WORKPLACE} == "/tests/bin"
TARGETDIRS!= ${FIND} . -type d -maxdepth 1 | ${SED} 's,^[.][/]*,,'
test:
${ENV} PATH=${BINDIR}:${PATH} ${KYUA} $@
build:
cd ${SRCDIR}/bin; ${MAKE} $@
clean:
cd ${SRCDIR}/bin; ${MAKE} $@
# /tests/bin/*
.elif ${WORKPLACE:C,/[^/]*$,,} == "/tests/bin"
test:
${ENV} PATH=${BINDIR}:${PATH} ${KYUA} $@
build:
cd ${SRCDIR}/${WORKPLACE:C,^/tests/,,}; ${MAKE} $@
clean:
cd ${SRCDIR}/${WORKPLACE:C,^/tests/,,}; ${MAKE} $@
.endif
build-recursive:
.for dir in ${TARGETDIRS}
cd ${dir}; ${MAKE} build
.endfor
clean-recursive:
.for dir in ${TARGETDIRS}
cd ${dir}; ${MAKE} clean
.endfor