xargs(1): Sync with FreeBSD
[dragonfly.git] / share / mk / bsd.patch.mk
1 # $DragonFly: src/share/mk/bsd.patch.mk,v 1.5 2006/11/25 17:23:21 pavalos Exp $
2 #
3 # The include file <bsd.patch.mk> handles patching of files and sources.
4 #
5 # It is advisable to include this file before a rule which deduces ${OBJS}
6 # from ${SRCS}.
7 #
8 # +++ variables +++
9 #
10 # SRCS          List of source files, especially patches (*.patch)
11 #
12 # CONTRIBDIR    Location of source files to which the patch files are relative
13 #
14 # Patch files are added to ${SRCS} and follow the following patterns:
15 #   *.no_obj.patch      The patched source file won't be added to ${SRCS}.
16 #   *.h.patch           The patched source file is a header and will be
17 #                       added to ${SRCS}.
18 #   *.patch             The patched source file will be compiled to an object
19 #                       and will be added to ${SRCS}.
20 #
21 # All commas contained in the patch filename will be replaced to slashes to
22 # form a path in a subdir.
23 #
24 # Example:
25 #
26 # CONTRIBDIR=   ${.CURDIR}/../../contrib/foo-1.4/src
27 # SRCS+=        foomain.c.patch include,fooconf.h.patch
28 #
29 # This will patch ${CONTRIBDIR}/foomain.c with foomain.c.patch and add
30 # the patched foomain.c to ${SRCS}.
31 # The file ${CONTRIBDIR}/include/fooconf.h will be patched with
32 # include,fooconf.h.patch;  the patched file will be created in
33 # ${.OBJDIR}/include/fooconf.h and will be added to ${SRCS}.
34 #
35
36 _PATCHFILE: .USE 
37         mkdir -p ${.TARGET:H}
38         patch -o ${.TARGET} -i ${.ALLSRC:M*.patch} ${.ALLSRC:N*.patch}
39
40 .if defined(SRCS)
41 CLEANFILES?=
42
43 .for _PSRC in ${SRCS:M*.no_obj.patch}
44 .for _PC in ${_PSRC:T:C/(\.no_obj)?\.patch$//:S|,|/|g}
45 .if !exists(${_PSRC})
46 .error non-existent patch file ${_PSRC}
47 .endif
48
49 ${_PC}: _PATCHFILE ${CONTRIBDIR}/${_PC} ${_PSRC}
50
51 beforedepend: ${PC_}
52
53 SRCS:=  ${SRCS:N${_PSRC}}
54 CLEANFILES:=    ${CLEANFILES} ${_PC}
55 CLEANDIRS+=     ${_PC:C|[^/]*$||}
56 .endfor
57 .endfor
58
59 .for _PSRC in ${SRCS:N*.no_obj.patch:M*.patch}
60 .for _PC in ${_PSRC:T:C/(\.no_obj)?\.patch$//:S|,|/|g}
61 .if !exists(${_PSRC})
62 .error non-existent patch file ${_PSRC}
63 .endif
64
65 ${_PC}: _PATCHFILE ${CONTRIBDIR}/${_PC} ${_PSRC}
66
67 SRCS:=  ${SRCS:N${_PC}:S|${_PSRC}|${_PC}|}
68 CLEANFILES:=    ${CLEANFILES} ${_PC}
69 CLEANDIRS+=     ${_PC:C|[^/]*$||}
70 .endfor
71 .endfor
72 .endif