package("libsdl_gfx") add_deps("libsdl") on_load(function(package) package:add("includedirs", "include") end) set_homepage("https://www.ferzkopp.net/wordpress/2016/01/02/sdl_gfx-sdl2_gfx/") set_description("Simple DirectMedia Layer primitives drawing library") if is_plat("windows") then set_urls("https://www.ferzkopp.net/Software/SDL2_gfx/SDL2_gfx-$(version).zip") add_versions("1.0.4", "b6da07583b7fb8f4d8cee97cac9176b97a287f56a8112e22f38183ecf47b9dcb") elseif is_plat("macosx", "linux") then set_urls("https://www.ferzkopp.net/Software/SDL2_gfx/SDL2_gfx-$(version).tar.gz") add_versions("1.0.4", "63e0e01addedc9df2f85b93a248f06e8a04affa014a835c2ea34bfe34e576262") end add_links("SDL2_gfx") on_install("windows", function(package) local file_name = "SDL2_gfx.vcxproj" local inf = io.open(file_name, 'r') local lines = "" local line_count = 1 while(true) do local line = inf:read("*line") if not line then break end lines = lines .. line .. "\n" if line_count == 11 then lines = lines .. "Debugx64\n" lines = lines .. "Releasex64\n" elseif line_count == 30 then lines = lines .. "DynamicLibraryUnicodetruev141\n" lines = lines .. "DynamicLibraryUnicodev141\n" elseif line_count == 39 then lines = lines .. "\n" lines = lines .. "\n" elseif line_count == 48 then lines = lines .. "$(Platform)\\$(Configuration)\\$(Platform)\\$(Configuration)\\true\n" lines = lines .. "$(Platform)\\$(Configuration)\\$(Platform)\\$(Configuration)\\false\n" elseif line_count == 106 then lines = lines .. "Disabled..\\SDL2-2.0.5\\include;%(AdditionalIncludeDirectories)WIN32;_DEBUG;_WINDOWS;_USRDLL;DLL_EXPORT;USE_MMX;%(PreprocessorDefinitions)trueEnableFastChecksMultiThreadedDebugDLLLevel3EditAndContinueSDL2.lib;%(AdditionalDependencies)..\\SDL2-2.0.5\\VisualC\\$(Platform)\\$(Configuration);%(AdditionalLibraryDirectories)trueWindowsfalseMachineX64\n" lines = lines .. "MaxSpeed..\\SDL2-2.0.5\\include;%(AdditionalIncludeDirectories)trueWIN32;_DEBUG;_WINDOWS;_USRDLL;DLL_EXPORT;%(PreprocessorDefinitions)MultiThreadedDLLtrueLevel3ProgramDatabaseSDL2.lib;%(AdditionalDependencies)..\\SDL2-2.0.5\\VisualC\\$(Platform)\\$(Configuration);%(AdditionalLibraryDirectories)trueWindowstruetrueMachineX64\n" elseif line_count == 123 then lines = lines .. "true\n" elseif line_count == 127 then lines = lines .. "true\n" end line_count = line_count + 1 end inf:close() io.writefile(file_name, lines) local file_name = "SDL2_gfx.vcxproj" local content = io.readfile(file_name) content = content:gsub("10.0.14393.0", "") content = content:gsub("v141", "v142") content = content:gsub("%%%(AdditionalIncludeDirectories%)", package:dep("libsdl"):installdir("include", "SDL2") .. ";%%%(AdditionalIncludeDirectories%)") content = content:gsub("%%%(AdditionalLibraryDirectories%)", package:dep("libsdl"):installdir("lib") .. ";%%%(AdditionalLibraryDirectories%)") io.writefile(file_name, content) local file_name = "SDL2_gfx.sln" local inf = io.open(file_name, 'r') local lines = "" local line_count = 1 while(true) do local line = inf:read("*line") if not line then break end lines = lines .. line .. "\n" if line_count == 17 then lines = lines .. "Debug|x64 = Debug|x64\n" lines = lines .. "Release|x64 = Release|x64\n" elseif line_count == 21 then lines = lines .. "\t\t{AE22EFD3-6E6D-48C0-AF3D-EF190406BEDC}.Debug|x64.ActiveCfg = Debug|x64\n\t\t{AE22EFD3-6E6D-48C0-AF3D-EF190406BEDC}.Debug|x64.Build.0 = Debug|x64\n" elseif line_count == 23 then lines = lines .. "\t\t{AE22EFD3-6E6D-48C0-AF3D-EF190406BEDC}.Release|x64.ActiveCfg = Release|x64\n\t\t{AE22EFD3-6E6D-48C0-AF3D-EF190406BEDC}.Release|x64.Build.0 = Release|x64\n" end line_count = line_count + 1 end inf:close() io.writefile(file_name, lines) local configs = {} local build_dir = "" if package:arch() == "x86" then build_dir = "Win32" else build_dir = "x64" end table.insert(configs, "/property:Configuration=Release") table.insert(configs, "/property:Platform=" .. build_dir) table.insert(configs, "-target:SDL2_gfx") import("package.tools.msbuild").build(package, configs) build_dir = path.join(build_dir, "Release") os.cp(path.join(build_dir, "*.lib"), package:installdir("lib")) os.cp(path.join(build_dir, "*.dll"), package:installdir("lib")) os.cp("*.h", package:installdir("include", "SDL2")) end) on_install("macosx", "linux", function (package) local configs = {} if package:config("shared") then table.insert(configs, "--enable-shared=yes") else table.insert(configs, "--enable-shared=no") end table.insert(configs, "--with-sdl-prefix=" .. package:dep("libsdl"):installdir()) import("package.tools.autoconf").install(package, configs) end) on_test(function (package) assert(package:has_cfuncs("aacircleRGBA", {includes = "SDL2/SDL2_gfxPrimitives.h", configs = {defines = "SDL_MAIN_HANDLED"}})) assert(package:has_cfuncs("SDL_initFramerate", {includes = "SDL2/SDL2_framerate.h", configs = {defines = "SDL_MAIN_HANDLED"}})) assert(package:has_cfuncs("rotozoomSurface", {includes = "SDL2/SDL2_rotozoom.h", configs = {defines = "SDL_MAIN_HANDLED"}})) assert(package:has_cfuncs("SDL_imageFilterAdd", {includes = "SDL2/SDL2_imageFilter.h", configs = {defines = "SDL_MAIN_HANDLED"}})) end)