function code_chart_header_file_custom_dll_target(fileNameInfo,...
chart)

% Copyright 2020 The MathWorks, Inc.

chartNumber = sf('get',chart,'chart.number');
headerFileName = fullfile(fileNameInfo.targetDirName,fileNameInfo.chartHeaderFiles{chartNumber+1});
sf_echo_generating('Coder',headerFileName);
chartUniqueName = sf('CodegenNameOf',chart);

file = fopen(headerFileName,'Wt');
if file<3
construct_coder_error([],sprintf('Failed to create file: %s.',headerFileName),1);
return;
end

global gChartInfo %#ok<GVMIS>
hasInput = numel(gChartInfo.chartInputData) > 0;
hasOutput = numel(gChartInfo.chartOutputData) > 0;

fprintf(file,'%s\n',get_boiler_plate_comment('chart',chart));
fprintf(file,'#ifndef __%s_h__\n',chartUniqueName);
fprintf(file,'#define __%s_h__\n',chartUniqueName);
fprintf(file,'\n');

fprintf(file,'#include "tmwtypes.h"\n');

fprintf(file,'#ifdef _MSC_VER\n');
fprintf(file,'#define SLTEST_DLL_EXPORT_SYM __declspec(dllexport)\n');
fprintf(file,'#define SLTEST_DLL_IMPORT_SYM __declspec(dllimport)\n');
fprintf(file,'#elif __GNUC__ >= 4\n');
fprintf(file,'#define SLTEST_DLL_EXPORT_SYM __attribute__ ((visibility("default")))\n');
fprintf(file,'#define SLTEST_DLL_IMPORT_SYM __attribute__ ((visibility("default")))\n');
fprintf(file,'#else\n');
fprintf(file,'#define SLTEST_DLL_EXPORT_SYM\n');
fprintf(file,'#define SLTEST_DLL_IMPORT_SYM\n');
fprintf(file,'#endif\n');

fprintf(file,'#if defined(SLTEST_BUILDING_SEQUENCE)\n');
fprintf(file,'#define SLTEST_PUBLISHED_API SLTEST_DLL_EXPORT_SYM\n');
fprintf(file,'#else\n');
fprintf(file,'#define SLTEST_PUBLISHED_API SLTEST_DLL_IMPORT_SYM\n');
fprintf(file,'#endif\n');

fprintf(file,'#ifdef __cplusplus\n');
fprintf(file,'extern "C" {\n');
fprintf(file,'#endif\n');
file = dump_module(headerFileName,file,chart,'header');
if file < 3
return;
end

fprintf(file,'SLTEST_PUBLISHED_API void sltest_realtime_dll_initializer(void *,void *,double);\n');
fprintf(file,'SLTEST_PUBLISHED_API void sltest_realtime_dll_step(void *,void *,double);\n');

fprintf(file,'#ifdef __cplusplus\n');
fprintf(file,'}\n');
fprintf(file,'#endif\n');
fprintf(file,'\n');
fprintf(file,'#endif\n');
fprintf(file,'\n');
fclose(file);
try_indenting_file(headerFileName);

% we need to generate the external interface header file valid for
% all scenarios just once. In the absence of scenarios, just do it for
% the main chart.
if(Stateflow.STT.Utils.ScenarioCodegenHelper.chart_has_scenarios(chart))
[~,activeScenarioIndex] = Stateflow.STT.Utils.ScenarioCodegenHelper.get_active_scenario_state(chart);
if(activeScenarioIndex~=1)
return;
end
end

templateDirectory = fullfile(matlabroot,'toolbox','simulinktest','realtime','dynamic_testsequence');

templaceSourceFileName = fullfile(templateDirectory,'SLTestSequenceDllInterface.cpp');
interfaceSourceFileName = fullfile(fileNameInfo.targetDirName,fileNameInfo.interfaceSourceFileName);
copyfile(templaceSourceFileName,interfaceSourceFileName);

templateHeaderFileName = fullfile(templateDirectory,fileNameInfo.interfaceHeaderFileName);
templateHeaderFileText = sfprivate('file2str',templateHeaderFileName);
interfaceHeaderFileName = fullfile(fileNameInfo.targetDirName,fileNameInfo.interfaceHeaderFileName);

typeDumpText = get_type_dump_text(interfaceHeaderFileName,chart);

if hasInput
globalInputStructDecl = sprintf('EXTERN_DECL SF%sInputDataStruct gChartInputData;',chartUniqueName);
typeDumpText = [typeDumpText, 10, globalInputStructDecl, 10];
hasInputDefine = sprintf('#define SEQUENCE_HAS_INPUTS 1');
typeDumpText = [typeDumpText, hasInputDefine, 10];
end

if hasOutput
globalOutputStructDecl = sprintf('EXTERN_DECL SF%sOutputDataStruct gChartOutputData;',chartUniqueName);
typeDumpText = [typeDumpText, 10, globalOutputStructDecl, 10];
hasOutputDefine = sprintf('#define SEQUENCE_HAS_OUTPUTS 1');
typeDumpText = [typeDumpText, hasOutputDefine, 10];
end

filledHeaderFileText = strrep(templateHeaderFileText,...
'/* REPLACE WITH TYPE INFO FROM THE SEQUENCE CHART */',...
typeDumpText);

sf_echo_generating('Coder',interfaceHeaderFileName);
sfprivate('str2file',filledHeaderFileText,interfaceHeaderFileName);

try_indenting_file(interfaceHeaderFileName);

return;

end

function typeDumpText = get_type_dump_text(fileName,chart)

file = fopen(fileName,'Wt');
if file<3
construct_coder_error([],sprintf('Failed to create file: %s.',fileName),1);
return;
end

file = dump_types(fileName,file,chart,'header');
if file < 3
return;
end
fclose(file);
typeDumpText = sfprivate('file2str',fileName);
end