<commit_before>--
-- make_cpp.lua
-- Generate a C/C++ project makefile.
-- Copyright (c) 2002-2012 <NAME> and the Premake project
--

	premake.make.cpp = {}
	local make = premake.make
	local cpp = premake.make.cpp
	local project = premake5.project
	local config = premake5.config


--
-- Generate a GNU make C++ project makefile, with support for the new platforms API.
--

	function make.cpp.generate(prj)
		make.header(prj)

		-- main build rule(s)
		_p('.PHONY: clean prebuild prelink')
		_p('')

		for cfg in project.eachconfig(prj) do
			cpp.config(cfg)
		end

		-- list intermediate files
		cpp.objects(prj)

		make.detectshell()

		-- common build target rules
		_p('$(TARGET): $(GCH) $(OBJECTS) $(LDDEPS) $(RESOURCES)')
		_p('\t@echo Linking %s', prj.name)
		_p('\t$(SILENT) $(LINKCMD)')
		_p('\t$(POSTBUILDCMDS)')
		_p('')

		make.mkdirrule("$(TARGETDIR)")
		make.mkdirrule("$(OBJDIR)")

		-- clean target
		_p('clean:')
		_p('\t@echo Cleaning %s', prj.name)
		_p('ifeq (posix,$(SHELLTYPE))')
		_p('\t$(SILENT) rm -f  $(TARGET)')
		_p('\t$(SILENT) rm -rf $(OBJDIR)')
		_p('else')
		_p('\t$(SILENT) if exist $(subst /,\\\\,$(TARGET)) del $(subst /,\\\\,$(TARGET))')
		_p('\t$(SILENT) if exist $(subst /,\\\\,$(OBJDIR)) rmdir /s /q $(subst /,\\\\,$(OBJDIR))')
		_p('endif')
		_p('')

		-- custom build step targets
		_p('prebuild:')
		_p('\t$(PREBUILDCMDS)')
		_p('')

		_p('prelink:')
		_p('\t$(PRELINKCMDS)')
		_p('')

		-- precompiler header rule
		cpp.pchrules(prj)

		-- file building rules
		cpp.filerules(prj)

		-- include the dependencies, built by GCC (with the -MMD flag)
		_p('-include $(OBJECTS:%%.o=%%.d)')
		_p('ifneq (,$(PCH))')
			_p('  -include $(OBJDIR)/$(notdir $(PCH)).d')
		_p('endif')
	end


--
-- Write out the settings for a particular configuration.
--

	function cpp.config(cfg)
		-- identify the toolset used by this configurations
		local toolset = premake.tools[cfg.toolset or "gcc"]
		if not toolset then
			error("Invalid toolset '" + cfg.toolset + "'")
		end

		_p('ifeq ($(config),%s)', make.esc(cfg.shortname))

		-- write toolset specific configurations
		cpp.toolconfig(cfg, toolset)

		-- write target information (target dir, name, obj dir)
		make.targetconfig(cfg)

		-- write flags
		cpp.flags(cfg, toolset)

		-- set up precompiled headers
		cpp.pchconfig(cfg)

		-- write the link step
		cpp.linkconfig(cfg, toolset)

		-- write the custom build commands
		_p('  define PREBUILDCMDS')
		if #cfg.prebuildcommands > 0 then
			_p('\t@echo Running pre-build commands')
			_p('\t%s', table.implode(cfg.prebuildcommands, "", "", "\n\t"))
		end
		_p('  endef')

		_p('  define PRELINKCMDS')
		if #cfg.prelinkcommands > 0 then
			_p('\t@echo Running pre-link commands')
			_p('\t%s', table.implode(cfg.prelinkcommands, "", "", "\n\t"))
		end
		_p('  endef')

		_p('  define POSTBUILDCMDS')
		if #cfg.postbuildcommands > 0 then
			_p('\t@echo Running post-build commands')
			_p('\t%s', table.implode(cfg.postbuildcommands, "", "", "\n\t"))
		end
		_p('  endef')
		_p('')

		-- write the target building rule
		cpp.targetrules(cfg)

		-- write out config-level makesettings blocks
		make.settings(cfg, toolset)

		_p('endif')
		_p('')
	end


