blob: 73ffeb289cc12808d3a88cb2862f3ede3896ea2e [file] [log] [blame]
Gavin Howardb33afd02018-08-28 17:08:20 -06001#
2# Copyright 2018 Gavin D. Howard
3#
4# Permission to use, copy, modify, and/or distribute this software for any
5# purpose with or without fee is hereby granted.
6#
7# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13# PERFORMANCE OF THIS SOFTWARE.
14#
15
Gavin Howard4ffe5a92018-09-26 20:58:31 -060016SRC = $(sort $(wildcard src/*.c))
17OBJ = $(SRC:.c=.o)
18
19BC_SRC = $(sort $(wildcard src/bc/*.c))
Gavin Howardb33afd02018-08-28 17:08:20 -060020BC_OBJ = $(BC_SRC:.c=.o)
21
Gavin Howard4ffe5a92018-09-26 20:58:31 -060022DC_SRC = $(sort $(wildcard src/dc/*.c))
23DC_OBJ = $(DC_SRC:.c=.o)
24
Gavin Howarde6e84762018-10-03 11:46:34 -060025BC_ENABLED = BC_ENABLED
26DC_ENABLED = DC_ENABLED
27
Gavin Howarda95501a2018-10-03 16:13:34 -060028VERSION = 1.0
29
Gavin Howardb6ca06d2018-09-07 13:42:37 -060030GEN_DIR = gen
31GEN_EXEC = strgen
Gavin Howardb33afd02018-08-28 17:08:20 -060032
Gavin Howardb6ca06d2018-09-07 13:42:37 -060033BC_LIB = $(GEN_DIR)/lib.bc
34BC_LIB_C = $(GEN_DIR)/lib.c
35BC_LIB_O = $(GEN_DIR)/lib.o
Gavin Howardb33afd02018-08-28 17:08:20 -060036
Gavin Howard86098f22018-09-25 11:19:27 -060037BC_HELP = $(GEN_DIR)/bc_help.txt
38BC_HELP_C = $(GEN_DIR)/bc_help.c
39BC_HELP_O = $(GEN_DIR)/bc_help.o
Gavin Howardbe3a3422018-09-07 13:29:10 -060040
Gavin Howard4ffe5a92018-09-26 20:58:31 -060041DC_HELP = $(GEN_DIR)/dc_help.txt
42DC_HELP_C = $(GEN_DIR)/dc_help.c
43DC_HELP_O = $(GEN_DIR)/dc_help.o
44
Gavin Howardb33afd02018-08-28 17:08:20 -060045BC_EXEC = bc
Gavin Howard4ffe5a92018-09-26 20:58:31 -060046DC_EXEC = dc
Gavin Howardb33afd02018-08-28 17:08:20 -060047
48PREFIX ?= /usr/local
49
50INSTALL = ./install.sh
51
52-include config.mak
53
54CFLAGS += -Wall -Wextra -pedantic -std=c99 -funsigned-char
Gavin Howarda95501a2018-10-03 16:13:34 -060055CPPFLAGS += -I./include/ -D_POSIX_C_SOURCE=200809L -DVERSION=$(VERSION)
Gavin Howardb33afd02018-08-28 17:08:20 -060056
Gavin Howardb33afd02018-08-28 17:08:20 -060057HOSTCC ?= $(CC)
58
Gavin Howarde6e84762018-10-03 11:46:34 -060059all: CPPFLAGS += -D$(DC_ENABLED) -D$(BC_ENABLED)
Gavin Howard4ffe5a92018-09-26 20:58:31 -060060all: clean $(DC_HELP_O) $(BC_HELP_O) $(BC_LIB_O) $(BC_OBJ) $(DC_OBJ) $(OBJ)
Gavin Howardec82bdc2018-10-08 23:50:57 -060061 $(CC) $(CFLAGS) $(OBJ) $(DC_OBJ) $(BC_OBJ) $(BC_LIB_O) $(BC_HELP_O) $(DC_HELP_O) -o $(BC_EXEC)
Gavin Howard4ffe5a92018-09-26 20:58:31 -060062 ln -s ./$(BC_EXEC) $(DC_EXEC)
63
64$(GEN_EXEC):
65 $(HOSTCC) -o $(GEN_EXEC) $(GEN_DIR)/$(GEN_EXEC).c
66
67$(BC_LIB_C): $(GEN_EXEC)
Gavin Howardeb5c6ab2018-10-03 11:47:36 -060068 $(GEN_EMU) ./$(GEN_EXEC) $(BC_LIB) $(BC_LIB_C) bc_lib bc_lib_name $(BC_ENABLED)
Gavin Howard4ffe5a92018-09-26 20:58:31 -060069
70$(BC_HELP_C): $(GEN_EXEC)
Gavin Howardeb5c6ab2018-10-03 11:47:36 -060071 $(GEN_EMU) ./$(GEN_EXEC) $(BC_HELP) $(BC_HELP_C) bc_help "" $(BC_ENABLED)
Gavin Howard4ffe5a92018-09-26 20:58:31 -060072
73$(DC_HELP_C): $(GEN_EXEC)
Gavin Howardeb5c6ab2018-10-03 11:47:36 -060074 $(GEN_EMU) ./$(GEN_EXEC) $(DC_HELP) $(DC_HELP_C) dc_help "" $(DC_ENABLED)
Gavin Howard4ffe5a92018-09-26 20:58:31 -060075
Gavin Howarde6e84762018-10-03 11:46:34 -060076$(DC_EXEC): CPPFLAGS += -D$(DC_ENABLED)
Gavin Howard4ffe5a92018-09-26 20:58:31 -060077$(DC_EXEC): clean $(DC_OBJ) $(DC_HELP_O) $(OBJ)
Gavin Howardec82bdc2018-10-08 23:50:57 -060078 $(CC) $(CFLAGS) $(OBJ) $(DC_OBJ) $(DC_HELP_O) -o $(DC_EXEC)
Gavin Howard4ffe5a92018-09-26 20:58:31 -060079
Gavin Howarde6e84762018-10-03 11:46:34 -060080$(BC_EXEC): CPPFLAGS += -D$(BC_ENABLED)
Gavin Howard4ffe5a92018-09-26 20:58:31 -060081$(BC_EXEC): clean $(BC_OBJ) $(BC_LIB_O) $(BC_HELP_O) $(OBJ)
Gavin Howardec82bdc2018-10-08 23:50:57 -060082 $(CC) $(CFLAGS) $(OBJ) $(BC_OBJ) $(BC_LIB_O) $(BC_HELP_O) -o $(BC_EXEC)
Gavin Howard4ffe5a92018-09-26 20:58:31 -060083
Gavin Howardb33afd02018-08-28 17:08:20 -060084help:
Gavin Howard8befc462018-10-10 10:03:12 -060085 @echo "all targets use config.mak, if there is one"
86 @echo ""
Gavin Howardb33afd02018-08-28 17:08:20 -060087 @echo "available targets:"
88 @echo ""
Gavin Howard8befc462018-10-10 10:03:12 -060089 @echo " all (default) build bc and dc"
90 @echo " bc build bc only"
91 @echo " clean remove all build files"
92 @echo " clean_tests remove all build files as well as generated tests"
93 @echo " dc build dc only"
94 @echo " install install to $(PREFIX)/bin"
95 @echo " uninstall uninstall from $(PREFIX)/bin"
96 @echo " test runs the test suite"
97 @echo " test_all runs the test suite as well as the Linux timeconst.bc test"
98 @echo " test_bc runs the bc test suite"
99 @echo " test_dc runs the dc test suite"
100 @echo " timeconst runs the test on the Linux timeconst.bc script"
101 @echo " valgrind runs the test suite through valgrind"
102 @echo " valgrind_all runs the test suite, and the Linux timeconst.bc test,"
103 @echo " through valgrind"
104 @echo " valgrind_bc runs the bc test suite through valgrind"
105 @echo " valgrind_dc runs the dc test suite through valgrind"
Gavin Howardb33afd02018-08-28 17:08:20 -0600106 @echo ""
107 @echo "useful environment variables:"
108 @echo ""
Gavin Howard1061ea62018-08-31 00:26:37 -0600109 @echo " CC C compiler"
110 @echo " HOSTCC Host C compiler"
111 @echo " CFLAGS C compiler flags"
112 @echo " CPPFLAGS C preprocessor flags"
Gavin Howard1061ea62018-08-31 00:26:37 -0600113 @echo " PREFIX the prefix to install to"
114 @echo " if PREFIX is \"/usr\", $(BC_EXEC) will be installed to \"/usr/bin\""
Gavin Howard8befc462018-10-10 10:03:12 -0600115 @echo " DESTDIR For package creation"
Gavin Howardb6ca06d2018-09-07 13:42:37 -0600116 @echo " GEN_EMU Emulator to run $(GEN_EXEC) under (leave empty if not necessary)"
Gavin Howardb33afd02018-08-28 17:08:20 -0600117
Gavin Howarda2b97d22018-10-04 11:35:50 -0600118test_all: test timeconst
119
Gavin Howard21ab3162018-10-04 11:26:33 -0600120test: test_bc test_dc
Gavin Howardb33afd02018-08-28 17:08:20 -0600121
Gavin Howard9c4ce072018-10-03 13:50:46 -0600122test_bc:
123 tests/all.sh bc
124
125test_dc:
126 tests/all.sh dc
127
Gavin Howard199ac6e2018-08-31 00:07:26 -0600128timeconst:
Gavin Howarda2b97d22018-10-04 11:35:50 -0600129 tests/bc/timeconst.sh
130
131valgrind_all: valgrind valgrind_timeconst
132
133valgrind: valgrind_bc valgrind_dc
134
135valgrind_bc:
136 tests/all.sh bc valgrind --leak-check=full --show-leak-kinds=all ./bc
137
138valgrind_dc:
139 tests/all.sh dc valgrind --leak-check=full --show-leak-kinds=all ./dc
140
141valgrind_timeconst:
142 tests/bc/timeconst.sh valgrind --leak-check=full --show-leak-kinds=all ./bc
Gavin Howard199ac6e2018-08-31 00:07:26 -0600143
Gavin Howarda95501a2018-10-03 16:13:34 -0600144version:
Gavin Howard30c6b552018-10-10 10:42:16 -0600145 @echo "$(VERSION)"
Gavin Howarda95501a2018-10-03 16:13:34 -0600146
147libcname:
Gavin Howard30c6b552018-10-10 10:42:16 -0600148 @echo "$(BC_LIB_C)"
Gavin Howarda95501a2018-10-03 16:13:34 -0600149
Gavin Howardb33afd02018-08-28 17:08:20 -0600150clean:
Gavin Howard4ffe5a92018-09-26 20:58:31 -0600151 $(RM) -f $(OBJ)
Gavin Howard7a5bab02018-09-22 21:13:26 -0600152 $(RM) -f $(BC_OBJ)
Gavin Howard4ffe5a92018-09-26 20:58:31 -0600153 $(RM) -f $(DC_OBJ)
Gavin Howard7a5bab02018-09-22 21:13:26 -0600154 $(RM) -f $(BC_EXEC)
Gavin Howard4ffe5a92018-09-26 20:58:31 -0600155 $(RM) -f $(DC_EXEC)
Gavin Howard7a5bab02018-09-22 21:13:26 -0600156 $(RM) -f $(GEN_EXEC)
157 $(RM) -f $(BC_LIB_C)
158 $(RM) -f $(BC_LIB_O)
159 $(RM) -f $(BC_HELP_C)
160 $(RM) -f $(BC_HELP_O)
Gavin Howard196b2212018-09-01 16:53:49 -0600161
162clean_tests: clean
Gavin Howard9c4ce072018-10-03 13:50:46 -0600163 $(RM) -f tests/bc/parse.txt tests/bc/parse_results.txt
164 $(RM) -f tests/bc/print.txt tests/bc/print_results.txt
165 $(RM) -f tests/bc/bessel.txt tests/bc/bessel_results.txt
Gavin Howard8df4c142018-09-25 11:15:26 -0600166 $(RM) -f .log_test.txt .log_bc.txt
167 $(RM) -f .math.txt .results.txt .ops.txt
168 $(RM) -f .test.txt
Gavin Howardb33afd02018-08-28 17:08:20 -0600169
Gavin Howardc494b572018-09-27 13:34:45 -0600170install: uninstall
Gavin Howard4ffe5a92018-09-26 20:58:31 -0600171 $(INSTALL) $(DESTDIR)$(PREFIX)/bin $(BC_EXEC) $(DC_EXEC)
Gavin Howardb33afd02018-08-28 17:08:20 -0600172
173uninstall:
Gavin Howarded77cc82018-09-25 11:16:18 -0600174 $(RM) -f $(DESTDIR)$(PREFIX)/bin/$(BC_EXEC)
Gavin Howard4ffe5a92018-09-26 20:58:31 -0600175 $(RM) -f $(DESTDIR)$(PREFIX)/bin/$(DC_EXEC)
Gavin Howardb33afd02018-08-28 17:08:20 -0600176
Gavin Howardd75bb452018-10-03 11:46:59 -0600177.PHONY: help clean clean_tests install uninstall test