-
Notifications
You must be signed in to change notification settings - Fork 70
/
Makefile.drv
193 lines (172 loc) · 7.03 KB
/
Makefile.drv
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
#---------------------------------------------------------------------
#
# Copyright (c) 2018 CloudMakers, s. r. o.
# All rights reserved.
#
# You can use this software under the terms of 'INDIGO Astronomy
# open-source license' (see LICENSE.md).
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHORS 'AS IS' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#---------------------------------------------------------------------
# This file is supposed to be called from within indigo_XXX_drivers/YYY folder if Makefile is not present.
include ../../Makefile.inc
ifneq ($(wildcard Makefile.inc),)
include Makefile.inc
endif
ifeq ($(OS_DETECTED),Darwin)
FORCE_ALL_ON=-Wl,-force_load
FORCE_ALL_OFF=
endif
ifeq ($(OS_DETECTED),Linux)
FORCE_ALL_ON=-Wl,--whole-archive
FORCE_ALL_OFF=-Wl,--no-whole-archive
endif
DRIVER = indigo_$(notdir $(shell pwd))
rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
SOURCES = $(wildcard *.c) $(wildcard *.cpp) $(wildcard *.m) $(ADDITIONAL_SOURCES)
DRIVER_A = $(BUILD_DRIVERS)/$(DRIVER).a
DRIVER_SO = $(BUILD_DRIVERS)/$(DRIVER).$(SOEXT)
ifeq ($(wildcard $(DRIVER)_main.c),)
ifneq ($(wildcard $(DRIVER)_main.cpp),)
DRIVER_EXECUTABLE = $(BUILD_DRIVERS)/$(DRIVER)
DRIVER_MAIN_O = $(DRIVER)_main.o
else
DRIVER_EXECUTABLE =
DRIVER_MAIN_O =
endif
else
DRIVER_EXECUTABLE = $(BUILD_DRIVERS)/$(DRIVER)
DRIVER_MAIN_O = $(DRIVER)_main.o
endif
DRIVER_O = $(filter-out $(DRIVER_MAIN_O),$(addsuffix .o, $(basename $(notdir $(wildcard *.c) $(wildcard *.cpp) $(wildcard *.m))))) $(addsuffix .o, $(basename $(ADDITIONAL_SOURCES)))
RULES = $(strip $(call rwildcard,,*.rules))
XML = $(notdir $(wildcard indi_go_*.xml))
SDK_INCLUDE ?= $(addprefix -I, $(wildcard bin_externals/*/include))
ifeq ($(OS_DETECTED),Darwin)
SDK_LIB_A ?= $(wildcard bin_externals/*/lib/macOS/*.a)
SDK_LIB_SO ?= $(wildcard bin_externals/*/lib/macOS/*.dylib)
endif
ifeq ($(OS_DETECTED),Linux)
SDK_LIB_A ?= $(wildcard bin_externals/*/lib/Linux/$(ARCH_DETECTED)/*.a)
SDK_LIB_SO ?= $(wildcard bin_externals/*/lib/Linux/$(ARCH_DETECTED)/*.so)
endif
SDK_LIB ?= $(addprefix -L, $(dir $(SDK_LIB_A))) $(addprefix -l, $(subst lib, , $(basename $(notdir $(SDK_LIB_A) $(SDK_LIB_SO)))))
FIRMWARE ?= $(strip $(wildcard bin_externals/*/firmware/*) $(wildcard *.hex))
FIRMWARE_TARGET ?= $(INSTALL_FIRMWARE)
CFLAGS += $(SDK_INCLUDE)
CXXFLAGS += $(SDK_INCLUDE)
FLAGS += $(SDK_INCLUDE)
.PHONY: all status install uninstall make_sdk
ifeq ($(notdir $(SOURCES)),)
all: status
@printf "No sources for $(DRIVER) \n\n"
else
all: status $(MAKE_SDK) $(DRIVER_A) $(DRIVER_SO) $(DRIVER_EXECUTABLE)
endif
status:
@printf "Sources: $(notdir $(SOURCES))\n"
@printf "Archive: $(notdir $(DRIVER_A))\n"
@printf "SO library: $(notdir $(DRIVER_SO))\n"
@printf "$(DRIVER_O)\n"
ifneq ($(DRIVER_EXECUTABLE),)
@printf "Executable: $(notdir $(DRIVER_EXECUTABLE))\n"
endif
ifneq ($(RULES),)
@printf "Rules: $(notdir $(RULES))\n"
endif
ifneq ($(XML),)
@printf "XML: $(notdir $(XML))\n"
endif
ifneq ($(FIRMWARE),)
@printf "FIRMWARE: $(notdir $(FIRMWARE))\n"
endif
ifneq ($(strip $(SDK_LIB_A) $(SDK_LIB_SO) $(SDK_INCLUDE)),)
@printf "SDK: $(strip $(SDK_LIB_A) $(SDK_LIB_SO) $(SDK_INCLUDE) $(SDK_LIB))\n"
endif
@printf "\n"
$(DRIVER_A): $(DRIVER_O)
$(AR) $(ARFLAGS) $@ $^
ifneq ($(SDK_LIB_SO),)
install -m 0644 $(SDK_LIB_SO) $(BUILD_LIB)
ifeq ($(OS_DETECTED),Darwin)
install_name_tool -id $(BUILD_LIB)/$(notdir $(SDK_LIB_SO)) $(BUILD_LIB)/$(notdir $(SDK_LIB_SO))
$(FIX_SDK_LIB_DYLIB)
endif
ifeq ($(OS_DETECTED),Linux)
$(FIX_SDK_LIB_SO)
endif
endif
$(DRIVER_SO): $(DRIVER_A)
$(CC) -shared -o $@ $(FORCE_ALL_ON) $(DRIVER_A) $(FORCE_ALL_OFF) $(SDK_LIB) -lindigo $(LDFLAGS) -lusb-1.0
$(DRIVER_EXECUTABLE): $(DRIVER_MAIN_O) $(DRIVER_A)
$(CC) -o $@ $^ $(SDK_LIB) -lindigo $(LDFLAGS) -lusb-1.0
install: status $(INSTALL_SDK)
install -m 0644 $(DRIVER_SO) $(INSTALL_LIB)
ifneq ($(DRIVER_EXECUTABLE),)
install -m 0755 $(DRIVER_EXECUTABLE) $(INSTALL_BIN)
endif
ifneq ($(SDK_LIB_SO),)
install -m 0644 $(addsuffix *$(SOEXT), $(basename $(SDK_LIB_SO))) $(INSTALL_LIB)
endif
ifneq ($(RULES),)
install -m 0644 $(RULES) $(INSTALL_RULES)/99-$(DRIVER).rules
endif
ifneq ($(XML),)
install -m 0644 $(XML) $(INSTALL_SHARE)/indi/indi_go_$(subst indigo_,,$(DRIVER)).xml
endif
ifneq ($(FIRMWARE),)
install -d $(FIRMWARE_TARGET)
install -m 0644 $(FIRMWARE) $(FIRMWARE_TARGET)
endif
uninstall: status
rm -f $(INSTALL_LIB)/$(DRIVER).$(SOEXT) $(INSTALL_BIN)/$(DRIVER) $(INSTALL_RULES)/99-$(DRIVER).rules $(INSTALL_SHARE)/indi/indi_go_$(subst indigo_,,$(DRIVER)).xml $(addprefix $(FIRMWARE_TARGET)/, $(notdir $(FIRMWARE)))
ifneq ($(SDK_LIB_SO),)
rm -f $(addprefix $(INSTALL_LIB)/, $(notdir $(addsuffix *.$(SOEXT), $(basename $(SDK_LIB_SO)))))
endif
clean: status
rm -f $(DRIVER_O) $(DRIVER_MAIN_O) $(DRIVER_A) $(DRIVER_SO) $(DRIVER_EXECUTABLE)
ifneq ($(wildcard $(SDK_DIR)/Makefile),)
make -C $(SDK_DIR) clean
ifneq ($(SDK_LIB_A),)
rm -f $(SDK_LIB_A)
endif
ifneq ($(SDK_LIB_SO),)
rm -f $(addsuffix *.$(SOEXT), $(basename $(SDK_LIB_SO))) $(addsuffix .la, $(basename $(SDK_LIB_SO)))
endif
endif
ifneq ($(SDK_LIB_SO),)
rm -f $(addprefix $(BUILD_LIB)/, $(notdir $(addsuffix *.$(SOEXT), $(basename $(SDK_LIB_SO)))))
endif
clean-all: status
git clean -dfx
$(SDK_LIB_A): $(SDK_DIR)/Makefile
ifneq ($(wildcard $(SDK_CONFIGURE_IN)),)
export MACOSX_DEPLOYMENT_TARGET=10.10; export CFLAGS="$(CFLAGS)" export LDFLAGS="$(LDFLAGS)"; make -C $(SDK_DIR) install
else
export MACOSX_DEPLOYMENT_TARGET=10.10; export CFLAGS="$(CFLAGS)" export LDFLAGS="$(LDFLAGS)"; make -C $(SDK_DIR)
endif
$(SDK_LIB_SO): $(SDK_DIR)/Makefile
ifneq ($(wildcard $(SDK_CONFIGURE_IN)),)
export MACOSX_DEPLOYMENT_TARGET=10.10; export CFLAGS="$(CFLAGS)" export LDFLAGS="$(LDFLAGS)"; make -C $(SDK_DIR) install
else
export MACOSX_DEPLOYMENT_TARGET=10.10; export CFLAGS="$(CFLAGS)" export LDFLAGS="$(LDFLAGS)"; make -C $(SDK_DIR)
endif
$(SDK_DIR)/Makefile: $(SDK_CONFIGURE)
ifneq ($(SDK_LIB_A),)
export CC=$(CC); export CXX=$(CC); export CFLAGS="$(CFLAGS)"; export CXXFLAGS="$(CXXFLAGS)"; export LDFLAGS="$(LDFLAGS)"; cd $(SDK_DIR); ./configure --prefix=$(abspath $(SDK_DIR)/build) --enable-shared=no --enable-static=yes $(CONFIGURE_FLAGS)
else
export CC=$(CC); export CXX=$(CC); export CFLAGS="$(CFLAGS)"; export CXXFLAGS="$(CXXFLAGS)"; export LDFLAGS="$(LDFLAGS)"; cd $(SDK_DIR); ./configure --prefix=$(abspath $(SDK_DIR)/build) --enable-shared=yes --enable-static=no $(CONFIGURE_FLAGS)
endif
$(SDK_DIR)/configure: $(SDK_CONFIGURE_IN)
cd $(SDK_DIR); autoreconf -fiv