xref: /freebsd/contrib/bc/Makefile.in (revision a0409676120c1e558d0ade943019934e0f15118d)
1#
2# SPDX-License-Identifier: BSD-2-Clause
3#
4# Copyright (c) 2018-2021 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.3.4
33
34SRC = %%SRC%%
35OBJ = %%OBJ%%
36GCDA = %%GCDA%%
37GCNO = %%GCNO%%
38
39BC_ENABLED_NAME = BC_ENABLED
40BC_ENABLED = %%BC_ENABLED%%
41DC_ENABLED_NAME = DC_ENABLED
42DC_ENABLED = %%DC_ENABLED%%
43
44HEADERS = include/args.h include/file.h include/lang.h include/lex.h include/num.h include/opt.h include/parse.h include/program.h include/read.h include/status.h include/vector.h include/vm.h
45BC_HEADERS = include/bc.h
46DC_HEADERS = include/dc.h
47HISTORY_HEADERS = include/history.h
48EXTRA_MATH_HEADERS = include/rand.h
49LIBRARY_HEADERS = include/bcl.h include/library.h
50
51GEN_DIR = gen
52GEN = %%GEN%%
53GEN_EXEC = $(GEN_DIR)/$(GEN)
54GEN_C = $(GEN_DIR)/$(GEN).c
55
56GEN_EMU = %%GEN_EMU%%
57
58BC_LIB = $(GEN_DIR)/lib.bc
59BC_LIB_C = $(GEN_DIR)/lib.c
60BC_LIB_O = %%BC_LIB_O%%
61BC_LIB_GCDA = $(GEN_DIR)/lib.gcda
62BC_LIB_GCNO = $(GEN_DIR)/lib.gcno
63
64BC_LIB2 = $(GEN_DIR)/lib2.bc
65BC_LIB2_C = $(GEN_DIR)/lib2.c
66BC_LIB2_O = %%BC_LIB2_O%%
67BC_LIB2_GCDA = $(GEN_DIR)/lib2.gcda
68BC_LIB2_GCNO = $(GEN_DIR)/lib2.gcno
69
70BC_HELP = $(GEN_DIR)/bc_help.txt
71BC_HELP_C = $(GEN_DIR)/bc_help.c
72BC_HELP_O = %%BC_HELP_O%%
73BC_HELP_GCDA = $(GEN_DIR)/bc_help.gcda
74BC_HELP_GCNO = $(GEN_DIR)/bc_help.gcno
75
76DC_HELP = $(GEN_DIR)/dc_help.txt
77DC_HELP_C = $(GEN_DIR)/dc_help.c
78DC_HELP_O = %%DC_HELP_O%%
79DC_HELP_GCDA = $(GEN_DIR)/dc_help.gcda
80DC_HELP_GCNO = $(GEN_DIR)/dc_help.gcno
81
82BIN = bin
83LOCALES = locales
84EXEC_SUFFIX = %%EXECSUFFIX%%
85EXEC_PREFIX = %%EXECPREFIX%%
86
87BC = bc
88DC = dc
89BC_EXEC = $(BIN)/$(EXEC_PREFIX)$(BC)
90DC_EXEC = $(BIN)/$(EXEC_PREFIX)$(DC)
91
92BC_TEST_OUTPUTS = tests/bc_outputs
93BC_FUZZ_OUTPUTS = tests/fuzzing/bc_outputs1 tests/fuzzing/bc_outputs2 tests/fuzzing/bc_outputs3
94DC_TEST_OUTPUTS = tests/dc_outputs
95DC_FUZZ_OUTPUTS = tests/fuzzing/dc_outputs
96
97LIB = libbcl
98LIB_NAME = $(LIB).a
99LIBBC = $(BIN)/$(LIB_NAME)
100BCL = bcl
101BCL_TEST = $(BIN)/$(BCL)
102BCL_TEST_C = tests/$(BCL).c
103
104MANUALS = manuals
105BC_MANPAGE_NAME = $(EXEC_PREFIX)$(BC)$(EXEC_SUFFIX).1
106BC_MANPAGE = $(MANUALS)/$(BC).1
107BC_MD = $(BC_MANPAGE).md
108DC_MANPAGE_NAME = $(EXEC_PREFIX)$(DC)$(EXEC_SUFFIX).1
109DC_MANPAGE = $(MANUALS)/$(DC).1
110DC_MD = $(DC_MANPAGE).md
111BCL_MANPAGE_NAME = bcl.3
112BCL_MANPAGE = $(MANUALS)/$(BCL_MANPAGE_NAME)
113BCL_MD = $(BCL_MANPAGE).md
114
115MANPAGE_INSTALL_ARGS = -Dm644
116BINARY_INSTALL_ARGS = -Dm755
117
118BCL_HEADER_NAME = bcl.h
119BCL_HEADER = include/$(BCL_HEADER_NAME)
120
121%%DESTDIR%%
122BINDIR = %%BINDIR%%
123INCLUDEDIR = %%INCLUDEDIR%%
124LIBDIR = %%LIBDIR%%
125MAN1DIR = %%MAN1DIR%%
126MAN3DIR = %%MAN3DIR%%
127MAIN_EXEC = $(EXEC_PREFIX)$(%%MAIN_EXEC%%)$(EXEC_SUFFIX)
128EXEC = $(%%EXEC%%)
129NLSPATH = %%NLSPATH%%
130
131BC_ENABLE_LIBRARY = %%LIBRARY%%
132
133BC_ENABLE_HISTORY = %%HISTORY%%
134BC_ENABLE_EXTRA_MATH_NAME = BC_ENABLE_EXTRA_MATH
135BC_ENABLE_EXTRA_MATH = %%EXTRA_MATH%%
136BC_ENABLE_NLS = %%NLS%%
137BC_ENABLE_PROMPT = %%PROMPT%%
138BC_LONG_BIT = %%LONG_BIT%%
139
140BC_ENABLE_AFL = %%FUZZ%%
141BC_ENABLE_MEMCHECK = %%MEMCHECK%%
142
143RM = rm
144MKDIR = mkdir
145
146INSTALL = ./exec-install.sh
147SAFE_INSTALL = ./safe-install.sh
148LINK = ./link.sh
149MANPAGE = ./manpage.sh
150KARATSUBA = ./karatsuba.py
151LOCALE_INSTALL = ./locale_install.sh
152LOCALE_UNINSTALL = ./locale_uninstall.sh
153
154VALGRIND_ARGS = --error-exitcode=100 --leak-check=full --show-leak-kinds=all --errors-for-leak-kinds=all
155
156TEST_STARS = "***********************************************************************"
157
158BC_NUM_KARATSUBA_LEN = %%KARATSUBA_LEN%%
159
160CPPFLAGS1 = -D$(BC_ENABLED_NAME)=$(BC_ENABLED) -D$(DC_ENABLED_NAME)=$(DC_ENABLED)
161CPPFLAGS2 = $(CPPFLAGS1) -I./include/ -DVERSION=$(VERSION) %%LONG_BIT_DEFINE%%
162CPPFLAGS3 = $(CPPFLAGS2) -DEXECPREFIX=$(EXEC_PREFIX) -DMAINEXEC=$(MAIN_EXEC)
163CPPFLAGS4 = $(CPPFLAGS3) -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700
164CPPFLAGS5 = $(CPPFLAGS4) -DBC_NUM_KARATSUBA_LEN=$(BC_NUM_KARATSUBA_LEN)
165CPPFLAGS6 = $(CPPFLAGS5) -DBC_ENABLE_NLS=$(BC_ENABLE_NLS) -DBC_ENABLE_PROMPT=$(BC_ENABLE_PROMPT)
166CPPFLAGS7 = $(CPPFLAGS6) -D$(BC_ENABLE_EXTRA_MATH_NAME)=$(BC_ENABLE_EXTRA_MATH)
167CPPFLAGS8 = $(CPPFLAGS7) -DBC_ENABLE_HISTORY=$(BC_ENABLE_HISTORY) -DBC_ENABLE_LIBRARY=$(BC_ENABLE_LIBRARY)
168CPPFLAGS = $(CPPFLAGS8) -DBC_ENABLE_MEMCHECK=$(BC_ENABLE_MEMCHECK) -DBC_ENABLE_AFL=$(BC_ENABLE_AFL)
169CFLAGS = $(CPPFLAGS) %%CPPFLAGS%% %%CFLAGS%%
170LDFLAGS = %%LDFLAGS%%
171
172HOSTCFLAGS = %%HOSTCFLAGS%%
173
174CC = %%CC%%
175HOSTCC = %%HOSTCC%%
176
177BC_LIB_C_ARGS = bc_lib bc_lib_name $(BC_ENABLED_NAME) 1
178BC_LIB2_C_ARGS = bc_lib2 bc_lib2_name "$(BC_ENABLED_NAME) && $(BC_ENABLE_EXTRA_MATH_NAME)" 1
179
180OBJS = $(DC_HELP_O) $(BC_HELP_O) $(BC_LIB_O) $(BC_LIB2_O) $(OBJ)
181
182all: %%DEFAULT_TARGET%%
183
184%%DEFAULT_TARGET%%: %%DEFAULT_TARGET_PREREQS%%
185	%%DEFAULT_TARGET_CMD%%
186
187%%SECOND_TARGET%%: %%SECOND_TARGET_PREREQS%%
188	%%SECOND_TARGET_CMD%%
189
190$(GEN_EXEC):
191	%%GEN_EXEC_TARGET%%
192
193$(BC_LIB_C): $(GEN_EXEC) $(BC_LIB)
194	$(GEN_EMU) $(GEN_EXEC) $(BC_LIB) $(BC_LIB_C) $(BC_LIB_C_ARGS)
195
196$(BC_LIB_O): $(BC_LIB_C)
197	$(CC) $(CFLAGS) -o $@ -c $<
198
199$(BC_LIB2_C): $(GEN_EXEC) $(BC_LIB2)
200	$(GEN_EMU) $(GEN_EXEC) $(BC_LIB2) $(BC_LIB2_C) $(BC_LIB2_C_ARGS)
201
202$(BC_LIB2_O): $(BC_LIB2_C)
203	$(CC) $(CFLAGS) -o $@ -c $<
204
205$(BC_HELP_C): $(GEN_EXEC) $(BC_HELP)
206	$(GEN_EMU) $(GEN_EXEC) $(BC_HELP) $(BC_HELP_C) bc_help "" $(BC_ENABLED_NAME)
207
208$(BC_HELP_O): $(BC_HELP_C)
209	$(CC) $(CFLAGS) -o $@ -c $<
210
211$(DC_HELP_C): $(GEN_EXEC) $(DC_HELP)
212	$(GEN_EMU) $(GEN_EXEC) $(DC_HELP) $(DC_HELP_C) dc_help "" $(DC_ENABLED_NAME)
213
214$(DC_HELP_O): $(DC_HELP_C)
215	$(CC) $(CFLAGS) -o $@ -c $<
216
217$(BIN):
218	$(MKDIR) -p $(BIN)
219
220headers: %%HEADERS%%
221
222help:
223	@printf 'available targets:\n'
224	@printf '\n'
225	@printf '    all (default)   builds %%EXECUTABLES%%\n'
226	@printf '    check           alias for `make test`\n'
227	@printf '    clean           removes all build files\n'
228	@printf '    clean_config    removes all build files as well as the generated Makefile\n'
229	@printf '    clean_tests     removes all build files, the generated Makefile,\n'
230	@printf '                    and generated tests\n'
231	@printf '    install         installs binaries to "%s%s"\n' "$(DESTDIR)" "$(BINDIR)"
232	@printf '                    and (if enabled) manpages to "%s%s"\n' "$(DESTDIR)" "$(MAN1DIR)"
233	@printf '    karatsuba       runs the karatsuba script (requires Python 3)\n'
234	@printf '    karatsuba_test  runs the karatsuba script while running tests\n'
235	@printf '                    (requires Python 3)\n'
236	@printf '    uninstall       uninstalls binaries from "%s%s"\n' "$(DESTDIR)" "$(BINDIR)"
237	@printf '                    and (if enabled) manpages from "%s%s"\n' "$(DESTDIR)" "$(MAN1DIR)"
238	@printf '    test            runs the test suite\n'
239	@printf '    test_bc         runs the bc test suite, if bc has been built\n'
240	@printf '    test_dc         runs the dc test suite, if dc has been built\n'
241	@printf '    time_test       runs the test suite, displaying times for some things\n'
242	@printf '    time_test_bc    runs the bc test suite, displaying times for some things\n'
243	@printf '    time_test_dc    runs the dc test suite, displaying times for some things\n'
244	@printf '    timeconst       runs the test on the Linux timeconst.bc script,\n'
245	@printf '                    if it exists and bc has been built\n'
246	@printf '    valgrind        runs the test suite through valgrind\n'
247	@printf '    valgrind_bc     runs the bc test suite, if bc has been built,\n'
248	@printf '                    through valgrind\n'
249	@printf '    valgrind_dc     runs the dc test suite, if dc has been built,\n'
250	@printf '                    through valgrind\n'
251
252run_all_tests:
253	%%BC_ALL_TESTS%%
254	%%TIMECONST_ALL_TESTS%%
255	%%DC_ALL_TESTS%%
256
257check: test
258
259test: %%TESTS%%
260
261test_bc: test_bc_header test_bc_tests test_bc_scripts test_bc_stdin test_bc_read test_bc_errors test_bc_other
262	@printf '\nAll bc tests passed.\n\n$(TEST_STARS)\n'
263
264test_bc_tests:%%BC_TESTS%%
265
266test_bc_scripts:%%BC_SCRIPT_TESTS%%
267
268test_bc_stdin:
269	@sh tests/stdin.sh bc %%BC_TEST_EXEC%%
270
271test_bc_read:
272	@sh tests/read.sh bc %%BC_TEST_EXEC%%
273
274test_bc_errors:
275	@sh tests/errors.sh bc %%BC_TEST_EXEC%%
276
277test_bc_other:
278	@sh tests/other.sh bc %%BC_TEST_EXEC%%
279
280test_bc_header:
281	@printf '$(TEST_STARS)\n\nRunning bc tests...\n\n'
282
283test_dc: test_dc_header test_dc_tests test_dc_scripts test_dc_stdin test_dc_read test_dc_errors test_dc_other
284	@printf '\nAll dc tests passed.\n\n$(TEST_STARS)\n'
285
286test_dc_tests:%%DC_TESTS%%
287
288test_dc_scripts:%%DC_SCRIPT_TESTS%%
289
290test_dc_stdin:
291	@sh tests/stdin.sh dc %%DC_TEST_EXEC%%
292
293test_dc_read:
294	@sh tests/read.sh dc %%DC_TEST_EXEC%%
295
296test_dc_errors:
297	@sh tests/errors.sh dc %%DC_TEST_EXEC%%
298
299test_dc_other:
300	@sh tests/other.sh dc %%DC_TEST_EXEC%%
301
302test_dc_header:
303	@printf '$(TEST_STARS)\n\nRunning dc tests...\n\n'
304
305timeconst:
306	%%TIMECONST%%
307
308library_test: $(LIBBC)
309	$(CC) $(CFLAGS) $(BCL_TEST_C) $(LIBBC) -o $(BCL_TEST)
310
311test_library: library_test
312	$(BCL_TEST)
313
314karatsuba:
315	%%KARATSUBA%%
316
317karatsuba_test:
318	%%KARATSUBA_TEST%%
319
320coverage_output:
321	%%COVERAGE_OUTPUT%%
322
323coverage:%%COVERAGE_PREREQS%%
324
325version:
326	@printf '%s' "$(VERSION)"
327
328libcname:
329	@printf '%s' "$(BC_LIB_C)"
330
331extra_math:
332	@printf '%s' "$(BC_ENABLE_EXTRA_MATH)"
333
334manpages:
335	$(MANPAGE) bc
336	$(MANPAGE) dc
337	$(MANPAGE) bcl
338
339clean_gen:
340	@$(RM) -f $(GEN_EXEC)
341
342clean:%%CLEAN_PREREQS%%
343	@printf 'Cleaning files...\n'
344	@$(RM) -f $(OBJ)
345	@$(RM) -f $(BC_EXEC)
346	@$(RM) -f $(DC_EXEC)
347	@$(RM) -fr $(BIN)
348	@$(RM) -f $(LOCALES)/*.cat
349	@$(RM) -f $(BC_LIB_C) $(BC_LIB_O)
350	@$(RM) -f $(BC_LIB2_C) $(BC_LIB2_O)
351	@$(RM) -f $(BC_HELP_C) $(BC_HELP_O)
352	@$(RM) -f $(DC_HELP_C) $(DC_HELP_O)
353	@$(RM) -fr $(BC_TEST_OUTPUTS) $(DC_TEST_OUTPUTS)
354	@$(RM) -fr $(BC_FUZZ_OUTPUTS) $(DC_FUZZ_OUTPUTS)
355
356clean_config: clean
357	@printf 'Cleaning config...\n'
358	@$(RM) -f Makefile
359	@$(RM) -f $(BC_MD) $(DC_MD)
360	@$(RM) -f $(BC_MANPAGE) $(DC_MANPAGE)
361
362clean_coverage:
363	@printf 'Cleaning coverage files...\n'
364	@$(RM) -f *.gcov
365	@$(RM) -f *.html
366	@$(RM) -f *.gcda *.gcno
367	@$(RM) -f *.profraw
368	@$(RM) -f $(GCDA) $(GCNO)
369	@$(RM) -f $(BC_GCDA) $(BC_GCNO)
370	@$(RM) -f $(DC_GCDA) $(DC_GCNO)
371	@$(RM) -f $(HISTORY_GCDA) $(HISTORY_GCNO)
372	@$(RM) -f $(RAND_GCDA) $(RAND_GCNO)
373	@$(RM) -f $(BC_LIB_GCDA) $(BC_LIB_GCNO)
374	@$(RM) -f $(BC_LIB2_GCDA) $(BC_LIB2_GCNO)
375	@$(RM) -f $(BC_HELP_GCDA) $(BC_HELP_GCNO)
376	@$(RM) -f $(DC_HELP_GCDA) $(DC_HELP_GCNO)
377
378clean_tests: clean clean_config clean_coverage
379	@printf 'Cleaning test files...\n'
380	@$(RM) -f tests/bc/parse.txt tests/bc/parse_results.txt
381	@$(RM) -f tests/bc/print.txt tests/bc/print_results.txt
382	@$(RM) -f tests/bc/bessel.txt tests/bc/bessel_results.txt
383	@$(RM) -f tests/bc/scripts/bessel.txt
384	@$(RM) -f tests/bc/scripts/parse.txt
385	@$(RM) -f tests/bc/scripts/print.txt
386	@$(RM) -f tests/bc/scripts/add.txt
387	@$(RM) -f tests/bc/scripts/divide.txt
388	@$(RM) -f tests/bc/scripts/multiply.txt
389	@$(RM) -f tests/bc/scripts/subtract.txt
390	@$(RM) -f tests/dc/scripts/prime.txt tests/dc/scripts/stream.txt
391	@$(RM) -f .log_*.txt
392	@$(RM) -f .math.txt .results.txt .ops.txt
393	@$(RM) -f .test.txt
394	@$(RM) -f tags .gdbbreakpoints .gdb_history .gdbsetup
395	@$(RM) -f cscope.*
396	@$(RM) -f bc.old
397
398install_locales:
399	%%INSTALL_LOCALES%%
400
401install_bc_manpage:
402	$(SAFE_INSTALL) $(MANPAGE_INSTALL_ARGS) $(BC_MANPAGE) $(DESTDIR)$(MAN1DIR)/$(BC_MANPAGE_NAME)
403
404install_dc_manpage:
405	$(SAFE_INSTALL) $(MANPAGE_INSTALL_ARGS) $(DC_MANPAGE) $(DESTDIR)$(MAN1DIR)/$(DC_MANPAGE_NAME)
406
407install_bcl_manpage:
408	$(SAFE_INSTALL) $(MANPAGE_INSTALL_ARGS) $(BCL_MANPAGE) $(DESTDIR)$(MAN3DIR)/$(BCL_MANPAGE_NAME)
409
410install_bcl_header:
411	$(SAFE_INSTALL) $(MANPAGE_INSTALL_ARGS) $(BCL_HEADER) $(DESTDIR)$(INCLUDEDIR)/$(BCL_HEADER_NAME)
412
413install_execs:
414	$(INSTALL) $(DESTDIR)$(BINDIR) "$(EXEC_SUFFIX)"
415
416install_library:
417	$(SAFE_INSTALL) $(BINARY_INSTALL_ARGS) $(LIBBC) $(DESTDIR)$(LIBDIR)/$(LIB_NAME)
418
419install:%%INSTALL_LOCALES_PREREQS%%%%INSTALL_MAN_PREREQS%%%%INSTALL_PREREQS%%
420
421uninstall_locales:
422	$(LOCALE_UNINSTALL) $(NLSPATH) $(MAIN_EXEC) $(DESTDIR)
423
424uninstall_bc_manpage:
425	$(RM) -f $(DESTDIR)$(MAN1DIR)/$(BC_MANPAGE_NAME)
426
427uninstall_bc:
428	$(RM) -f $(DESTDIR)$(BINDIR)/$(EXEC_PREFIX)$(BC)$(EXEC_SUFFIX)
429
430uninstall_dc_manpage:
431	$(RM) -f $(DESTDIR)$(MAN1DIR)/$(DC_MANPAGE_NAME)
432
433uninstall_dc:
434	$(RM) -f $(DESTDIR)$(BINDIR)/$(EXEC_PREFIX)$(DC)$(EXEC_SUFFIX)
435
436uninstall_library:
437	$(RM) -f $(DESTDIR)$(LIBDIR)/$(LIB_NAME)
438
439uninstall_bcl_header:
440	$(RM) -f $(DESTDIR)$(INCLUDEDIR)/$(BCL_HEADER_NAME)
441
442uninstall_bcl_manpage:
443	$(RM) -f $(DESTDIR)$(MAN3DIR)/$(BCL_MANPAGE_NAME)
444
445uninstall:%%UNINSTALL_LOCALES_PREREQS%%%%UNINSTALL_MAN_PREREQS%%%%UNINSTALL_PREREQS%%
446