Makefile.common.in 13.5 KB
Newer Older
1 2 3 4
# This is a part of PolyORB-HI-C distribution, a minimal
# middleware written for generated code from AADL models.
# You should use it with the Ocarina toolsuite.

5 6 7
CYGPATH_U = @CYGPATH_U@
CYGPATH_W = @CYGPATH_W@

jdelange's avatar
jdelange committed
8
GCC_GENERIC_CFLAGS=-Wall -g
9 10

all: build-node
11

12 13 14
include $(RUNTIME_PATH)/make/Makefile.$(TARGET)
-include ../../userdefined.mk

yoogx's avatar
yoogx committed
15 16 17 18
ifneq ($(USE_CPP_LINKER),)
LD=$(LD_CPP)
endif

yoogx's avatar
yoogx committed
19
build-node: compile-node
yoogx's avatar
yoogx committed
20

21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
################################################################################
# Configuration
#
# In userdefined.mk, we defined the following variables
# - USER_CFLAGS   : Additional flags to compile .c files
# - USER_CPPFLAGS : Additional flags to compile .cpp files
# - USER_CC       : User overrides CC compiler
# - USER_CPP      : User ovverides CPP compiler

ifneq ($(USER_CC),)
CC=$(USER_CC)
endif

ifneq ($(USER_CPP),)
CPP=$(USER_CPP)
endif

ifneq ($(USER_LD),)
LD=$(USER_LD)
endif

42
CFLAGS=$(TARGET_CFLAGS) $(USER_CFLAGS)
43
CPPFLAGS=$(CFLAGS) $(USER_CPPFLAGS)
jdelange's avatar
jdelange committed
44
LDFLAGS=$(TARGET_LDFLAGS) $(USER_LDFLAGS)
45

46 47 48
ifdef USE_GPROF
CFLAGS+=-D__PO_HI_USE_GPROF -pg
endif
49 50 51 52 53

ifeq ($(ENABLE_DYNAMIC_CONFIGURATION),1)
CFLAGS+=-D__PO_HI_USE_DYNAMIC_CONFIGURATION
endif

54 55 56 57
ifeq ($(NEED_TRANSPORT),yes)
CFLAGS+=-D__PO_HI_USE_TRANSPORT
endif

yoogx's avatar
yoogx committed
58 59
INCLUDE=-I. -I"${shell $(CYGPATH_W) "${RUNTIME_PATH}/include"}"

60
ifdef TARGET_INCLUDE
yoogx's avatar
yoogx committed
61
INCLUDE += $(TARGET_INCLUDE)
62 63
endif

64
ifdef USER_SOURCES_DIRS
yoogx's avatar
yoogx committed
65
INCLUDE+=$(USER_SOURCES_DIRS)
66 67
endif

68 69
INCLUDE+=$(USER_INCLUDE)

70 71 72 73 74 75
ifndef $(TARGET_NAME)
TARGET_NAME=$(TARGET)
endif

INCLUDE+=-DTARGET=$(TARGET_NAME)

76 77 78 79
################################################################################
# Files to be compiled

ifeq ($(NEED_TRANSPORT), yes)
julien.delange's avatar
julien.delange committed
80 81 82 83 84 85 86 87 88 89
   PO_HI_OBJS =                              \
	po_hi_task.o                              \
	po_hi_time.o                              \
	po_hi_protected.o                         \
	po_hi_main.o                              \
	po_hi_messages.o                          \
	po_hi_marshallers.o                       \
	po_hi_giop.o                              \
	po_hi_utils.o                             \
	po_hi_types.o                             \
jdelange's avatar
jdelange committed
90
   po_hi_monitor.o                           \
jdelange's avatar
jdelange committed
91
   po_hi_storage.o                           \
julien.delange's avatar
julien.delange committed
92 93
	po_hi_gqueue.o                            \
   drivers/po_hi_driver_exarm.o              \
julien.delange's avatar
julien.delange committed
94
   drivers/po_hi_driver_keyboard.o           \
95 96
   drivers/po_hi_driver_exarm_ni_6071e_analog.o \
   drivers/po_hi_driver_exarm_ni_6071e_digital.o \
