Makefile.common.in 18 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
CYGPATH_U = @CYGPATH_U@
6
CYGPATH_W = @CYGPATH_U@
7

yoogx's avatar
yoogx committed
8 9 10 11 12
# Regarding compilation warning flags:
#
# - Gaisler's RTEMS 4.10 doesn't currently support Wjump-misses-init.
#   Let's wait one more release cycle before adding this in.
# - -Wswitch-enum silent this flag, too verbose
13

yoogx's avatar
yoogx committed
14 15
GCC_GENERIC_CFLAGS= -g -Wall -Wextra -fdiagnostics-show-option -Wcast-align \
		    -Wswitch
16 17

all: build-node
18

19
LOCAL_RUNTIME_PATH=$(shell pwd)/../polyorb-hi-c
20

21 22 23 24 25 26 27
# Test whether we are simply including this makefile, e.g. to get some
# configuration parameters, or used as part of the general build from
# an Ocarina generated makefile

ifneq ($strip ($(wildcard $(LOCAL_RUNTIME_PATH)/config)),)
include $(RUNTIME_PATH)/make/Makefile.$(TARGET)
else
28
include $(LOCAL_RUNTIME_PATH)/make/Makefile.$(TARGET)
29 30 31
endif

# Include user-defined makefile
32 33
-include ../../userdefined.mk

yoogx's avatar
yoogx committed
34 35 36 37
ifneq ($(USE_CPP_LINKER),)
LD=$(LD_CPP)
endif

yoogx's avatar
yoogx committed
38
build-node: compile-node
yoogx's avatar
yoogx committed
39

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
################################################################################
# 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

61
CFLAGS=$(POHI_CFLAGS) $(USER_CFLAGS) $(GCC_GENERIC_CFLAGS)
62
CPPFLAGS=$(CFLAGS) $(USER_CPPFLAGS)
yoogx's avatar
yoogx committed
63
LDFLAGS=$(TARGET_LDFLAGS) $(USER_LDFLAGS)
64

65 66 67
ifdef USE_GPROF
CFLAGS+=-D__PO_HI_USE_GPROF -pg
endif
68 69 70 71 72

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

73 74 75 76
ifeq ($(NEED_TRANSPORT),yes)
CFLAGS+=-D__PO_HI_USE_TRANSPORT
endif

77
INCLUDE=-I. -I"${shell $(CYGPATH_W) "${LOCAL_RUNTIME_PATH}/include"}"
yoogx's avatar
yoogx committed
78

79
ifdef TARGET_INCLUDE
yoogx's avatar
yoogx committed
80
INCLUDE += $(TARGET_INCLUDE)
81 82
endif

83
ifdef USER_SOURCES_DIRS
yoogx's avatar
yoogx committed
84
INCLUDE+=$(USER_SOURCES_DIRS)
85 86
endif

87 88
INCLUDE+=$(USER_INCLUDE)

89 90 91 92 93 94
ifndef $(TARGET_NAME)
TARGET_NAME=$(TARGET)
endif

INCLUDE+=-DTARGET=$(TARGET_NAME)

95 96 97 98
################################################################################
# Files to be compiled

ifeq ($(NEED_TRANSPORT), yes)
99 100 101
   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 po_hi_monitor.o	\
102 103 104 105 106 107 108 109 110 111 112
	po_hi_semaphore.o po_hi_storage.o po_hi_gqueue.o		\
	po_hi_driver_exarm.o po_hi_driver_keyboard.o			\
	po_hi_driver_exarm_ni_6071e_analog.o				\
	po_hi_driver_exarm_ni_6071e_digital.o				\
	po_hi_driver_usbbrick_spacewire.o po_hi_driver_linux_serial.o	\
	po_hi_driver_leon_serial.o po_hi_driver_leon_eth.o		\
	po_hi_driver_serial_common.o po_hi_driver_sockets.o		\
	po_hi_driver_rtems_ne2000.o po_hi_driver_rasta_serial.o		\
	po_hi_driver_rasta_common.o po_hi_driver_rasta_1553.o		\
	po_hi_driver_xc4v_fpga.o po_hi_driver_rasta_1553_brmlib.o	\
	po_hi_driver_rasta_spacewire.o $(ACTUAL_TRANSPORT)		\
113 114
	po_hi_transport.o $(TARGET_TRANSPORT_SOURCES)

