Merge from vendor branch TNF:
[pkgsrcv2.git] / emulators / compat_netbsd / Makefile.common
1 # $NetBSD: Makefile.common,v 1.10 2008/03/03 19:21:37 jlam Exp $
2 #
3 # Common infrastructure for NetBSD compat* packages.
4 #
5 # This file should be included after EMUL_PLATFORMS and NETBSD_VERSION are
6 # defined and before EMUL_PLATFORM is used.
7 #
8
9 CATEGORIES=             emulators
10 MASTER_SITES=           ${MASTER_SITE_LOCAL:=${DIST_SUBDIR}${DIST_SUBDIR:D/}}
11 EXTRACT_SUFX=           .tar.bz2
12
13 MAINTAINER=             pkgsrc-users@NetBSD.org
14
15 PKG_DESTDIR_SUPPORT=    destdir
16
17 NO_SRC_ON_FTP=          Already in MASTER_SITE_LOCAL
18
19 USE_TOOLS+=     pax
20
21 NETBSD_PKG=             yes
22 EMUL_REQD=              netbsd>=${NETBSD_VERSION}
23
24 .include "../../mk/bsd.prefs.mk"
25
26 .if defined(NETBSD_COMPAT32) && defined(ACCEPTABLE_NETBSD)
27 ONLY_FOR_PLATFORM+=     ${ACCEPTABLE_NETBSD:S/$/-sparc64/}
28 ONLY_FOR_PLATFORM+=     ${ACCEPTABLE_NETBSD:S/$/-x86_64/}
29 .endif
30
31 NETBSD_PKGSRCDIR?=      ${.CURDIR}/../${.CURDIR:T:S/^netbsd32_//}
32 FILESDIR=               ${NETBSD_PKGSRCDIR}/files
33 PATCHDIR=               ${NETBSD_PKGSRCDIR}/patches
34 PKGDIR=                 ${NETBSD_PKGSRCDIR}
35
36 .if defined(NETBSD_COMPAT32)
37 PKGNAME=                netbsd32_${DISTNAME:S/-${EMUL_ARCH}-/-/}
38 COMMENT:=               ${COMMENT:S/NetBSD/NetBSD 32-bit/}
39 NETBSD_BASE=            netbsd32_
40 .else
41 PKGNAME=                ${DISTNAME:S/-${EMUL_ARCH}-/-/}
42 NETBSD_BASE=            # empty
43 .endif
44
45 BUILD_DIRS=             # empty
46 MAKE_DIRS+=             ${EMULDIR}
47 ELF_SYMLINKS_DATA=      ${WRKDIR}/.symlinks-data
48
49 #
50 # PLISTs are composed from the following bits, in order:
51 #
52 #       PLIST.${EMUL_ARCH}      e.g. PLIST.alpha
53 #       PLIST.${EMUL_EXEC_FMT}  e.g. PLIST.ELF
54 #       PLIST                   e.g. PLIST
55 #
56 .if exists(${PKGDIR}/PLIST.${EMUL_ARCH})
57 PLIST_SRC+=             ${PKGDIR}/PLIST.${EMUL_ARCH}
58 .endif
59 .if exists(${PKGDIR}/PLIST.${EMUL_EXEC_FMT})
60 PLIST_SRC+=             ${PKGDIR}/PLIST.${EMUL_EXEC_FMT}
61 .endif
62 .if exists(${PKGDIR}/PLIST)
63 PLIST_SRC+=             ${PKGDIR}/PLIST
64 .endif
65
66 # Set NATIVE_EXEC_FMT and EMUL_EXEC_FMT appropriately.  Normally, these
67 # are set by mk/emulator.mk, included in bsd.pkg.mk, but this happens
68 # too late for us here.
69 #
70 # Directly set NATIVE_EXEC_FMT and include the correct emulator.mk file
71 # to define EMUL_EXEC_FMT.
72 #
73 NATIVE_EXEC_FMT=        ${_NATIVE_EXEC_FMT_cmd:sh}
74 _NATIVE_EXEC_FMT_cmd=   sh ${.CURDIR}/../../mk/scripts/shlib-type       \
75                                 ${_OPSYS_SHLIB_TYPE:Q} ${MAKE:Q}
76
77 .include "${PKGSRCDIR}/emulators/${COMPAT_PKG}/emulator.mk"
78
79 #
80 # Different combinations of the native executable format and the emulated
81 # executable format require different ways of making the installed shared
82 # libraries useful after installation.
83 #
84 #       native  emul    action
85 #       -----   ----    ------
86 #       a.out   a.out   append to ld.so.conf and run ldconfig
87 #       ELF     a.out   run ldconfig
88 #       ELF     ELF     create symlinks to shlibs into base system
89 #       ELF64   ELF32   nothing
90 #
91 .if (${NATIVE_EXEC_FMT} == "a.out") && (${EMUL_EXEC_FMT} == "a.out")
92 INSTALL_TEMPLATES+=     ${PKGSRCDIR}/emulators/compat_netbsd/INSTALL.a.out
93
94 .elif (${NATIVE_EXEC_FMT} == "ELF") && (${EMUL_EXEC_FMT} == "a.out")
95 INSTALL_TEMPLATES+=     ${PKGSRCDIR}/emulators/compat_netbsd/INSTALL.emulaout
96
97 .elif defined(NETBSD_COMPAT32)
98 INSTALL_TEMPLATES+=     ${PKGSRCDIR}/emulators/compat_netbsd/INSTALL.emulnetbsd32
99
100 .else # (${NATIVE_EXEC_FMT} == "ELF") && (${EMUL_EXEC_FMT} == "ELF")
101 INSTALL_TEMPLATES+=     ${PKGSRCDIR}/emulators/compat_netbsd/INSTALL.ELF
102 INSTALL_TEMPLATES+=     ${ELF_SYMLINKS_DATA}
103 post-build: symlinks-data
104 .endif
105
106 DEINSTALL_TEMPLATES+=   ${PKGSRCDIR}/emulators/compat_netbsd/DEINSTALL
107
108 #
109 # For ELF platforms, the INSTALL.ELF script needs SYMLINK data lines to
110 # tell it which shared libraries need to be symlinked to where.  Generate
111 # this information from the PLIST.
112 #
113 .PHONY: symlinks-data
114 symlinks-data: ${ELF_SYMLINKS_DATA}
115 ${ELF_SYMLINKS_DATA}: plist
116         ${RUN} ${CAT} ${PLIST} | ${AWK}                                 \
117         'BEGIN { print "#" } END { print "#" } /^@/ { next }            \
118          { src = $$0; dst = src; sub("^${EMULSUBDIRSLASH}", "/", dst);  \
119            print "# SYMLINK: " src " " dst }' > ${.TARGET}
120
121 #
122 # The compat* packages have a very strict package layout:
123 #
124 #       ${WRKSRC}/lib
125 #       ${WRKSRC}/libexec
126 #       ${WRKSRC}/usr
127 #
128 # Each of these directories, if they exist, are copied directly into
129 # ${EMULDIR}.
130 #
131 .PHONY: compat-install
132 do-install: compat-install
133 compat-install:
134         ${INSTALL_DATA_DIR} ${DESTDIR}${PREFIX}/${EMULSUBDIR}
135         cd ${WRKSRC} && for dir in lib libexec usr; do                  \
136                 if ${TEST} -d "$$dir"; then                             \
137                         pax -rw "$$dir"                         \
138                                 ${DESTDIR}${PREFIX}/${EMULSUBDIR};      \
139                 fi;                                                     \
140         done