2018-11-09 11:19:49 -06:00
|
|
|
PROJ = mpc
|
|
|
|
CC ?= gcc
|
|
|
|
STND = -ansi
|
|
|
|
DIST = build
|
2019-05-23 21:23:05 -05:00
|
|
|
MKDIR ?= mkdir -p
|
2018-11-09 11:19:49 -06:00
|
|
|
PREFIX ?= /usr/local
|
|
|
|
CFLAGS ?= $(STND) -pedantic -O3 -g -Wall -Werror -Wextra -Wformat=2 -Wshadow \
|
2015-03-10 10:44:29 +00:00
|
|
|
-Wno-long-long -Wno-overlength-strings -Wno-format-nonliteral -Wcast-align \
|
|
|
|
-Wwrite-strings -Wstrict-prototypes -Wold-style-definition -Wredundant-decls \
|
|
|
|
-Wnested-externs -Wmissing-include-dirs -Wswitch-default
|
2014-10-14 23:16:11 -07:00
|
|
|
|
2013-09-19 20:57:40 +01:00
|
|
|
TESTS = $(wildcard tests/*.c)
|
2014-01-26 11:25:50 +00:00
|
|
|
EXAMPLES = $(wildcard examples/*.c)
|
|
|
|
EXAMPLESEXE = $(EXAMPLES:.c=)
|
2013-09-19 20:57:40 +01:00
|
|
|
|
2018-11-09 11:19:49 -06:00
|
|
|
.PHONY: all check clean libs
|
|
|
|
|
|
|
|
all: $(EXAMPLESEXE) check
|
|
|
|
|
|
|
|
$(DIST):
|
2019-05-23 21:23:05 -05:00
|
|
|
$(MKDIR) $(DIST)/examples
|
2018-11-09 11:19:49 -06:00
|
|
|
|
|
|
|
check: test-file test-static test-dynamic
|
|
|
|
./$(DIST)/test-file
|
|
|
|
./$(DIST)/test-static
|
|
|
|
LD_LIBRARY_PATH=$(DIST) ./$(DIST)/test-dynamic
|
|
|
|
|
|
|
|
test-file: $(DIST) $(TESTS) $(PROJ).c
|
|
|
|
$(CC) $(filter-out -Werror, $(CFLAGS)) $(TESTS) $(PROJ).c -lm -o $(DIST)/test-file
|
|
|
|
|
|
|
|
test-dynamic: $(DIST) $(TESTS) lib$(PROJ).so
|
|
|
|
$(CC) $(filter-out -Werror, $(CFLAGS)) $(TESTS) -lm -L$(DIST) -l$(PROJ) -o $(DIST)/test-dynamic
|
2014-10-14 22:33:21 -07:00
|
|
|
|
2018-11-09 11:19:49 -06:00
|
|
|
test-static: $(DIST) $(TESTS) lib$(PROJ).a
|
|
|
|
$(CC) $(filter-out -Werror, $(CFLAGS)) $(TESTS) -lm -L$(DIST) -l$(PROJ) -static -o $(DIST)/test-static
|
2014-10-14 22:33:21 -07:00
|
|
|
|
2018-11-09 11:19:49 -06:00
|
|
|
examples/%: $(DIST) examples/%.c $(PROJ).c
|
|
|
|
$(CC) $(CFLAGS) $(filter-out $(DIST), $^) -lm -o $(DIST)/$@
|
|
|
|
|
|
|
|
lib$(PROJ).so: $(DIST) $(PROJ).c
|
2019-05-29 19:39:33 -05:00
|
|
|
ifneq ($(OS),Windows_NT)
|
2018-11-09 11:19:49 -06:00
|
|
|
$(CC) $(CFLAGS) -fPIC -shared $(PROJ).c -o $(DIST)/lib$(PROJ).so
|
2019-05-29 19:39:33 -05:00
|
|
|
else
|
|
|
|
$(CC) $(CFLAGS) -shared $(PROJ).c -o $(DIST)/lib$(PROJ).so
|
|
|
|
endif
|
2018-11-09 11:19:49 -06:00
|
|
|
|
|
|
|
lib$(PROJ).a: $(DIST) $(PROJ).c
|
|
|
|
$(CC) $(CFLAGS) -c $(PROJ).c -o $(DIST)/$(PROJ).o
|
2019-05-23 21:23:05 -05:00
|
|
|
$(AR) rcs $(DIST)/lib$(PROJ).a $(DIST)/$(PROJ).o
|
2018-11-09 11:19:49 -06:00
|
|
|
|
|
|
|
libs: lib$(PROJ).so lib$(PROJ).a
|
2014-01-26 11:25:50 +00:00
|
|
|
|
2013-09-19 20:57:40 +01:00
|
|
|
clean:
|
2018-11-09 11:19:49 -06:00
|
|
|
rm -rf -- $(DIST)
|
|
|
|
|
|
|
|
install: all
|
|
|
|
install -d -m644 $(DESTDIR)$(PREFIX)/{include,lib,share/$(PROJ)}
|
|
|
|
install -m755 -t $(DESTDIR)$(PREFIX)/lib $(DIST)/lib*
|
|
|
|
install -m644 -t $(DESTDIR)$(PREFIX)/share/$(PROJ) $(PROJ).{c,h}
|
|
|
|
install -m644 $(PROJ).h $(DESTDIR)$(PREFIX)/include/$(PROJ).h
|
|
|
|
|
|
|
|
uninstall:
|
|
|
|
rm -rf -- \
|
|
|
|
$(DESTDIR)$(PREFIX)/include/$(PROJ).h \
|
|
|
|
$(DESTDIR)$(PREFIX)/share/$(PROJ)/$(PROJ).{c,h} \
|
|
|
|
$(DESTDIR)$(PREFIX)/lib/lib$(PROJ).{so,a}
|