97
   drivers/po_hi_driver_usbbrick_spacewire.o \
julien.delange's avatar
julien.delange committed
98
   drivers/po_hi_driver_linux_serial.o       \
99
   drivers/po_hi_driver_leon_serial.o        \
jdelange's avatar
jdelange committed
100
   drivers/po_hi_driver_leon_eth.o           \
101
   drivers/po_hi_driver_serial_common.o      \
julien.delange's avatar
julien.delange committed
102 103 104
   drivers/po_hi_driver_sockets.o            \
   drivers/po_hi_driver_rtems_ne2000.o       \
   drivers/po_hi_driver_rasta_serial.o       \
105
   drivers/po_hi_driver_rasta_common.o       \
julien.delange's avatar
julien.delange committed
106
   drivers/po_hi_driver_rasta_1553.o         \
107
   drivers/po_hi_driver_xc4v_fpga.o          \
julien.delange's avatar
julien.delange committed
108 109
   drivers/po_hi_driver_rasta_1553_brmlib.o  \
   drivers/po_hi_driver_rasta_spacewire.o    \
110 111 112
	$(ACTUAL_TRANSPORT) \
	po_hi_transport.o $(TARGET_TRANSPORT_SOURCES)

julien.delange's avatar
julien.delange committed
113 114 115 116 117 118
   GENERATED_OBJS =                 \
	activity.o                       \
	subprograms.o                    \
	types.o                          \
	request.o                        \
	marshallers.o                    \
119
	deployment.o                     \
julien.delange's avatar
julien.delange committed
120
	naming.o                         \
121 122
	main.o
else
julien.delange's avatar
julien.delange committed
123 124 125 126 127
   PO_HI_OBJS =                     \
	po_hi_task.o                     \
	po_hi_time.o                     \
	po_hi_utils.o                    \
	po_hi_protected.o                \
jdelange's avatar
jdelange committed
128
   po_hi_monitor.o                  \
jdelange's avatar
jdelange committed
129
   po_hi_storage.o                  \
130
	po_hi_main.o
julien.delange's avatar
julien.delange committed
131 132 133 134

   GENERATED_OBJS =                 \
	activity.o                       \
	subprograms.o                    \
135
	deployment.o                     \
julien.delange's avatar
julien.delange committed
136
	types.o                          \
137 138 139
	main.o
endif

jdelange's avatar
jdelange committed
140 141

ifeq ($(TARGET), $(filter $(TARGET), linux32 linux64 linux32-xenomai-posix linux32-xenomai-native))
142
PO_HI_OBJS += po_hi_lua.o
jdelange's avatar
jdelange committed
143 144
endif

jdelange's avatar
jdelange committed
145
ifeq ($(USE_ASN1_DEPLOYMENT), yes)
146
generate-asn1-deployment:
jdelange's avatar
jdelange committed
147 148 149
	if [ ! -d ../asn-types ]; then mkdir -p ../asn-types ; fi
	asn1.exe -c -uPER $(ASN_SOURCES) -o ../asn-types
	for f in real.o asn1crt.o acn.o ber.o xer.o; do \
150
	   c_file="`basename $$f .o`.c"; \
jdelange's avatar
jdelange committed
151 152 153 154 155 156
	      $(CC) $(INCLUDE) $(CFLAGS) -c -o $$f ../asn-types/$$c_file || exit 1 ; \
	done
	for f in $(ASN_SOURCES); do \
	   c_file="`basename $$f .asn`.c"; \
	   o_file="`basename $$f .asn`.o"; \
      if [ -f ../asn-types/$$c_file ]; then $(CC) $(INCLUDE) $(CFLAGS) -c -o $$o_file ../asn-types/$$c_file || exit 1 ; fi \
157
	done
158

jdelange's avatar
jdelange committed
159
GENERATED_OBJS += real.o asn1crt.o xer.o ber.o acn.o $(ASN_OBJS)
160
LDFLAGS += -lm
161
CFLAGS+=-DPO_HI_USE_ASN1 -I../../ -I../asn-types/
162

