blob: 7f76685715e20de3444d0c57850287254ab4f820 [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
16BC_SRC = $(sort $(wildcard src/*.c))
17BC_OBJ = $(BC_SRC:.c=.o)
18
Gavin Howardb6ca06d2018-09-07 13:42:37 -060019GEN_DIR = gen
20GEN_EXEC = strgen
Gavin Howardb33afd02018-08-28 17:08:20 -060021
Gavin Howardb6ca06d2018-09-07 13:42:37 -060022BC_LIB = $(GEN_DIR)/lib.bc
23BC_LIB_C = $(GEN_DIR)/lib.c
24BC_LIB_O = $(GEN_DIR)/lib.o
Gavin Howardb33afd02018-08-28 17:08:20 -060025
Gavin Howardb6ca06d2018-09-07 13:42:37 -060026BC_HELP = $(GEN_DIR)/help.txt
27BC_HELP_C = $(GEN_DIR)/help.c
28BC_HELP_O = $(GEN_DIR)/help.o
Gavin Howardbe3a3422018-09-07 13:29:10 -060029
Gavin Howardb33afd02018-08-28 17:08:20 -060030BC_EXEC = bc
31
32PREFIX ?= /usr/local
33
34INSTALL = ./install.sh
35
36-include config.mak
37
38CFLAGS += -Wall -Wextra -pedantic -std=c99 -funsigned-char
39CPPFLAGS += -I./include/ -D_POSIX_C_SOURCE=200809L
40
41LDLIBS += -lm
42
43HOSTCC ?= $(CC)
44
45all: $(BC_EXEC)
46
47help:
48 @echo "available targets:"
49 @echo ""
Gavin Howard1061ea62018-08-31 00:26:37 -060050 @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 Howardb33afd02018-08-28 17:08:20 -060057 @echo ""
58 @echo "useful environment variables:"
59 @echo ""
Gavin Howard1061ea62018-08-31 00:26:37 -060060 @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 Howardb6ca06d2018-09-07 13:42:37 -060067 @echo " GEN_EMU Emulator to run $(GEN_EXEC) under (leave empty if not necessary)"
Gavin Howardb33afd02018-08-28 17:08:20 -060068
Gavin Howardb6ca06d2018-09-07 13:42:37 -060069$(GEN_EXEC):
70 $(HOSTCC) -o $(GEN_EXEC) $(GEN_DIR)/$(GEN_EXEC).c
Gavin Howardb33afd02018-08-28 17:08:20 -060071
Gavin Howardb6ca06d2018-09-07 13:42:37 -060072$(BC_LIB_C): $(GEN_EXEC)
73 $(GEN_EMU) ./$(GEN_EXEC) $(BC_LIB) $(BC_LIB_C) bc_lib bc_lib_name
Gavin Howardb33afd02018-08-28 17:08:20 -060074
Gavin Howardb6ca06d2018-09-07 13:42:37 -060075$(BC_HELP_C): $(GEN_EXEC)
76 $(GEN_EMU) ./$(GEN_EXEC) $(BC_HELP) $(BC_HELP_C) bc_help
Gavin Howardbe3a3422018-09-07 13:29:10 -060077
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 Howardb33afd02018-08-28 17:08:20 -060080
81test:
82 tests/all.sh
83
Gavin Howardd43ae752018-09-06 19:36:18 -060084valgrind:
85 tests/all.sh valgrind --leak-check=full --show-leak-kinds=all ./bc
86
Gavin Howard199ac6e2018-08-31 00:07:26 -060087timeconst:
88 tests/timeconst.sh
89
Gavin Howardb33afd02018-08-28 17:08:20 -060090clean:
91 $(RM) $(BC_OBJ)
92 $(RM) $(BC_EXEC)
Gavin Howardb6ca06d2018-09-07 13:42:37 -060093 $(RM) $(GEN_EXEC)
Gavin Howardb33afd02018-08-28 17:08:20 -060094 $(RM) $(BC_LIB_C)
95 $(RM) $(BC_LIB_O)
Gavin Howardbe3a3422018-09-07 13:29:10 -060096 $(RM) $(BC_HELP_C)
97 $(RM) $(BC_HELP_O)
Gavin Howardd43ae752018-09-06 19:36:18 -060098 $(RM) .log_test.txt .log_bc.txt
Gavin Howard4b1d1102018-09-08 20:08:55 -060099 $(RM) .math.txt .results.txt .ops.txt
Gavin Howard196b2212018-09-01 16:53:49 -0600100
101clean_tests: clean
Gavin Howard31690622018-08-30 09:56:37 -0600102 $(RM) tests/parse.txt tests/parse_results.txt
103 $(RM) tests/print.txt tests/print_results.txt
Gavin Howard56eeb5a2018-09-01 22:53:47 -0600104 $(RM) tests/bessel.txt tests/bessel_results.txt
Gavin Howardb33afd02018-08-28 17:08:20 -0600105
106install: $(BC_EXEC)
107 $(INSTALL) -Dm 755 $(BC_EXEC) $(DESTDIR)$(PREFIX)/bin/$(BC_EXEC)
108
109uninstall:
110 rm -rf $(DESTDIR)$(PREFIX)/bin/$(BC_EXEC)
111
Gavin Howard196b2212018-09-01 16:53:49 -0600112.PHONY: all help clean clean_tests install uninstall test