Skip to content

Commit

Permalink
Merge pull request #38 from openlgtv/toolchain-cflags
Browse files Browse the repository at this point in the history
  • Loading branch information
smx-smx authored Sep 11, 2023
2 parents 3308ae6 + 7520350 commit f65ef91
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
7 changes: 7 additions & 0 deletions package/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,13 @@ ifeq ($(BR2_COMPILER_PARANOID_UNSAFE_PATH),y)
export BR_COMPILER_PARANOID_UNSAFE_PATH=enabled
endif

# Create a set of compiler flags without TARGET_DEBUGGING and TARGET_OPTIMIZATION for toolchain
$(foreach flag,CFLAGS CXXFLAGS FCFLAGS LDFLAGS CONFIGURE_OPTS, \
$(eval TOOLCHAIN_TARGET_$(flag) := $(strip \
$(subst $(TARGET_DEBUGGING),, \
$(subst $(TARGET_OPTIMIZATION),, \
$(TARGET_$(flag)))))))

include package/pkg-download.mk
include package/pkg-autotools.mk
include package/pkg-cmake.mk
Expand Down
4 changes: 3 additions & 1 deletion package/environment-setup/environment-setup.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ENVIRONMENT_SETUP_FILE = $(HOST_DIR)/environment-setup

define HOST_ENVIRONMENT_SETUP_INSTALL_CMDS
cp package/environment-setup/environment-setup $(ENVIRONMENT_SETUP_FILE)
for var in $(TARGET_CONFIGURE_OPTS); do \
for var in $(TOOLCHAIN_TARGET_CONFIGURE_OPTS); do \
printf "export \"$$var\"\n" >> $(ENVIRONMENT_SETUP_FILE); \
done
printf "export \"ARCH=$(NORMALIZED_ARCH)\"\n" >> $(ENVIRONMENT_SETUP_FILE)
Expand All @@ -21,6 +21,8 @@ define HOST_ENVIRONMENT_SETUP_INSTALL_CMDS
--sysconfdir=/etc \
--localstatedir=/var \
--program-prefix=\"\n" >> $(ENVIRONMENT_SETUP_FILE)
printf "export \"CMAKE_TOOLCHAIN_FILE=$(HOST_DIR)/share/buildroot/toolchainfile.cmake\"\n" \
>> $(ENVIRONMENT_SETUP_FILE)
printf "alias configure=\"./configure \$${CONFIGURE_FLAGS}\"\n" \
>> $(ENVIRONMENT_SETUP_FILE)
printf "alias cmake=\"cmake \
Expand Down
8 changes: 4 additions & 4 deletions package/pkg-cmake.mk
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ define TOOLCHAIN_CMAKE_INSTALL_FILES
@mkdir -p $(HOST_DIR)/share/buildroot
sed \
-e 's#@@STAGING_SUBDIR@@#$(call qstrip,$(STAGING_SUBDIR))#' \
-e 's#@@TARGET_CFLAGS@@#$(call qstrip,$(TARGET_CFLAGS))#' \
-e 's#@@TARGET_CXXFLAGS@@#$(call qstrip,$(TARGET_CXXFLAGS))#' \
-e 's#@@TARGET_FCFLAGS@@#$(call qstrip,$(TARGET_FCFLAGS))#' \
-e 's#@@TARGET_LDFLAGS@@#$(call qstrip,$(TARGET_LDFLAGS))#' \
-e 's#@@TARGET_CFLAGS@@#$(call qstrip,$(TOOLCHAIN_TARGET_CFLAGS))#' \
-e 's#@@TARGET_CXXFLAGS@@#$(call qstrip,$(TOOLCHAIN_TARGET_CXXFLAGS))#' \
-e 's#@@TARGET_FCFLAGS@@#$(call qstrip,$(TOOLCHAIN_TARGET_FCFLAGS))#' \
-e 's#@@TARGET_LDFLAGS@@#$(call qstrip,$(TOOLCHAIN_TARGET_LDFLAGS))#' \
-e 's#@@TARGET_CC@@#$(subst $(HOST_DIR)/,,$(call qstrip,$(TARGET_CC)))#' \
-e 's#@@TARGET_CXX@@#$(subst $(HOST_DIR)/,,$(call qstrip,$(TARGET_CXX)))#' \
-e 's#@@TARGET_FC@@#$(subst $(HOST_DIR)/,,$(call qstrip,$(TARGET_FC)))#' \
Expand Down
20 changes: 16 additions & 4 deletions support/misc/toolchainfile.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@ endif()
# if the project forces some of these flag variables, Buildroot is
# screwed up and there is nothing Buildroot can do about that :(
if(NOT DEFINED CMAKE_C_FLAGS_DEBUG)
set(CMAKE_C_FLAGS_DEBUG "" CACHE STRING "Debug CFLAGS")
set(CMAKE_C_FLAGS_DEBUG "-g" CACHE STRING "Debug CFLAGS")
endif()
if(NOT DEFINED CMAKE_C_FLAGS_RELEASE)
set(CMAKE_C_FLAGS_RELEASE " -DNDEBUG" CACHE STRING "Release CFLAGS")
set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG" CACHE STRING "Release CFLAGS")
endif()
if(NOT DEFINED CMAKE_C_FLAGS_MINSIZEREL)
set(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG" CACHE STRING "MinSizeRel CFLAGS")
endif()
if(NOT DEFINED CMAKE_C_FLAGS_RELWITHDEBINFO)
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG" CACHE STRING "RelWithDebInfo CFLAGS")
endif()

# Build type from the Buildroot configuration
Expand Down Expand Up @@ -99,10 +105,16 @@ if(NOT DEFINED CMAKE_C_COMPILER)
endif()
if(@@TOOLCHAIN_HAS_CXX@@)
if(NOT DEFINED CMAKE_CXX_FLAGS_DEBUG)
set(CMAKE_CXX_FLAGS_DEBUG "" CACHE STRING "Debug CXXFLAGS")
set(CMAKE_CXX_FLAGS_DEBUG "-g" CACHE STRING "Debug CXXFLAGS")
endif()
if(NOT DEFINED CMAKE_CXX_FLAGS_RELEASE)
set(CMAKE_CXX_FLAGS_RELEASE " -DNDEBUG" CACHE STRING "Release CXXFLAGS")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG" CACHE STRING "Release CXXFLAGS")
endif()
if(NOT DEFINED CMAKE_C_FLAGS_MINSIZEREL)
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG" CACHE STRING "MinSizeRel CXXFLAGS")
endif()
if(NOT DEFINED CMAKE_C_FLAGS_RELWITHDEBINFO)
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG" CACHE STRING "RelWithDebInfo CXXFLAGS")
endif()
if(NOT DEFINED CMAKE_CXX_FLAGS)
set(CMAKE_CXX_FLAGS "@@TARGET_CXXFLAGS@@" CACHE STRING "Buildroot CXXFLAGS")
Expand Down

0 comments on commit f65ef91

Please sign in to comment.