2010-09-10 05:13:59 +02:00
|
|
|
# $NetBSD: replace.mk,v 1.14 2010/09/10 03:13:59 taca Exp $
|
2004-11-27 14:57:20 +01:00
|
|
|
#
|
|
|
|
|
2005-12-05 21:49:47 +01:00
|
|
|
.if !defined(_RUBY_REPLACE_MK)
|
2004-11-27 14:57:20 +01:00
|
|
|
_RUBY_REPLACE_MK= # defined
|
|
|
|
|
2006-06-25 11:31:43 +02:00
|
|
|
.include "${.PARSEDIR}/rubyversion.mk"
|
|
|
|
|
2004-11-27 14:57:20 +01:00
|
|
|
# fix shebang line.
|
|
|
|
#
|
|
|
|
# REPLACE_RUBY replace shebang line of specified files.
|
2005-11-02 08:44:33 +01:00
|
|
|
#
|
|
|
|
.if defined(REPLACE_RUBY)
|
|
|
|
REPLACE_INTERPRETER+= ${RUBY_NAME}
|
|
|
|
|
2009-02-19 13:15:15 +01:00
|
|
|
REPLACE.${RUBY_NAME}.old= .*ruby[0-9.]*
|
2010-09-10 05:13:59 +02:00
|
|
|
|
|
|
|
.if empty(RUBY_ENCODING_ARG)
|
2006-07-20 15:54:44 +02:00
|
|
|
REPLACE.${RUBY_NAME}.new= ${RUBY}
|
2010-09-10 05:13:59 +02:00
|
|
|
.else
|
|
|
|
REPLACE.${RUBY_NAME}.new= ${RUBY} ${RUBY_ENCODING_ARG}
|
|
|
|
.endif
|
2006-07-20 15:54:44 +02:00
|
|
|
REPLACE_FILES.${RUBY_NAME}= ${REPLACE_RUBY}
|
2005-11-02 08:44:33 +01:00
|
|
|
|
|
|
|
.endif # defined(REPLACE_RUBY)
|
|
|
|
|
2004-11-27 14:57:20 +01:00
|
|
|
# REPLACE_RUBY_DIRS replace shebang line of files under specified
|
2008-03-17 21:57:04 +01:00
|
|
|
# directories; relative paths are assumed to be
|
|
|
|
# under ${WRKSRC}.
|
2007-12-13 15:46:58 +01:00
|
|
|
# REPLACE_RUBY_PAT specify pattern to match target files under
|
2004-11-27 14:57:20 +01:00
|
|
|
# REPLACE_RUBY_DIRS directories.
|
|
|
|
#
|
2007-12-13 15:46:58 +01:00
|
|
|
REPLACE_RUBY_PAT?= *.rb
|
|
|
|
|
2005-11-02 08:44:33 +01:00
|
|
|
.if defined(REPLACE_RUBY_DIRS) && !empty(REPLACE_RUBY_DIRS)
|
|
|
|
pre-configure: replace-ruby-dirs
|
2004-11-27 14:57:20 +01:00
|
|
|
|
2007-12-13 15:46:58 +01:00
|
|
|
.for f in ${REPLACE_RUBY_PAT}
|
|
|
|
_REPLACE_RUBY_PAT+= -o -name "${f}"
|
2004-11-27 14:57:20 +01:00
|
|
|
.endfor
|
2007-12-13 15:46:58 +01:00
|
|
|
_REPLACE_RUBY_FIND_ARGS=\( ${_REPLACE_RUBY_PAT:S/-o//1} \)
|
2004-11-27 14:57:20 +01:00
|
|
|
|
|
|
|
replace-ruby-dirs:
|
2008-09-15 10:40:55 +02:00
|
|
|
${RUN} cd ${WRKSRC} && \
|
|
|
|
for d in ${REPLACE_RUBY_DIRS}; do \
|
2008-09-22 18:42:06 +02:00
|
|
|
if [ -d $$d ]; then \
|
|
|
|
dirs="$$dirs $$d"; \
|
|
|
|
fi; \
|
2008-09-15 10:40:55 +02:00
|
|
|
done; \
|
|
|
|
if [ -z "$$dirs" ]; then \
|
|
|
|
exit 0; \
|
|
|
|
fi; \
|
|
|
|
${FIND} $$dirs \
|
|
|
|
-type f ${_REPLACE_RUBY_FIND_ARGS} -print | \
|
2004-11-27 14:57:20 +01:00
|
|
|
while read f; do \
|
2008-09-21 23:50:31 +02:00
|
|
|
${SED} -e '1s|^#! *[a-z0-9_/\.-][a-z0-9_/\.-]*/env *|#!|g' \
|
|
|
|
-e '1s|^#! *[a-z0-9_/\.-]*ruby|#!${RUBY}|' $$f > $$f.tmp; \
|
2004-11-27 14:57:20 +01:00
|
|
|
if ${CMP} -s $$f $$f.tmp; then \
|
|
|
|
${RM} $$f.tmp; \
|
|
|
|
else \
|
|
|
|
${MV} $$f.tmp $$f; \
|
|
|
|
fi; \
|
|
|
|
done
|
|
|
|
.else
|
|
|
|
replace-ruby-dirs:
|
2005-11-02 08:44:33 +01:00
|
|
|
.endif # defined(REPLACE_RUBY_DIRS)
|
2004-11-27 14:57:20 +01:00
|
|
|
.endif # _RUBY_REPLACE_MK
|