@@ -15,18 +15,39 @@ PARALLEL_BUILD?=-j 4
1515# Build type can be either Debug or Release
1616BUILD_TYPE? =Debug
1717
18+ # If set to 1, compilation is done natively on the current os otherwise a dedicated docker container is used to build the project
19+ DISABLE_DOCKER? =0
20+
21+
22+ DOCKER_COMPILE_IMAGE =open-ocpp-simu-compile
23+
24+
1825# Default target
1926default : gcc-native
2027
2128# Silent makefile
22- .SILENT :
29+ # .SILENT:
2330
2431# Install prefix
2532ifneq ($(strip $(INSTALL_PREFIX ) ) ,)
2633CMAKE_INSTALL_PREFIX: =-D CMAKE_INSTALL_PREFIX=$(INSTALL_PREFIX )
2734CMAKE_INSTALL_PREFIX_CMD: =--prefix $(INSTALL_PREFIX )
2835endif
2936
37+
38+ INTERACTIVE: =$(shell [ -t 0 ] && echo 1)
39+ ifdef INTERACTIVE
40+ DOCKER_INTERACTIVE =-ti
41+ else
42+ DOCKER_INTERACTIVE =-i
43+ endif
44+ ifeq ($(DISABLE_DOCKER ) ,0)
45+ DOCKER_RUN =docker run $(DOCKER_INTERACTIVE ) --rm -v $(ROOT_DIR ) :$(ROOT_DIR ) :rw -w $(ROOT_DIR ) -e http_proxy="${http_proxy}" -e https_proxy="${https_proxy}" -e no_proxy="${no_proxy}" $(DOCKER_COMPILE_IMAGE ) docker/Entrypoint/entrypoint.sh
46+ else
47+ DOCKER_RUN =
48+ endif
49+
50+
3051# Build/clean all targets
3152all : gcc-native clang-native
3253clean : clean-gcc-native clean-clang-native
@@ -38,7 +59,7 @@ GCC_NATIVE_BIN_DIR:=$(BIN_DIR)/gcc_native
3859gcc-native : $(GCC_NATIVE_BUILD_DIR ) /Makefile
3960 @echo " Starting gcc-native build..."
4061 @mkdir -p $(GCC_NATIVE_BIN_DIR )
41- @ make --silent -C $(GCC_NATIVE_BUILD_DIR ) $(VERBOSE ) $(PARALLEL_BUILD )
62+ ${DOCKER_RUN} eval " make --silent -C $( GCC_NATIVE_BUILD_DIR) $( VERBOSE) $( PARALLEL_BUILD) "
4263 @echo " gcc-native build done!"
4364
4465clean-gcc-native :
@@ -50,7 +71,8 @@ $(GCC_NATIVE_BUILD_DIR)/Makefile:
5071 @echo " Generating gcc-native makefiles..."
5172 @mkdir -p $(GCC_NATIVE_BUILD_DIR )
5273 @mkdir -p $(GCC_NATIVE_BIN_DIR )
53- @cd $(GCC_NATIVE_BUILD_DIR ) && export CC=gcc && export CXX=g++ && cmake -D CMAKE_BUILD_TYPE=$(BUILD_TYPE ) -D TARGET=native -D BIN_DIR=$(GCC_NATIVE_BIN_DIR ) $(CMAKE_INSTALL_PREFIX ) $(ROOT_DIR )
74+ ${DOCKER_RUN} eval " cd $( GCC_NATIVE_BUILD_DIR) && CC=gcc CXX=g++ cmake -D CMAKE_BUILD_TYPE=$( BUILD_TYPE) -D TARGET=native -D BIN_DIR=$( GCC_NATIVE_BIN_DIR) $( CMAKE_INSTALL_PREFIX) $( ROOT_DIR) "
75+
5476
5577
5678# Targets for clang-native build
@@ -59,7 +81,7 @@ CLANG_NATIVE_BIN_DIR:=$(BIN_DIR)/clang_native
5981clang-native : $(CLANG_NATIVE_BUILD_DIR ) /Makefile
6082 @echo " Starting clang native build..."
6183 @mkdir -p $(CLANG_NATIVE_BIN_DIR )
62- @make --silent -C $(CLANG_NATIVE_BUILD_DIR ) $(VERBOSE ) $(PARALLEL_BUILD )
84+ @${DOCKER_RUN} eval " make --silent -C $( CLANG_NATIVE_BUILD_DIR) $( VERBOSE) $( PARALLEL_BUILD) "
6385 @echo " clang native build done!"
6486
6587clean-clang-native :
@@ -71,4 +93,23 @@ $(CLANG_NATIVE_BUILD_DIR)/Makefile:
7193 @echo " Generating clang-native makefiles..."
7294 @mkdir -p $(CLANG_NATIVE_BUILD_DIR )
7395 @mkdir -p $(CLANG_NATIVE_BIN_DIR )
74- @cd $(CLANG_NATIVE_BUILD_DIR ) && export CC=clang && export CXX=clang++ && cmake -D CMAKE_BUILD_TYPE=$(BUILD_TYPE ) -D TARGET=native -D _CMAKE_TOOLCHAIN_PREFIX=llvm- -D BIN_DIR=$(CLANG_NATIVE_BIN_DIR ) $(CMAKE_INSTALL_PREFIX ) $(ROOT_DIR )
96+ @${DOCKER_RUN} eval " cd $( CLANG_NATIVE_BUILD_DIR) && CC=clang CXX=clang++ cmake -D CMAKE_BUILD_TYPE=$( BUILD_TYPE) -D TARGET=native -D _CMAKE_TOOLCHAIN_PREFIX=llvm- -D BIN_DIR=$( CLANG_NATIVE_BIN_DIR) $( CMAKE_INSTALL_PREFIX) $( ROOT_DIR) "
97+
98+
99+ DOCKER_BUILD =docker build --build-arg http_proxy="${http_proxy}" --build-arg https_proxy="${https_proxy}" --build-arg no_proxy="${no_proxy}" --build-arg uid=$$(id -u ) --build-arg gid=$$(id -g )
100+ DOCKER_SIMULATOR_IMAGE =open-ocpp-cp-simulator
101+ docker-build-images : docker-build-simu-compile docker-build-cp-simulator
102+
103+ docker-build-simu-compile :
104+ @${DOCKER_BUILD} -f docker/Dockerfile -t $(DOCKER_COMPILE_IMAGE ) $(ROOT_DIR ) /docker
105+
106+ docker-build-cp-simulator :
107+ @${DOCKER_BUILD} -f docker/Dockerfile_cp_simulator -t $(DOCKER_SIMULATOR_IMAGE ) $(ROOT_DIR ) /bin/
108+
109+
110+ run-simu :
111+ docker run $(DOCKER_INTERACTIVE ) --rm --network=host --name ocpp-simu $(DOCKER_SIMULATOR_IMAGE )
112+
113+ run-launcher :
114+ docker run $(DOCKER_INTERACTIVE ) --rm --network=host --name ocpp-launcher --entrypoint /cp_simulator/launcher $(DOCKER_SIMULATOR_IMAGE )
115+
0 commit comments