Gordons Projects

--> Projects Top-Level GIT

Makefiles: Do not override PREFIX or DESTDIR from the environment
[wiringPi] / devLib / Makefile
1 #
2 # Makefile:
3 #       wiringPi device - Wiring Compatable library for the Raspberry Pi
4 #
5 #       Copyright (c) 2012-2015 Gordon Henderson
6 #################################################################################
7 # This file is part of wiringPi:
8 #       https://projects.drogon.net/raspberry-pi/wiringpi/
9 #
10 #    wiringPi is free software: you can redistribute it and/or modify
11 #    it under the terms of the GNU Lesser General Public License as published by
12 #    the Free Software Foundation, either version 3 of the License, or
13 #    (at your option) any later version.
14 #
15 #    wiringPi is distributed in the hope that it will be useful,
16 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
17 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 #    GNU Lesser General Public License for more details.
19 #
20 #    You should have received a copy of the GNU Lesser General Public License
21 #    along with wiringPi.  If not, see <http://www.gnu.org/licenses/>.
22 #################################################################################
23
24 VERSION=$(shell cat ../VERSION)
25 DESTDIR?=/usr
26 PREFIX?=/local
27
28 ifneq ($V,1)
29 Q ?= @
30 endif
31
32 STATIC=libwiringPiDev.a
33 DYNAMIC=libwiringPiDev.so.$(VERSION)
34
35 #DEBUG  = -g -O0
36 DEBUG   = -O2
37 CC      = gcc
38 INCLUDE = -I.
39 DEFS    = -D_GNU_SOURCE
40 CFLAGS  = $(DEBUG) $(DEFS) -Wformat=2 -Wall -Winline $(INCLUDE) -pipe -fPIC
41
42 LIBS    =
43
44 ###############################################################################
45
46 SRC     =       ds1302.c maxdetect.c  piNes.c           \
47                 gertboard.c piFace.c                    \
48                 lcd128x64.c lcd.c                       \
49                 piGlow.c
50
51 OBJ     =       $(SRC:.c=.o)
52
53 HEADERS =       ds1302.h gertboard.h  lcd128x64.h  lcd.h  maxdetect.h piFace.h  piGlow.h  piNes.h
54
55 all:            $(DYNAMIC)
56
57 static:         $(STATIC)
58
59 $(STATIC):      $(OBJ)
60         $Q echo "[Link (Static)]"
61         $Q ar rcs $(STATIC) $(OBJ)
62         $Q ranlib $(STATIC)
63 #       @size   $(STATIC)
64
65 $(DYNAMIC):     $(OBJ)
66         $Q echo "[Link (Dynamic)]"
67         $Q $(CC) -shared -Wl,-soname,libwiringPiDev.so -o libwiringPiDev.so.$(VERSION) -lpthread $(OBJ)
68
69 .c.o:
70         $Q echo [Compile] $<
71         $Q $(CC) -c $(CFLAGS) $< -o $@
72
73 .PHONY: clean
74 clean:
75         $Q echo "[Clean]"
76         $Q rm -f $(OBJ) $(OBJ_I2C) *~ core tags Makefile.bak libwiringPiDev.*
77
78 .PHONY: tags
79 tags:   $(SRC)
80         $Q echo [ctags]
81         $Q ctags $(SRC)
82
83
84 .PHONY: install
85 install:        $(DYNAMIC)
86         $Q echo "[Install Headers]"
87         $Q install -m 0755 -d                                           $(DESTDIR)$(PREFIX)/include
88         $Q install -m 0644 $(HEADERS)                                   $(DESTDIR)$(PREFIX)/include
89         $Q echo "[Install Dynamic Lib]"
90         $Q install -m 0755 -d                                           $(DESTDIR)$(PREFIX)/lib
91         $Q install -m 0755 libwiringPiDev.so.$(VERSION)                 $(DESTDIR)$(PREFIX)/lib/libwiringPiDev.so.$(VERSION)
92         $Q ln -sf $(DESTDIR)$(PREFIX)/lib/libwiringPiDev.so.$(VERSION)  $(DESTDIR)/lib/libwiringPiDev.so
93         $Q ldconfig
94
95 .PHONY: install-static
96 install-static: $(STATIC)
97         $Q echo "[Install Headers]"
98         $Q install -m 0755 -d                                           $(DESTDIR)$(PREFIX)/include
99         $Q install -m 0644 $(HEADERS)                                   $(DESTDIR)$(PREFIX)/include
100         $Q echo "[Install Static Lib]"
101         $Q install -m 0755 -d                                           $(DESTDIR)$(PREFIX)/lib
102         $Q install -m 0755 libwiringPiDev.a                             $(DESTDIR)$(PREFIX)/lib
103
104 .PHONY: install-deb
105 install-deb:    $(DYNAMIC)
106         $Q echo "[Install Headers: deb]"
107         $Q install -m 0755 -d                                                   ~/wiringPi/debian-template/wiringPi/usr/include
108         $Q install -m 0644 $(HEADERS)                                           ~/wiringPi/debian-template/wiringPi/usr/include
109         $Q echo "[Install Dynamic Lib: deb]"
110         install -m 0755 -d                                                      ~/wiringPi/debian-template/wiringPi/usr/lib
111         install -m 0755 libwiringPiDev.so.$(VERSION)                            ~/wiringPi/debian-template/wiringPi/usr/lib/libwiringPiDev.so.$(VERSION)
112         ln -sf ~/wiringPi/debian-template/wiringPi/usr/lib/libwiringPiDev.so.$(VERSION) ~/wiringPi/debian-template/wiringPi/usr/lib/libwiringPiDev.so
113
114 .PHONY: uninstall
115 uninstall:
116         $Q echo "[UnInstall]"
117         $Q cd $(DESTDIR)$(PREFIX)/include/ && rm -f $(HEADERS)
118         $Q cd $(DESTDIR)$(PREFIX)/lib/     && rm -f libwiringPiDev.*
119         $Q ldconfig
120
121
122 .PHONY: depend
123 depend:
124         makedepend -Y $(SRC)
125
126 # DO NOT DELETE
127
128 ds1302.o: ds1302.h
129 maxdetect.o: maxdetect.h
130 piNes.o: piNes.h
131 gertboard.o: gertboard.h
132 piFace.o: piFace.h
133 lcd128x64.o: font.h lcd128x64.h
134 lcd.o: lcd.h
135 piGlow.o: piGlow.h