115 116
   GENERATED_OBJS = activity.o subprograms.o types.o request.o	\
	marshallers.o deployment.o naming.o main.o
117
else
118 119
   PO_HI_OBJS = po_hi_task.o po_hi_time.o po_hi_utils.o		\
	po_hi_protected.o po_hi_monitor.o po_hi_storage.o	\
120
	po_hi_main.o
julien.delange's avatar
julien.delange committed
121

122
   GENERATED_OBJS = activity.o subprograms.o deployment.o types.o	\
123 124 125
	main.o
endif

jdelange's avatar
jdelange committed
126

yoogx's avatar
yoogx committed
127
ifeq ($(TARGET), $(filter $(TARGET), linux32 linux64 linux32-xenomai-posix linux32-xenomai-native linux_dll))
128
PO_HI_OBJS += po_hi_lua.o
jdelange's avatar
jdelange committed
129 130
endif

jdelange's avatar
jdelange committed
131
ifeq ($(USE_ASN1_DEPLOYMENT), yes)
132
generate-asn1-deployment:
jdelange's avatar
jdelange committed
133
	if [ ! -d ../asn-types ]; then mkdir -p ../asn-types ; fi
yoogx's avatar
yoogx committed
134
	mono $(which asn1.exe) -c -uPER $(ASN_SOURCES) -o ../asn-types
jdelange's avatar
jdelange committed
135
	for f in real.o asn1crt.o acn.o ber.o xer.o; do \
136
	   c_file="`basename $$f .o`.c"; \
