Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Oct 2005 10:40:02 +1000 (EST)
From:      Edwin Groothuis <edwin@mavetju.org>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   ports/87234: [patch] add patch-dos2unix target
Message-ID:  <20051011004002.00F5B614D@k7.mavetju>
Resent-Message-ID: <200510110050.j9B0oEhT092685@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         87234
>Category:       ports
>Synopsis:       [patch] add patch-dos2unix target
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Oct 11 00:50:14 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator:     Edwin Groothuis
>Release:        FreeBSD 5.2.1-RELEASE i386
>Organization:
-
>Environment:
System: FreeBSD k7.mavetju 5.2.1-RELEASE FreeBSD 5.2.1-RELEASE #8: Wed Dec 15 16:58:01 EST 2004 edwin@k7.mavetju:/usr/src-5.2.1/sys/i386/compile/k7 i386

>Description:

The porters handbook says at
http://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/slow-patch.html:

    To quickly convert those files from CR/LF to just LF, you can
    do something like this:

    USE_REINPLACE= yes
    post-extract:
	@${FIND} -E ${WRKDIR} -type f -iregex ".*\.(c|cpp|h|txt)" -print0 | \
	    ${XARGS} -0 ${REINPLACE_CMD} -e 's/[[:cntrl:]]*$$//'

    Of course, if you need to process each and every file, -iregex
    above can be omitted. Be aware that this piece of code will
    strip all trailing control characters from each line of processed
    file (except \n).

Let's for simplicty sake replace that one ugly statement with a
simple USE_ statement and let bsd.port.mk figure out the rest:

    USE_DOS2UNIX=	yes
    			^-- run dos2unix over all files under WRKSRC
    USE_DOS2UNIX=	foo bar
    			^-- run dos2unix over WRKSRC/foo and WRKSRC/bar


Once commited (or on the row to be commited), I volunteer to...

- Fix the porters handbook with regarding to documentation, and
- Fix the ports with their own dos2unix implementation with this
  new statement.

>How-To-Repeat:
>Fix:


--- bsd.port.mk.orig	Sat Oct  8 09:58:14 2005
+++ bsd.port.mk	Tue Oct 11 10:36:51 2005
@@ -216,6 +216,9 @@
 #				  compression.
 # USE_ZIP		- If set, this port distfile uses zip, not tar w/[bg]zip
 #				  for compression.
+# USE_DOS2UNIX  - If set to "YES", remove the ^M from all files
+#				  under ${WRKSRC}. If set to a string, remove in all
+#				  files under ${WRKSRC} with one of these names the ^Ms.
 # USE_GCC		- If set, this port requires this version of gcc, either in
 #				  the system or installed from a port.
 # USE_GMAKE		- If set, this port uses gmake.
@@ -1465,6 +1468,10 @@
 CONFIGURE_ENV+=	MAKE=${GMAKE}
 .endif
 
+.if defined(USE_DOS2UNIX)
+USE_REINPLACE=	yes
+.endif
+
 .if defined(USE_GCC)
 .include "${PORTSDIR}/Mk/bsd.gcc.mk"
 .endif
@@ -3259,9 +3266,27 @@
 
 # Patch
 
+.if !target(patch-dos2unix)
+patch-dos2unix:
+.if defined(USE_DOS2UNIX)
+.if ${USE_DOS2UNIX:U}=="YES"
+	@${ECHO_MSG} "===>   Converting DOS text files to UNIX text files"
+	@${FIND} -E ${WRKSRC} -type f -print0 | \
+			${XARGS} -0 ${REINPLACE_CMD} -i"" -e 's/[[:cntrl:]]*$$//'
+.else
+.for f in ${USE_DOS2UNIX}
+	@${ECHO_MSG} "===>   Converting DOS text file to UNIX text file: ${f}"
+	@${REINPLACE_CMD} -i"" -e 's/[[:cntrl:]]*$$//' ${WRKSRC}/${f}
+.endfor
+.else
+	${DO_NADA}
+.endif
+.endif
+
 .if !target(do-patch)
 do-patch:
 .if defined(PATCHFILES)
+.endif
 	@${ECHO_MSG} "===>  Applying distribution patches for ${PKGNAME}"
 	@(cd ${_DISTDIR}; \
 	  for i in ${_PATCHFILES}; do \
@@ -3761,9 +3786,9 @@
 # Please note that the order of the following targets is important, and
 # should not be modified.
 
-_SANITY_SEQ=		pre-everything check-makefile check-categories \
-			check-makevars check-depends check-deprecated \
-			check-vulnerable buildanyway-message options-message
+_SANITY_SEQ=	pre-everything check-makefile check-categories \
+				check-makevars check-depends check-deprecated \
+				check-vulnerable buildanyway-message options-message
 _FETCH_DEP=		check-sanity
 _FETCH_SEQ=		fetch-depends pre-fetch pre-fetch-script \
 				do-fetch post-fetch post-fetch-script
@@ -3772,12 +3797,12 @@
 				pre-extract-script do-extract \
 				post-extract post-extract-script
 _PATCH_DEP=		extract
-_PATCH_SEQ=		patch-message patch-depends pre-patch pre-patch-script \
-				do-patch post-patch post-patch-script
+_PATCH_SEQ=		patch-message patch-depends patch-dos2unix pre-patch \
+				pre-patch-script do-patch post-patch post-patch-script
 _CONFIGURE_DEP=	patch
 _CONFIGURE_SEQ=	build-depends lib-depends misc-depends configure-message \
-		pre-configure pre-configure-script patch-autotools \
-		run-autotools do-configure post-configure post-configure-script
+				pre-configure pre-configure-script patch-autotools \
+				run-autotools do-configure post-configure post-configure-script
 _BUILD_DEP=		configure
 _BUILD_SEQ=		build-message pre-build pre-build-script do-build \
 				post-build post-build-script
>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20051011004002.00F5B614D>