--
-- Build command for a single file.
--

	function cpp.buildcommand(prj, objext)
		local flags = iif(prj.language == "C", '$(CC) $(ALL_CFLAGS)', '$(CXX) $(ALL_CXXFLAGS)')
		_p('\t$(SILENT) %s -o "$@" -MF $(@:%%.%s=%%.d) -c "$<"', flags, objext)
	end


--
-- Output the list of file building rules.
--

	function cpp.filerules(prj)
		local tr = project.getsourcetree(prj)
		premake.tree.traverse(tr, {
			onleaf = function(node, depth)
				-- check to see if this file has custom rules
				local rules
				for cfg in project.eachconfig(prj) do
					local filecfg = config.getfileconfig(cfg, node.abspath)
					if config.hasCustomBuildRule(filecfg) then
						rules = true
						break
					end
				end

				-- if it has custom rules, need to break them out
				-- into individual configurations
				if rules then
					cpp.customfilerules(prj, node)
				else
					cpp.standardfilerules(prj, node)
				end
			end
		})
		_p('')
	end

	function cpp.standardfilerules(prj, node)
		-- C/C++ file
		if path.iscppfile(node.abspath) then
			local objectname = project.getfileobject(prj, node.abspath)
			_p('$(OBJDIR)/%s.o: %s', make.esc(objectname), make.esc(node.relpath))
			_p('\t@echo $(notdir $<)')
			cpp.buildcommand(prj, "o")

		-- resource file
		elseif path.isresourcefile(node.abspath) then<commit_msg>[gmake] allow mixing c files in cpp projects<commit_after>--
-- make_cpp.lua
-- Generate a C/C++ project makefile.
-- Copyright (c) 2002-2012 <NAME> and the Premake project
--

	premake.make.cpp = {}
	local make = premake.make
	local cpp = premake.make.cpp
	local project = premake5.project
	local config = premake5.config


--
-- Generate a GNU make C++ project makefile, with support for the new platforms API.
--

	function make.cpp.generate(prj)
		make.header(prj)

		-- main build rule(s)
		_p('.PHONY: clean prebuild prelink')
		_p('')

		for cfg in project.eachconfig(prj) do
			cpp.config(cfg)
		end

		-- list intermediate files
		cpp.objects(prj)

		make.detectshell()

		-- common build target rules
		_p('$(TARGET): $(GCH) $(OBJECTS) $(LDDEPS) $(RESOURCES)')
		_p('\t@echo Linking %s', prj.name)
		_p('\t$(SILENT) $(LINKCMD)')
		_p('\t$(POSTBUILDCMDS)')
		_p('')

		make.mkdirrule("$(TARGETDIR)")
		make.mkdirrule("$(OBJDIR)")

		-- clean target
		_p('clean:')
		_p('\t@echo Cleaning %s', prj.name)
		_p('ifeq (posix,$(SHELLTYPE))')
		_p('\t$(SILENT) rm -f  $(TARGET)')
		_p('\t$(SILENT) rm -rf $(OBJDIR)')
		_p('else')
		_p('\t$(SILENT) if exist $(subst /,\\\\,$(TARGET)) del $(subst /,\\\\,$(TARGET))')
		_p('\t$(SILENT) if exist $(subst /,\\\\,$(OBJDIR)) rmdir /s /q $(subst /,\\\\,$(OBJDIR))')
		_p('endif')
		_p('')

		-- custom build step targets
		_p('prebuild:')
		_p('\t$(PREBUILDCMDS)')
		_p('')

		_p('prelink:')
		_p('\t$(PRELINKCMDS)')
		_p('')

		-- precompiler header rule
		cpp.pchrules(prj)

		-- file building rules
		cpp.filerules(prj)

		-- include the dependencies, built by GCC (with the -MMD flag)
		_p('-include $(OBJECTS:%%.o=%%.d)')
		_p('ifneq (,$(PCH))')
			_p('  -include $(OBJDIR)/$(notdir $(PCH)).d')
		_p('endif')
	end


