-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathmakefile
223 lines (174 loc) · 6.65 KB
/
makefile
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# main compiler
CC := gcc
# CC := clang --analyze # and comment out the linker last line for sanity
# define the directories
SRCDIR := src
INCDIR := include
BUILDDIR := build
BINDIR := bin
LIBDIR := lib
# define common variables
SRCEXT := c
SOURCES := $(shell find $(SRCDIR) -maxdepth 1 -type f \( -iname "*.$(SRCEXT)" ! -iname "*main-*.$(SRCEXT)" \) )
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
CFLAGS := -g -fPIC # -Wall
INC := $(shell find $(INCDIR) -maxdepth 1 -type d -exec echo -I {} \;)
PYLIBDIR := lib/python$(PYTHON_VERSION)
PYINC := "-I/usr/include/python$(PYTHON_VERSION)"
INC += $(PYINC)
# define specific binaries to create
# C libraries
LIBD := liboniondebug
SOURCE_LIBD := src/lib/onion-debug.$(SRCEXT)
OBJECT_LIBD := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCE_LIBD:.$(SRCEXT)=.o))
TARGET_LIBD := $(LIBDIR)/$(LIBD).so
LIB0 := libonioni2c
SOURCE_LIB0 := src/lib/onion-i2c.$(SRCEXT)
OBJECT_LIB0 := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCE_LIB0:.$(SRCEXT)=.o))
TARGET_LIB0 := $(LIBDIR)/$(LIB0).so
LIB_LIB0 := -L$(LIBDIR) -loniondebug
LIB1 := libonionmcp23008
SOURCE_LIB1 := src/lib/onion-mcp23008-driver.$(SRCEXT)
OBJECT_LIB1 := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCE_LIB1:.$(SRCEXT)=.o))
TARGET_LIB1 := $(LIBDIR)/$(LIB1).so
LIB_LIB1 := -L$(LIBDIR) -loniondebug -lonioni2c
LIB2 := libonionpwmexp
SOURCE_LIB2 := src/pwm-exp.$(SRCEXT)
OBJECT_LIB2 := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCE_LIB2:.$(SRCEXT)=.o))
TARGET_LIB2 := $(LIBDIR)/$(LIB2).so
LIB_LIB2 := -L$(LIBDIR) -loniondebug -lonioni2c
LIB3 := libonionrelayexp
SOURCE_LIB3 := src/relay-exp.$(SRCEXT)
OBJECT_LIB3 := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCE_LIB3:.$(SRCEXT)=.o))
TARGET_LIB3 := $(LIBDIR)/$(LIB3).so
LIB_LIB3 := -L$(LIBDIR) -loniondebug -lonioni2c -lonionmcp23008
LIB4 := libonionoledexp
SOURCE_LIB4 := src/oled-exp.$(SRCEXT)
OBJECT_LIB4 := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCE_LIB4:.$(SRCEXT)=.o))
TARGET_LIB4 := $(LIBDIR)/$(LIB4).so
LIB_LIB4 := -L$(LIBDIR) -loniondebug -lonioni2c
# C applications
APP0 := pwm-exp
SOURCE_APP0 := $(SRCDIR)/main-$(APP0).$(SRCEXT)
OBJECT_APP0 := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCE_APP0:.$(SRCEXT)=.o))
LIB_APP0 := -L$(LIBDIR) -loniondebug -lonioni2c -lonionpwmexp
TARGET_APP0 := $(BINDIR)/$(APP0)
APP1 := relay-exp
SOURCE_APP1 := $(SRCDIR)/main-$(APP1).$(SRCEXT)
OBJECT_APP1 := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCE_APP1:.$(SRCEXT)=.o))
LIB_APP1 := -L$(LIBDIR) -loniondebug -lonioni2c -lonionmcp23008 -lonionrelayexp
TARGET_APP1 := $(BINDIR)/$(APP1)
APP2 := oled-exp
SOURCE_APP2 := $(SRCDIR)/main-$(APP2).$(SRCEXT) $(SRCDIR)/$(APP2).$(SRCEXT)
OBJECT_APP2 := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCE_APP2:.$(SRCEXT)=.o))
LIB_APP2 := -L$(LIBDIR) -loniondebug -lonioni2c -lonionoledexp
TARGET_APP2 := $(BINDIR)/$(APP2)
# Python Modules
PYLIB00 := onionI2C
SOURCE_PYLIB00 := src/python/onion-i2c-module.$(SRCEXT)
OBJECT_PYLIB00 := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCE_PYLIB00:.$(SRCEXT)=.o))
TARGET_PYLIB00 := $(PYLIBDIR)/$(PYLIB00).so
LIB_PYLIB00 := -L$(LIBDIR) -loniondebug -lonioni2c -lpython$(PYTHON_VERSION)
PYLIB0 := pwmExp
SOURCE_PYLIB0 := src/python/pwm-exp-module.$(SRCEXT)
OBJECT_PYLIB0 := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCE_PYLIB0:.$(SRCEXT)=.o))
TARGET_PYLIB0 := $(PYLIBDIR)/$(PYLIB0).so
LIB_PYLIB0 := -L$(LIBDIR) -loniondebug -lonioni2c -lonionpwmexp -lpython$(PYTHON_VERSION)
PYLIB1 := relayExp
SOURCE_PYLIB1 := src/python/relay-exp-module.$(SRCEXT)
OBJECT_PYLIB1 := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCE_PYLIB1:.$(SRCEXT)=.o))
TARGET_PYLIB1 := $(PYLIBDIR)/$(PYLIB1).so
LIB_PYLIB1 := -L$(LIBDIR) -loniondebug -lonioni2c -lonionmcp23008 -lonionrelayexp -lpython$(PYTHON_VERSION)
PYLIB2 := oledExp
SOURCE_PYLIB2 := src/python/oled-exp-module.$(SRCEXT)
OBJECT_PYLIB2 := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCE_PYLIB2:.$(SRCEXT)=.o))
TARGET_PYLIB2 := $(PYLIBDIR)/$(PYLIB2).so
LIB_PYLIB2 := -L$(LIBDIR) -loniondebug -lonioni2c -lonionoledexp -lpython$(PYTHON_VERSION)
all: validate resp $(TARGET_LIBD) $(TARGET_LIB0) $(TARGET_LIB1) $(TARGET_LIB2) $(TARGET_LIB3) $(TARGET_LIB4) $(TARGET_APP0) $(TARGET_APP1) $(TARGET_APP2) $(TARGET_PYLIB00) $(TARGET_PYLIB0) $(TARGET_PYLIB1) $(TARGET_PYLIB2)
# libraries
$(TARGET_LIBD): $(OBJECT_LIBD)
@echo " Compiling $@"
@mkdir -p $(LIBDIR)
$(CC) -shared -o $@ $^ $(LIB_LIBD)
$(TARGET_LIB0): $(OBJECT_LIB0)
@echo " Compiling $@"
@mkdir -p $(LIBDIR)
$(CC) -shared -o $@ $^ $(LIB_LIB0)
$(TARGET_LIB1): $(OBJECT_LIB1)
@echo " Compiling $@"
@mkdir -p $(LIBDIR)
$(CC) -shared -o $@ $^ $(LIB_LIB1)
$(TARGET_LIB2): $(OBJECT_LIB2)
@echo " Compiling $@"
@mkdir -p $(LIBDIR)
$(CC) -shared -o $@ $^ $(LIB_LIB2)
$(TARGET_LIB3): $(OBJECT_LIB3)
@echo " Compiling $@"
@mkdir -p $(LIBDIR)
$(CC) -shared -o $@ $^ $(LIB_LIB3)
$(TARGET_LIB4): $(OBJECT_LIB4)
@echo " Compiling $@"
@mkdir -p $(LIBDIR)
$(CC) -shared -o $@ $^ $(LIB_LIB4)
# application binaries
$(TARGET_APP0): $(OBJECT_APP0)
@echo " Compiling $(APP0)"
@mkdir -p $(BINDIR)
@echo " Linking..."
$(CC) $^ $(CFLAGS) $(LDFLAGS) -o $(TARGET_APP0) $(LIB) $(LIB_APP0)
$(TARGET_APP1): $(OBJECT_APP1)
@echo " Compiling $(APP1)"
@mkdir -p $(BINDIR)
@echo " Linking..."
$(CC) $^ $(CFLAGS) $(LDFLAGS) -o $(TARGET_APP1) $(LIB) $(LIB_APP1)
$(TARGET_APP2): $(OBJECT_APP2)
@echo " Compiling $(APP2)"
@mkdir -p $(BINDIR)
@echo " Linking..."
$(CC) $^ $(CFLAGS) $(LDFLAGS) -o $(TARGET_APP2) $(LIB) $(LIB_APP2)
$(TARGET_PYLIB00): $(OBJECT_PYLIB00)
@echo " Compiling $@"
@mkdir -p $(PYLIBDIR)
$(CC) -shared -o $@ $^ $(LIB_PYLIB00)
$(TARGET_PYLIB0): $(OBJECT_PYLIB0)
@echo " Compiling $@"
@mkdir -p $(PYLIBDIR)
$(CC) -shared -o $@ $^ $(LIB_PYLIB0)
$(TARGET_PYLIB1): $(OBJECT_PYLIB1)
@echo " Compiling $@"
@mkdir -p $(PYLIBDIR)
$(CC) -shared -o $@ $^ $(LIB_PYLIB1)
$(TARGET_PYLIB2): $(OBJECT_PYLIB2)
@echo " Compiling $@"
@mkdir -p $(PYLIBDIR)
$(CC) -shared -o $@ $^ $(LIB_PYLIB2)
# generic: build any object file required
$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
@mkdir -p $(dir $@)
@echo " $(CC) $(CFLAGS) $(INC) -c -o $@ $<"; $(CC) $(CFLAGS) $(INC) -c -o $@ $<
clean:
@echo " Cleaning...";
$(RM) -r $(BUILDDIR) $(BINDIR) $(LIBDIR)
bla:
@echo "$(BLA)"
@echo "TARGET_APP0: $(APP0) $(SOURCE_APP0) $(OBJECT_APP0) $(TARGET_APP0)"
@echo "Sources: $(SOURCES)"
@echo "Objects: $(OBJECTS)"
resp:
@echo "CC: $(CC)"
@echo "CFLAGS: $(CFLAGS)"
@echo "LDFLAGS: $(LDFLAGS)"
@echo "LIB: $(LIB)"
validate:
ifeq ($(PYTHON_VERSION),)
$(error "PYTHON_VERSION variable is not set")
else
$(info "Using PYTHON_VERSION $(PYTHON_VERSION)")
endif
# Tests
tester:
$(CC) $(CFLAGS) test/tester.cpp $(INC) $(LIB) -o bin/tester
# Spikes
#ticket:
# $(CC) $(CFLAGS) spikes/ticket.cpp $(INC) $(LIB) -o bin/ticket
.PHONY: clean