misc: experimental configure script 77/32177/7
authorDamjan Marion <damarion@cisco.com>
Thu, 29 Apr 2021 16:47:25 +0000 (18:47 +0200)
committerAndrew Yourtchenko <ayourtch@gmail.com>
Fri, 30 Apr 2021 17:02:32 +0000 (17:02 +0000)
Type: make
Change-Id: Iaeb9d22eec9a7a763b63899814a44e78c8050f1f
Signed-off-by: Damjan Marion <damarion@cisco.com>
13 files changed:
.gitignore
Makefile
build-data/packages/vpp.mk
configure [new file with mode: 0755]
src/CMakeLists.txt
src/cmake/api.cmake
src/pkg/CMakeLists.txt
src/pkg/debian/rules.in
src/scripts/compdb_cleanup.py [moved from extras/scripts/compdb_cleanup.py with 85% similarity]
src/vlib/CMakeLists.txt
src/vpp/CMakeLists.txt
src/vpp/conf/startup.conf.in [new file with mode: 0644]
src/vppinfra/CMakeLists.txt

index 455316c..d91975e 100644 (file)
@@ -39,7 +39,6 @@ config.log
 config.guess
 config.sub
 config.status
-configure
 configure.scan
 coverage_report
 depcomp
index e228131..807d1ea 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -628,7 +628,7 @@ cscope: cscope.files
 compdb:
        @ninja -C build-root/build-vpp_debug-native/vpp build.ninja
        @ninja -C build-root/build-vpp_debug-native/vpp -t compdb | \
-         extras/scripts/compdb_cleanup.py > compile_commands.json
+         src/scripts/compdb_cleanup.py > compile_commands.json
 
 .PHONY: checkstyle
 checkstyle: checkfeaturelist
index bbff1ba..7db450e 100644 (file)
@@ -54,8 +54,8 @@ vpp_build = $(CMAKE) --build $(PACKAGE_BUILD_DIR) -- $(MAKE_PARALLEL_FLAGS)
 vpp_install = $(CMAKE) --build $(PACKAGE_BUILD_DIR) -- install | grep -v 'Set runtime path'
 
 vpp-package-deb: vpp-install
-       @$(CMAKE) --build $(PACKAGE_BUILD_DIR)/vpp -- package-deb
+       @$(CMAKE) --build $(PACKAGE_BUILD_DIR)/vpp -- pkg-deb
        @find $(PACKAGE_BUILD_DIR) \
-          -maxdepth 1 \
+          -maxdepth 2 \
           \( -name '*.changes' -o -name '*.deb' -o -name '*.buildinfo' \) \
           -exec mv {} $(CURDIR) \;
diff --git a/configure b/configure
new file mode 100755 (executable)
index 0000000..165429a
--- /dev/null
+++ b/configure
@@ -0,0 +1,96 @@
+#!/usr/bin/env bash
+
+# Experimental script, please consult with dmarion@me.com before
+# submitting any changes
+
+# defaults
+build_dir=.
+install_dir=/usr/local
+build_type=release
+prefix_path=/opt/vpp/external/$(uname -m)/
+
+help()
+{
+  cat << __EOF__
+VPP Build Configuration Script
+
+USAGE: ${0} [options]
+
+OPTIONS:
+  --help, -h              This help
+  --build-dir, -b         Build directory
+  --install-dir, -i       Install directory
+  --type, -t              Build type (release, debug, ... )
+  --wipe, -w              Wipe whole repo (except startup.* files)
+__EOF__
+}
+
+while (( "$#" )); do
+  case "$1" in
+    -h|--help)
+      help
+      exit 1
+      ;;
+    -b|--build-dir)
+      if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
+        build_dir=$2
+        shift 2
+      else
+        echo "Error: Argument for $1 is missing" >&2
+        exit 1
+      fi
+      ;;
+    -i|--install-dir)
+      if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
+        install_dir=$2
+        shift 2
+      else
+        echo "Error: Argument for $1 is missing" >&2
+        exit 1
+      fi
+      ;;
+    -t|--build-type)
+      if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
+        build_type=$2
+        shift 2
+      else
+        echo "Error: Argument for $1 is missing" >&2
+        exit 1
+      fi
+      ;;
+    -w|--wipe)
+      git clean -fdx --exclude=startup.\*
+      exit 1
+      ;;
+    -*|--*=) # unsupported flags
+      echo "Error: Unsupported flag $1" >&2
+      exit 1
+      ;;
+    *) # preserve positional arguments
+      PARAMS="$PARAMS $1"
+      shift
+      ;;
+  esac
+done
+
+cmake \
+  -G Ninja \
+  -S src \
+  -B ${build_dir} \
+  -DCMAKE_PREFIX_PATH=${prefix_path} \
+  -DCMAKE_INSTALL_PREFIX=${install_dir} \
+  -DCMAKE_BUILD_TYPE:STRING=${build_type}
+
+  cat << __EOF__
+
+  Useful build commands:
+
+  ninja             Build VPP
+  ninja menu        Start build configuration TUI
+  ninja compdb      Generate compile_commands.json
+  ninja run         Runs VPP using startup.conf in the build directory
+  ninja debug       Runs VPP inside GDB using startup.conf in the build directory
+  ninja pkg-deb     Create .deb packages
+  ninja install     Install VPP to $install_dir
+
+__EOF__
index 7dfd76a..96d373a 100644 (file)
@@ -64,6 +64,7 @@ set(VPP_LIBRARY_DIR "lib" CACHE STRING "Relative library directory path")
 
 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${VPP_RUNTIME_DIR})
 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${VPP_LIBRARY_DIR})
