1#!/bin/make
2#
3# cal - makefile for calc standard resource files
4#
5# Copyright (C) 1999-2006,2017,2021  Landon Curt Noll
6#
7# SRC: cal/Makefile
8#
9#	The "# SRC: ... - ..." comment line above indicates
10#	the origin of this file.
11#
12# IMPORTANT: Please see the section on Makefiles near the
13#	     bottom of the HOWTO.INSTALL file.
14#
15# Calc is open software; you can redistribute it and/or modify it under
16# the terms of the version 2.1 of the GNU Lesser General Public License
17# as published by the Free Software Foundation.
18#
19# Calc is distributed in the hope that it will be useful, but WITHOUT
20# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21# or FITNESS FOR A PARTICULAR PURPOSE.	See the GNU Lesser General
22# Public License for more details.
23#
24# A copy of version 2.1 of the GNU Lesser General Public License is
25# distributed with calc under the filename COPYING-LGPL.  You should have
26# received a copy with calc; if not, write to Free Software Foundation, Inc.
27# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
28#
29# Under source code control:	1991/07/21 05:00:54
30# File existed as early as:	1991
31#
32# chongo <was here> /\oo/\	http://www.isthe.com/chongo/
33# Share and enjoy!  :-) http://www.isthe.com/chongo/tech/comp/calc/
34#
35# calculator by David I. Bell with help/mods from others
36# Makefile by Landon Curt Noll
37
38
39# The shell used by this Makefile
40#
41# On some systems, /bin/sh is a rather reduced shell with
42# deprecated behavior.
43#
44# If your system has a up to date, bash shell, then
45# you may wish to use:
46#
47#	SHELL= /bin/sh
48#
49# On some systems such as macOS, the bash shell is very
50# far behind to the point where is cannot be depended on.
51# On such systems, the sh may be a much better alternative
52# shell for this Makefile to use:
53#
54#	SHELL= /bin/sh
55#
56SHELL= /bin/sh
57#SHELL= /bin/sh
58#if 0	/* start of skip for non-Gnu makefiles */
59ifeq ($(target),Darwin)
60SHELL:= /bin/zsh
61endif
62#endif	/* end of skip for non-Gnu makefiles */
63
64
65####
66# Normally, the upper level makefile will set these values.  We provide
67# a default here just in case you want to build from this directory.
68####
69
70# PREFIX - Top level location for calc
71#
72# The PREFIX is often prepended to paths within calc and calc Makefiles.
73#
74# Starting with calc v2.13.0.1, nearly all Makefile places that used
75# /usr/local now use ${PREFIX}.  An exception is the olduninstall rule
76# and, of course, this section. :-)
77#
78# NOTE: The ${PREFIX} is not the same as ${T}.  The ${T} specifies
79#	a top level directory under which calc installs things.
80#	While usually ${T} is empty, it can be specific path
81#	as if calc where "chrooted" during an install.
82#	The ${PREFIX} value, during install, is a path between
83#	the top level ${T} install directory and the object
84#	such as an include file.
85#
86# NOTE: See also, ${T}, below.
87#
88# There are some paths that do NOT call under ${PREFIX}, such as
89# ${CALCPATH}, that include paths not under ${PREFIX}, but those
90# too are exceptions to this general rule.
91#
92# When in doubt, try:
93#
94#	PREFIX= /usr/local
95#
96PREFIX= /usr/local
97#PREFIX= /usr
98#PREFIX= /usr/global
99
100# Normally certain files depend on the Makefile.  If the Makefile is
101# changed, then certain steps should be redone.  If MAKE_FILE is
102# set to Makefile, then these files will depend on Makefile.  If
103# MAKE_FILE is empty, then they wont.
104#
105# If in doubt, set MAKE_FILE to Makefile
106#
107MAKE_FILE= Makefile
108
109# Where the system include (.h) files are kept
110#
111# For DJGPP, select:
112#
113#	INCDIR= /dev/env/DJDIR/include
114#
115# If in doubt, set:
116#
117#	INCDIR= /usr/include
118#
119
120#INCDIR= ${PREFIX}/include
121#INCDIR= /dev/env/DJDIR/include
122INCDIR= /usr/include
123
124# where to install calc related things
125#
126# ${BINDIR}		where to install calc binary files
127# ${LIBDIR}		where calc link library (*.a) files are installed
128# ${CALC_SHAREDIR}	where to install calc help, .cal, startup, config files
129#
130# NOTE: The install rule prepends installation paths with ${T}, which
131#	by default is empty.  If ${T} is non-empty, then installation
132#	locations will be relative to the ${T} directory.
133#
134# For DJGPP, select:
135#
136#	BINDIR= /dev/env/DJDIR/bin
137#	LIBDIR= /dev/env/DJDIR/lib
138#	CALC_SHAREDIR= /dev/env/DJDIR/share/calc
139#
140# If in doubt, set:
141#
142#	BINDIR= /usr/bin
143#	LIBDIR= /usr/lib
144#	CALC_SHAREDIR= /usr/share/calc
145#
146#BINDIR= ${PREFIX}/bin
147#BINDIR= /dev/env/DJDIR/bin
148BINDIR= /usr/bin
149
150#LIBDIR= ${PREFIX}/lib
151#LIBDIR= /dev/env/DJDIR/lib
152LIBDIR= /usr/lib
153
154#CALC_SHAREDIR= ${PREFIX}/lib/calc
155#CALC_SHAREDIR= /dev/env/DJDIR/share/calc
156CALC_SHAREDIR= /usr/share/calc
157
158# By default, these values are based CALC_SHAREDIR, INCDIR, BINDIR
159# ---------------------------------------------------------------
160# ${HELPDIR}		where the help directory is installed
161# ${CALC_INCDIR}	where the calc include files are installed
162# ${SCRIPTDIR}		where calc shell scripts are installed
163#
164# NOTE: The install rule prepends installation paths with ${T}, which
165#	by default is empty.  If ${T} is non-empty, then installation
166#	locations will be relative to the ${T} directory.
167#
168# If in doubt, set:
169#
170#	HELPDIR= ${CALC_SHAREDIR}/help
171#	CALC_INCDIR= ${INCDIR}/calc
172#	SCRIPTDIR= ${BINDIR}/cscript
173#
174HELPDIR= ${CALC_SHAREDIR}/help
175CALC_INCDIR= ${INCDIR}/calc
176SCRIPTDIR= ${BINDIR}/cscript
177
178# T - top level directory under which calc will be installed
179#
180# The calc install is performed under ${T}, the calc build is
181# performed under /.	The purpose for ${T} is to allow someone
182# to install calc somewhere other than into the system area.
183#
184# For example, if:
185#
186#     BINDIR= /usr/bin
187#     LIBDIR= /usr/lib
188#     CALC_SHAREDIR= /usr/share/calc
189#
190# and if:
191#
192#     T= /var/tmp/testing
193#
194# Then the installation locations will be:
195#
196#     calc binary files:	/var/tmp/testing/usr/bin
197#     calc link library:	/var/tmp/testing/usr/lib
198#     calc help, .cal ...:	/var/tmp/testing/usr/share/calc
199#     ... etc ...		/var/tmp/testing/...
200#
201# If ${T} is empty, calc is installed under /, which is the same
202# top of tree for which it was built.  If ${T} is non-empty, then
203# calc is installed under ${T}, as if one had to chroot under
204# ${T} for calc to operate.
205#
206# If in doubt, use T=
207#
208T=
209
210# Makefile debug
211#
212# Q=@	do not echo internal Makefile actions (quiet mode)
213# Q=	echo internal Makefile actions (debug / verbose mode)
214#
215# H=@:	do not report hsrc file formation progress
216# H=@	do echo hsrc file formation progress
217#
218# S= >/dev/null 2>&1	silence ${CC} output during hsrc file formation
219# S=			full ${CC} output during hsrc file formation
220#
221# E= 2>/dev/null	silence command stderr during hsrc file formation
222# E=			full command stderr during hsrc file formation
223#
224# V=@:	do not echo debug statements (quiet mode)
225# V=@	do echo debug statements (debug / verbose mode)
226#
227#Q=
228Q=@
229#
230S= >/dev/null 2>&1
231#S=
232#
233E= 2>/dev/null
234#E=
235#
236#H=@:
237H=@
238#
239V=@:
240#V=@
241
242# standard tools
243#
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# The calc files to install
259#
260# This list is produced by the detaillist rule when no WARNINGS are detected.
261#
262# Please use:
263#
264#	make calc_files_list
265#
266# to keep this list in nice sorted order.
267#
268CALC_FILES= README alg_config.cal beer.cal bernoulli.cal \
269	bernpoly.cal bigprime.cal bindings brentsolve.cal chi.cal chrem.cal \
270	constants.cal deg.cal dms.cal dotest.cal ellip.cal factorial.cal \
271	factorial2.cal gvec.cal hello.cal hms.cal infinities.cal intfile.cal \
272	intnum.cal lambertw.cal linear.cal lnseries.cal lucas.cal \
273	lucas_chk.cal mersenne.cal mfactor.cal mod.cal natnumset.cal \
274	palindrome.cal pell.cal pi.cal pix.cal pollard.cal poly.cal prompt.cal \
275	psqrt.cal qtime.cal quat.cal randbitrun.cal randmprime.cal \
276	randombitrun.cal randomrun.cal randrun.cal regress.cal repeat.cal \
277	screen.cal seedrandom.cal set8700.cal set8700.line smallfactors.cal \
278	solve.cal specialfunctions.cal statistics.cal strings.cal sumsq.cal \
279	sumtimes.cal surd.cal test1700.cal test2300.cal test2600.cal \
280	test2700.cal test3100.cal test3300.cal test3400.cal test3500.cal \
281	test4000.cal test4100.cal test4600.cal test5100.cal test5200.cal \
282	test8400.cal test8500.cal test8600.cal test8900.cal toomcook.cal \
283	unitfrac.cal varargs.cal xx_print.cal zeta2.cal
284
285# These calc files are now obsolete and are removed by the install rule.
286#
287DEAD_CALC_FILES= lucas_tbl.cal
288
289# These files are found (but not built) in the distribution
290#
291DISTLIST= ${CALC_FILES} ${MAKE_FILE}
292
293# These files are used to make (but not built) a calc .a link library
294#
295CALCLIBLIST=
296
297all: ${CALC_FILES} ${MAKE_FILE} .all
298
299# used by the upper level Makefile to determine of we have done all
300#
301.all:
302	${RM} -f .all
303	${TOUCH} .all
304
305##
306#
307# File list generation.	 You can ignore this section.
308#
309#
310# We will form the names of source files as if they were in a
311# sub-directory called calc/cal.
312#
313# NOTE: Due to bogus shells found on one common system we must have
314#	an non-empty else clause for every if condition.  *sigh*
315#
316##
317
318distlist: ${DISTLIST}
319	${Q} for i in ${DISTLIST} /dev/null; do \
320	    if [ X"$$i" != X"/dev/null" ]; then \
321		echo cal/$$i; \
322	    fi; \
323	done
324
325distdir:
326	${Q} echo cal
327
328calcliblist:
329	${Q} for i in ${CALCLIBLIST} /dev/null; do \
330	    if [ X"$$i" != X"/dev/null" ]; then \
331		echo cal/$$i; \
332	    fi; \
333	done
334
335# These next rule help form the ${CALC_FILES} makefile variables above.
336#
337calc_files_list:
338	${Q} -(find .  -mindepth 1 -maxdepth 1 -type f -name '*.cal' -print | \
339	    while read i; do \
340		echo $$i; \
341	    done; \
342	    echo '--first_line--'; \
343	    echo README; \
344	    echo set8700.line; \
345	    echo bindings) | \
346	    ${SED} -e 's:^\./::' | LANG=C ${SORT} | ${FMT} -70 | \
347	    ${SED} -e '1s/--first_line--/CALC_FILES=/' -e '2,$$s/^/	/' \
348		   -e 's/$$/ \\/' -e '$$s/ \\$$//'
349
350##
351#
352# rpm rules
353#
354##
355
356echo_inst_files:
357	${Q} for i in ${CALC_FILES} /dev/null; do \
358	    if [ X"$$i" != X"/dev/null" ]; then \
359		echo __file__ ${CALC_SHAREDIR}/$$i; \
360	    fi; \
361	done
362
363##
364#
365# Utility rules
366#
367##
368
369clean:
370
371clobber: clean
372	${RM} -f .all
373	-${Q} if [ -e .DS_Store ]; then \
374	    echo ${RM} -rf .DS_Store; \
375	    ${RM} -rf .DS_Store; \
376	fi
377	-${Q} for i in ${DEAD_CALC_FILES} /dev/null; do \
378	    if [ "$$i" = "/dev/null" ]; then \
379		continue; \
380	    fi; \
381	    if [ -e "${T}${CALC_SHAREDIR}/$$i" ]; then \
382		echo "${RM} -f ${T}${CALC_SHAREDIR}/$$i"; \
383		${RM} -f ${T}${CALC_SHAREDIR}/$$i; \
384	    fi; \
385	    if [ -e "./$$i" ]; then \
386		echo "${RM} -f ./$$i"; \
387		${RM} -f ./$$i; \
388	    fi; \
389	done
390
391# install everything
392#
393# NOTE: Keep the uninstall rule in reverse order to the install rule
394#
395install: all
396	-${Q} if [ ! -d ${T}${CALC_SHAREDIR} ]; then \
397	    echo ${MKDIR} -p ${T}${CALC_SHAREDIR}; \
398	    ${MKDIR} -p ${T}${CALC_SHAREDIR}; \
399	    if [ ! -d "${T}${CALC_SHAREDIR}" ]; then \
400		echo ${MKDIR} -p "${T}${CALC_SHAREDIR}"; \
401		${MKDIR} -p "${T}${CALC_SHAREDIR}"; \
402	    fi; \
403	    echo ${CHMOD} 0755 ${T}${CALC_SHAREDIR}; \
404	    ${CHMOD} 0755 ${T}${CALC_SHAREDIR}; \
405	else \
406	    ${TRUE}; \
407	fi
408	${Q} for i in ${CALC_FILES} /dev/null; do \
409	    if [ "$$i" = "/dev/null" ]; then \
410		continue; \
411	    fi; \
412	    if ${CMP} -s $$i ${T}${CALC_SHAREDIR}/$$i; then \
413		${TRUE}; \
414	    else \
415		${RM} -f ${T}${CALC_SHAREDIR}/$$i.new; \
416		${CP} -f $$i ${T}${CALC_SHAREDIR}/$$i.new; \
417		${CHMOD} 0444 ${T}${CALC_SHAREDIR}/$$i.new; \
418		${MV} -f ${T}${CALC_SHAREDIR}/$$i.new ${T}${CALC_SHAREDIR}/$$i;\
419		echo "installed ${T}${CALC_SHAREDIR}/$$i"; \
420	    fi; \
421	done
422	${Q} for i in ${DEAD_CALC_FILES} /dev/null; do \
423	    if [ "$$i" = "/dev/null" ]; then \
424		continue; \
425	    fi; \
426	    if [ -e "${T}${CALC_SHAREDIR}/$$i" ]; then \
427		echo "${RM} -f ${T}${CALC_SHAREDIR}/$$i"; \
428		${RM} -f ${T}${CALC_SHAREDIR}/$$i; \
429	    fi; \
430	    if [ -e "./$$i" ]; then \
431		echo "${RM} -f ./$$i"; \
432		${RM} -f ./$$i; \
433	    fi; \
434	done
435
436# Try to remove everything that was installed
437#
438# NOTE: Keep the uninstall rule in reverse order to the install rule
439#
440uninstall:
441	- ${Q} for i in ${DEAD_CALC_FILES} /dev/null; do \
442	    if [ "$$i" = "/dev/null" ]; then \
443		continue; \
444	    fi; \
445	    if [ -e "${T}${CALC_SHAREDIR}/$$i" ]; then \
446		echo "${RM} -f ${T}${CALC_SHAREDIR}/$$i"; \
447		${RM} -f ${T}${CALC_SHAREDIR}/$$i; \
448	    fi; \
449	    if [ -e "./$$i" ]; then \
450		echo "${RM} -f ./$$i"; \
451		${RM} -f ./$$i; \
452	    fi; \
453	done
454	-${Q} for i in ${CALC_FILES} /dev/null; do \
455	    if [ "$$i" = "/dev/null" ]; then \
456		continue; \
457	    fi; \
458	    if [ -f "${T}${CALC_SHAREDIR}/$$i" ]; then \
459		${RM} -f "${T}${CALC_SHAREDIR}/$$i"; \
460		if [ -f "${T}${CALC_SHAREDIR}/$$i" ]; then \
461		   echo "cannot uninstall ${T}${CALC_SHAREDIR}/$$i"; \
462		else \
463		   echo "un-installed ${T}${CALC_SHAREDIR}/$$i"; \
464		fi; \
465	    fi; \
466	done
467	-${Q} for i in ${CALC_SHAREDIR}; do \
468	    if [ -d "${T}$$i" ]; then \
469		${RMDIR} "${T}$$i" 2>/dev/null; \
470		echo "cleaned up ${T}$$i"; \
471	    fi; \
472	done
473