xref: /freebsd/contrib/bc/Makefile.in (revision 9e5787d2284e187abb5b654d924394a65772e004)
1#
2# SPDX-License-Identifier: BSD-2-Clause
3#
4# Copyright (c) 2018-2020 Gavin D. Howard and contributors.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are met:
8#
9# * Redistributions of source code must retain the above copyright notice, this
10#   list of conditions and the following disclaimer.
11#
12# * Redistributions in binary form must reproduce the above copyright notice,
13#   this list of conditions and the following disclaimer in the documentation
14#   and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26# POSSIBILITY OF SUCH DAMAGE.
27#
28# %%WARNING%%
29#
30.POSIX:
31
32VERSION = 3.1.5
33
34SRC = %%SRC%%
35OBJ = %%OBJ%%
36GCDA = %%GCDA%%
37GCNO = %%GCNO%%
38
39BC_SRC = %%BC_SRC%%
40BC_OBJ = %%BC_OBJ%%
41BC_GCDA = %%BC_GCDA%%
42BC_GCNO = %%BC_GCNO%%
43
44DC_SRC = %%DC_SRC%%
45DC_OBJ = %%DC_OBJ%%
46DC_GCDA = %%DC_GCDA%%
47DC_GCNO = %%DC_GCNO%%
48
49HISTORY_SRC = %%HISTORY_SRC%%
50HISTORY_OBJ = %%HISTORY_OBJ%%
51HISTORY_GCDA = %%HISTORY_GCDA%%
52HISTORY_GCNO = %%HISTORY_GCNO%%
53
54RAND_SRC = %%RAND_SRC%%
55RAND_OBJ = %%RAND_OBJ%%
56RAND_GCDA = %%RAND_GCDA%%
57RAND_GCNO = %%RAND_GCNO%%
58
59BC_ENABLED_NAME = BC_ENABLED
60BC_ENABLED = %%BC_ENABLED%%
61DC_ENABLED_NAME = DC_ENABLED
62DC_ENABLED = %%DC_ENABLED%%
63
64GEN_DIR = gen
65GEN = %%GEN%%
66GEN_EXEC = $(GEN_DIR)/$(GEN)
67GEN_C = $(GEN_DIR)/$(GEN).c
68
69GEN_EMU = %%GEN_EMU%%
70
71BC_LIB = $(GEN_DIR)/lib.bc
72BC_LIB_C = $(GEN_DIR)/lib.c
73BC_LIB_O = %%BC_LIB_O%%
74BC_LIB_GCDA = $(GEN_DIR)/lib.gcda
75BC_LIB_GCNO = $(GEN_DIR)/lib.gcno
76
77BC_LIB2 = $(GEN_DIR)/lib2.bc
78BC_LIB2_C = $(GEN_DIR)/lib2.c
79BC_LIB2_O = %%BC_LIB2_O%%
80BC_LIB2_GCDA = $(GEN_DIR)/lib2.gcda
81BC_LIB2_GCNO = $(GEN_DIR)/lib2.gcno
82
83BC_HELP = $(GEN_DIR)/bc_help.txt
84BC_HELP_C = $(GEN_DIR)/bc_help.c
85BC_HELP_O = %%BC_HELP_O%%
86BC_HELP_GCDA = $(GEN_DIR)/bc_help.gcda
87BC_HELP_GCNO = $(GEN_DIR)/bc_help.gcno
88
89DC_HELP = $(GEN_DIR)/dc_help.txt
90DC_HELP_C = $(GEN_DIR)/dc_help.c
91DC_HELP_O = %%DC_HELP_O%%
92DC_HELP_GCDA = $(GEN_DIR)/dc_help.gcda
93DC_HELP_GCNO = $(GEN_DIR)/dc_help.gcno
94
95BIN = bin
96LOCALES = locales
97EXEC_SUFFIX = %%EXECSUFFIX%%
98EXEC_PREFIX = %%EXECPREFIX%%
99
100BC = bc
101DC = dc
102BC_EXEC = $(BIN)/$(EXEC_PREFIX)$(BC)
103DC_EXEC = $(BIN)/$(EXEC_PREFIX)$(DC)
104
105MANUALS = manuals
106BC_MANPAGE_NAME = $(EXEC_PREFIX)$(BC)$(EXEC_SUFFIX).1
107BC_MANPAGE = $(MANUALS)/$(BC).1
108BC_MD = $(BC_MANPAGE).md
109DC_MANPAGE_NAME = $(EXEC_PREFIX)$(DC)$(EXEC_SUFFIX).1
110DC_MANPAGE = $(MANUALS)/$(DC).1
111DC_MD = $(DC_MANPAGE).md
112
113MANPAGE_INSTALL_ARGS = -Dm644
114
115%%DESTDIR%%
116BINDIR = %%BINDIR%%
117MAN1DIR = %%MAN1DIR%%
118MAIN_EXEC = $(EXEC_PREFIX)$(%%MAIN_EXEC%%)$(EXEC_SUFFIX)
119EXEC = $(%%EXEC%%)
120NLSPATH = %%NLSPATH%%
121
122BC_ENABLE_HISTORY = %%HISTORY%%
123BC_ENABLE_EXTRA_MATH_NAME = BC_ENABLE_EXTRA_MATH
124BC_ENABLE_EXTRA_MATH = %%EXTRA_MATH%%
125BC_ENABLE_NLS = %%NLS%%
126BC_ENABLE_PROMPT = %%PROMPT%%
127BC_LONG_BIT = %%LONG_BIT%%
128
129RM = rm
130MKDIR = mkdir
131
132INSTALL = ./install.sh
133SAFE_INSTALL = ./safe-install.sh
134LINK = ./link.sh
135MANPAGE = ./manpage.sh
136KARATSUBA = ./karatsuba.py
137LOCALE_INSTALL = ./locale_install.sh
138LOCALE_UNINSTALL = ./locale_uninstall.sh
139
140VALGRIND_ARGS = --error-exitcode=100 --leak-check=full --show-leak-kinds=all --errors-for-leak-kinds=all
141
142BC_NUM_KARATSUBA_LEN = %%KARATSUBA_LEN%%
143
144CPPFLAGS1 = -D$(BC_ENABLED_NAME)=$(BC_ENABLED) -D$(DC_ENABLED_NAME)=$(DC_ENABLED)
145CPPFLAGS2 = $(CPPFLAGS1) -I./include/ -DVERSION=$(VERSION) %%LONG_BIT_DEFINE%%
146CPPFLAGS3 = $(CPPFLAGS2) -DEXECPREFIX=$(EXEC_PREFIX) -DMAINEXEC=$(MAIN_EXEC)
147CPPFLAGS4 = $(CPPFLAGS3) -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700
148CPPFLAGS5 = $(CPPFLAGS4) -DBC_NUM_KARATSUBA_LEN=$(BC_NUM_KARATSUBA_LEN)
149CPPFLAGS6 = $(CPPFLAGS5) -DBC_ENABLE_NLS=$(BC_ENABLE_NLS) -DBC_ENABLE_PROMPT=$(BC_ENABLE_PROMPT)
150CPPFLAGS7 = $(CPPFLAGS6) -D$(BC_ENABLE_EXTRA_MATH_NAME)=$(BC_ENABLE_EXTRA_MATH)
151CPPFLAGS = $(CPPFLAGS7) -DBC_ENABLE_HISTORY=$(BC_ENABLE_HISTORY)
152CFLAGS = $(CPPFLAGS) %%CPPFLAGS%% %%CFLAGS%%
153LDFLAGS = %%LDFLAGS%%
154
155HOSTCFLAGS = %%HOSTCFLAGS%%
156
157CC = %%CC%%
158HOSTCC = %%HOSTCC%%
159
160BC_LIB_C_ARGS = bc_lib bc.h bc_lib_name $(BC_ENABLED_NAME) 1
161BC_LIB2_C_ARGS = bc_lib2 bc.h bc_lib2_name "$(BC_ENABLED_NAME) && $(BC_ENABLE_EXTRA_MATH_NAME)" 1
162
163OBJS1 = $(OBJ) $(DC_OBJ) $(BC_OBJ) $(HISTORY_OBJ) $(RAND_OBJ) $(BC_HELP_O) $(DC_HELP_O)
164OBJS = $(OBJS1) $(BC_LIB_O) $(BC_LIB2_O) $(BC_LIB3_O)
165OBJ_TARGETS1 = $(DC_HELP_O) $(BC_HELP_O) $(BC_LIB_O) $(BC_LIB2_O) $(BC_LIB3_O)
166OBJ_TARGETS = $(OBJ_TARGETS1) $(BC_OBJ) $(DC_OBJ) $(HISTORY_OBJ) $(RAND_OBJ) $(OBJ)
167
168.c.o:
169	$(CC) $(CFLAGS) -o $@ -c $<
170
171all: make_bin $(OBJ_TARGETS)
172	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(EXEC)
173	%%LINK%%
174
175$(GEN_EXEC):
176	%%GEN_EXEC_TARGET%%
177
178$(BC_LIB_C): $(GEN_EXEC) $(BC_LIB)
179	$(GEN_EMU) $(GEN_EXEC) $(BC_LIB) $(BC_LIB_C) $(BC_LIB_C_ARGS)
180
181$(BC_LIB2_C): $(GEN_EXEC) $(BC_LIB2)
182	$(GEN_EMU) $(GEN_EXEC) $(BC_LIB2) $(BC_LIB2_C) $(BC_LIB2_C_ARGS)
183
184$(BC_HELP_C): $(GEN_EXEC) $(BC_HELP)
185	$(GEN_EMU) $(GEN_EXEC) $(BC_HELP) $(BC_HELP_C) bc_help bc.h "" $(BC_ENABLED_NAME)
186
187$(DC_HELP_C): $(GEN_EXEC) $(DC_HELP)
188	$(GEN_EMU) $(GEN_EXEC) $(DC_HELP) $(DC_HELP_C) dc_help dc.h "" $(DC_ENABLED_NAME)
189
190make_bin:
191	$(MKDIR) -p $(BIN)
192
193help:
194	@printf 'available targets:\n'
195	@printf '\n'
196	@printf '    all (default)   builds %%EXECUTABLES%%\n'
197	@printf '    check           alias for `make test`\n'
198	@printf '    clean           removes all build files\n'
199	@printf '    clean_config    removes all build files as well as the generated Makefile\n'
200	@printf '    clean_tests     removes all build files, the generated Makefile,\n'
201	@printf '                    and generated tests\n'
202	@printf '    install         installs binaries to "%s%s"\n' "$(DESTDIR)" "$(BINDIR)"
203	@printf '                    and (if enabled) manpages to "%s%s"\n' "$(DESTDIR)" "$(MAN1DIR)"
204	@printf '    karatsuba       runs the karatsuba script (requires Python 3)\n'
205	@printf '    karatsuba_test  runs the karatsuba script while running tests\n'
206	@printf '                    (requires Python 3)\n'
207	@printf '    uninstall       uninstalls binaries from "%s%s"\n' "$(DESTDIR)" "$(BINDIR)"
208	@printf '                    and (if enabled) manpages from "%s%s"\n' "$(DESTDIR)" "$(MAN1DIR)"
209	@printf '    test            runs the test suite\n'
210	@printf '    test_bc         runs the bc test suite, if bc has been built\n'
211	@printf '    test_dc         runs the dc test suite, if dc has been built\n'
212	@printf '    time_test       runs the test suite, displaying times for some things\n'
213	@printf '    time_test_bc    runs the bc test suite, displaying times for some things\n'
214	@printf '    time_test_dc    runs the dc test suite, displaying times for some things\n'
215	@printf '    timeconst       runs the test on the Linux timeconst.bc script,\n'
216	@printf '                    if it exists and bc has been built\n'
217	@printf '    valgrind        runs the test suite through valgrind\n'
218	@printf '    valgrind_bc     runs the bc test suite, if bc has been built,\n'
219	@printf '                    through valgrind\n'
220	@printf '    valgrind_dc     runs the dc test suite, if dc has been built,\n'
221	@printf '                    through valgrind\n'
222
223check: test
224
225test: test_bc timeconst test_dc
226
227test_bc:
228	%%BC_TEST%%
229
230test_dc:
231	%%DC_TEST%%
232
233time_test: time_test_bc timeconst time_test_dc
234
235time_test_bc:
236	%%BC_TIME_TEST%%
237
238time_test_dc:
239	%%DC_TIME_TEST%%
240
241timeconst:
242	%%TIMECONST%%
243
244valgrind: valgrind_bc valgrind_dc
245
246valgrind_bc:
247	%%VG_BC_TEST%%
248
249valgrind_dc:
250	%%VG_DC_TEST%%
251
252karatsuba:
253	%%KARATSUBA%%
254
255karatsuba_test:
256	%%KARATSUBA_TEST%%
257
258coverage_output:
259	%%COVERAGE_OUTPUT%%
260
261coverage:%%COVERAGE_PREREQS%%
262
263version:
264	@printf '%s' "$(VERSION)"
265
266libcname:
267	@printf '%s' "$(BC_LIB_C)"
268
269extra_math:
270	@printf '%s' "$(BC_ENABLE_EXTRA_MATH)"
271
272manpages:
273	$(MANPAGE) bc
274	$(MANPAGE) dc
275
276clean_gen:
277	@$(RM) -f $(GEN_EXEC)
278
279clean:%%CLEAN_PREREQS%%
280	@printf 'Cleaning files...\n'
281	@$(RM) -f $(OBJ)
282	@$(RM) -f $(BC_OBJ)
283	@$(RM) -f $(DC_OBJ)
284	@$(RM) -f $(HISTORY_OBJ)
285	@$(RM) -f $(RAND_OBJ)
286	@$(RM) -f $(BC_EXEC)
287	@$(RM) -f $(DC_EXEC)
288	@$(RM) -fr $(BIN)
289	@$(RM) -f $(LOCALES)/*.cat
290	@$(RM) -f $(BC_LIB_C) $(BC_LIB_O)
291	@$(RM) -f $(BC_LIB2_C) $(BC_LIB2_O)
292	@$(RM) -f $(BC_HELP_C) $(BC_HELP_O)
293	@$(RM) -f $(DC_HELP_C) $(DC_HELP_O)
294
295clean_config: clean
296	@printf 'Cleaning config...\n'
297	@$(RM) -f Makefile
298	@$(RM) -f $(BC_MD) $(DC_MD)
299	@$(RM) -f $(BC_MANPAGE) $(DC_MANPAGE)
300
301clean_coverage:
302	@printf 'Cleaning coverage files...\n'
303	@$(RM) -f *.gcov
304	@$(RM) -f *.html
305	@$(RM) -f *.gcda *.gcno
306	@$(RM) -f *.profraw
307	@$(RM) -f $(GCDA) $(GCNO)
308	@$(RM) -f $(BC_GCDA) $(BC_GCNO)
309	@$(RM) -f $(DC_GCDA) $(DC_GCNO)
310	@$(RM) -f $(HISTORY_GCDA) $(HISTORY_GCNO)
311	@$(RM) -f $(RAND_GCDA) $(RAND_GCNO)
312	@$(RM) -f $(BC_LIB_GCDA) $(BC_LIB_GCNO)
313	@$(RM) -f $(BC_LIB2_GCDA) $(BC_LIB2_GCNO)
314	@$(RM) -f $(BC_HELP_GCDA) $(BC_HELP_GCNO)
315	@$(RM) -f $(DC_HELP_GCDA) $(DC_HELP_GCNO)
316
317clean_tests: clean clean_config clean_coverage
318	@printf 'Cleaning test files...\n'
319	@$(RM) -f tests/bc/parse.txt tests/bc/parse_results.txt
320	@$(RM) -f tests/bc/print.txt tests/bc/print_results.txt
321	@$(RM) -f tests/bc/bessel.txt tests/bc/bessel_results.txt
322	@$(RM) -f tests/bc/scripts/bessel.txt
323	@$(RM) -f tests/bc/scripts/parse.txt
324	@$(RM) -f tests/bc/scripts/print.txt
325	@$(RM) -f tests/bc/scripts/add.txt
326	@$(RM) -f tests/bc/scripts/divide.txt
327	@$(RM) -f tests/bc/scripts/multiply.txt
328	@$(RM) -f tests/bc/scripts/subtract.txt
329	@$(RM) -f tests/dc/scripts/prime.txt tests/dc/scripts/stream.txt
330	@$(RM) -f .log_*.txt
331	@$(RM) -f .math.txt .results.txt .ops.txt
332	@$(RM) -f .test.txt
333	@$(RM) -f tags .gdbbreakpoints .gdb_history .gdbsetup
334	@$(RM) -f cscope.*
335	@$(RM) -f bc.old
336
337install_locales:
338	%%INSTALL_LOCALES%%
339
340install_bc_manpage:
341	$(SAFE_INSTALL) $(MANPAGE_INSTALL_ARGS) $(BC_MANPAGE) $(DESTDIR)$(MAN1DIR)/$(BC_MANPAGE_NAME)
342
343install_dc_manpage:
344	$(SAFE_INSTALL) $(MANPAGE_INSTALL_ARGS) $(DC_MANPAGE) $(DESTDIR)$(MAN1DIR)/$(DC_MANPAGE_NAME)
345
346install:%%INSTALL_LOCALES_PREREQS%%%%INSTALL_PREREQS%%
347	$(INSTALL) $(DESTDIR)$(BINDIR) "$(EXEC_SUFFIX)"
348
349uninstall_locales:
350	$(LOCALE_UNINSTALL) $(NLSPATH) $(MAIN_EXEC) $(DESTDIR)
351
352uninstall_bc_manpage:
353	$(RM) -f $(DESTDIR)$(MAN1DIR)/$(BC_MANPAGE_NAME)
354
355uninstall_bc:
356	$(RM) -f $(DESTDIR)$(BINDIR)/$(EXEC_PREFIX)$(BC)$(EXEC_SUFFIX)
357
358uninstall_dc_manpage:
359	$(RM) -f $(DESTDIR)$(MAN1DIR)/$(DC_MANPAGE_NAME)
360
361uninstall_dc:
362	$(RM) -f $(DESTDIR)$(BINDIR)/$(EXEC_PREFIX)$(DC)$(EXEC_SUFFIX)
363
364uninstall:%%UNINSTALL_LOCALES_PREREQS%%%%UNINSTALL_MAN_PREREQS%%%%UNINSTALL_PREREQS%%
365