+set(VPP_BINARY_DIR ${CMAKE_BINARY_DIR}/CMakeFiles)
 
 if (CMAKE_BUILD_TYPE)
   set(CMAKE_C_FLAGS "-g -fPIC -Werror -Wall ${CMAKE_C_FLAGS}")
@@ -151,8 +152,7 @@ set(CMAKE_INSTALL_MESSAGE NEVER)
 
 include_directories (
        ${CMAKE_SOURCE_DIR}
-       ${CMAKE_BINARY_DIR}
-       ${CMAKE_BINARY_DIR}/include
+       ${VPP_BINARY_DIR}
 )
 set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "vpp")
 
@@ -185,7 +185,7 @@ else()
 endif()
 
 foreach(DIR ${SUBDIRS})
-  add_subdirectory(${DIR})
+  add_subdirectory(${DIR} ${VPP_BINARY_DIR}/${DIR})
 endforeach()
 
 ##############################################################################
@@ -206,6 +206,36 @@ if (VPP_GIT_TOPLEVEL_DIR)
   )
 endif()
 
+##############################################################################
+# custom targets
+##############################################################################
+
+add_custom_target(run
+  COMMAND ./${VPP_RUNTIME_DIR}/vpp -c startup.conf
+  COMMENT "Starting VPP..."
+  USES_TERMINAL
+)
+
+add_custom_target(debug
+  COMMAND gdb --args ./${VPP_RUNTIME_DIR}/vpp -c startup.conf
+  COMMENT "Starting VPP in the debugger..."
+  USES_TERMINAL
+)
+
+add_custom_target(menu
+  COMMAND ccmake ${CMAKE_BINARY_DIR}
+  COMMENT "Starting Configuration TUI..."
+  USES_TERMINAL
+)
+
+add_custom_target(compdb
+  COMMAND ninja -C ${CMAKE_BINARY_DIR} -t compdb |
+          ${CMAKE_SOURCE_DIR}/scripts/compdb_cleanup.py >
+         ${CMAKE_BINARY_DIR}/compile_commands.json
+  COMMENT "Generating compile_commands.json"
+  USES_TERMINAL
+)
+
 ##############################################################################
 # print configuration
 ##############################################################################
index 6747285..007a906 100644 (file)
@@ -80,7 +80,7 @@ endfunction()
 ##############################################################################
 function(vpp_generate_vapi_c_header f)
   get_filename_component(output ${f}.vapi.h NAME)
