1# $MirOS: src/bin/mksh/Makefile,v 1.136 2014/09/03 19:22:48 tg Exp $
2#-
3# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
4#		2011, 2012, 2013, 2014
5#	Thorsten Glaser <tg@mirbsd.org>
6#
7# Provided that these terms and disclaimer and all copyright notices
8# are retained or reproduced in an accompanying document, permission
9# is granted to deal in this work without restriction, including un-
10# limited rights to use, publicly perform, distribute, sell, modify,
11# merge, give away, or sublicence.
12#
13# This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
14# the utmost extent permitted by applicable law, neither express nor
15# implied; without malicious intent or gross negligence. In no event
16# may a licensor, author or contributor be held liable for indirect,
17# direct, other damage, loss, or other issues arising in any way out
18# of dealing in the work, even if advised of the possibility of such
19# damage or existence of a defect, except proven that it results out
20# of said person's immediate fault when using the work as intended.
21
22.ifmake d
23__CRAZY=	Yes
24MKC_DEBG=	cpp
25DEBUGFILE=	Yes
26NOMAN=		Yes
27.endif
28
29.include <bsd.own.mk>
30
31PROG=		mksh
32SRCS=		edit.c eval.c exec.c expr.c funcs.c histrap.c jobs.c \
33		lalloc.c lex.c main.c misc.c shf.c syn.c tree.c var.c
34.if !make(test-build)
35CPPFLAGS+=	-DMKSH_ASSUME_UTF8 -DMKSH_DISABLE_DEPRECATED \
36		-DHAVE_ATTRIBUTE_BOUNDED=1 -DHAVE_ATTRIBUTE_FORMAT=1 \
37		-DHAVE_ATTRIBUTE_NORETURN=1 -DHAVE_ATTRIBUTE_PURE=1 \
38		-DHAVE_ATTRIBUTE_UNUSED=1 -DHAVE_ATTRIBUTE_USED=1 \
39		-DHAVE_SYS_TIME_H=1 -DHAVE_TIME_H=1 -DHAVE_BOTH_TIME_H=1 \
40		-DHAVE_SYS_BSDTYPES_H=0 -DHAVE_SYS_FILE_H=1 \
41		-DHAVE_SYS_MKDEV_H=0 -DHAVE_SYS_MMAN_H=1 -DHAVE_SYS_PARAM_H=1 \
42		-DHAVE_SYS_RESOURCE_H=1 -DHAVE_SYS_SELECT_H=1 \
43		-DHAVE_SYS_SYSMACROS_H=0 -DHAVE_BSTRING_H=0 -DHAVE_GRP_H=1 \
44		-DHAVE_LIBGEN_H=1 -DHAVE_LIBUTIL_H=0 -DHAVE_PATHS_H=1 \
45		-DHAVE_STDINT_H=1 -DHAVE_STRINGS_H=1 -DHAVE_TERMIOS_H=1 \
46		-DHAVE_ULIMIT_H=0 -DHAVE_VALUES_H=0 -DHAVE_CAN_INTTYPES=1 \
47		-DHAVE_CAN_UCBINTS=1 -DHAVE_CAN_INT8TYPE=1 \
48		-DHAVE_CAN_UCBINT8=1 -DHAVE_RLIM_T=1 -DHAVE_SIG_T=1 \
49		-DHAVE_SYS_ERRLIST=1 -DHAVE_SYS_SIGNAME=1 -DHAVE_SYS_SIGLIST=1 \
50		-DHAVE_FLOCK=1 -DHAVE_LOCK_FCNTL=1 -DHAVE_GETRUSAGE=1 \
51		-DHAVE_GETSID=1 -DHAVE_GETTIMEOFDAY=1 -DHAVE_KILLPG=1 \
52		-DHAVE_MEMMOVE=1 -DHAVE_MKNOD=0 -DHAVE_MMAP=1 -DHAVE_NICE=1 \
53		-DHAVE_REVOKE=1 -DHAVE_SETLOCALE_CTYPE=0 \
54		-DHAVE_LANGINFO_CODESET=0 -DHAVE_SELECT=1 -DHAVE_SETRESUGID=1 \
55		-DHAVE_SETGROUPS=1 -DHAVE_STRERROR=0 -DHAVE_STRSIGNAL=0 \
56		-DHAVE_STRLCPY=1 -DHAVE_FLOCK_DECL=1 -DHAVE_REVOKE_DECL=1 \
57		-DHAVE_SYS_ERRLIST_DECL=1 -DHAVE_SYS_SIGLIST_DECL=1 \
58		-DHAVE_PERSISTENT_HISTORY=1 -DMKSH_BUILD_R=502
59CPPFLAGS+=	-D${${PROG:L}_tf:C/(Mir${MAN:E}{0,1}){2}/4/:S/x/mksh_BUILD/:U}
60CPPFLAGS+=	-I.
61COPTS+=		-std=c89 -Wall
62.endif
63
64USE_PRINTF_BUILTIN?=	0
65.if ${USE_PRINTF_BUILTIN} == 1
66.PATH: ${BSDSRCDIR}/usr.bin/printf
67SRCS+=		printf.c
68CPPFLAGS+=	-DMKSH_PRINTF_BUILTIN
69.endif
70
71DEBUGFILE?=	No
72.if ${DEBUGFILE:L} == "yes"
73CPPFLAGS+=	-DDF=mksh_debugtofile
74.endif
75
76MANLINKS=	[ false pwd sh sleep test true
77BINLINKS=	${MANLINKS} echo domainname kill
78.for _i in ${BINLINKS}
79LINKS+=		${BINDIR}/${PROG} ${BINDIR}/${_i}
80.endfor
81.for _i in ${MANLINKS}
82MLINKS+=	${PROG}.1 ${_i}.1
83.endfor
84
85OPTGENS!=	cd ${.CURDIR:Q} && echo *.opt
86.for _i in ${OPTGENS}
87GENERATED+=	${_i:R}.gen
88${_i:R}.gen: ${_i} ${.CURDIR}/Build.sh
89	/bin/sh ${.CURDIR:Q}/Build.sh -G ${.CURDIR:Q}/${_i:Q}
90.endfor
91CLEANFILES+=	${GENERATED}
92
93${PROG} beforedepend: ${GENERATED}
94
95regress: ${PROG} check.pl check.t
96	-rm -rf regress-dir
97	mkdir -p regress-dir
98	echo export FNORD=666 >regress-dir/.mkshrc
99	HOME=$$(realpath regress-dir) perl ${.CURDIR}/check.pl \
100	    -s ${.CURDIR}/check.t -v -p ./${PROG} \
101	    -C shell:legacy-no,int:32,fastbox
102
103test-build: .PHONY
104	-rm -rf build-dir
105	mkdir -p build-dir
106.if ${USE_PRINTF_BUILTIN} == 1
107	cp ${BSDSRCDIR}/usr.bin/printf/printf.c build-dir/
108.endif
109	cd build-dir; env CC=${CC:Q} CFLAGS=${CFLAGS:M*:Q} \
110	    CPPFLAGS=${CPPFLAGS:M*:Q} LDFLAGS=${LDFLAGS:M*:Q} \
111	    LIBS= NOWARN=-Wno-error TARGET_OS= CPP= /bin/sh \
112	    ${.CURDIR}/Build.sh -Q -r ${_TBF} && ./test.sh -v -f
113
114CLEANFILES+=	lksh.cat1
115test-build-lksh: .PHONY
116	cd ${.CURDIR} && exec ${MAKE} lksh.cat1 test-build \
117	    _TBF=-L USE_PRINTF_BUILTIN=0
118
119bothmans: .PHONY
120	cd ${.CURDIR} && exec ${MAKE} MAN='lksh.1 mksh.1' __MANALL
121
122cleandir: clean-extra
123
124clean-extra: .PHONY
125	-rm -rf build-dir regress-dir printf.o printf.ln
126
127mksh_tf=xMakefile${OStype:S/${MACHINE_OS}/1/1g}${OSNAME}
128distribution:
129	sed 's!\$$I''d\([:$$]\)!$$M''irSecuCron\1!g' \
130	    ${.CURDIR}/dot.mkshrc >${DESTDIR}/etc/skel/.mkshrc
131	chown ${BINOWN}:${CONFGRP} ${DESTDIR}/etc/skel/.mkshrc
132	chmod 0644 ${DESTDIR}/etc/skel/.mkshrc
133
134.include <bsd.prog.mk>
135
136.ifmake cats
137V_GROFF!=	pkg_info -e 'groff-*'
138V_GHOSTSCRIPT!=	pkg_info -e 'ghostscript-*'
139.  if empty(V_GROFF) || empty(V_GHOSTSCRIPT)
140.    error empty V_GROFF=${V_GROFF} or V_GHOSTSCRIPT=${V_GHOSTSCRIPT}
141.  endif
142.endif
143
144CLEANFILES+=	${MANALL:S/.cat/.ps/} ${MAN:S/$/.pdf/} ${MANALL:S/$/.gz/}
145CLEANFILES+=	${MAN:S/$/.htm/} ${MAN:S/$/.htm.gz/}
146CLEANFILES+=	${MAN:S/$/.txt/} ${MAN:S/$/.txt.gz/}
147CATS_KW=	mksh, ksh, sh
148CATS_TITLE_mksh_1=mksh - The MirBSD Korn Shell
149cats: ${MANALL} ${MANALL:S/.cat/.ps/}
150.if "${MANALL:Nlksh.cat1:Nmksh.cat1}" != ""
151.  error Adjust here.
152.endif
153.for _m _n in mksh 1
154	x=$$(ident ${.CURDIR:Q}/${_m}.${_n} | \
155	    awk '/MirOS:/ { print $$4$$5; }' | \
156	    tr -dc 0-9); (( $${#x} == 14 )) || exit 1; exec \
157	    ${MKSH} ${BSDSRCDIR:Q}/contrib/hosted/tg/ps2pdfmir -c \
158	    -o ${_m}.${_n}.pdf '[' /Author '(The MirOS Project)' \
159	    /Title '('${CATS_TITLE_${_m}_${_n}:Q}')' \
160	    /Subject '(BSD Reference Manual)' /ModDate "(D:$$x)" \
161	    /Creator '(GNU groff version ${V_GROFF:S/groff-//} \(MirPorts\))' \
162	    /Producer '(Artifex Ghostscript ${V_GHOSTSCRIPT:S/ghostscript-//:S/-artifex//} \(MirPorts\))' \
163	    /Keywords '('${CATS_KW:Q}')' /DOCINFO pdfmark \
164	    -f ${_m}.ps${_n}
165.endfor
166	set -e; . ${BSDSRCDIR:Q}/scripts/roff2htm; set_target_absolute; \
167	    for m in ${MANALL}; do \
168		bn=$${m%.*}; ext=$${m##*.cat}; \
169		[[ $$bn != $$m ]]; [[ $$ext != $$m ]]; \
170		gzip -n9 <"$$m" >"$$m.gz"; \
171		col -bx <"$$m" >"$$bn.$$ext.txt"; \
172		rm -f "$$bn.$$ext.txt.gz"; gzip -n9 "$$bn.$$ext.txt"; \
173		do_conversion_verbose "$$bn" "$$ext" "$$m" "$$bn.$$ext.htm"; \
174		rm -f "$$bn.$$ext.htm.gz"; gzip -n9 "$$bn.$$ext.htm"; \
175	done
176
177.ifmake d
178.  ifmake obj || depend || all || install || regress || test-build
179d:
180.  else
181d: all
182.  endif
183.endif
184
185dr:
186	p=$$(realpath ${PROG:Q}) && cd ${.CURDIR:Q} && exec ${MKSH} \
187	    ${BSDSRCDIR:Q}/contrib/hosted/tg/sdmksh "$$p"
188