Browse Source

Fix encoding issues when generating the makedep file

In some cases the input will be parsed as UTF-8 and converted
to "characters" and in others it won't and will be processed
as bytes (for example, `erl -oldshell` will do that). This means
that encoding-dependent characters such as "é" only need to be
converted to binary in the former case.

To detect which situation we are in we check what the value of
"é" is. If it is [233] then the eval input was parsed as UTF-8
and converted to characters. Otherwise we assume it wasn't.
Loïc Hoguin 5 years ago
parent
commit
44b3c70a9e
1 changed files with 7 additions and 2 deletions
  1. 7 2
      core/erlc.mk

+ 7 - 2
core/erlc.mk

@@ -256,11 +256,16 @@ define makedep.erl
 				string:join(DirSubname ++ [atom_to_list(Target)], "/")
 		end
 	end,
-	ok = file:write_file("$(1)", unicode:characters_to_binary([
+	Output0 = [
 		"# Generated by Erlang.mk. Edit at your own risk!\n\n",
 		[[F, "::", [[" ", D] || D <- Deps], "; @touch \$$@\n"] || {F, Deps} <- Depend],
 		"\nCOMPILE_FIRST +=", [[" ", TargetPath(CF)] || CF <- CompileFirst], "\n"
-	])),
+	],
+	Output = case "é" of
+		[233] -> unicode:characters_to_binary(Output0);
+		_ -> Output0
+	end,
+	ok = file:write_file("$(1)", Output),
 	halt()
 endef