aboutsummaryrefslogtreecommitdiffstats
path: root/Make.rules
blob: 3410d7b0ddc43a2348455bee7b2046f5af28f66d (plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# build rules for linuxtv.org dvb-apps

CFLAGS ?= -g -Wall -W -Wshadow -Wpointer-arith -Wstrict-prototypes

ifneq ($(lib_name),)

# additional rules for libraries

CFLAGS_LIB ?= -fPIC
CFLAGS += $(CFLAGS_LIB)

libraries = $(lib_name).so $(lib_name).a

.PHONY: library

library: $(libraries)

$(libraries): $(objects)

endif

prerequisites = $(subst .o,.d,$(objects)) $(addsuffix .d,$(binaries))

.PHONY: clean install

ifeq ($(static),1)
LDFLAGS += -static
endif

prefix ?= /usr

bindir     ?= $(prefix)/bin
includedir ?= $(prefix)/include
libdir     ?= $(prefix)/lib
sharedir   ?= $(prefix)/share

ifneq ($(DESTDIR),)
DESTDIR := $(DESTDIR)/
endif

ifeq ($(V),1)
%.o: %.c
	$(CC) -c $(CPPFLAGS) $(CFLAGS) -MMD -o $@ $< $(filter-out %.h %.c,$^)
%: %.o
	$(CC) $(LDFLAGS) -o $@ $^ $(LOADLIBES) $(LDLIBS)
%: %.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -MMD $(LDFLAGS) -o $@ $< $(filter-out %.h %.c,$^) $(LOADLIBES) $(LDLIBS)
%.so:
	$(CC) -shared -o $@ $^
%.a:
	$(AR) rcs $@ $^
clean::
	$(RM) -f $(prerequisites) $(objects) $(libraries) $(binaries) $(removing) *~
install::
ifneq ($(includes),)
	mkdir -p $(DESTDIR)$(includedir)/$(lib_name)
	install -m 644 $(includes) $(DESTDIR)$(includedir)/$(lib_name)/
endif
ifneq ($(libraries),)
	mkdir -p $(DESTDIR)$(libdir)
	install -m 644 $(libraries) $(DESTDIR)$(libdir)/
endif
ifneq ($(inst_bin),)
	mkdir -p $(DESTDIR)$(bindir)
	install -m 755 $(inst_bin) $(DESTDIR)$(bindir)/
endif
else
%.o: %.c
	@echo CC $@
	@$(CC) -c $(CPPFLAGS) $(CFLAGS) -MMD -o $@ $< $(filter-out %.h %.c,$^)
%: %.o
	@echo CC $@
	@$(CC) $(LDFLAGS) -o $@ $^ $(LOADLIBES) $(LDLIBS)
%: %.c
	@echo CC $@
	@$(CC) $(CPPFLAGS) $(CFLAGS) -MMD $(LDFLAGS) -o $@ $< $(filter-out %.h %.c,$^) $(LOADLIBES) $(LDLIBS)
%.so:
	@echo CC $@
	@$(CC) -shared -o $@ $^
%.a:
	@echo AR $@
	@$(AR) rcs $@ $^
clean::
	@echo cleaning
	@$(RM) -f $(prerequisites) $(objects) $(libraries) $(binaries) $(removing) *~
install::
ifneq ($(includes),)
	@echo installing headers
	@mkdir -p $(DESTDIR)$(includedir)/$(lib_name)
	@install -m 644 $(includes) $(DESTDIR)$(includedir)/$(lib_name)/
endif
ifneq ($(libraries),)
	@echo installing libraries
	@mkdir -p $(DESTDIR)$(libdir)
	@install -m 644 $(libraries) $(DESTDIR)$(libdir)/
endif
ifneq ($(inst_bin),)
	@echo installing binaries
	@mkdir -p $(DESTDIR)$(bindir)
	@install -m 755 $(inst_bin) $(DESTDIR)$(bindir)/
endif
endif

-include $(prerequisites)