--
-- Write out the settings for a particular configuration.
--

	function cpp.config(cfg)
		-- identify the toolset used by this configurations
		local toolset = premake.tools[cfg.toolset or "gcc"]
		if not toolset then
			error("Invalid toolset '" + cfg.toolset + "'")
		end

		_p('ifeq ($(config),%s)', make.esc(cfg.shortname))

		-- write toolset specific configurations
		cpp.toolconfig(cfg, toolset)

		-- write target information (target dir, name, obj dir)
		make.targetconfig(cfg)

		-- write flags
		cpp.flags(cfg, toolset)

		-- set up precompiled headers
		cpp.pchconfig(cfg)

		-- write the link step
		cpp.linkconfig(cfg, toolset)

		-- write the custom build commands
		_p('  define PREBUILDCMDS')
		if #cfg.prebuildcommands > 0 then
			_p('\t@echo Running pre-build commands')
			_p('\t%s', table.implode(cfg.prebuildcommands, "", "", "\n\t"))
		end
		_p('  endef')

		_p('  define PRELINKCMDS')
		if #cfg.prelinkcommands > 0 then
			_p('\t@echo Running pre-link commands')
			_p('\t%s', table.implode(cfg.prelinkcommands, "", "", "\n\t"))
		end
		_p('  endef')

		_p('  define POSTBUILDCMDS')
		if #cfg.postbuildcommands > 0 then
			_p('\t@echo Running post-build commands')
			_p('\t%s', table.implode(cfg.postbuildcommands, "", "", "\n\t"))
		end
		_p('  endef')
		_p('')

		-- write the target building rule
		cpp.targetrules(cfg)

		-- write out config-level makesettings blocks
		make.settings(cfg, toolset)

		_p('endif')
		_p('')
	end


--
-- Build command for a single file.
--

	function cpp.buildcommand(prj, objext, is_cfile_)
		local is_cfile = is_cfile_ and is_cfile_ or false
		local flags = iif(prj.language == "C" or is_cfile, '$(CC) $(ALL_CFLAGS)', '$(CXX) $(ALL_CXXFLAGS)')
		_p('\t$(SILENT) %s -o "$@" -MF $(@:%%.%s=%%.d) -c "$<"', flags, objext)
	end


--
-- Output the list of file building rules.
--

	function cpp.filerules(prj)
		local tr = project.getsourcetree(prj)
		premake.tree.traverse(tr, {
			onleaf = function(node, depth)
				-- check to see if this file has custom rules
				local rules
				for cfg in project.eachconfig(prj) do
					local filecfg = config.getfileconfig(cfg, node.abspath)
					if config.hasCustomBuildRule(filecfg) then
						rules = true
						break
					end
				end

				-- if it has custom rules, need to break them out
				-- into individual configurations
				if rules then
					cpp.customfilerules(prj, node)
				else
					cpp.standardfilerules(prj, node)
				end
			end
		})
		_p('')
	end

	function cpp.standardfilerules(prj, node)
		-- C/C++ file
		if path.iscppfile(node.abspath) then
			local objectname = project.getfileobject(prj, node.abspath)
			_p('$(OBJDIR)/%s.o: %s', make.esc(objectname), make.esc(node.relpath))
			_p('\t@echo $(notdir $<)')
			cpp.buildcommand(prj, "o", path.iscfile(node.abspath))

		-- resource file
		elseif path.isresourcefile(node.abspath) then
{'fraction_non_alphanumeric': 0.17618002195389681, 'fraction_numerical': 0.002854006586169045, 'mean_word_length': 3.249533582089552, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, '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': '6412568', 'n_tokens_mistral': 3896, 'n_tokens_neox': 3429, 'n_words': 849}