<commit_before>require "hardware"
require "extend/ENV/shared"

# TODO: deprecate compiling related codes after it's only used by brew test.
# @private
module Stdenv
  include SharedEnvExtension

  # @private
  SAFE_CFLAGS_FLAGS = "-w -pipe"
  DEFAULT_FLAGS = "-march=core2 -msse4"

  def self.extended(base)
    unless ORIGINAL_PATHS.include? HOMEBREW_PREFIX/"bin"
      base.prepend_path "PATH", "#{HOMEBREW_PREFIX}/bin"
    end
  end

  # @private
  def setup_build_environment(formula = nil)
    super

    if MacOS.version >= :mountain_lion
      # Mountain Lion's sed is stricter, and errors out when
      # it encounters files with mixed character sets
      delete("LC_ALL")
      self["LC_CTYPE"]="C"
    end

    # Set the default pkg-config search path, overriding the built-in paths
    # Anything in PKG_CONFIG_PATH is searched before paths in this variable
    self["PKG_CONFIG_LIBDIR"] = determine_pkg_config_libdir

    # make any aclocal stuff installed in Homebrew available
    self["ACLOCAL_PATH"] = "#{HOMEBREW_PREFIX}/share/aclocal" if MacOS.has_apple_developer_tools? && MacOS::Xcode.provides_autotools?

    self["MAKEFLAGS"] = "-j#{make_jobs}"

    unless HOMEBREW_PREFIX.to_s == "/usr/local"
      # /usr/local is already an -isystem and -L directory so we skip it
      self["CPPFLAGS"] = "-isystem#{HOMEBREW_PREFIX}/include"
      self["LDFLAGS"] = "-L#{HOMEBREW_PREFIX}/lib"
      # CMake ignores the variables above
      self["CMAKE_PREFIX_PATH"] = HOMEBREW_PREFIX.to_s
    end

    frameworks = HOMEBREW_PREFIX.join("Frameworks")
    if frameworks.directory?
      append "CPPFLAGS", "-F#{frameworks}"
      append "LDFLAGS", "-F#{frameworks}"
      self["CMAKE_FRAMEWORK_PATH"] = frameworks.to_s
    end

    # Os is the default Apple uses for all its stuff so let's trust them
    set_cflags "-Os #{SAFE_CFLAGS_FLAGS}"

    append "LDFLAGS", "-Wl,-headerpad_max_install_names" if OS.mac?

    if OS.linux? && !["glibc", "glibc25"].include?(formula && formula.name)
      if formula
        # Work around a bug in glibc 2.19 fixed in 2.20:
        # segfault when LD_LIBRARY_PATH is set to non-existent directory.
        # See https://github.com/Linuxbrew/linuxbrew/issues/841
        FileUtils.mkdir_p formula.lib
        # Add this formula's library directory to the shared library search path.
        prepend "LD_LIBRARY_PATH", formula.lib, File::PATH_SEPARATOR
      end

      # Set the search path for header files.
      prepend_path "CPATH", HOMEBREW_PREFIX/"include"
      # Set the dynamic linker and library search path.
      append "LDFLAGS", "-Wl,--dynamic-linker=#{HOMEBREW_PREFIX}/lib/ld.so -Wl,-rpath,#{HOMEBREW_PREFIX}/lib"
      prepend_path "LIBRARY_PATH", HOMEBREW_PREFIX/"lib"
      prepend_path "LD_RUN_PATH", HOMEBREW_PREFIX/"lib"
    end

    if inherit?
      # Inherit CC, CXX and compiler flags from the parent environment.
    elsif respond_to?(compiler)
      send(compiler)
    else
      self.cc = determine_cc
      self.cxx = determine_cxx
      set_cpu_cflags
    end

    if cc =~ GNU_GCC_REGEXP && !inherit?<commit_msg>ENV/std: Do not mkdir lib for Linuxbrew<commit_after>require "hardware"
require "extend/ENV/shared"

