1#	$NetBSD: Makefile,v 1.92 2023/05/30 18:27:04 lukem Exp $
2
3HOSTLIB=	nbcompat
4
5.include <bsd.hostinit.mk>
6
7SRCS=		atoll.c basename.c cdbr.c cdbw.c dirname.c \
8		dprintf.c fgetln.c flock.c fparseln.c fpurge.c \
9		getcap.c getline.c getmode.c getopt_long.c gettemp.c \
10		heapsort.c getsubopt.c \
11		issetugid.c lchflags.c lchmod.c lchown.c libyywrap.c \
12		md2.c md2hl.c md4c.c md4hl.c md5c.c md5hl.c \
13		mi_vector_hash.c mkdtemp.c \
14		mkstemp.c pread.c putc_unlocked.c pwcache.c pwrite.c \
15		pw_scan.c \
16		raise_default_signal.c rb.c reallocarr.c reallocarray.c \
17		rmd160.c rmd160hl.c \
18		regcomp.c regerror.c regexec.c regfree.c \
19		setenv.c setgroupent.c \
20		setpassent.c setprogname.c sha1.c sha1hl.c sha2.c \
21		sha256hl.c sha384hl.c sha512hl.c snprintb.c snprintf.c \
22		stat_flags.c strlcat.c strlcpy.c strmode.c \
23		strcasecmp.c strncasecmp.c strndup.c strnlen.c \
24		strsep.c strsuftoll.c strtoll.c \
25		strtoi.c strtou.c \
26		unvis.c vis.c err.c errx.c errc.c verr.c verrx.c verrc.c \
27		vwarn.c vwarnx.c vwarnc.c warn.c warnx.c warnc.c \
28		fts.c glob.c efun.c
29
30BUILD_OSTYPE!=  uname -s
31
32# Disable use of pre-compiled headers on Darwin.
33.if ${BUILD_OSTYPE} == "Darwin"
34HOST_CPPFLAGS+=	-no-cpp-precomp
35.endif
36
37# -D_FILE_OFFSET_BITS=64 produces a much more amenable `struct stat', and
38# other file ops, on many systems, without changing function names.
39
40HOST_CPPFLAGS+=	-I. -I./include -I${.CURDIR} -I${.CURDIR}/sys \
41		-DHAVE_NBTOOL_CONFIG_H=1 -D_FILE_OFFSET_BITS=64
42
43.PATH:		${.CURDIR}/../../lib/libc/cdb \
44		${.CURDIR}/../../lib/libc/gen \
45		${.CURDIR}/../../lib/libc/hash \
46		${.CURDIR}/../../lib/libc/hash/md2 \
47		${.CURDIR}/../../lib/libc/hash/md5 \
48		${.CURDIR}/../../lib/libc/hash/rmd160 \
49		${.CURDIR}/../../lib/libc/hash/sha1 \
50		${.CURDIR}/../../lib/libc/hash/sha2 \
51		${.CURDIR}/../../lib/libc/md \
52		${.CURDIR}/../../lib/libc/regex \
53		${.CURDIR}/../../lib/libc/stdio \
54		${.CURDIR}/../../lib/libc/stdlib \
55		${.CURDIR}/../../lib/libc/string \
56		${.CURDIR}/../../lib/libutil \
57		${.CURDIR}/../../common/lib/libc/cdb \
58		${.CURDIR}/../../common/lib/libc/gen \
59		${.CURDIR}/../../common/lib/libc/string \
60		${.CURDIR}/../../common/lib/libc/hash/rmd160 \
61		${.CURDIR}/../../common/lib/libc/hash/sha1 \
62		${.CURDIR}/../../common/lib/libc/hash/sha2 \
63		${.CURDIR}/../../common/lib/libc/md \
64		${.CURDIR}/../../common/lib/libc/stdlib \
65		${.CURDIR}/../../common/lib/libutil \
66		${.CURDIR}/../../external/bsd/flex/dist/src
67
68DPSRCS+=	defs.mk
69CLEANFILES+=	config.log config.status configure.lineno *.stamp
70CLEANDIRFILES+=	defs.mk config.cache confdefs.h
71
72# Get components of Berkeley DB.
73_CURDIR:=	${.CURDIR}
74.CURDIR:=	${_CURDIR}/../../lib/libc
75.include "${.CURDIR}/db/Makefile.inc"
76.CURDIR:=	${_CURDIR}
77
78SRCS:=		${SRCS:M*.c}
79
80CONFIGURE_ARGS=	--cache-file=config.cache
81.if ${MAKEVERBOSE} == 0
82CONFIGURE_ARGS+=--silent
83.endif
84
85config.cache: include/.stamp configure nbtool_config.h.in defs.mk.in
86	rm -f ${.TARGET}
87	CC=${HOST_CC:Q} CFLAGS=${HOST_CFLAGS:Q} CPPFLAGS=${HOST_CPPFLAGS:Q} \
88		LDFLAGS=${HOST_LDFLAGS:Q} \
89		${HOST_SH} ${.CURDIR}/configure ${CONFIGURE_ARGS}
90
91defs.mk: config.cache
92	@touch ${.TARGET}
93
94INCFILES=	nbtool_config.h
95INCSUBDIRS=	sys machine rpc arpa
96CLEANDIRFILES+= ${INCFILES}
97
98# CLEANDIRFILES may not contain directory names
99cleandir:	cleandir.include
100cleandir.include: .PHONY
101		rm -rf include
102
103include/.stamp:
104	mkdir -p ${INCSUBDIRS:@d@ include/$d @}
105	@touch ${.TARGET}
106
107# Install rules
108
109HOST_LIBDIR=	${TOOLDIR}/lib
110HOST_INCSDIR=	${TOOLDIR}/include
111HOST_SHAREDIR= ${TOOLDIR}/share
112
113install:	.PHONY install.lib includes install.defs.mk
114
115# Install lib${HOSTLIB}.a in ${TOOLDIR}/lib
116install.lib: .PHONY ${HOST_LIBDIR}/lib${HOSTLIB}.a
117${HOST_LIBDIR}/lib${HOSTLIB}.a: lib${HOSTLIB}.a
118	${_MKTARGET_INSTALL}
119	${HOST_INSTALL_DIR} ${HOST_LIBDIR}
120	${HOST_INSTALL_FILE} -m ${LIBMODE} ${.ALLSRC} ${.TARGET}
121
122.for _f in ${INCFILES}
123HOST_INCINSTFILES+= ${HOST_INCSDIR}/compat/${_f}
124${HOST_INCSDIR}/compat/${_f}: ${_f}
125	${_MKTARGET_INSTALL}
126	${HOST_INSTALL_FILE} ${.ALLSRC} ${.TARGET}
127.endfor
128
129.for _d in ${INCSUBDIRS}
130HOST_INCINSTDIRS+= ${HOST_INCSDIR}/compat/${_d}
131${HOST_INCSDIR}/compat/${_d}:
132	${_MKTARGET_INSTALL}
133	${HOST_INSTALL_DIR} ${.TARGET}
134.endfor
135
136# Install include files in ${TOOLDIR}/include/compat
137includes: .PHONY ${HOST_INCINSTDIRS} .WAIT ${HOST_INCINSTFILES}
138	@(cd include && find . -name '*.h' -print | while read f ; do \
139	    ${HOST_INSTALL_FILE} $$f ${HOST_INCSDIR}/compat/$$f ; \
140	done)
141
142
143# Install defs.mk in ${TOOLDIR}/share/compat
144install.defs.mk: .PHONY ${HOST_SHAREDIR}/compat/defs.mk
145${HOST_SHAREDIR}/compat/defs.mk: defs.mk
146	${_MKTARGET_INSTALL}
147	${HOST_INSTALL_DIR} ${HOST_SHAREDIR}
148	${HOST_INSTALL_DIR} ${HOST_SHAREDIR}/compat
149	${HOST_INSTALL_FILE} ${.ALLSRC} ${.TARGET}
150
151# bsd.hostlib.mk wants HOST_CPPFLAGS, not CPPFLAGS
152
153HOST_CPPFLAGS+=	${CPPFLAGS}
154
155.include <bsd.hostlib.mk>
156
157# Use uninstalled copy of host-mkdep
158HOST_MKDEP_OBJ!= cd ${.CURDIR}/../host-mkdep && ${PRINTOBJDIR}
159HOST_MKDEP=	${HOST_MKDEP_OBJ}/host-mkdep
160MKDEP=		${HOST_MKDEP}
161
162# Use uninstalled copy of the install program
163INSTALL_OBJ!=	cd ${NETBSDSRCDIR}/tools/binstall && ${PRINTOBJDIR}
164INSTALL=	${INSTALL_OBJ}/xinstall
165
166# Run "${TOOLDIR}/bin/nbmake-${MACHINE} regen" by hand after editing
167# configure.ac.  See more detailed instructions in configure.ac.
168regen:
169	${_MKMSG_REGEN} configure nbtool_config.h.in
170	cd ${.CURDIR} && ${TOOLDIR}/bin/${_TOOL_PREFIX}autoreconf \
171		${${MAKEVERBOSE} >= 2 :? -v :}
172