Merge pull request #93 from HalosGhost/master
Dramatically update Makefile
This commit is contained in:
66
Makefile
66
Makefile
@@ -1,7 +1,10 @@
|
|||||||
|
PROJ = mpc
|
||||||
CC = gcc
|
CC ?= gcc
|
||||||
STND=-ansi
|
STND = -ansi
|
||||||
CFLAGS = $(STND) -pedantic -O3 -g -Wall -Werror -Wextra -Wformat=2 -Wshadow \
|
DIST = build
|
||||||
|
MKDIR ?= mkdir -p
|
||||||
|
PREFIX ?= /usr/local
|
||||||
|
CFLAGS ?= $(STND) -pedantic -O3 -g -Wall -Werror -Wextra -Wformat=2 -Wshadow \
|
||||||
-Wno-long-long -Wno-overlength-strings -Wno-format-nonliteral -Wcast-align \
|
-Wno-long-long -Wno-overlength-strings -Wno-format-nonliteral -Wcast-align \
|
||||||
-Wwrite-strings -Wstrict-prototypes -Wold-style-definition -Wredundant-decls \
|
-Wwrite-strings -Wstrict-prototypes -Wold-style-definition -Wredundant-decls \
|
||||||
-Wnested-externs -Wmissing-include-dirs -Wswitch-default
|
-Wnested-externs -Wmissing-include-dirs -Wswitch-default
|
||||||
@@ -10,15 +13,54 @@ TESTS = $(wildcard tests/*.c)
|
|||||||
EXAMPLES = $(wildcard examples/*.c)
|
EXAMPLES = $(wildcard examples/*.c)
|
||||||
EXAMPLESEXE = $(EXAMPLES:.c=)
|
EXAMPLESEXE = $(EXAMPLES:.c=)
|
||||||
|
|
||||||
all: $(EXAMPLESEXE) check
|
.PHONY: all check clean libs
|
||||||
|
|
||||||
check: $(TESTS) mpc.c
|
all: $(EXAMPLESEXE) check
|
||||||
$(CC) $(filter-out -Werror, $(CFLAGS)) $^ -lm -o test
|
|
||||||
./test
|
|
||||||
|
|
||||||
examples/%: examples/%.c mpc.c
|
$(DIST):
|
||||||
$(CC) $(CFLAGS) $^ -lm -o $@
|
$(MKDIR) $(DIST)/examples
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
test-static: $(DIST) $(TESTS) lib$(PROJ).a
|
||||||
|
$(CC) $(filter-out -Werror, $(CFLAGS)) $(TESTS) -lm -L$(DIST) -l$(PROJ) -static -o $(DIST)/test-static
|
||||||
|
|
||||||
|
examples/%: $(DIST) examples/%.c $(PROJ).c
|
||||||
|
$(CC) $(CFLAGS) $(filter-out $(DIST), $^) -lm -o $(DIST)/$@
|
||||||
|
|
||||||
|
lib$(PROJ).so: $(DIST) $(PROJ).c
|
||||||
|
ifneq ($(OS),Windows_NT)
|
||||||
|
$(CC) $(CFLAGS) -fPIC -shared $(PROJ).c -o $(DIST)/lib$(PROJ).so
|
||||||
|
else
|
||||||
|
$(CC) $(CFLAGS) -shared $(PROJ).c -o $(DIST)/lib$(PROJ).so
|
||||||
|
endif
|
||||||
|
|
||||||
|
lib$(PROJ).a: $(DIST) $(PROJ).c
|
||||||
|
$(CC) $(CFLAGS) -c $(PROJ).c -o $(DIST)/$(PROJ).o
|
||||||
|
$(AR) rcs $(DIST)/lib$(PROJ).a $(DIST)/$(PROJ).o
|
||||||
|
|
||||||
|
libs: lib$(PROJ).so lib$(PROJ).a
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf test examples/doge examples/lispy examples/maths examples/smallc \
|
rm -rf -- $(DIST)
|
||||||
examples/foobar examples/tree_traversal
|
|
||||||
|
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}
|
||||||
|
Reference in New Issue
Block a user