jdelange's avatar
jdelange committed
137 138 139 140 141 142
	      $(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 \
143
	done
144

jdelange's avatar
jdelange committed
145
GENERATED_OBJS += real.o asn1crt.o xer.o ber.o acn.o $(ASN_OBJS)
146
LDFLAGS += -lm
147
CFLAGS+=-DPO_HI_USE_ASN1 -I../../ -I../asn-types/
148

149 150 151 152 153
else
generate-asn1-deployment:

endif

154 155 156 157 158 159 160 161 162
################################################################################
# Simulink

ifdef SIMULINK_NODE
   PO_HI_OBJS += po_hi_simulink.o
endif

ifdef SIMULINK_DIR
   INCLUDE += -I$(SIMULINK_DIR) \
yoogx's avatar
yoogx committed
163 164 165 166 167
	      -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 \
	      -I$(SIMULINK_DIRECTORY)/rtw/c/libsrc
168 169 170 171 172 173 174 175
   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
176 177
INCLUDE += -I$(SCADE_DIR)
USER_OBJS += $(SCADE_DIR)/*.o
178 179
endif

julien.delange's avatar
julien.delange committed
180 181 182 183 184 185 186 187
################################################################################
# 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

188 189 190
################################################################################
# TASTE-RUNTIME-MONITORING

191
ifeq ($(MONITORING), true)
192

193
MONITORING_OBJS = trace_manager.o
yoogx's avatar
yoogx committed
194 195
PO_HI_OBJS += $(MONITORING_OBJS)
CFLAGS += -DMONITORING
196 197 198 199 200
INCLUDE += -I$(LOCAL_RUNTIME_PATH)/src \
-I$(LOCAL_RUNTIME_PATH)/src/monitoring \
-I$(LOCAL_RUNTIME_PATH)/include \
-I$(LOCAL_RUNTIME_PATH)/include/monitoring \
-I$(LOCAL_RUNTIME_PATH)/src/monitoring/cheddar_scheduling
201 202 203 204 205 206 207

endif

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

208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
################################################################################
# Code coverage + runtime-analysis

# gcov
ifeq ($(COVERAGE), gcov)
CFLAGS  += -fprofile-arcs -ftest-coverage -lgcov -coverage
LDFLAGS += -fprofile-arcs -ftest-coverage -lgcov -coverage
endif

# gnatcoverage
ifeq ($(COVERAGE), gnatcov)
CFLAGS  += -g -fpreserve-control-flow -fdump-scos -ffunction-sections -fdata-sections -Wl,--gc-sections
LDFLAGS += -g -fpreserve-control-flow -fdump-scos -ffunction-sections -fdata-sections -Wl,--gc-sections
endif

# valgrind
ifeq ($(VALGRIND_PROF), true)
CFLAGS  += -g
LDFLAGS += -g
endif

229 230 231 232 233 234 235
################################################################################
# General compilation rules

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

237 238 239
ifdef SCADE_DIR
	(cd $(SCADE_DIR) && for v in `ls *.c`; do $(CC) -c $$v; done)
endif
240

241 242
	for f in $(PO_HI_OBJS); do \
	   c_file="`basename $$f .o`.c"; \
243 244
	   c_file_dirname="`dirname $$f`"; \
      if [ -n "$$c_file_dirname" ]; then \
yoogx's avatar
yoogx committed
245
	 if [ ! -d $$c_file_dirname ]; then mkdir -p $$c_file_dirname ; fi ; \
246
	      $(CC) $(INCLUDE) $(CFLAGS) -c -o $$f '$(LOCAL_RUNTIME_PATH)/src/'$$c_file_dirname'/'$$c_file  || exit 1 ; \
247
      else \
248
	      $(CC) $(INCLUDE) $(CFLAGS) -c -o $$f '$(LOCAL_RUNTIME_PATH)/src/'$$c_file || exit 1 ; \
249
      fi ; \
250 251
	done

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

263
compile-node: $(BINARY)
264

yoogx's avatar
yoogx committed
265
ifeq ($(TARGET), $(filter $(TARGET), leon3-scoc3 leon.rtems leon.rtems_posix air))
266 267
OBJS = $(USER_OBJS) $(PO_HI_OBJS) $(GENERATED_OBJS) $(EXTERNAL_OBJECTS)
$(BINARY):
yoogx's avatar
yoogx committed
268
	if [  x"$$RTEMS_MAKEFILE_PATH" = x"" ]; then \
269 270
		echo "Please define the RTEMS_MAKEFILE_PATH variable, exiting" ; \
	else \
271
		$(MAKE) generate-asn1-deployment compile-c-files compile-cpp-files compile-ada-files target-objects compile-po-hi $(USER_OBJS) $(GENERATED_OBJS) $(BINARY).exe ;\
272
	fi
273 274 275 276

$(BINARY).exe:
	$(make-exe)

julien.delange's avatar
julien.delange committed
277 278
endif

279
### The following is to be revisited
280
ifeq ($(TARGET), leon3-xm3)
281
OBJS = $(USER_OBJS) $(PO_HI_OBJS) $(GENERATED_OBJS) $(EXTERNAL_OBJECTS)
282
$(BINARY):
283
	@echo XtratuM target disabled
284
endif
285 286 287 288 289 290
#if [ x"$(shell which sparc-rtems-gcc)" = x ]; then \
#		echo "XtratuM not installed, exiting" ; \
#	else \
#		$(MAKE) generate-asn1-deployment target-objects compile-po-hi $(USER_OBJS) $(GENERATED_OBJS); \
#	fi

291 292


jrosa's avatar
jrosa committed
293
ifeq ($(TARGET), $(filter $(TARGET), x86.rtems x86.rtems_posix))
294
OBJS = $(USER_OBJS) $(PO_HI_OBJS) $(GENERATED_OBJS) $(EXTERNAL_OBJECTS)
295
$(BINARY): generate-asn1-deployment target-objects compile-po-hi $(USER_OBJS) $(GENERATED_OBJS)
296 297 298
	$(make-exe)
	cp $(BINARY) binary

299 300 301
ifeq ($(NEED_TRANSPORT), yes)
run: $(BINARY)
	pidof qemu >/dev/null 2>&1 ; if [ $$?  -eq 0 ]; then \
302
		( sleep 5 ; qemu -net nic,model=ne2k_pci,macaddr=52:54:00:12:34:93 -net socket,connect=127.0.0.1:12345 -fda $(LOCAL_RUNTIME_PATH)/utils/x86-rtems-boot.img -hda fat:. -boot a -serial /dev/stdout ; )& \
303 304
		echo "Launching QEMU in connect mode" ; \
	else \
305
		qemu -net nic,model=ne2k_pci,macaddr=52:54:00:12:34:92 -net socket,listen=:12345 -fda $(LOCAL_RUNTIME_PATH)/utils/x86-rtems-boot.img -hda fat:. -boot a -serial /dev/stdout; \
306 307 308
		echo "Launching QEMU in listen mode" ; \
	fi
else
309
run: $(BINARY)
310
	qemu -fda $(LOCAL_RUNTIME_PATH)/utils/x86-rtems-boot.img -hda fat:. -boot a
311 312
endif #NEED_TRANSPORT
endif #TARGET=x86qemu
313

julien.delange's avatar
julien.delange committed
314
ifeq ($(TARGET), nds.rtems)
315
OBJS = $(USER_OBJS) $(PO_HI_OBJS) $(GENERATED_OBJS) $(EXTERNAL_OBJECTS)
316
$(BINARY): generate-asn1-deployment target-objects compile-po-hi $(USER_OBJS) $(GENERATED_OBJS)
317
	$(CC) -o $(BINARY) $(EXTERNAL_OBJECTS) $(PO_HI_OBJS) $(GENERATED_OBJS) $(USER_OBJS) $(LDFLAGS)
julien.delange's avatar
julien.delange committed
318 319
endif

julien.delange's avatar
julien.delange committed
320 321

ifeq ($(TARGET), gumstix.rtems)
322
OBJS = $(USER_OBJS) $(PO_HI_OBJS) $(GENERATED_OBJS) $(EXTERNAL_OBJECTS)
323
$(BINARY): generate-asn1-deployment target-objects compile-po-hi $(USER_OBJS) $(GENERATED_OBJS)
julien.delange's avatar
julien.delange committed
324 325 326
	$(make-exe)
endif

jdelange's avatar
jdelange committed
327
ifeq ($(TARGET), compcert)
328
$(BINARY):
329
	@if [ x"$(shell which ccomp)" = x ]; then \
330 331
		echo "Compcert not installed, exiting" ; \
	else \
yoogx's avatar
yoogx committed
332
		$(MAKE) generate-asn1-deployment compile-c-files compile-cpp-files compile-ada-files target-objects compile-po-hi $(GENERATED_OBJS) $(TARGET_OBJECTS); \
333 334
		$(CC) -o $(BINARY) $(EXTERNAL_OBJECTS) $(PO_HI_OBJS) $(GENERATED_OBJS) $(USER_OBJS) $(LDFLAGS); \
	fi
jdelange's avatar
jdelange committed
335
endif
julien.delange's avatar
julien.delange committed
336

yoogx's avatar
yoogx committed
337
ifeq ($(TARGET), $(filter $(TARGET), native bench linux32 linux64 linux_dll))
338
EXE=$(BINARY)$(EXEEXT)
yoogx's avatar
yoogx committed
339
$(BINARY): generate-asn1-deployment target-objects compile-c-files compile-cpp-files compile-ada-files compile-po-hi $(USER_OBJS) $(GENERATED_OBJS) $(TARGET_OBJECTS)
340
	$(LD) -o $(EXE) $(EXTERNAL_OBJECTS) $(PO_HI_OBJS) $(PO_HI_CPPOBJS) $(GENERATED_OBJS) $(USER_OBJS) $(LDFLAGS)
jdelange's avatar
jdelange committed
341
endif
342 343 344 345

ifeq ($(TARGET), $(filter $(TARGET), win32))
EXE=$(BINARY).exe
$(BINARY):
yoogx's avatar
yoogx committed
346
	@if [ x"$(shell which i686-w64-mingw32-gcc)" = x ]; then \
347 348
		echo "Windows compiler is not installed in your system, exiting" ; \
	else \
yoogx's avatar
yoogx committed
349
		$(MAKE) generate-asn1-deployment target-objects compile-c-files compile-ada-files compile-po-hi $(USER_OBJS) $(GENERATED_OBJS) $(TARGET_OBJECTS) ; \
350 351 352 353 354 355 356
		$(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):
357 358 359 360 361 362 363 364
	@echo Xenomai target disabled

#@if [ x"$(shell which xeno-config)" = x ]; then \
#		echo "Xenomai is not installed in your system, exiting" ; \
#	else \
#		$(MAKE) generate-asn1-deployment target-objects compile-c-files compile-ada-files compile-po-hi $(USER_OBJS) $(GENERATED_OBJS) $(TARGET_OBJECTS) ; \
#		$(LD) -o $(EXE) $(EXTERNAL_OBJECTS) $(PO_HI_OBJS) $(GENERATED_OBJS) $(USER_OBJS) $(LDFLAGS) ; \
#	fi
365 366
endif

julien.delange's avatar
julien.delange committed
367 368
ifeq ($(TARGET), arm.dslinux)
$(BINARY): generate-asn1-deployment target-objects compile-po-hi $(USER_OBJS) $(GENERATED_OBJS) $(TARGET_OBJECTS)
369
	$(CC) -o $(BINARY) $(EXTERNAL_OBJECTS) $(PO_HI_OBJS) $(GENERATED_OBJS) $(USER_OBJS) $(LDFLAGS)
julien.delange's avatar
julien.delange committed
370 371
endif

julien.delange's avatar
julien.delange committed
372 373
ifeq ($(TARGET), x86.linuxtaste)
$(BINARY): check-linuxtaste generate-asn1-deployment target-objects compile-po-hi $(USER_OBJS) $(GENERATED_OBJS) $(TARGET_OBJECTS)
374
	$(CC) -o $(BINARY) $(EXTERNAL_OBJECTS) $(PO_HI_OBJS) $(GENERATED_OBJS) $(USER_OBJS) $(LDFLAGS)
julien.delange's avatar
julien.delange committed
375 376
endif

yoogx's avatar
yoogx committed
377 378 379 380
ifeq ($(TARGET), freertos)
OBJS = $(USER_OBJS) $(PO_HI_OBJS) $(GENERATED_OBJS) $(EXTERNAL_OBJECTS)
$(BINARY): generate-asn1-deployment compile-po-hi compile-c-files compile-cpp-files $(USER_OBJS) $(GENERATED_OBJS) $(COMPILE_FREERTOS_OBJ)
	$(make-exe)
381
	$(LD) $(LDFLAGS) -o $(EXE).elf $(PO_HI_OBJS) $(GENERATED_OBJS) $(COMPILE_FREERTOS_OBJ) $(USER_OBJS)  $(USER_LIBS)
yoogx's avatar
yoogx committed
382 383
endif

384
%.o: %.cpp
yoogx's avatar
yoogx committed
385
	$(CXX) $(INCLUDE) $(CPPFLAGS) -c -o $@ $<
386

387
%.o: %.cc
yoogx's avatar
yoogx committed
388
	$(CXX) $(INCLUDE) $(CPPFLAGS) -c -o $@ $<
389

390 391 392
%.o: %.c
	$(CC) $(INCLUDE) $(CFLAGS) -c -o $@ $<

yoogx's avatar
yoogx committed
393 394 395
%.o: %.s
	$(AS) $(INCLUDE) $(CFLAGS) -c -o $@ $<

396 397
clean: #target-clean
	@-rm -f *~ *.o *.al temp.* *.metrix $(BINARY) $(BINARY).bin $(BINARY).bt $(BINARY).num $(BINARY).nxe b~*.* *.ali *.gcda *.gcno *.log *.xml
398
	@-rm -rf drivers
399 400 401
	if test ! "$(CLEANDIRS)" = "";  then \
	  rm -rf $(CLEANDIRS); \
	fi
402

jdelange's avatar
jdelange committed
403
generate-doc:
404 405
	@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
406 407


408 409 410 411 412
ifdef USE_GPROF
gprof:
	./$(BINARY)
	gprof ./$(BINARY) > gprof.out
endif
413 414 415 416 417 418

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

python_wrapper:
419
	swig -python -I$(LOCAL_RUNTIME_PATH)/include -outdir . -o po_hi_c_python_wrap.c $(LOCAL_RUNTIME_PATH)/src/po_hi_c_python.i
420 421 422

	$(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
423 424 425 426 427 428 429 430 431 432 433 434 435

################################################################################
# Execution of scripts to collect information for sonarqube.
# Note: it assumes a complete and running installation of sonarqube

sonar_run: clean
	   make all > build.log
	   make cppcheck
	   make --ignore-errors valgrind_xml
	   make sonarproperties
	   make coverage
	   sonar-scanner

yoogx's avatar
yoogx committed
436 437 438 439
export SONAR_PROJECT_DIR=$(PWD)/..
export SONAR_RESULTS_RELATIVE_PATH=$(shell echo "$(PWD)" | sed  's:$(SONAR_PROJECT_DIR)/::g')
export TEMPLATE_PATH=$(shell sed -e 's:polyorb-hi-c/.*:polyorb-hi-c:' <<< $(PWD))

440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
################################################################################
# sonarproperties: generation of configuration file for sonarqube
#

export SONAR_PROJECT_DIR=$(PWD)/..
export SONAR_RESULTS_RELATIVE_PATH=$(shell echo "$(PWD)" | sed  's:$(SONAR_PROJECT_DIR)/::g')

sonarproperties:
	cp $(RUNTIME_PATH)/utils/template_sonar-project.properties tmpsonar-project.properties
	sed -i 's/@PROJECT_KEY@/$(MAINAPP):$(BINARY)/g' tmpsonar-project.properties
	sed -i 's/@PROJECT_NAME@/$(MAINAPP)::$(BINARY)/g' tmpsonar-project.properties
	sed -i 's:@MASTER_PROJECT_DIR@:$(SONAR_PROJECT_DIR):g' tmpsonar-project.properties
	echo "#sources files for analysis" >> tmpsonar-project.properties
	echo "sonar.sources = $(PWD), $(LOCAL_RUNTIME_PATH)/src" >> tmpsonar-project.properties
	echo "#Include files" >> tmpsonar-project.properties
	echo "sonar.cxx.includeDirectories=$(LOCAL_RUNTIME_PATH)/include, $(LOCAL_RUNTIME_PATH)/include/silulator, $(LOCAL_RUNTIME_PATH)/include/monitoring, $(LOCAL_RUNTIME_PATH)/include/drivers, $(LOCAL_RUNTIME_PATH)/include/drivers/configuration, $(PWD)" >> tmpsonar-project.properties
	echo "#Reports to sonarqube" >> tmpsonar-project.properties
	sed  's:$(SONAR_PROJECT_DIR)/::g' <<< $(PWD)
	echo "sonar.cxx.cppcheck.reportPath=$(SONAR_RESULTS_RELATIVE_PATH)/cppcheck.xml" >> tmpsonar-project.properties
	echo "sonar.cxx.compiler.reportPath=$(SONAR_RESULTS_RELATIVE_PATH)/build.log" >> tmpsonar-project.properties
	echo "sonar.cxx.valgrind.reportPath=$(SONAR_RESULTS_RELATIVE_PATH)/valgrind*.xml" >> tmpsonar-project.properties
	echo "sonar.cxx.coverage.reportPath=$(SONAR_RESULTS_RELATIVE_PATH)/gcovr*.xml" >> tmpsonar-project.properties
	echo "sonar.cxx.coverage.itReportPat=$(SONAR_RESULTS_RELATIVE_PATH)/gcovr*.xml" >> tmpsonar-project.properties
	echo "sonar.cxx.coverage.overallReportPath=$(SONAR_RESULTS_RELATIVE_PATH)/gcovr*.xml" >> tmpsonar-project.properties
	cp tmpsonar-project.properties sonar-project.properties

################################################################################
# cppcheck: run the static code analyser, see http://cppcheck.sourceforge.net
#

CPPCHECK_FLAGS= -v --enable=all --xml-version=2 --std=c99 --platform=unix64 --rule-file=gnu.cfg --rule-file=std.cfg --rule-file=posix.cfg

cppcheck:
473
	cppcheck $(CPPCHECK_FLAGS) $(INCLUDE) -I$(LOCAL_RUNTIME_PATH)/include  $(POHI_CFLAGS) $(USER_CFLAGS) $(LOCAL_RUNTIME_PATH)/src $(PWD) 2> cppcheck.xml
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500

################################################################################
# valgrind: run the valgrind binary analyser
#

valgrind:
	cp $(RUNTIME_PATH)/utils/template_prof_gen.sh prof_gen.sh
	chmod +x+w prof_gen.sh
	sed -i 's/@PROGRAM_NAME@/$(BINARY)/g' prof_gen.sh
	sh prof_gen.sh --output-dir-name=valgrind_output --check=call
	sh prof_gen.sh --output-dir-name=valgrind_output --check=cache
	sh prof_gen.sh --output-dir-name=valgrind_output --check=mem

valgrind_xml:
	valgrind --tool=memcheck --leak-check=full --xml=yes --xml-file=valgrind_memcheck.xml ./$(BINARY)

valgrind_log:
	valgrind --tool=memcheck --leak-check=full --log-file=valgrind_memcheck.log ./$(BINARY)

################################################################################
# collect code coverage metrics

coverage:
	cp $(RUNTIME_PATH)/utils/template_lcov_gen.sh lcov_gen.sh
	chmod +x+w lcov_gen.sh
	sh lcov_gen.sh --output-dir-name=govcoverage_output
	gcovr -r $(SONAR_PROJECT_DIR) -s -x -o gcovr_report.xml