163 164 165 166 167
else
generate-asn1-deployment:

endif

168 169 170 171 172 173 174 175 176 177 178 179 180
################################################################################
# Simulink

ifdef SIMULINK_NODE
   PO_HI_OBJS += po_hi_simulink.o
endif

ifdef SIMULINK_DIR
   INCLUDE += -I$(SIMULINK_DIR) \
              -I$(SIMULINK_DIRECTORY)/simulink/include \
              -I$(SIMULINK_DIRECTORY)/extern/include \
              -I$(SIMULINK_DIRECTORY)/rtw/c/src \
              -I$(SIMULINK_DIRECTORY)/rtw/c/src/ext_mode/common \
181
              -I$(SIMULINK_DIRECTORY)/rtw/c/libsrc
182 183 184 185 186 187 188 189 190 191 192 193
   CFLAGS += -DRT -DUSE_RTMODEL -DMODEL=$(SIMULINK_NODE) -DRT -DNUMST=2 -DTID01EQ=1 -DNCSTATES=0 -DUNIX -DMT=0 -DHAVESTDIO
   LDFLAGS += $(SIMULINK_LDFLAGS)
endif

################################################################################
# SCADE

ifdef SCADE_DIR
   INCLUDE += -I$(SCADE_DIR)
	USER_OBJS += $(SCADE_DIR)/*.o
endif

julien.delange's avatar
julien.delange committed
194 195 196 197 198 199 200 201
################################################################################
# General LINUXTASTE stuff
check-linuxtaste:
	if [ ! -d $$LINUXTASTE_PATH/output/staging ]; then \
		echo "Please define the LINUXTASTE_PATH variable" ; \
      echo "It should point to the directory where the distro was built" && exit 2 ; \
	fi

202 203 204
################################################################################
# TASTE-RUNTIME-MONITORING

205
ifeq ($(MONITORING), true)
206 207 208

MONITORING_OBJS = trace_manager.o remote_configuration.o
PO_HI_CPPOBJS += $(MONITORING_OBJS)
209
PO_HI_OBJS += um_threads.o
210 211 212 213 214 215 216

INCLUDE += -I$(RUNTIME_PATH)/src \
-I$(RUNTIME_PATH)/src/monitoring \
-I$(RUNTIME_PATH)/include \
-I$(RUNTIME_PATH)/include/monitoring \
-I$(RUNTIME_PATH)/src/monitoring/cheddar_scheduling

yoogx's avatar
yoogx committed
217
CPPFLAGS += -std=c++1y -g @BOOST_CPPFLAGS@
218 219 220 221 222 223 224
LDFLAGS += -lstdc++
endif

hyperperiod-cheddar:
	python get_cheddar_schedule.py
	python parser_cheddar_et.py

225 226 227 228 229 230 231
################################################################################
# General compilation rules

compile-po-hi:
ifdef SIMULINK_DIR
	(cd $(SIMULINK_DIR) && $(MAKE) -f $(SIMULINK_NODE).mk  && rm -f grt_main.o)
endif
232

233 234 235
ifdef SCADE_DIR
	(cd $(SCADE_DIR) && for v in `ls *.c`; do $(CC) -c $$v; done)
endif
236

237 238
	for f in $(PO_HI_OBJS); do \
	   c_file="`basename $$f .o`.c"; \
239 240 241 242 243 244 245
	   c_file_dirname="`dirname $$f`"; \
      if [ -n "$$c_file_dirname" ]; then \
         if [ ! -d $$c_file_dirname ]; then mkdir -p $$c_file_dirname ; fi ; \
	      $(CC) $(INCLUDE) $(CFLAGS) -c -o $$f '$(RUNTIME_PATH)/src/'$$c_file_dirname'/'$$c_file  || exit 1 ; \
      else \
	      $(CC) $(INCLUDE) $(CFLAGS) -c -o $$f '$(RUNTIME_PATH)/src/'$$c_file || exit 1 ; \
      fi ; \
246 247
	done

248 249 250 251 252
	for f in $(PO_HI_CPPOBJS); do \
	   c_file="`basename $$f .o`.cc"; \
	   c_file_dirname="`dirname $$f`"; \
      if [ -n "$$c_file_dirname" ]; then \
         if [ ! -d $$c_file_dirname ]; then mkdir -p $$c_file_dirname ; fi ; \
yoogx's avatar
yoogx committed
253
	      $(CXX) $(INCLUDE) $(CPPFLAGS) -c -o $$f '$(RUNTIME_PATH)/src/'$$c_file_dirname'/'$$c_file  || exit 1 ; \
254
      else \
yoogx's avatar
yoogx committed
255
	      $(CXX) $(INCLUDE) $(CPPFLAGS) -c -o $$f '$(RUNTIME_PATH)/src/'$$c_file || exit 1 ; \
256 257 258
      fi ; \
	done

259 260
compile-node: $(BINARY)

jdelange's avatar
jdelange committed
261
ifeq ($(TARGET), $(filter $(TARGET), leon3-scoc3 leon.rtems leon.rtems_posix))
262 263
OBJS = $(USER_OBJS) $(PO_HI_OBJS) $(GENERATED_OBJS) $(EXTERNAL_OBJECTS)
$(BINARY):
yoogx's avatar
yoogx committed
264
	if [  x"$$RTEMS_MAKEFILE_PATH" = x"" ]; then \
265 266
		echo "Please define the RTEMS_MAKEFILE_PATH variable, exiting" ; \
	else \
yoogx's avatar
yoogx committed
267
		$(MAKE) generate-asn1-deployment compile-c-files compile-cpp-files compile-ada-files target-objects compile-po-hi $(USER_OBJS) $(GENERATED_OBJS) ; \
268 269
		$(CC) -o $(BINARY) $(EXTERNAL_OBJECTS) $(PO_HI_OBJS) $(GENERATED_OBJS) $(USER_OBJS) $(LDFLAGS) $(CFLAGS) ; \
	fi
julien.delange's avatar
julien.delange committed
270 271
endif

272
ifeq ($(TARGET), leon3-xm3)
273
$(BINARY):
274
OBJS = $(USER_OBJS) $(PO_HI_OBJS) $(GENERATED_OBJS) $(EXTERNAL_OBJECTS)
275 276 277 278 279
$(BINARY): generate-asn1-deployment target-objects check-rtems compile-po-hi $(USER_OBJS) $(GENERATED_OBJS)
	$(make-exe)
endif


jrosa's avatar
jrosa committed
280
ifeq ($(TARGET), $(filter $(TARGET), x86.rtems x86.rtems_posix))
281
OBJS = $(USER_OBJS) $(PO_HI_OBJS) $(GENERATED_OBJS) $(EXTERNAL_OBJECTS)
282 283 284 285
$(BINARY): generate-asn1-deployment target-objects check-rtems compile-po-hi $(USER_OBJS) $(GENERATED_OBJS)
	$(make-exe)
	cp $(BINARY) binary

286 287 288
ifeq ($(NEED_TRANSPORT), yes)
run: $(BINARY)
	pidof qemu >/dev/null 2>&1 ; if [ $$?  -eq 0 ]; then \
289
		( sleep 5 ; qemu -net nic,model=ne2k_pci,macaddr=52:54:00:12:34:93 -net socket,connect=127.0.0.1:12345 -fda $(RUNTIME_PATH)/utils/x86-rtems-boot.img -hda fat:. -boot a -serial /dev/stdout ; )& \
290 291
		echo "Launching QEMU in connect mode" ; \
	else \
292
		qemu -net nic,model=ne2k_pci,macaddr=52:54:00:12:34:92 -net socket,listen=:12345 -fda $(RUNTIME_PATH)/utils/x86-rtems-boot.img -hda fat:. -boot a -serial /dev/stdout; \
293 294 295
		echo "Launching QEMU in listen mode" ; \
	fi
else
296 297
run: $(BINARY)
	qemu -fda $(RUNTIME_PATH)/utils/x86-rtems-boot.img -hda fat:. -boot a
298 299
endif #NEED_TRANSPORT
endif #TARGET=x86qemu
300

julien.delange's avatar
julien.delange committed
301
ifeq ($(TARGET), nds.rtems)
302
OBJS = $(USER_OBJS) $(PO_HI_OBJS) $(GENERATED_OBJS) $(EXTERNAL_OBJECTS)
julien.delange's avatar
julien.delange committed
303
$(BINARY): generate-asn1-deployment target-objects check-rtems compile-po-hi $(USER_OBJS) $(GENERATED_OBJS)
304
	$(CC) -o $(BINARY) $(EXTERNAL_OBJECTS) $(PO_HI_OBJS) $(GENERATED_OBJS) $(USER_OBJS) $(LDFLAGS)
julien.delange's avatar
julien.delange committed
305 306
endif

julien.delange's avatar
julien.delange committed
307 308

ifeq ($(TARGET), gumstix.rtems)
309
OBJS = $(USER_OBJS) $(PO_HI_OBJS) $(GENERATED_OBJS) $(EXTERNAL_OBJECTS)
julien.delange's avatar
julien.delange committed
310 311 312 313
$(BINARY): generate-asn1-deployment target-objects check-rtems compile-po-hi $(USER_OBJS) $(GENERATED_OBJS)
	$(make-exe)
endif

jdelange's avatar
jdelange committed
314
ifeq ($(TARGET), compcert)
315 316 317 318
$(BINARY):
	@if [ ! -f ccomp ]; then \
		echo "Compcert not installed, exiting" ; \
	else \
yoogx's avatar
yoogx committed
319
		$(MAKE) generate-asn1-deployment compile-c-files compile-cpp-files compile-ada-files target-objects compile-po-hi $(GENERATED_OBJS) $(TARGET_OBJECTS); \
320 321 322 323 324
		for v in $(USER_OBJS); do mv ../../$$v . ; done ; \
 		mkdir -p drivers; \
		for v in $(PO_HI_OBJS); do mv $(RUNTIME_PATH)/src/$$v $$v ; done; \
		$(CC) -o $(BINARY) $(EXTERNAL_OBJECTS) $(PO_HI_OBJS) $(GENERATED_OBJS) $(USER_OBJS) $(LDFLAGS); \
	fi
jdelange's avatar
jdelange committed
325
endif
julien.delange's avatar
julien.delange committed
326

327
ifeq ($(TARGET), $(filter $(TARGET), native bench linux32 linux64))
jdelange's avatar
jdelange committed
328
EXE=$(BINARY)
329
$(BINARY):
yoogx's avatar
yoogx committed
330
	$(MAKE) generate-asn1-deployment target-objects compile-c-files compile-cpp-files compile-ada-files compile-po-hi $(USER_OBJS) $(GENERATED_OBJS) $(TARGET_OBJECTS)
331
	$(LD) -o $(EXE) $(EXTERNAL_OBJECTS) $(PO_HI_OBJS) $(PO_HI_CPPOBJS) $(GENERATED_OBJS) $(USER_OBJS) $(LDFLAGS)
jdelange's avatar
jdelange committed
332
endif
333 334 335 336

ifeq ($(TARGET), $(filter $(TARGET), win32))
EXE=$(BINARY).exe
$(BINARY):
yoogx's avatar
yoogx committed
337
	@if [ x"$(shell which i686-w64-mingw32-gcc)" = x ]; then \
338 339
		echo "Windows compiler is not installed in your system, exiting" ; \
	else \
yoogx's avatar
yoogx committed
340
		$(MAKE) generate-asn1-deployment target-objects compile-c-files compile-ada-files compile-po-hi $(USER_OBJS) $(GENERATED_OBJS) $(TARGET_OBJECTS) ; \
341 342 343 344 345 346 347
		$(LD) -o $(EXE) $(EXTERNAL_OBJECTS) $(PO_HI_OBJS) $(GENERATED_OBJS) $(USER_OBJS) $(LDFLAGS) ; \
	fi
endif

ifeq ($(TARGET), $(filter $(TARGET), linux32-xenomai-posix linux32-xenomai-native))
EXE=$(BINARY)
$(BINARY):
yoogx's avatar
yoogx committed
348
	@if [ x"$(shell which xeno-config)" = x ]; then \
349 350
		echo "Xenomai is not installed in your system, exiting" ; \
	else \
yoogx's avatar
yoogx committed
351
		$(MAKE) generate-asn1-deployment target-objects compile-c-files compile-ada-files compile-po-hi $(USER_OBJS) $(GENERATED_OBJS) $(TARGET_OBJECTS) ; \
352 353
		$(LD) -o $(EXE) $(EXTERNAL_OBJECTS) $(PO_HI_OBJS) $(GENERATED_OBJS) $(USER_OBJS) $(LDFLAGS) ; \
	fi
354 355
endif

julien.delange's avatar
julien.delange committed
356 357
ifeq ($(TARGET), arm.dslinux)
$(BINARY): generate-asn1-deployment target-objects compile-po-hi $(USER_OBJS) $(GENERATED_OBJS) $(TARGET_OBJECTS)
358
	$(CC) -o $(BINARY) $(EXTERNAL_OBJECTS) $(PO_HI_OBJS) $(GENERATED_OBJS) $(USER_OBJS) $(LDFLAGS)
julien.delange's avatar
julien.delange committed
359 360
endif

julien.delange's avatar
julien.delange committed
361 362
ifeq ($(TARGET), x86.linuxtaste)
$(BINARY): check-linuxtaste generate-asn1-deployment target-objects compile-po-hi $(USER_OBJS) $(GENERATED_OBJS) $(TARGET_OBJECTS)
363
	$(CC) -o $(BINARY) $(EXTERNAL_OBJECTS) $(PO_HI_OBJS) $(GENERATED_OBJS) $(USER_OBJS) $(LDFLAGS)
julien.delange's avatar
julien.delange committed
364 365
endif

366
%.o: %.cpp
yoogx's avatar
yoogx committed
367
	$(CXX) $(INCLUDE) $(CPPFLAGS) -c -o $@ $<
368

369
%.o: %.cc
yoogx's avatar
yoogx committed
370
	$(CXX) $(INCLUDE) $(CPPFLAGS) -c -o $@ $<
371

372 373 374 375
%.o: %.c
	$(CC) $(INCLUDE) $(CFLAGS) -c -o $@ $<

clean: target-clean
376
	@-rm -f *~ *.o *.al temp.* *.metrix $(BINARY) $(BINARY).bin $(BINARY).bt $(BINARY).num $(BINARY).nxe b~*.* *.ali
377
	@-rm -rf drivers
378 379 380
	if test ! "$(CLEANDIRS)" = "";  then \
	  rm -rf $(CLEANDIRS); \
	fi
381

jdelange's avatar
jdelange committed
382
generate-doc:
383 384
	@if [ -d generated-documentation ]; then rm  -rf generated-documentation ; fi
	@( DOXYBIN=`which doxygen 2>/dev/null` && if [ -x "$$DOXYBIN" ]; then ` which doxygen` doxygen.cfg ; fi ) || exit 0
jdelange's avatar
jdelange committed
385 386


387 388 389 390 391
ifdef USE_GPROF
gprof:
	./$(BINARY)
	gprof ./$(BINARY) > gprof.out
endif
392 393 394 395 396 397 398 399 400 401

################################################################################
# Generate Python wrapper for generated code, suppose the generated
# code uses the DLL target, and assumes a Linux OS for ld

python_wrapper:
	swig -python -I$(RUNTIME_PATH)/include -outdir . -o po_hi_c_python_wrap.c $(RUNTIME_PATH)/src/po_hi_c_python.i

	$(CC) -fPIC -c po_hi_c_python_wrap.c $(INCLUDE) $(CFLAGS) `python-config --includes`
	ld -dylib po_hi_c_python_wrap.o $(EXTERNAL_OBJECTS) $(PO_HI_OBJS) $(PO_HI_CPPOBJS) $(GENERATED_OBJS) $(USER_OBJS) $(LDFLAGS) `python-config --libs` -o _po_hi_c_python.so