1#
2# cscript - makefile for calc shell script files
3#
4# Copyright (C) 1999-2006,2014,2017,2021  Landon Curt Noll
5#
6# SRC: cscript/Makefile
7#
8#	The "# SRC: ... - ..." comment line above indicates
9#	the origin of this file.
10#
11# IMPORTANT: Please see the section on Makefiles near the
12#	     bottom of the HOWTO.INSTALL file.
13#
14# Calc is open software; you can redistribute it and/or modify it under
15# the terms of the version 2.1 of the GNU Lesser General Public License
16# as published by the Free Software Foundation.
17#
18# Calc is distributed in the hope that it will be useful, but WITHOUT
19# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20# or FITNESS FOR A PARTICULAR PURPOSE.	See the GNU Lesser General
21# Public License for more details.
22#
23# A copy of version 2.1 of the GNU Lesser General Public License is
24# distributed with calc under the filename COPYING-LGPL.  You should have
25# received a copy with calc; if not, write to Free Software Foundation, Inc.
26# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
27#
28# Under source code control:	1999/11/29 11:10:26
29# File existed as early as:	1999
30#
31# chongo <was here> /\oo/\	http://www.isthe.com/chongo/
32# Share and enjoy!  :-) http://www.isthe.com/chongo/tech/comp/calc/
33#
34# calculator by David I. Bell with help/mods from others
35# Makefile by Landon Curt Noll
36
37
38# The shell used by this Makefile
39#
40# On some systems, /bin/sh is a rather reduced shell with
41# deprecated behavior.
42#
43# If your system has a up to date, bash shell, then
44# you may wish to use:
45#
46#	SHELL= /bin/sh
47#
48# On some systems such as macOS, the bash shell is very
49# far behind to the point where is cannot be depended on.
50# On such systems, the sh may be a much better alternative
51# shell for this Makefile to use:
52#
53#	SHELL= /bin/sh
54#
55SHELL= /bin/sh
56#SHELL= /bin/sh
57#if 0	/* start of skip for non-Gnu makefiles */
58ifeq ($(target),Darwin)
59SHELL:= /bin/zsh
60endif
61#endif	/* end of skip for non-Gnu makefiles */
62
63
64####
65# Normally, the upper level makefile will set these values.  We provide
66# a default here just in case you want to build from this directory.
67####
68
69# PREFIX - Top level location for calc
70#
71# The PREFIX is often prepended to paths within calc and calc Makefiles.
72#
73# Starting with calc v2.13.0.1, nearly all Makefile places that used
74# /usr/local now use ${PREFIX}.  An exception is the olduninstall rule
75# and, of course, this section. :-)
76#
77# NOTE: The ${PREFIX} is not the same as ${T}.  The ${T} specifies
78#	a top level directory under which calc installs things.
79#	While usually ${T} is empty, it can be specific path
80#	as if calc where "chrooted" during an install.
81#	The ${PREFIX} value, during install, is a path between
82#	the top level ${T} install directory and the object
83#	such as an include file.
84#
85# NOTE: See also, ${T}, below.
86#
87# There are some paths that do NOT call under ${PREFIX}, such as
88# ${CALCPATH}, that include paths not under ${PREFIX}, but those
89# too are exceptions to this general rule.
90#
91# When in doubt, try:
92#
93#	PREFIX= /usr/local
94#
95PREFIX= /usr/local
96#PREFIX= /usr
97#PREFIX= /usr/global
98
99# Normally certain files depend on the Makefile.  If the Makefile is
100# changed, then certain steps should be redone.  If MAKE_FILE is
101# set to Makefile, then these files will depend on Makefile.  If
102# MAKE_FILE is empty, then they wont.
103#
104# If in doubt, set MAKE_FILE to Makefile
105#
106MAKE_FILE= Makefile
107
108# Where the system include (.h) files are kept
109#
110# For DJGPP, select:
111#
112#	INCDIR= /dev/env/DJDIR/include
113#
114# If in doubt, set:
115#
116#	INCDIR= /usr/include
117#
118
119#INCDIR= ${PREFIX}/include
120#INCDIR= /dev/env/DJDIR/include
121INCDIR= /usr/include
122
123# where to install calc related things
124#
125# ${BINDIR}		where to install calc binary files
126# ${LIBDIR}		where calc link library (*.a) files are installed
127# ${CALC_SHAREDIR}	where to install calc help, .cal, startup, config files
128#
129# NOTE: The install rule prepends installation paths with ${T}, which
130#	by default is empty.  If ${T} is non-empty, then installation
131#	locations will be relative to the ${T} directory.
132#
133# For DJGPP, select:
134#
135#	BINDIR= /dev/env/DJDIR/bin
136#	LIBDIR= /dev/env/DJDIR/lib
137#	CALC_SHAREDIR= /dev/env/DJDIR/share/calc
138#
139# If in doubt, set:
140#
141#	BINDIR= /usr/bin
142#	LIBDIR= /usr/lib
143#	CALC_SHAREDIR= /usr/share/calc
144#
145#BINDIR= ${PREFIX}/bin
146#BINDIR= /dev/env/DJDIR/bin
147BINDIR= /usr/bin
148
149#LIBDIR= ${PREFIX}/lib
150#LIBDIR= /dev/env/DJDIR/lib
151LIBDIR= /usr/lib
152
153#CALC_SHAREDIR= ${PREFIX}/lib/calc
154#CALC_SHAREDIR= /dev/env/DJDIR/share/calc
155CALC_SHAREDIR= /usr/share/calc
156
157# By default, these values are based CALC_SHAREDIR, INCDIR, BINDIR
158# ---------------------------------------------------------------
159# ${HELPDIR}		where the help directory is installed
160# ${CALC_INCDIR}	where the calc include files are installed
161# ${SCRIPTDIR}		where calc shell scripts are installed
162#
163# NOTE: The install rule prepends installation paths with ${T}, which
164#	by default is empty.  If ${T} is non-empty, then installation
165#	locations will be relative to the ${T} directory.
166#
167# If in doubt, set:
168#
169#	HELPDIR= ${CALC_SHAREDIR}/help
170#	CALC_INCDIR= ${INCDIR}/calc
171#	SCRIPTDIR= ${BINDIR}/cscript
172#
173HELPDIR= ${CALC_SHAREDIR}/help
174CALC_INCDIR= ${INCDIR}/calc
175SCRIPTDIR= ${BINDIR}/cscript
176
177# T - top level directory under which calc will be installed
178#
179# The calc install is performed under ${T}, the calc build is
180# performed under /.	The purpose for ${T} is to allow someone
181# to install calc somewhere other than into the system area.
182#
183# For example, if:
184#
185#     BINDIR= /usr/bin
186#     LIBDIR= /usr/lib
187#     CALC_SHAREDIR= /usr/share/calc
188#
189# and if:
190#
191#     T= /var/tmp/testing
192#
193# Then the installation locations will be:
194#
195#     calc binary files:	/var/tmp/testing/usr/bin
196#     calc link library:	/var/tmp/testing/usr/lib
197#     calc help, .cal ...:	/var/tmp/testing/usr/share/calc
198#     ... etc ...		/var/tmp/testing/...
199#
200# If ${T} is empty, calc is installed under /, which is the same
201# top of tree for which it was built.  If ${T} is non-empty, then
202# calc is installed under ${T}, as if one had to chroot under
203# ${T} for calc to operate.
204#
205# If in doubt, use T=
206#
207T=
208
209# Makefile debug
210#
211# Q=@	do not echo internal Makefile actions (quiet mode)
212# Q=	echo internal Makefile actions (debug / verbose mode)
213#
214# H=@:	do not report hsrc file formation progress
215# H=@	do echo hsrc file formation progress
216#
217# S= >/dev/null 2>&1	silence ${CC} output during hsrc file formation
218# S=			full ${CC} output during hsrc file formation
219#
220# E= 2>/dev/null	silence command stderr during hsrc file formation
221# E=			full command stderr during hsrc file formation
222#
223# V=@:	do not echo debug statements (quiet mode)
224# V=@	do echo debug statements (debug / verbose mode)
225#
226#Q=
227Q=@
228#
229S= >/dev/null 2>&1
230#S=
231#
232E= 2>/dev/null
233#E=
234#
235#H=@:
236H=@
237#
238V=@:
239#V=@
240
241# standard tools
242#
243CAT= cat
244CHMOD= chmod
245CMP= cmp
246CO= co
247CP= cp
248FMT= fmt
249MKDIR= mkdir
250MV= mv
251RM= rm
252RMDIR= rmdir
253SED= sed
254SORT= sort
255TOUCH= touch
256TRUE= true
257
258# NOTE: On some shells, echo is a builtin that does
259#	not understand -n, so we call /bin/echo -n
260#	directly to get around such shells.
261#
262ECHON= /bin/echo -n
263
264# The ${SCRIPT} list is the list of calc shell script files (without the .calc
265# extension) which will be installed.
266#
267# The ${SCRIPT_SRC} is built from ${SCRIPT} and has the .calc extensions.
268#
269# This list is produced by the detaillist rule when no WARNINGS are detected.
270# To add a script:
271#
272#	1) Name the file with a .calc filename extension
273#	2) Add the name, without the .calc extension to the ${SCRIPT} below
274#	3) Write out this Makefile
275#	4) Replace the SCRIPT= and SCRIPT_SRC= lines with the output of:
276#
277#		make detaillist
278#
279SCRIPT= 4dsphere fproduct mersenne piforever plus powerterm simple \
280	square
281
282SCRIPT_SRC= 4dsphere.calc fproduct.calc mersenne.calc piforever.calc \
283	plus.calc powerterm.calc simple.calc square.calc
284
285# These files are found (but not built) in the distribution
286#
287DISTLIST= ${SCRIPT_SRC} ${MAKE_FILE} README.src
288
289# These files are used to make (but not build) a calc .a library
290#
291CALCLIBLIST=
292
293# complete list of targets
294#
295# NOTE: This list MUST be coordinated with the ${CSCRIPT_TARGETS} variable
296#	in the upper level ../Makefile
297#
298CSCRIPT_TARGETS= ${SCRIPT}
299TARGETS= ${CSCRIPT_TARGETS} README
300
301# The reason for this Makefile
302#
303all: ${TARGETS} .all
304
305README: README.src
306	@${RM} -f $@
307	@${SED} -e "s:#!/usr/local/src/bin/calc/calc:#!${BINDIR}/calc:" $?>$@
308
309# used by the upper level Makefile to determine if we have done all
310#
311# NOTE: Due to bogus shells found on one common system we must have
312#	a non-empty else clause for every if condition.  *sigh*
313#
314.all:
315	${RM} -f .all
316	${TOUCH} .all
317
318##
319#
320# File list generation.	 You can ignore this section.
321#
322#
323# We will form the names of source files as if they were in a
324# sub-directory called calc/cscript.
325#
326##
327
328distlist: ${DISTLIST}
329	${Q} for i in ${DISTLIST} /dev/null; do \
330	    if [ X"$$i" != X"/dev/null" ]; then \
331		echo cscript/$$i; \
332	    fi; \
333	done | LANG=C ${SORT}
334
335distdir:
336	${Q} echo cscript
337
338calcliblist:
339
340# These next rule help me form the ${SCRIPT} and ${SCRIPT_SRC} makefile
341# variables above.
342#
343detaillist:
344	${Q} -(echo "xxxxxxx"; \
345	   for i in ${SCRIPT} /dev/null; do \
346	    if [ X"$$i" != X"/dev/null" ]; then \
347		echo $$i; \
348	    fi; \
349	done | LANG=C ${SORT}) | ${FMT} -70 | \
350	    ${SED} -e '1s/xxxxxxx/SCRIPT=/' -e '2,$$s/^/	/' \
351		   -e 's/$$/ \\/' -e '$$s/ \\$$//'
352	${Q} echo
353	${Q} -(echo "xxxxxxxxxxx"; \
354	    for i in ${SCRIPT} /dev/null; do \
355	    if [ X"$$i" != X"/dev/null" ]; then \
356		echo $$i.calc; \
357	    fi; \
358	done | LANG=C ${SORT}) | ${FMT} -70 | \
359	    ${SED} -e '1s/xxxxxxxxxxx/SCRIPT_SRC=/' -e '2,$$s/^/	/' \
360		   -e 's/$$/ \\/' -e '$$s/ \\$$//'
361
362##
363#
364# Home grown make dependency rules.  Your system make not support
365# or have the needed tools.  You can ignore this section.
366#
367# We will form a skeleton tree of *.c files containing only #include "foo.h"
368# lines and .h files containing the same lines surrounded by multiple include
369# prevention lines.  This allows us to build a static depend list that will
370# satisfy all possible cpp symbol definition combinations.
371#
372##
373
374depend:
375	${Q} if [ -f ${MAKE_FILE}.bak ]; then \
376	    echo "${MAKE_FILE}.bak exists, remove or move it"; \
377	    exit 1; \
378	else \
379	    ${TRUE}; \
380	fi
381	${Q} ${RM} -f makedep.out
382	${Q} echo forming cscript dependency list
383	${Q} for i in ${SCRIPT} /dev/null; do \
384	    if [ X"$$i" != X"/dev/null" ]; then \
385		echo "$$i: $$i.calc"; \
386		echo '	@$${RM} -f $$@'; \
387		${ECHON} '	@$${SED} -e "1s:^#!/usr/local/src/bin/'; \
388		echo 'calc/calc:#!$${BINDIR}/calc:" $$?>$$@'; \
389		echo '	@$${CHMOD} +x $$@'; \
390	    fi; \
391	done >> makedep.out
392	${Q} echo sample dependency list formed
393	${Q} echo forming new cscript/${MAKE_FILE}
394	${Q} ${RM} -f ${MAKE_FILE}.bak
395	${Q} ${MV} ${MAKE_FILE} ${MAKE_FILE}.bak
396	${Q} ${SED} -n '1,/^# DO NOT DELETE THIS LINE/p' \
397		    ${MAKE_FILE}.bak > ${MAKE_FILE}
398	${Q} echo "" >> ${MAKE_FILE}
399	${Q} ${CAT} makedep.out >> ${MAKE_FILE}
400	${Q} ${RM} -f makedep.out
401	-${Q} if ${CMP} -s ${MAKE_FILE}.bak ${MAKE_FILE}; then \
402	    echo 'cscript/${MAKE_FILE} was already up to date'; \
403	    echo 'restoring original cscript/${MAKE_FILE}'; \
404	    ${MV} -f ${MAKE_FILE}.bak ${MAKE_FILE}; \
405	else \
406	    echo 'old cscript/${MAKE_FILE} is now cscript/${MAKE_FILE}.bak'; \
407	    echo 'new cscript/${MAKE_FILE} formed'; \
408	    echo 'try: diff -u cscript/${MAKE_FILE}.bak cscript/${MAKE_FILE}'; \
409	fi
410
411##
412#
413# rpm rules
414#
415##
416
417echo_inst_files:
418	${Q} for i in ${SCRIPT} /dev/null; do \
419	    if [ X"$$i" != X"/dev/null" ]; then \
420		echo __file__ ${SCRIPTDIR}/$$i; \
421	    fi; \
422	done
423
424##
425#
426# Utility rules
427#
428##
429
430clean:
431	${RM} -f makedep.out
432
433clobber: clean
434	${RM} -f .all
435	${RM} -f ${TARGETS}
436	-${Q} if [ -e .DS_Store ]; then \
437	    echo ${RM} -rf .DS_Store; \
438	    ${RM} -rf .DS_Store; \
439	fi
440
441# install everything
442#
443# NOTE: Keep the uninstall rule in reverse order to the install rule
444#
445install: all
446	-${Q} if [ ! -d ${T}${BINDIR} ]; then \
447	    echo ${MKDIR} -p ${T}${BINDIR}; \
448	    ${MKDIR} -p ${T}${BINDIR}; \
449	    if [ ! -d "${T}${BINDIR}" ]; then \
450		echo ${MKDIR} -p "${T}${BINDIR}"; \
451		${MKDIR} -p "${T}${BINDIR}"; \
452	    fi; \
453	    echo ${CHMOD} 0755 ${T}${BINDIR}; \
454	    ${CHMOD} 0755 ${T}${BINDIR}; \
455	else \
456	    ${TRUE}; \
457	fi
458	-${Q} if [ ! -d ${T}${SCRIPTDIR} ]; then \
459	    echo ${MKDIR} -p ${T}${SCRIPTDIR}; \
460	    ${MKDIR} -p ${T}${SCRIPTDIR}; \
461	    if [ ! -d "${T}${SCRIPTDIR}" ]; then \
462		echo ${MKDIR} -p "${T}${SCRIPTDIR}"; \
463		${MKDIR} -p "${T}${SCRIPTDIR}"; \
464	    fi; \
465	    echo ${CHMOD} 0755 ${T}${SCRIPTDIR}; \
466	    ${CHMOD} 0755 ${T}${SCRIPTDIR}; \
467	else \
468	    ${TRUE}; \
469	fi
470	${Q} for i in ${SCRIPT} /dev/null; do \
471	    if [ "$$i" = "/dev/null" ]; then \
472		continue; \
473	    fi; \
474	    if ${CMP} -s $$i ${T}${SCRIPTDIR}/$$i; then \
475		${TRUE}; \
476	    else \
477		${RM} -f ${T}${SCRIPTDIR}/$$i.new; \
478		${CP} -f $$i ${T}${SCRIPTDIR}/$$i.new; \
479		${CHMOD} 0755 ${T}${SCRIPTDIR}/$$i.new; \
480		${MV} -f ${T}${SCRIPTDIR}/$$i.new ${T}${SCRIPTDIR}/$$i; \
481		echo "installed ${T}${SCRIPTDIR}/$$i"; \
482	    fi; \
483	done
484
485# Try to remove everything that was installed
486#
487# NOTE: Keep the uninstall rule in reverse order to the install rule
488#
489uninstall:
490	-${Q} for i in ${SCRIPT} /dev/null; do \
491	    if [ "$$i" = "/dev/null" ]; then \
492		continue; \
493	    fi; \
494	    if [ -f "${T}${SCRIPTDIR}/$$i" ]; then \
495		${RM} -f "${T}${SCRIPTDIR}/$$i"; \
496		if [ -f "${T}${SCRIPTDIR}/$$i" ]; then \
497		   echo "cannot uninstall ${T}${SCRIPTDIR}/$$i"; \
498		else \
499		   echo "uninstalled ${T}${SCRIPTDIR}/$$i"; \
500		fi; \
501	    fi; \
502	done
503	-${Q} for i in ${SCRIPTDIR} ${BINDIR}; do \
504	    if [ -d "${T}$$i" ]; then \
505		${RMDIR} "${T}$$i" 2>/dev/null; \
506		echo "cleaned up ${T}$$i"; \
507	    fi; \
508	done
509
510# DO NOT DELETE THIS LINE -- make depend depends on it.
511
5124dsphere: 4dsphere.calc
513	@${RM} -f $@
514	@${SED} -e "1s:^#!/usr/local/src/bin/calc/calc:#!${BINDIR}/calc:" $?>$@
515	@${CHMOD} +x $@
516fproduct: fproduct.calc
517	@${RM} -f $@
518	@${SED} -e "1s:^#!/usr/local/src/bin/calc/calc:#!${BINDIR}/calc:" $?>$@
519	@${CHMOD} +x $@
520mersenne: mersenne.calc
521	@${RM} -f $@
522	@${SED} -e "1s:^#!/usr/local/src/bin/calc/calc:#!${BINDIR}/calc:" $?>$@
523	@${CHMOD} +x $@
524piforever: piforever.calc
525	@${RM} -f $@
526	@${SED} -e "1s:^#!/usr/local/src/bin/calc/calc:#!${BINDIR}/calc:" $?>$@
527	@${CHMOD} +x $@
528plus: plus.calc
529	@${RM} -f $@
530	@${SED} -e "1s:^#!/usr/local/src/bin/calc/calc:#!${BINDIR}/calc:" $?>$@
531	@${CHMOD} +x $@
532powerterm: powerterm.calc
533	@${RM} -f $@
534	@${SED} -e "1s:^#!/usr/local/src/bin/calc/calc:#!${BINDIR}/calc:" $?>$@
535	@${CHMOD} +x $@
536simple: simple.calc
537	@${RM} -f $@
538	@${SED} -e "1s:^#!/usr/local/src/bin/calc/calc:#!${BINDIR}/calc:" $?>$@
539	@${CHMOD} +x $@
540square: square.calc
541	@${RM} -f $@
542	@${SED} -e "1s:^#!/usr/local/src/bin/calc/calc:#!${BINDIR}/calc:" $?>$@
543	@${CHMOD} +x $@
544