-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile.in
149 lines (121 loc) · 4.91 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Inter-Integrated Circuit (I2C) Library for the Raspberry Pi
#
# Copyright (c) 2021 Benjamin Spencer
# ============================================================================
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
# =============================================================================
# Compiler:
CC := gcc
# Versioning:
CUR := 0
REV := 0
AGE := 0
# Target shared library soname:
TARGET := libpii2c.so
# Header file
HEADER := pi_i2c.h
# Root directories:
ROOT := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
# Directories:
SRCDIR := $(ROOT)/src
INCDIR := $(ROOT)/include
BUILDDIR := $(ROOT)/obj
TARGETDIR := $(ROOT)/bin
LIBDESTDIR := $(PREFIX)/lib
INCDESTDIR := $(PREFIX)/include
SRCSUBDIR := $(shell find $(SRCDIR) -type d)
# Extensions:
SRCEXT := c
DEPEXT := d
OBJEXT := o
# Flags, Libraries and Includes:
CFLAGS := -fPIC -Wall -Wextra -O2 $(DEBUG_SYM) # C flags
LDFLAGS := -shared
LIB :=
INC := -I$(INCDIR) $(addprefix -I,$(SRCSUBDIR))
INCDEP := -I$(INCDIR) $(addprefix -I,$(SRCSUBDIR))
MACRO := $(DEBUG_LOG)
# Find source and object files:
SOURCES := $(shell find $(SRCDIR) -type f -name "*.$(SRCEXT)")
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,\
$(SOURCES:.$(SRCEXT)=.$(OBJEXT)))
# -------------------------------------------------------------------------- #
# Rules (DO NOT EDIT)
# -------------------------------------------------------------------------- #
# Default make:
all: $(TARGET).$(CUR).$(REV).$(AGE)
# Remake:
remake: clean all
# Make the directories
directories:
@mkdir -p $(TARGETDIR)
@mkdir -p $(BUILDDIR)
# Clean target and object files:
clean:
@rm -rf $(BUILDDIR)/* $(TARGETDIR)/*
# Pull in dependency info for *existing* .o files:
-include $(OBJECTS:.$(OBJEXT)=.$(DEPEXT))
# Link:
$(TARGET).$(CUR).$(REV).$(AGE): $(OBJECTS)
@mkdir -p $(TARGETDIR)
$(CC) -o $(TARGETDIR)/$(TARGET).$(CUR).$(REV).$(AGE) $^ $(LIB) $(CFLAGS) $(LDFLAGS)
# Compile:
$(BUILDDIR)/%.$(OBJEXT): $(SRCDIR)/%.$(SRCEXT)
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(INC) -Wall $(MACRO) -c -o $@ $<
@$(CC) $(CFLAGS) $(INCDEP) -MM $(SRCDIR)/$*.$(SRCEXT) > \
$(BUILDDIR)/$*.$(DEPEXT)
@cp -f $(BUILDDIR)/$*.$(DEPEXT) $(BUILDDIR)/$*.$(DEPEXT).tmp
@sed -e 's|.*:|$(BUILDDIR)/$*.$(OBJEXT):|' \
< $(BUILDDIR)/$*.$(DEPEXT).tmp > $(BUILDDIR)/$*.$(DEPEXT)
@sed -e 's/.*://' -e 's/\\$$//' < $(BUILDDIR)/$*.$(DEPEXT).tmp \
| fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $(BUILDDIR)/$*.$(DEPEXT)
@rm -f $(BUILDDIR)/$*.$(DEPEXT).tmp
# Install libary and header file:
install:
@echo "Installing library to $(LIBDESTDIR)"
@echo "cp $(TARGETDIR)/$(TARGET).$(CUR).$(REV).$(AGE) $(LIBDESTDIR)/$(TARGET).$(CUR).$(REV).$(AGE)"
@cp $(TARGETDIR)/$(TARGET).$(CUR).$(REV).$(AGE) $(LIBDESTDIR)/$(TARGET).$(CUR).$(REV).$(AGE)
@echo "Creating symbolic link $(TARGET)"
@echo "ln -sf $(LIBDESTDIR)/$(TARGET).$(CUR).$(REV).$(AGE) $(LIBDESTDIR)/$(TARGET)"
@ln -sf $(LIBDESTDIR)/$(TARGET).$(CUR).$(REV).$(AGE) $(LIBDESTDIR)/$(TARGET)
@echo "Configuring dynamic linker run-time bindings"
@echo "ldconfig -v -n $(LIBDESTDIR)/"
@ldconfig -v -n $(LIBDESTDIR)/
@ldconfig
@echo "Copying header file to $(INCDESTDIR)"
@echo "cp $(INCDIR)/$(HEADER) $(INCDESTDIR)/$(HEADER)"
@cp $(INCDIR)/$(HEADER) $(INCDESTDIR)/$(HEADER)
@echo "Installing Python library"
@echo "pip3 install python/"
@pip3 install python/
# Uninstall libary and header file:
uninstall:
@echo "Removing installed library at $(LIBDESTDIR)"
@echo "Removing installed header files at $(INCDESTDIR)"
@echo "rm -rf $(LIBDESTDIR)/$(TARGET).$(CUR).$(REV).$(AGE) $(LIBDESTDIR)/$(TARGET) $(INCDESTDIR)/$(HEADER)"
@rm -rf $(LIBDESTDIR)/$(TARGET).$(CUR).$(REV).$(AGE) $(LIBDESTDIR)/$(TARGET) $(INCDESTDIR)/$(HEADER)
@echo "Configuring dynamic linker run-time bindings"
@echo "ldconfig -n $(LIBDESTDIR)"
@ldconfig -n $(LIBDESTDIR)
@echo "Uninstalling Python library"
@echo "pip3 uninstall pi_i2c"
@pip3 uninstall -y pi_i2c
# Non-file targets:
.PHONY: all remake clean install uninstall