-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile.in
77 lines (60 loc) · 2.18 KB
/
Makefile.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# This is a pretty much general Makefile for libraries
SHELL := /bin/bash
CC = gcc
INCLUDE += -I.
CFLAGS += -std=c99 $(INCLUDE) -Wall -Wextra -O3 $(dbg) $(profile)
SED = sed
RANLIB = ranlib
obj = $(src:.c=.o)
dep = $(obj:.o=.d) # one dependency file for each source
LDFLAGS += $(profile)
ifeq ($(shared), true)
target := $(addsuffix .so,$(target_lib))
CFLAGS += -fPIC
else
target := $(addsuffix .a,$(target_lib))
strip_flags = --strip-unneeded
endif
all: $(target) $(pkg_conf_pc)
%.a: $(obj)
$(AR) rcs $@ $^
$(RANLIB) $@
%.so: $(obj)
$(CC) -shared -fPIC -o $@ $^ $(LIBS)
-include $(dep) # include all dep files in the makefile
# rule to generate a dep file by using the C preprocessor
# (see man cpp for details on the -MM and -MT options)
%.d: %.c
@$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@
%.pc: %.pc.in
@echo 'Building pkg-config file: $@'
@$(SED) \
-e 's|@PREFIX@|${PREFIX}|g' \
-e 's|@bindir@|${PREFIX}/bin|g' \
-e 's|@libdir@|${PREFIX}/lib|g' \
-e 's|@includedir@|${PREFIX}/include|g' \
-e 's|@PKG_CONFIG_RPATH@|${PKG_CONFIG_RPATH}|g' \
-e 's|@PROJECT_VERSION@|${PROJECT_VERSION}|g' \
-e 's|@LIBS@|${LIBS}|g' \
$< >$@
.PHONY: clean
clean: cleandep
@$(RM) $(obj) $(target) $(pkg_conf_pc) && echo 'Deleting object files and $(target)'
.PHONY: cleandep
cleandep:
@$(RM) $(dep) && echo 'Deleting dep. files'
.PHONY: install
install: $(target) $(header_files) $(pkg_conf_pc)
@mkdir -p $(DESTDIR)$(PREFIX)/lib
@mkdir -p $(DESTDIR)$(PREFIX)/include
@cp $(target) $(DESTDIR)$(PREFIX)/lib/$(target)
@echo 'Copying $(target)'
@strip $(strip_flags) $(DESTDIR)$(PREFIX)/lib/$(target)
@for h in $(header_files); do cp $$h $(DESTDIR)$(PREFIX)/include/ ; echo "Copying $$h"; done
@if (( $EUID == 0 )); then ldconfig; fi
@if [ -e $(pkg_conf_pc) ]; then mkdir -p $(DESTDIR)$(pkg_config_path); cp $(pkg_conf_pc) $(DESTDIR)$(pkg_config_path) && echo "Copying $(pkg_conf_pc) to $(pkg_config_path)"; fi
.PHONY: uninstall
uninstall:
@$(RM) $(DESTDIR)$(PREFIX)/lib/$(target) && echo 'Removing $(target)'
@for h in $(header_files); do $(RM) $(DESTDIR)$(PREFIX)/include/$$h ; echo "Removing $$h"; done
@$(RM) $(pkg_config_path)/$(pkg_conf_pc) && echo 'Removing $(pkg_conf_pc)'