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 | |
| 16 | BC_SRC = $(sort $(wildcard src/*.c)) |
| 17 | BC_OBJ = $(BC_SRC:.c=.o) |
| 18 | |
Gavin Howard | b6ca06d | 2018-09-07 13:42:37 -0600 | [diff] [blame] | 19 | GEN_DIR = gen |
| 20 | GEN_EXEC = strgen |
Gavin Howard | b33afd0 | 2018-08-28 17:08:20 -0600 | [diff] [blame] | 21 | |
Gavin Howard | b6ca06d | 2018-09-07 13:42:37 -0600 | [diff] [blame] | 22 | BC_LIB = $(GEN_DIR)/lib.bc |
| 23 | BC_LIB_C = $(GEN_DIR)/lib.c |
| 24 | BC_LIB_O = $(GEN_DIR)/lib.o |
Gavin Howard | b33afd0 | 2018-08-28 17:08:20 -0600 | [diff] [blame] | 25 | |
Gavin Howard | b6ca06d | 2018-09-07 13:42:37 -0600 | [diff] [blame] | 26 | BC_HELP = $(GEN_DIR)/help.txt |
| 27 | BC_HELP_C = $(GEN_DIR)/help.c |
| 28 | BC_HELP_O = $(GEN_DIR)/help.o |
Gavin Howard | be3a342 | 2018-09-07 13:29:10 -0600 | [diff] [blame] | 29 | |
Gavin Howard | b33afd0 | 2018-08-28 17:08:20 -0600 | [diff] [blame] | 30 | BC_EXEC = bc |
| 31 | |
| 32 | PREFIX ?= /usr/local |
| 33 | |
| 34 | INSTALL = ./install.sh |
| 35 | |
| 36 | -include config.mak |
| 37 | |
| 38 | CFLAGS += -Wall -Wextra -pedantic -std=c99 -funsigned-char |
| 39 | CPPFLAGS += -I./include/ -D_POSIX_C_SOURCE=200809L |
| 40 | |
| 41 | LDLIBS += -lm |
| 42 | |
| 43 | HOSTCC ?= $(CC) |
| 44 | |
| 45 | all: $(BC_EXEC) |
| 46 | |
| 47 | help: |
| 48 | @echo "available targets:" |
| 49 | @echo "" |
Gavin Howard | 1061ea6 | 2018-08-31 00:26:37 -0600 | [diff] [blame] | 50 | @echo " all build bc (uses config.mak if there is one)" |
| 51 | @echo " clean remove all build files" |
| 52 | @echo " install install to $(PREFIX)/bin" |
| 53 | @echo " uninstall uninstall from $(PREFIX)/bin" |
| 54 | @echo " test runs the test suite" |
| 55 | @echo " timeconst runs the test on the Linux timeconst.bc script" |
| 56 | @echo " the timeconst.bc script must be in the parent directory" |
Gavin Howard | b33afd0 | 2018-08-28 17:08:20 -0600 | [diff] [blame] | 57 | @echo "" |
| 58 | @echo "useful environment variables:" |
| 59 | @echo "" |
Gavin Howard | 1061ea6 | 2018-08-31 00:26:37 -0600 | [diff] [blame] | 60 | @echo " CC C compiler" |
| 61 | @echo " HOSTCC Host C compiler" |
| 62 | @echo " CFLAGS C compiler flags" |
| 63 | @echo " CPPFLAGS C preprocessor flags" |
| 64 | @echo " LDLIBS Libraries to link to" |
| 65 | @echo " PREFIX the prefix to install to" |
| 66 | @echo " if PREFIX is \"/usr\", $(BC_EXEC) will be installed to \"/usr/bin\"" |
Gavin Howard | b6ca06d | 2018-09-07 13:42:37 -0600 | [diff] [blame] | 67 | @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] | 68 | |
Gavin Howard | b6ca06d | 2018-09-07 13:42:37 -0600 | [diff] [blame] | 69 | $(GEN_EXEC): |
| 70 | $(HOSTCC) -o $(GEN_EXEC) $(GEN_DIR)/$(GEN_EXEC).c |
Gavin Howard | b33afd0 | 2018-08-28 17:08:20 -0600 | [diff] [blame] | 71 | |
Gavin Howard | b6ca06d | 2018-09-07 13:42:37 -0600 | [diff] [blame] | 72 | $(BC_LIB_C): $(GEN_EXEC) |
| 73 | $(GEN_EMU) ./$(GEN_EXEC) $(BC_LIB) $(BC_LIB_C) bc_lib bc_lib_name |
Gavin Howard | b33afd0 | 2018-08-28 17:08:20 -0600 | [diff] [blame] | 74 | |
Gavin Howard | b6ca06d | 2018-09-07 13:42:37 -0600 | [diff] [blame] | 75 | $(BC_HELP_C): $(GEN_EXEC) |
| 76 | $(GEN_EMU) ./$(GEN_EXEC) $(BC_HELP) $(BC_HELP_C) bc_help |
Gavin Howard | be3a342 | 2018-09-07 13:29:10 -0600 | [diff] [blame] | 77 | |
| 78 | $(BC_EXEC): $(BC_OBJ) $(BC_LIB_O) $(BC_HELP_O) |
| 79 | $(CC) $(CFLAGS) -o $(BC_EXEC) $(BC_OBJ) $(BC_LIB_O) $(BC_HELP_O) $(LDLIBS) $(LDFLAGS) |
Gavin Howard | b33afd0 | 2018-08-28 17:08:20 -0600 | [diff] [blame] | 80 | |
| 81 | test: |
| 82 | tests/all.sh |
| 83 | |
Gavin Howard | d43ae75 | 2018-09-06 19:36:18 -0600 | [diff] [blame] | 84 | valgrind: |
| 85 | tests/all.sh valgrind --leak-check=full --show-leak-kinds=all ./bc |
| 86 | |
Gavin Howard | 199ac6e | 2018-08-31 00:07:26 -0600 | [diff] [blame] | 87 | timeconst: |
| 88 | tests/timeconst.sh |
| 89 | |
Gavin Howard | b33afd0 | 2018-08-28 17:08:20 -0600 | [diff] [blame] | 90 | clean: |
| 91 | $(RM) $(BC_OBJ) |
| 92 | $(RM) $(BC_EXEC) |
Gavin Howard | b6ca06d | 2018-09-07 13:42:37 -0600 | [diff] [blame] | 93 | $(RM) $(GEN_EXEC) |
Gavin Howard | b33afd0 | 2018-08-28 17:08:20 -0600 | [diff] [blame] | 94 | $(RM) $(BC_LIB_C) |
| 95 | $(RM) $(BC_LIB_O) |
Gavin Howard | be3a342 | 2018-09-07 13:29:10 -0600 | [diff] [blame] | 96 | $(RM) $(BC_HELP_C) |
| 97 | $(RM) $(BC_HELP_O) |
Gavin Howard | d43ae75 | 2018-09-06 19:36:18 -0600 | [diff] [blame] | 98 | $(RM) .log_test.txt .log_bc.txt |
Gavin Howard | 4b1d110 | 2018-09-08 20:08:55 -0600 | [diff] [blame] | 99 | $(RM) .math.txt .results.txt .ops.txt |
Gavin Howard | 196b221 | 2018-09-01 16:53:49 -0600 | [diff] [blame] | 100 | |
| 101 | clean_tests: clean |
Gavin Howard | 3169062 | 2018-08-30 09:56:37 -0600 | [diff] [blame] | 102 | $(RM) tests/parse.txt tests/parse_results.txt |
| 103 | $(RM) tests/print.txt tests/print_results.txt |
Gavin Howard | 56eeb5a | 2018-09-01 22:53:47 -0600 | [diff] [blame] | 104 | $(RM) tests/bessel.txt tests/bessel_results.txt |
Gavin Howard | b33afd0 | 2018-08-28 17:08:20 -0600 | [diff] [blame] | 105 | |
| 106 | install: $(BC_EXEC) |
| 107 | $(INSTALL) -Dm 755 $(BC_EXEC) $(DESTDIR)$(PREFIX)/bin/$(BC_EXEC) |
| 108 | |
| 109 | uninstall: |
| 110 | rm -rf $(DESTDIR)$(PREFIX)/bin/$(BC_EXEC) |
| 111 | |
Gavin Howard | 196b221 | 2018-09-01 16:53:49 -0600 | [diff] [blame] | 112 | .PHONY: all help clean clean_tests install uninstall test |