Gavin Howard | b33afd0 | 2018-08-28 17:08:20 -0600 | [diff] [blame] | 1 | # |
| 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 Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 16 | SRC = $(sort $(wildcard src/*.c)) |
| 17 | OBJ = $(SRC:.c=.o) |
| 18 | |
| 19 | BC_SRC = $(sort $(wildcard src/bc/*.c)) |
Gavin Howard | b33afd0 | 2018-08-28 17:08:20 -0600 | [diff] [blame] | 20 | BC_OBJ = $(BC_SRC:.c=.o) |
| 21 | |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 22 | DC_SRC = $(sort $(wildcard src/dc/*.c)) |
| 23 | DC_OBJ = $(DC_SRC:.c=.o) |
| 24 | |
Gavin Howard | e6e8476 | 2018-10-03 11:46:34 -0600 | [diff] [blame] | 25 | BC_ENABLED = BC_ENABLED |
| 26 | DC_ENABLED = DC_ENABLED |
| 27 | |
Gavin Howard | a95501a | 2018-10-03 16:13:34 -0600 | [diff] [blame] | 28 | VERSION = 1.0 |
| 29 | |
Gavin Howard | b6ca06d | 2018-09-07 13:42:37 -0600 | [diff] [blame] | 30 | GEN_DIR = gen |
Gavin Howard | 633b29b | 2018-10-12 13:52:28 -0600 | [diff] [blame^] | 31 | GEN_EXEC = strgen$(EXE) |
Gavin Howard | b33afd0 | 2018-08-28 17:08:20 -0600 | [diff] [blame] | 32 | |
Gavin Howard | b6ca06d | 2018-09-07 13:42:37 -0600 | [diff] [blame] | 33 | BC_LIB = $(GEN_DIR)/lib.bc |
| 34 | BC_LIB_C = $(GEN_DIR)/lib.c |
| 35 | BC_LIB_O = $(GEN_DIR)/lib.o |
Gavin Howard | b33afd0 | 2018-08-28 17:08:20 -0600 | [diff] [blame] | 36 | |
Gavin Howard | 86098f2 | 2018-09-25 11:19:27 -0600 | [diff] [blame] | 37 | BC_HELP = $(GEN_DIR)/bc_help.txt |
| 38 | BC_HELP_C = $(GEN_DIR)/bc_help.c |
| 39 | BC_HELP_O = $(GEN_DIR)/bc_help.o |
Gavin Howard | be3a342 | 2018-09-07 13:29:10 -0600 | [diff] [blame] | 40 | |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 41 | DC_HELP = $(GEN_DIR)/dc_help.txt |
| 42 | DC_HELP_C = $(GEN_DIR)/dc_help.c |
| 43 | DC_HELP_O = $(GEN_DIR)/dc_help.o |
| 44 | |
Gavin Howard | 633b29b | 2018-10-12 13:52:28 -0600 | [diff] [blame^] | 45 | BC_EXEC = bc$(EXE) |
| 46 | DC_EXEC = dc$(EXE) |
Gavin Howard | b33afd0 | 2018-08-28 17:08:20 -0600 | [diff] [blame] | 47 | |
| 48 | PREFIX ?= /usr/local |
| 49 | |
| 50 | INSTALL = ./install.sh |
| 51 | |
| 52 | -include config.mak |
| 53 | |
| 54 | CFLAGS += -Wall -Wextra -pedantic -std=c99 -funsigned-char |
Gavin Howard | a95501a | 2018-10-03 16:13:34 -0600 | [diff] [blame] | 55 | CPPFLAGS += -I./include/ -D_POSIX_C_SOURCE=200809L -DVERSION=$(VERSION) |
Gavin Howard | b33afd0 | 2018-08-28 17:08:20 -0600 | [diff] [blame] | 56 | |
Gavin Howard | b33afd0 | 2018-08-28 17:08:20 -0600 | [diff] [blame] | 57 | HOSTCC ?= $(CC) |
| 58 | |
Gavin Howard | e6e8476 | 2018-10-03 11:46:34 -0600 | [diff] [blame] | 59 | all: CPPFLAGS += -D$(DC_ENABLED) -D$(BC_ENABLED) |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 60 | all: clean $(DC_HELP_O) $(BC_HELP_O) $(BC_LIB_O) $(BC_OBJ) $(DC_OBJ) $(OBJ) |
Gavin Howard | ec82bdc | 2018-10-08 23:50:57 -0600 | [diff] [blame] | 61 | $(CC) $(CFLAGS) $(OBJ) $(DC_OBJ) $(BC_OBJ) $(BC_LIB_O) $(BC_HELP_O) $(DC_HELP_O) -o $(BC_EXEC) |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 62 | 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 Howard | eb5c6ab | 2018-10-03 11:47:36 -0600 | [diff] [blame] | 68 | $(GEN_EMU) ./$(GEN_EXEC) $(BC_LIB) $(BC_LIB_C) bc_lib bc_lib_name $(BC_ENABLED) |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 69 | |
| 70 | $(BC_HELP_C): $(GEN_EXEC) |
Gavin Howard | eb5c6ab | 2018-10-03 11:47:36 -0600 | [diff] [blame] | 71 | $(GEN_EMU) ./$(GEN_EXEC) $(BC_HELP) $(BC_HELP_C) bc_help "" $(BC_ENABLED) |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 72 | |
| 73 | $(DC_HELP_C): $(GEN_EXEC) |
Gavin Howard | eb5c6ab | 2018-10-03 11:47:36 -0600 | [diff] [blame] | 74 | $(GEN_EMU) ./$(GEN_EXEC) $(DC_HELP) $(DC_HELP_C) dc_help "" $(DC_ENABLED) |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 75 | |
Gavin Howard | e6e8476 | 2018-10-03 11:46:34 -0600 | [diff] [blame] | 76 | $(DC_EXEC): CPPFLAGS += -D$(DC_ENABLED) |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 77 | $(DC_EXEC): clean $(DC_OBJ) $(DC_HELP_O) $(OBJ) |
Gavin Howard | ec82bdc | 2018-10-08 23:50:57 -0600 | [diff] [blame] | 78 | $(CC) $(CFLAGS) $(OBJ) $(DC_OBJ) $(DC_HELP_O) -o $(DC_EXEC) |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 79 | |
Gavin Howard | e6e8476 | 2018-10-03 11:46:34 -0600 | [diff] [blame] | 80 | $(BC_EXEC): CPPFLAGS += -D$(BC_ENABLED) |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 81 | $(BC_EXEC): clean $(BC_OBJ) $(BC_LIB_O) $(BC_HELP_O) $(OBJ) |
Gavin Howard | ec82bdc | 2018-10-08 23:50:57 -0600 | [diff] [blame] | 82 | $(CC) $(CFLAGS) $(OBJ) $(BC_OBJ) $(BC_LIB_O) $(BC_HELP_O) -o $(BC_EXEC) |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 83 | |
Gavin Howard | b33afd0 | 2018-08-28 17:08:20 -0600 | [diff] [blame] | 84 | help: |
Gavin Howard | 8befc46 | 2018-10-10 10:03:12 -0600 | [diff] [blame] | 85 | @echo "all targets use config.mak, if there is one" |
| 86 | @echo "" |
Gavin Howard | b33afd0 | 2018-08-28 17:08:20 -0600 | [diff] [blame] | 87 | @echo "available targets:" |
| 88 | @echo "" |
Gavin Howard | 8befc46 | 2018-10-10 10:03:12 -0600 | [diff] [blame] | 89 | @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 Howard | b33afd0 | 2018-08-28 17:08:20 -0600 | [diff] [blame] | 106 | @echo "" |
| 107 | @echo "useful environment variables:" |
| 108 | @echo "" |
Gavin Howard | 1061ea6 | 2018-08-31 00:26:37 -0600 | [diff] [blame] | 109 | @echo " CC C compiler" |
| 110 | @echo " HOSTCC Host C compiler" |
| 111 | @echo " CFLAGS C compiler flags" |
| 112 | @echo " CPPFLAGS C preprocessor flags" |
Gavin Howard | 1061ea6 | 2018-08-31 00:26:37 -0600 | [diff] [blame] | 113 | @echo " PREFIX the prefix to install to" |
| 114 | @echo " if PREFIX is \"/usr\", $(BC_EXEC) will be installed to \"/usr/bin\"" |
Gavin Howard | 8befc46 | 2018-10-10 10:03:12 -0600 | [diff] [blame] | 115 | @echo " DESTDIR For package creation" |
Gavin Howard | b6ca06d | 2018-09-07 13:42:37 -0600 | [diff] [blame] | 116 | @echo " GEN_EMU Emulator to run $(GEN_EXEC) under (leave empty if not necessary)" |
Gavin Howard | b33afd0 | 2018-08-28 17:08:20 -0600 | [diff] [blame] | 117 | |
Gavin Howard | a2b97d2 | 2018-10-04 11:35:50 -0600 | [diff] [blame] | 118 | test_all: test timeconst |
| 119 | |
Gavin Howard | 21ab316 | 2018-10-04 11:26:33 -0600 | [diff] [blame] | 120 | test: test_bc test_dc |
Gavin Howard | b33afd0 | 2018-08-28 17:08:20 -0600 | [diff] [blame] | 121 | |
Gavin Howard | 9c4ce07 | 2018-10-03 13:50:46 -0600 | [diff] [blame] | 122 | test_bc: |
| 123 | tests/all.sh bc |
| 124 | |
| 125 | test_dc: |
| 126 | tests/all.sh dc |
| 127 | |
Gavin Howard | 199ac6e | 2018-08-31 00:07:26 -0600 | [diff] [blame] | 128 | timeconst: |
Gavin Howard | a2b97d2 | 2018-10-04 11:35:50 -0600 | [diff] [blame] | 129 | tests/bc/timeconst.sh |
| 130 | |
| 131 | valgrind_all: valgrind valgrind_timeconst |
| 132 | |
| 133 | valgrind: valgrind_bc valgrind_dc |
| 134 | |
| 135 | valgrind_bc: |
| 136 | tests/all.sh bc valgrind --leak-check=full --show-leak-kinds=all ./bc |
| 137 | |
| 138 | valgrind_dc: |
| 139 | tests/all.sh dc valgrind --leak-check=full --show-leak-kinds=all ./dc |
| 140 | |
| 141 | valgrind_timeconst: |
| 142 | tests/bc/timeconst.sh valgrind --leak-check=full --show-leak-kinds=all ./bc |
Gavin Howard | 199ac6e | 2018-08-31 00:07:26 -0600 | [diff] [blame] | 143 | |
Gavin Howard | a95501a | 2018-10-03 16:13:34 -0600 | [diff] [blame] | 144 | version: |
Gavin Howard | 30c6b55 | 2018-10-10 10:42:16 -0600 | [diff] [blame] | 145 | @echo "$(VERSION)" |
Gavin Howard | a95501a | 2018-10-03 16:13:34 -0600 | [diff] [blame] | 146 | |
| 147 | libcname: |
Gavin Howard | 30c6b55 | 2018-10-10 10:42:16 -0600 | [diff] [blame] | 148 | @echo "$(BC_LIB_C)" |
Gavin Howard | a95501a | 2018-10-03 16:13:34 -0600 | [diff] [blame] | 149 | |
Gavin Howard | b33afd0 | 2018-08-28 17:08:20 -0600 | [diff] [blame] | 150 | clean: |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 151 | $(RM) -f $(OBJ) |
Gavin Howard | 7a5bab0 | 2018-09-22 21:13:26 -0600 | [diff] [blame] | 152 | $(RM) -f $(BC_OBJ) |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 153 | $(RM) -f $(DC_OBJ) |
Gavin Howard | 7a5bab0 | 2018-09-22 21:13:26 -0600 | [diff] [blame] | 154 | $(RM) -f $(BC_EXEC) |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 155 | $(RM) -f $(DC_EXEC) |
Gavin Howard | 7a5bab0 | 2018-09-22 21:13:26 -0600 | [diff] [blame] | 156 | $(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 Howard | 196b221 | 2018-09-01 16:53:49 -0600 | [diff] [blame] | 161 | |
| 162 | clean_tests: clean |
Gavin Howard | 9c4ce07 | 2018-10-03 13:50:46 -0600 | [diff] [blame] | 163 | $(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 Howard | 8df4c14 | 2018-09-25 11:15:26 -0600 | [diff] [blame] | 166 | $(RM) -f .log_test.txt .log_bc.txt |
| 167 | $(RM) -f .math.txt .results.txt .ops.txt |
| 168 | $(RM) -f .test.txt |
Gavin Howard | b33afd0 | 2018-08-28 17:08:20 -0600 | [diff] [blame] | 169 | |
Gavin Howard | c494b57 | 2018-09-27 13:34:45 -0600 | [diff] [blame] | 170 | install: uninstall |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 171 | $(INSTALL) $(DESTDIR)$(PREFIX)/bin $(BC_EXEC) $(DC_EXEC) |
Gavin Howard | b33afd0 | 2018-08-28 17:08:20 -0600 | [diff] [blame] | 172 | |
| 173 | uninstall: |
Gavin Howard | ed77cc8 | 2018-09-25 11:16:18 -0600 | [diff] [blame] | 174 | $(RM) -f $(DESTDIR)$(PREFIX)/bin/$(BC_EXEC) |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 175 | $(RM) -f $(DESTDIR)$(PREFIX)/bin/$(DC_EXEC) |
Gavin Howard | b33afd0 | 2018-08-28 17:08:20 -0600 | [diff] [blame] | 176 | |
Gavin Howard | d75bb45 | 2018-10-03 11:46:59 -0600 | [diff] [blame] | 177 | .PHONY: help clean clean_tests install uninstall test |