premake/util/sdl_depends.lua
changeset 7925 f090a47eb7f7
child 8149 681eb46b8ac4
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/premake/util/sdl_depends.lua	Sun Nov 10 00:38:37 2013 -0500
     1.3 @@ -0,0 +1,74 @@
     1.4 +-- Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
     1.5 +--
     1.6 +-- This software is provided 'as-is', without any express or implied
     1.7 +-- warranty.  In no event will the authors be held liable for any damages
     1.8 +-- arising from the use of this software.
     1.9 +--
    1.10 +-- Permission is granted to anyone to use this software for any purpose,
    1.11 +-- including commercial applications, and to alter it and redistribute it
    1.12 +-- freely.
    1.13 +--
    1.14 +-- Meta-build system using premake created and maintained by
    1.15 +-- Benjamin Henning <b.henning@digipen.edu>
    1.16 +
    1.17 +-- This is kept just for windows because the other platforms use different means
    1.18 +-- for determining dependence or compatibility.
    1.19 +
    1.20 +--[[
    1.21 +sdl_depends.lua
    1.22 +
    1.23 +	This file simply contains a function for determining whether a dependency
    1.24 +	exists on the Windows platform, given a possible environmental variable,
    1.25 +	delimited search paths, and a main and/or sub-directory paths for more
    1.26 +	elaborate pattern matching.
    1.27 +]]
    1.28 +
    1.29 +-- find_dependency_dir_windows(env, main_search_path, main_dir_path)
    1.30 +--   Attempt to resolve a dependency (true or false) folder based on either an
    1.31 +--   environmental variable, start search path, or both. If both are present,
    1.32 +--   the environmental variable will be preferred. If neither are present, this
    1.33 +--   function returns false.
    1.34 +--
    1.35 +--   Arguments:
    1.36 +--     env                The name of the environmental variable to treat as a path
    1.37 +--     main_search_paths  Paths to look for the main directory in
    1.38 +--     main_dir_path      The a path that must be contained between main_search_path and sub_dir_path
    1.39 +--     sub_dir_path       The path of the directories that should exist at the searched path
    1.40 +function find_dependency_dir_windows(env, main_search_paths, main_dir_path, sub_dir_path)
    1.41 +	if not os.is("windows") then -- if not windows, then fail
    1.42 +		return false
    1.43 +	end
    1.44 +	if env == nil and (main_search_paths == nil or #main_search_paths == 0) then
    1.45 +		return false
    1.46 +	end
    1.47 +	local env_path = nil
    1.48 +	local main_path = nil
    1.49 +	if env ~= nil then env_path = os.getenv(env) end
    1.50 +	local search_table = { n = 0 }
    1.51 +	if main_search_paths ~= nil then
    1.52 +		for k,main_search_path in ipairs(explode(main_search_paths, ";")) do
    1.53 +			local directories = os.matchdirs(main_search_path .. "/**" .. main_dir_path .. "*")
    1.54 +			for k,v in pairs(directories) do
    1.55 +				table.insert(search_table, v)
    1.56 +			end
    1.57 +		end
    1.58 +	end
    1.59 +	if env_path ~= nil then table.insert(search_table, env_path) end
    1.60 +	local search_path = table.concat(search_table, ";")
    1.61 +	local result_path = os.dirpathsearch(sub_dir_path, search_path, ";")
    1.62 +	if result_path == nil then
    1.63 +		return false
    1.64 +	end
    1.65 +	local found_dir = os.isdir(result_path)
    1.66 +	local abs_path = path.getabsolute(result_path)
    1.67 +	if found_dir and env_path ~= nil then
    1.68 +		abs_path = abs_path:gsub("\\", "/")
    1.69 +		env_path = env_path:gsub("\\", "/")
    1.70 +		local pos = abs_path:indexOf(env_path)
    1.71 +		if pos ~= nil then
    1.72 +			abs_path = abs_path:sub(1, pos - 1) .. "$(" .. env .. ")/" .. abs_path:sub(pos + #env_path)
    1.73 +		end
    1.74 +	end
    1.75 +	-- we want the path in terms of '/'
    1.76 +	return found_dir, abs_path
    1.77 +end
    1.78 \ No newline at end of file