-  set (output_name ${CMAKE_BINARY_DIR}/vpp-api/vapi/${output})
+  set (output_name ${VPP_BINARY_DIR}/vpp-api/vapi/${output})
   if(NOT VPP_VAPI_C_GEN)
     set(VPP_VAPI_C_GEN ${CMAKE_SOURCE_DIR}/vpp-api/vapi/vapi_c_gen.py)
     set(VPP_VAPI_C_GEN_DEPENDS
@@ -93,7 +93,7 @@ function(vpp_generate_vapi_c_header f)
   set(input ${CMAKE_CURRENT_BINARY_DIR}/${f}.json)
   add_custom_command(
     OUTPUT ${output_name}
-    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/vpp-api/vapi
+    WORKING_DIRECTORY ${VPP_BINARY_DIR}/vpp-api/vapi
     COMMAND ${VPP_VAPI_C_GEN}
     ARGS --remove-path ${input}
     DEPENDS ${input} ${VPP_VAPI_C_GEN_DEPENDS}
@@ -108,7 +108,7 @@ endfunction ()
 
 function (vpp_generate_vapi_cpp_header f)
   get_filename_component(output ${f}.vapi.hpp NAME)
-  set (output_name ${CMAKE_BINARY_DIR}/vpp-api/vapi/${output})
+  set (output_name ${VPP_BINARY_DIR}/vpp-api/vapi/${output})
   if(NOT VPP_VAPI_CPP_GEN)
     set(VPP_VAPI_CPP_GEN ${CMAKE_SOURCE_DIR}/vpp-api/vapi/vapi_cpp_gen.py)
     set(VPP_VAPI_CPP_GEN_DEPENDS
@@ -120,7 +120,7 @@ function (vpp_generate_vapi_cpp_header f)
   set(input ${CMAKE_CURRENT_BINARY_DIR}/${f}.json)
   add_custom_command(
     OUTPUT ${output_name}
-    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/vpp-api/vapi
+    WORKING_DIRECTORY ${VPP_BINARY_DIR}/vpp-api/vapi
     COMMAND ${VPP_VAPI_CPP_GEN}
     ARGS --gen-h-prefix=vapi --remove-path ${input}
     DEPENDS ${input} ${VPP_VAPI_CPP_GEN_DEPENDS}
@@ -164,8 +164,8 @@ function(vpp_add_api_files name dir component)
       ${file}_enum.h
       ${file}_types.h
       ${file}.json
-      ${CMAKE_BINARY_DIR}/vpp-api/vapi/${name}.vapi.h
-      ${CMAKE_BINARY_DIR}/vpp-api/vapi/${name}.vapi.hpp
+      ${VPP_BINARY_DIR}/vpp-api/vapi/${name}.vapi.h
+      ${VPP_BINARY_DIR}/vpp-api/vapi/${name}.vapi.hpp
     )
   endforeach()
   add_custom_target(${target} DEPENDS ${header_files})
index e466fe8..d447774 100644 (file)
@@ -41,7 +41,7 @@ set(VPP_DEB_WITH_PYTHON2 "no")
 foreach(f rules changelog control)
   configure_file(
     ${CMAKE_CURRENT_SOURCE_DIR}/debian/${f}.in
-    ${CMAKE_BINARY_DIR}/debian/${f}
+    ${VPP_BINARY_DIR}/debian/${f}
     @ONLY
   )
 endforeach()
@@ -49,15 +49,15 @@ endforeach()
 foreach(f copyright vpp.preinst vpp.postrm vpp.postinst vpp.service)
   file(COPY
     ${CMAKE_CURRENT_SOURCE_DIR}/debian/${f}
-    DESTINATION ${CMAKE_BINARY_DIR}/debian
+    DESTINATION ${VPP_BINARY_DIR}/debian
   )
 endforeach()
 
-file(WRITE ${CMAKE_BINARY_DIR}/debian/compat "10\n")
+file(WRITE ${VPP_BINARY_DIR}/debian/compat "10\n")
 
-add_custom_target(package-deb
+add_custom_target(pkg-deb
   COMMENT "Building .deb packages..."
-  WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+  WORKING_DIRECTORY ${VPP_BINARY_DIR}
   COMMAND "dpkg-buildpackage" "-us" "-uc" "-b"
   USES_TERMINAL
 )
index 3249220..15f8eb6 100755 (executable)
@@ -30,7 +30,7 @@ override_dh_install:
          @CMAKE_COMMAND@ \
            -D CMAKE_INSTALL_CONFIG_NAME=@CMAKE_BUILD_TYPE@ \
            -D CMAKE_INSTALL_COMPONENT=$$c \
-           -D CMAKE_INSTALL_PREFIX=@CMAKE_BINARY_DIR@/debian/$$c \
+           -D CMAKE_INSTALL_PREFIX=@VPP_BINARY_DIR@/debian/$$c \
            -P @CMAKE_BINARY_DIR@/cmake_install.cmake 2>&1 \
            | grep -v 'Set runtime path of' ; \
          if [ -d debian/$$c/lib ] ; then \
similarity index 85%
rename from extras/scripts/compdb_cleanup.py
rename to src/scripts/compdb_cleanup.py
index 0139b6b..0302fc2 100755 (executable)
@@ -18,6 +18,11 @@ for i in range(len(objects) - 1, -1, -1):
         objects.remove(obj)
         continue
 
+    # remove if there is no command
+    if obj["command"] == "":
+        objects.remove(obj)
+        continue
+
     # remove ccache prefix
     s = str.split(obj["command"])
     if s[0] == "ccache":
index dbd74f1..78fe936 100644 (file)
@@ -37,10 +37,10 @@ set(VLIB_PROCESS_LOG2_STACK_SIZE
 
 configure_file(
   ${CMAKE_SOURCE_DIR}/vlib/config.h.in
-  ${CMAKE_BINARY_DIR}/vlib/config.h
+  ${CMAKE_CURRENT_BINARY_DIR}/config.h
 )
 install(
-  FILES ${CMAKE_BINARY_DIR}/vlib/config.h
+  FILES ${CMAKE_CURRENT_BINARY_DIR}/config.h
   DESTINATION include/vlib
   COMPONENT vpp-dev
 )
index df83837..0798350 100644 (file)
 # Generate vpp/app/version.h
 ##############################################################################
 add_custom_command(
-  OUTPUT ${CMAKE_BINARY_DIR}/include/vpp/app/version.h
+  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/app/version.h
   WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
   COMMAND mkdir
-  ARGS -p ${CMAKE_BINARY_DIR}/include/vpp/app
+  ARGS -p ${CMAKE_CURRENT_BINARY_DIR}/app
   COMMAND scripts/generate_version_h
-  ARGS ${CMAKE_BINARY_DIR}/include/vpp/app/version.h
+  ARGS ${CMAKE_CURRENT_BINARY_DIR}/app/version.h
   COMMENT "Generating VPP version.h"
 )
 
 add_custom_target(vpp_version_h
-  DEPENDS ${CMAKE_BINARY_DIR}/include/vpp/app/version.h
+  DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/app/version.h
 )
 
 ##############################################################################
@@ -35,7 +35,7 @@ option(VPP_API_TEST_BUILTIN "Use builtin VPP API test." ON)
 
 configure_file(
   ${CMAKE_SOURCE_DIR}/vpp/vnet/config.h.in
-  ${CMAKE_BINARY_DIR}/vpp/vnet/config.h
+  ${CMAKE_CURRENT_BINARY_DIR}/vnet/config.h
 )
 
 set(VPP_API_FILES
@@ -141,3 +141,13 @@ install(FILES conf/80-vpp.conf DESTINATION etc/sysctl.d COMPONENT vpp)
 add_vpp_test_library(vpp
   ${VPP_API_FILES}
 )
+
+##############################################################################
+# minimal interactive startup.conf  - only if not present
+##############################################################################
+if(NOT EXISTS ${CMAKE_BINARY_DIR}/startup.conf)
+  configure_file(
+    ${CMAKE_CURRENT_SOURCE_DIR}/conf/startup.conf.in
+    ${CMAKE_BINARY_DIR}/startup.conf
+  )
+endif()
diff --git a/src/vpp/conf/startup.conf.in b/src/vpp/conf/startup.conf.in
new file mode 100644 (file)
index 0000000..dd3c371
--- /dev/null
@@ -0,0 +1,47 @@
+
+unix {
+  interactive
+  # log @CMAKE_BINARY_DIR@/vpp.log
+  # full-coredump
+  # cli-listen @CMAKE_BINARY_DIR@/cli.sock
+  # exec @CMAKE_BINARY_DIR@/startup.vpp
+}
+
+api-trace {
+  on
+}
+
+memory {
+  main-heap-size 1G
+  # main-heap-page-size 1G
+}
+
+cpu {
+  # main-core 1
+  # corelist-workers 2-3,18-19
+}
+
+# buffers {
+  # buffers-per-numa 128000
+  # page-size default-hugepage
+# }
+
+plugins {
+  plugin dpdk_plugin.so { disable }
+  plugin unittest_plugin.so { enable }
+}
+
+# dpdk {
+#  no-pci
+#}
+
+statseg {
+  size 32m
+  # page-size 4k
+  # socket-name @CMAKE_BINARY_DIR@/stats.sock
+}
+
+#logging {
+  # default-syslog-log-level debug
+  # class dpdk/cryptodev { rate-limit 100 level debug syslog-level error }
+#}
index 11193a3..dd3690b 100644 (file)
@@ -27,11 +27,11 @@ endif(VPP_VECTOR_GROW_BY_ONE)
 
 configure_file(
   ${CMAKE_SOURCE_DIR}/vppinfra/config.h.in
-  ${CMAKE_BINARY_DIR}/vppinfra/config.h
+  ${CMAKE_CURRENT_BINARY_DIR}/config.h
 )
 
 install(
-  FILES ${CMAKE_BINARY_DIR}/vppinfra/config.h
+  FILES ${CMAKE_CURRENT_BINARY_DIR}/config.h
   DESTINATION include/vppinfra
   COMPONENT vpp-dev
 )