Sync Mk with ports
[dports.git] / Mk / Uses / dos2unix.mk
1 # $FreeBSD$
2 #
3 # Provide support to convert files from dos2unix
4 #
5 # DOS2UNIX_REGEX        a regular expression to match files that needs to be converted
6 # DOS2UNIX_FILES        list of files of glob pattern relative to ${WRKSRC}
7 # DOS2UNIX_GLOB         list of glob pattern find(1) will match with
8 # DOS2UNIX_WRKSRC       top-level path for directory traversal instead of ${WRKSRC}
9 #
10 # MAINTAINER: portmgr@FreeBSD.org
11
12 .if !defined(_INCLUDE_USES_DOS2UNIX_MK)
13 _INCLUDE_USES_DOS2UNIX_MK=      yes
14
15 .if !defined(DOS2UNIX_FILES) && !defined(DOS2UNIX_REGEX) && !defined(DOS2UNIX_GLOB)
16 _DOS2UNIX_ALL=  yes
17 .endif
18
19 DOS2UNIX_WRKSRC?=       ${WRKSRC}
20
21 _USES_patch+=   200:dos2unix
22 dos2unix:
23         @${ECHO_MSG} "===>   Converting DOS text files to UNIX text files"
24 .if defined(_DOS2UNIX_ALL)
25         @${FIND} ${DOS2UNIX_WRKSRC} -type f -print0 | \
26                 ${XARGS} -0 ${SED} -i '' -e 's/\r$$//'
27 .else
28 .if defined(DOS2UNIX_FILES)
29         @(cd ${DOS2UNIX_WRKSRC}; \
30                 ${ECHO_CMD} ${DOS2UNIX_FILES} | ${XARGS} ${SED} -i '' -e 's/\r$$//' )
31 .elif defined(DOS2UNIX_REGEX)
32         @${FIND} -E ${DOS2UNIX_WRKSRC} -type f -iregex '${DOS2UNIX_REGEX}' -print0 | \
33                 ${XARGS} -0 ${SED} -i '' -e 's/\r$$//'
34 .else
35 .for f in ${DOS2UNIX_GLOB}
36         @${FIND} ${DOS2UNIX_WRKSRC} -type f -name '${f}' -print0 | \
37                 ${XARGS} -0 ${SED} -i '' -e 's/\r$$//'
38 .endfor
39 .endif
40 .endif
41
42 .endif