# TODO: deprecate compiling related codes after it's only used by brew test.
# @private
module Stdenv
  include SharedEnvExtension

  # @private
  SAFE_CFLAGS_FLAGS = "-w -pipe"
  DEFAULT_FLAGS = "-march=core2 -msse4"

  def self.extended(base)
    unless ORIGINAL_PATHS.include? HOMEBREW_PREFIX/"bin"
      base.prepend_path "PATH", "#{HOMEBREW_PREFIX}/bin"
    end
  end

  # @private
  def setup_build_environment(formula = nil)
    super

    if MacOS.version >= :mountain_lion
      # Mountain Lion's sed is stricter, and errors out when
      # it encounters files with mixed character sets
      delete("LC_ALL")
      self["LC_CTYPE"]="C"
    end

    # Set the default pkg-config search path, overriding the built-in paths
    # Anything in PKG_CONFIG_PATH is searched before paths in this variable
    self["PKG_CONFIG_LIBDIR"] = determine_pkg_config_libdir

    # make any aclocal stuff installed in Homebrew available
    self["ACLOCAL_PATH"] = "#{HOMEBREW_PREFIX}/share/aclocal" if MacOS.has_apple_developer_tools? && MacOS::Xcode.provides_autotools?

    self["MAKEFLAGS"] = "-j#{make_jobs}"

    unless HOMEBREW_PREFIX.to_s == "/usr/local"
      # /usr/local is already an -isystem and -L directory so we skip it
      self["CPPFLAGS"] = "-isystem#{HOMEBREW_PREFIX}/include"
      self["LDFLAGS"] = "-L#{HOMEBREW_PREFIX}/lib"
      # CMake ignores the variables above
      self["CMAKE_PREFIX_PATH"] = HOMEBREW_PREFIX.to_s
    end

    frameworks = HOMEBREW_PREFIX.join("Frameworks")
    if frameworks.directory?
      append "CPPFLAGS", "-F#{frameworks}"
      append "LDFLAGS", "-F#{frameworks}"
      self["CMAKE_FRAMEWORK_PATH"] = frameworks.to_s
    end

    # Os is the default Apple uses for all its stuff so let's trust them
    set_cflags "-Os #{SAFE_CFLAGS_FLAGS}"

    append "LDFLAGS", "-Wl,-headerpad_max_install_names" if OS.mac?

    if OS.linux? && !["glibc", "glibc25"].include?(formula && formula.name)
      if formula
        # To work around a bug in glibc 2.19 that is fixed in 2.20
        # add both lib and prefix to LD_LIBRARY_PATH.
        # segfault when LD_LIBRARY_PATH is set to non-existent directory.
        # See https://github.com/Linuxbrew/linuxbrew/issues/841
        prepend "LD_LIBRARY_PATH", formula.prefix, File::PATH_SEPARATOR
        prepend "LD_LIBRARY_PATH", formula.lib, File::PATH_SEPARATOR
      end

      # Set the search path for header files.
      prepend_path "CPATH", HOMEBREW_PREFIX/"include"
      # Set the dynamic linker and library search path.
      append "LDFLAGS", "-Wl,--dynamic-linker=#{HOMEBREW_PREFIX}/lib/ld.so -Wl,-rpath,#{HOMEBREW_PREFIX}/lib"
      prepend_path "LIBRARY_PATH", HOMEBREW_PREFIX/"lib"
      prepend_path "LD_RUN_PATH", HOMEBREW_PREFIX/"lib"
    end

    if inherit?
      # Inherit CC, CXX and compiler flags from the parent environment.
    elsif respond_to?(compiler)
      send(compiler)
    else
      self.cc = determine_cc
      self.cxx = determine_cxx
      set_cpu_cflags
    end

    if cc =~ GNU_GCC_REGEXP && !inherit?
{'fraction_non_alphanumeric': 0.10298843187660668, 'fraction_numerical': 0.004177377892030848, 'mean_word_length': 3.304979253112033, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3726301', 'n_tokens_mistral': 2121, 'n_tokens_neox': 1977, 'n_words': 534}