forked from opencpi/opencpi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile.ocpi.for-pkg
234 lines (211 loc) · 8.93 KB
/
Makefile.ocpi.for-pkg
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
224
225
226
227
228
229
230
231
232
233
234
# This file is protected by Copyright. Please refer to the COPYRIGHT file
# distributed with this source distribution.
#
# This file is part of OpenCPI <http://www.opencpi.org>
#
# OpenCPI is free software: you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# OpenCPI is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
all: bin
include $(OCPI_BASE_DIR)/MakeVars.ocpi
ifneq ($(OCPI_OUT_DIR),)
OBJDIR = $(OCPI_OUT_DIR)
else
OBJDIR = .
endif
include $(OCPI_BASE_DIR)/Makefile.ocpi.common
ifndef IMPORTS_INCLUDED
ifneq ($(wildcard Makefile.ocpi.imports),)
include Makefile.ocpi.imports
IMPORTS_INCLUDED:=1
else ifneq ($(wildcard ../Makefile.ocpi.imports),)
include ../Makefile.ocpi.imports
IMPORTS_INCLUDED:=1
endif
endif
ifndef PACKAGE
export PACKAGE = $(shell pwd|sed 's-.*/\([^/]*$$\)-\1-')
endif
export PACKAGE
#$(info PACKAGE $(PACKAGE))
export UNIXLIB = $(OBJDIR)/libocpi_$(PACKAGE).a
export UNIXSHLIB = $(OBJDIR)/libocpi_$(PACKAGE).$(SO)
export UNIXSHLIB_S = $(OBJDIR)/libocpi_$(PACKAGE)_s.$(SO)
#export EXPORTSHLIB=$(OCPI_BASE_DIR)/lib/$(OCPI_OUT_DIR)/$(notdir $(UNIXSHLIB))
#export EXPORTSHLIB_S=$(OCPI_BASE_DIR)/lib/$(OCPI_OUT_DIR)/$(notdir $(UNIXSHLIB_S))
#export EXPORTLIB=$(OCPI_BASE_DIR)/lib/$(OCPI_OUT_DIR)/$(notdir $(UNIXLIB))
$(infox PACKAGE $(PACKAGE))
ifneq ($(filter linux macos,$(OCPI_TARGET_OS)),)
EXCLUDE_FACILITIES += winnt vxworksdkm
ifeq ($(OCPI_BUILD_SHARED_LIBRARIES),1)
PACKAGELIB = \
$(UNIXSHLIB) \
$(and $(filter 0,$(OCPI_PREVIOUS_DYNAMIC)),$(UNIXSHLIB_S))
else
PACKAGELIB = $(UNIXLIB)
endif
endif
GENERATED = $(filter-out $(EXCLUDE_FACILITIES),$(patsubst %/idl,%,$(wildcard */idl)))
FACILITIES = $(filter-out bin lib Makefile $(EXCLUDE_FACILITIES),$(patsubst %,%,$(wildcard *)))
CSOURCES = $(filter-out $(addprefix %/,$(EXCLUDE_SOURCES)),\
$(wildcard src/*.c) $(wildcard $(patsubst %,%/src/*.c,$(FACILITIES))))
CXXSOURCES = $(filter-out $(addprefix %/,$(EXCLUDE_SOURCES)),\
$(wildcard src/*.cxx) $(wildcard $(patsubst %,%/src/*.cxx,$(FACILITIES)))) \
$(patsubst %.idl,%_c.cxx,$(wildcard idl/*.idl) $(wildcard $(patsubst %,%/idl/*.idl,$(FACILITIES))))
CPPSOURCES = $(filter-out $(addprefix %/,$(EXCLUDE_SOURCES)),\
$(wildcard src/*.cpp) $(wildcard $(patsubst %,%/src/*.cpp,$(FACILITIES)))) \
$(patsubst %.idl,%_c.cpp,$(wildcard idl/*.idl) $(wildcard $(patsubst %,%/idl/*.idl,$(FACILITIES))))
ASMSOURCES = $(filter-out $(addprefix %/,$(EXCLUDE_SOURCES)),$(wildcard $(patsubst %,%/src/*.asm,$(FACILITIES))))
ifneq ($(OBJDIR),.)
OBJECTS = $(sort $(patsubst %.c,$(OBJDIR)/%.obj,$(notdir $(CSOURCES))) \
$(patsubst %.cxx,$(OBJDIR)/%.obj,$(notdir $(CXXSOURCES))) \
$(patsubst %.cpp,$(OBJDIR)/%.obj,$(notdir $(CPPSOURCES))) \
$(patsubst %.asm,$(OBJDIR)/%.obj,$(notdir $(ASMSOURCES))))
else
OBJECTS = $(sort $(patsubst %.c,%.obj,$(CSOURCES)) \
$(patsubst %.cxx,%.obj,$(CXXSOURCES)) \
$(patsubst %.cpp,%.obj,$(CPPSOURCES)) \
$(patsubst %.asm,%.obj,$(ASMSOURCES)))
endif
FILTEROBJS=$(foreach o,$(filter-out %_main.obj,$1),$(if $(foreach x,$(foreach f,$2,$(findstring $f,$(notdir $o))),$x),,$o))
export PKGOBJECTS=$(call FILTEROBJS,$(OBJECTS),$(EXCLUDE_OBJECTS))
.SUFFIXES:
.PHONY: bin lib objects depends generated clean distclean cleanup distcleanup
ifeq ($(findstring bin,$(EXCLUDE_FACILITIES)),bin)
bin: lib subbin
else
bin: lib subbin
$(AT)if test -d bin/src ; then \
if test -f bin/src/Makefile.ocpi ; then \
$(MAKE) $(call DescendMake2,bin/src) -f Makefile.ocpi $(SYSTEMOPTION) ; \
else \
$(MAKE) $(call DescendMake2,bin/src) -f $(DescendFile2)/Makefile.ocpi.for-bin $(SYSTEMOPTION) ; \
fi ; \
fi
endif
lib: objects
$(AT)if test -f Makefile.ocpi ; then \
$(MAKE) -f Makefile.ocpi $(PACKAGELIB) $(SYSTEMOPTION) ; \
else \
$(MAKE) -f $(OCPI_BASE_DIR)/Makefile.ocpi.for-pkg $(SYSTEMOPTION) $(PACKAGELIB) ; \
fi
ifneq ($(filter linux macos,$(OCPI_TARGET_OS)),)
$(UNIXLIB): $(OBJECTS)
-rm -f $@
ar r $@ $(call FILTEROBJS,$(OBJECTS),$(EXCLUDE_OBJECTS))
$(EXPORTSHLIB): $(UNIXSHLIB)
if ! test -d $(OCPI_BASE_DIR)/lib; then mkdir -p $(OCPI_BASE_DIR)/lib; fi
if ! test -d $(OCPI_BASE_DIR)/lib/$(OCPI_OUT_DIR); then mkdir -p $(OCPI_BASE_DIR)/lib/$(OCPI_OUT_DIR); fi
cp -p $(UNIXSHLIB) "$@"
$(EXPORTSHLIB_S): $(UNIXSHLIB_S)
$(AT)if ! test -d $(OCPI_BASE_DIR)/lib; then mkdir -p $(OCPI_BASE_DIR)/lib; fi
$(AT)if ! test -d $(OCPI_BASE_DIR)/lib/$(OCPI_OUT_DIR); then mkdir -p $(OCPI_BASE_DIR)/lib/$(OCPI_OUT_DIR); fi
$(AT)cp -p $(UNIXSHLIB_S) "$@"
$(EXPORTLIB): $(UNIXLIB)
$(AT)if ! test -d $(OCPI_BASE_DIR)/lib; then mkdir -p $(OCPI_BASE_DIR)/lib; fi
$(AT)if ! test -d $(OCPI_BASE_DIR)/lib/$(OCPI_OUT_DIR); then mkdir -p $(OCPI_BASE_DIR)/lib/$(OCPI_OUT_DIR); fi
$(AT)cp -p $(UNIXLIB) "$@"
# Note the "sort" below. It gets rid of duplicates, but messes with the ordering.
DOSHLIB= \
$(CXX) $(OCPI_SHARED_LIBRARIES_FLAGS) $(infox PPP $(OCPI_PREVIOUS_DYNAMIC))\
$(if $(filter 0,$(OCPI_PREVIOUS_DYNAMIC)),$(SHARED_ALLOW_UNDEFINED),$(SHARED)) \
-o "$@" $(call FILTEROBJS,$(OBJECTS),$(EXCLUDE_OBJECTS)) $(EXTRALIBOBJS) \
$(if $(filter 0,$(OCPI_PREVIOUS_DYNAMIC)),,$(foreach l,$(ALLLIBS),$(call LIBDEP,$l))) \
$(foreach p,$(PREQLIBS),$(call PREQDEP,$p)) \
$(sort $(addprefix -L,$(call OcpiDir,$(SYSLIBS)))) \
$(addprefix -l,$(notdir $(SYSLIBS))) \
$(BASICLIBS)
$(UNIXSHLIB): $(OBJECTS)
$(AT)$(DOSHLIB)
PatchElf=$(OCPI_PREREQUISITES_INSTALL_DIR)/patchelf/$(OCPI_TOOL_DIR)/bin/patchelf
$(UNIXSHLIB_S): $(UNIXSHLIB)
$(AT)echo Creating $@ for use with statically linked executables.
$(AT)$(DOSHLIB)
$(AT)if test "$(OCPI_TARGET_OS)" == macos; then \
cp $< $@; \
else \
$(PatchElf) \
$(foreach l,$(ALLLIBS), --remove-needed libocpi_$(notdir $l).$(SO)) \
$(foreach l,$(PREQLIBS), \
$(foreach x,\
$(wildcard $(OCPI_PREREQUISITES_INSTALL_DIR)/$l/$(OCPI_TOOL_DIR)/lib/lib$l.*), \
--remove-needed $(notdir $x))) \
$@; \
fi
endif
objects: generated
$(AT)if test "x$(OCPI_OUT_DIR)" != "x" -a ! -d $(OBJDIR); then \
echo Creating object directory $(OBJDIR); \
mkdir -p $(OBJDIR) ; \
fi
$(AT)set -e; \
if test -d src; then \
if test -f src/Makefile.ocpi; then \
$(MAKE) $(call DescendMake1,src) -f Makefile.ocpi \
OBJDIR=../$(OCPI_OUT_DIR) $(SYSTEMOPTION) $@ ; \
else \
$(MAKE) $(call DescendMake1,src) -f $(DescendFile1)/Makefile.ocpi.for-src \
OBJDIR=../$(OCPI_OUT_DIR) $(SYSTEMOPTION) all ; \
fi; \
fi
$(AT)set -e; for facility in $(FACILITIES) ; do \
if test -d $$facility/src ; then \
if test -f $$facility/src/Makefile.ocpi ; then \
$(MAKE) $(call DescendMake2,$$facility/src) -f Makefile.ocpi $(SYSTEMOPTION) $@ ; \
else \
$(MAKE) $(call DescendMake2,$$facility/src) -f $(DescendFile2)/Makefile.ocpi.for-src $(SYSTEMOPTION) all ; \
fi ; \
fi; \
done
generated:
$(AT)set -e; \
if test -d idl; then \
if test -f idl/Makefile.ocpi; then \
$(MAKE) $(call DescendMake1,idl) -f Makefile.ocpi $(SYSTEMOPTION) $@ ; \
else \
$(MAKE) $(call DescendMake1,idl) -f $(DescendFile1)/Makefile.ocpi.for-idl $(SYSTEMOPTION) $@ ; \
fi; \
else \
for facility in $(GENERATED) ; do \
if test -d $$facility/idl ; then \
if test -f $$facility/idl/Makefile.ocpi ; then \
$(MAKE) $(call DescendMake2,$$facility/idl) -f Makefile.ocpi $(SYSTEMOPTION) $@ ; \
else \
$(MAKE) $(call DescendMake2,$$facility/idl) -f $(DescendFile2)/Makefile.ocpi.for-idl $(SYSTEMOPTION) $@ ; \
fi ; \
fi; \
done ;\
fi
clean:
$(AT)if test "$(CleanTarget)" = ""; then \
echo Cleaning: `pwd` for all targets '(and generated)'; \
find . -depth -name "target-*" -exec rm -r -f "{}" ";" ; \
find . -depth -name "gen" -exec rm -r -f "{}" ";" ; \
else \
echo Cleaning: `pwd` for target $(CleanTarget); \
find . -depth -name "target-$(CleanTarget)" -exec rm -r -f "{}" ";"; \
fi
distclean: clean
$(AT)echo Cleaning for distribution: `pwd`
$(AT)find . -name '*~' -exec rm {} \;
subbin: lib
$(AT)set -e; \
if test -d src; then \
$(MAKE) $(call DescendMake1,src) -f $(DescendFile1)/Makefile.ocpi.for-src \
OBJDIR=../$(OCPI_OUT_DIR) $(SYSTEMOPTION) executables ; \
else \
for facility in $(FACILITIES) ; do \
if test -d $$facility/src ; then \
$(MAKE) $(call DescendMake2,$$facility/src) -f $(DescendFile2)/Makefile.ocpi.for-src $(SYSTEMOPTION) executables ; \
fi; \
done; \
fi