premake/util/sdl_depends.lua
author Sam Lantinga
Thu, 01 Sep 2016 01:26:56 -0700
changeset 10304 ee83e0b4a36f
parent 9998 f67cf37e9cd4
permissions -rwxr-xr-x
wayland: Add support for relative mouse mode, by Jonas Ã…dahl <jadahl@gmail.com>

Generate the C protocol files from the protocol XML files installed by
wayland-protocols, and use them to implement support for relative pointer
motions and pointer locking.

Note that at the time, the protocol is unstable and may change in the future.
Any future breaking changes will, however, fail gracefully and result in no
regressions compared to before this patch.
     1 -- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
     2 --
     3 -- This software is provided 'as-is', without any express or implied
     4 -- warranty.  In no event will the authors be held liable for any damages
     5 -- arising from the use of this software.
     6 --
     7 -- Permission is granted to anyone to use this software for any purpose,
     8 -- including commercial applications, and to alter it and redistribute it
     9 -- freely.
    10 --
    11 -- Meta-build system using premake created and maintained by
    12 -- Benjamin Henning <b.henning@digipen.edu>
    13 
    14 -- This is kept just for windows because the other platforms use different means
    15 -- for determining dependence or compatibility.
    16 
    17 --[[
    18 sdl_depends.lua
    19 
    20 	This file simply contains a function for determining whether a dependency
    21 	exists on the Windows platform, given a possible environmental variable,
    22 	delimited search paths, and a main and/or sub-directory paths for more
    23 	elaborate pattern matching.
    24 ]]
    25 
    26 -- find_dependency_dir_windows(env, main_search_path, main_dir_path)
    27 --   Attempt to resolve a dependency (true or false) folder based on either an
    28 --   environmental variable, start search path, or both. If both are present,
    29 --   the environmental variable will be preferred. If neither are present, this
    30 --   function returns false.
    31 --
    32 --   Arguments:
    33 --     env                The name of the environmental variable to treat as a path
    34 --     main_search_paths  Paths to look for the main directory in
    35 --     main_dir_path      The a path that must be contained between main_search_path and sub_dir_path
    36 --     sub_dir_path       The path of the directories that should exist at the searched path
    37 function find_dependency_dir_windows(env, main_search_paths, main_dir_path, sub_dir_path)
    38 	if not os.is("windows") then -- if not windows, then fail
    39 		return false
    40 	end
    41 	if env == nil and (main_search_paths == nil or #main_search_paths == 0) then
    42 		return false
    43 	end
    44 	local env_path = nil
    45 	local main_path = nil
    46 	if env ~= nil then env_path = os.getenv(env) end
    47 	local search_table = { n = 0 }
    48 	if main_search_paths ~= nil then
    49 		for k,main_search_path in ipairs(explode(main_search_paths, ";")) do
    50 			local directories = os.matchdirs(main_search_path .. "/**" .. main_dir_path .. "*")
    51 			for k,v in pairs(directories) do
    52 				table.insert(search_table, v)
    53 			end
    54 		end
    55 	end
    56 	if env_path ~= nil then table.insert(search_table, env_path) end
    57 	local search_path = table.concat(search_table, ";")
    58 	local result_path = os.dirpathsearch(sub_dir_path, search_path, ";")
    59 	if result_path == nil then
    60 		return false
    61 	end
    62 	local found_dir = os.isdir(result_path)
    63 	local abs_path = path.getabsolute(result_path)
    64 	if found_dir and env_path ~= nil then
    65 		abs_path = abs_path:gsub("\\", "/")
    66 		env_path = env_path:gsub("\\", "/")
    67 		local pos = abs_path:indexOf(env_path)
    68 		if pos ~= nil then
    69 			abs_path = abs_path:sub(1, pos - 1) .. "$(" .. env .. ")/" .. abs_path:sub(pos + #env_path)
    70 		end
    71 	end
    72 	-- we want the path in terms of '/'
    73 	return found_dir, abs_path
    74 end