diff --git a/compiler2/makefile.c b/compiler2/makefile.c
index b944e43a717fe457ed7e60201d88fa7160bdf20c..6b80673476aba5b7e64df2f666423255f20273a2 100644
--- a/compiler2/makefile.c
+++ b/compiler2/makefile.c
@@ -3880,6 +3880,48 @@ static void run_makefilegen_commands(struct string2_list* run_command_list)
   }
 }
 
+/** execute makefileScript */
+static void executeMakefileScript(const char* makefileScript, const char* output_file) {
+  char* output_file_name = NULL;
+  if (output_file != NULL) {
+    if (get_path_status(output_file) == PS_DIRECTORY)
+      output_file_name = mprintf("%s/Makefile", output_file);
+    else {
+      output_file_name = mcopystr(output_file);
+    }
+  } else {
+    output_file_name = mcopystr("Makefile");
+  }
+  char* tmp_output_file_name = mprintf("%s.tmp", output_file_name);
+  
+  char* command = mprintf("%s %s %s", makefileScript, output_file_name, tmp_output_file_name);
+  fprintf(stderr, "Executing '%s' command\n", command);
+  int rv = system(command);
+  if (rv) ERROR("MakefileScript execution failed with error code %d", rv);
+  
+  if(access(output_file_name, W_OK) == -1) {
+    ERROR("%s does not exist, needed by makefile modifier script", output_file_name);
+    goto free_str;
+  }
+  if(access(tmp_output_file_name, W_OK) == -1) {
+    ERROR("%s does not exist, needed by makefile modifier script", tmp_output_file_name);
+    goto free_str;
+  }
+  // Replace old file with new
+  rv = rename(tmp_output_file_name, output_file_name);
+  if (rv != 0) {
+    ERROR("Moving makefile contents is unsuccessful");
+    goto free_str;
+  }
+  
+  fprintf(stderr, "makefile modifier script executed successfully.\n");
+ 
+free_str:
+  Free(output_file_name);
+  Free(tmp_output_file_name);
+  Free(command);
+}
+
 /** create symlinks and delete list */
 static void generate_symlinks(struct string2_list* create_symlink_list)
 {
@@ -4215,6 +4257,7 @@ int main(int argc, char *argv[])
   struct string2_list* target_placement_list = NULL;
   struct string2_list* run_command_list = NULL;
   struct string2_list* required_configs = NULL;
+  char* makefileScript = NULL;
 
 #ifdef LICENSE
   license_struct lstr;
@@ -4595,7 +4638,7 @@ int main(int argc, char *argv[])
       &quflag, &dsflag, &cxxcompiler, &optlevel, &optflags, &dbflag, &drflag, &dtflag, &dxflag, &djflag, &fxflag, &doflag, &gfflag, &lnflag, &isflag,
       &asflag, &temp_wflag, &Yflag, &Mflag, &Eflag, &nflag, &diflag, solspeclibraries, sol8speclibraries, linuxspeclibraries, freebsdspeclibraries, win32speclibraries, &ttcn3prep,
       linkerlibraries, additionalObjects, linkerlibsearchpath, Vflag, Dflag, &Zflag, &Hflag,
-      &generatorCommandOutput, target_placement_list, Wflag, run_command_list, required_configs, &profiled_file_list, search_paths, n_search_paths);
+      &generatorCommandOutput, target_placement_list, Wflag, run_command_list, required_configs, &profiled_file_list, search_paths, n_search_paths, &makefileScript);
     
     // wflag overrides temp_wflag
     if (!wflag) {
@@ -4640,6 +4683,9 @@ int main(int argc, char *argv[])
       drflag, dtflag, dxflag, djflag, fxflag, doflag, gfflag, lnflag, isflag, asflag, wflag, Yflag, Mflag, Eflag, nflag, diflag, solspeclibraries,
       sol8speclibraries, linuxspeclibraries, freebsdspeclibraries, win32speclibraries, ttcn3prep, linkerlibraries, additionalObjects,
       linkerlibsearchpath, generatorCommandOutput, target_placement_list);
+    if (makefileScript != NULL) {
+      executeMakefileScript(makefileScript, output_file);
+    }
   }
 
   free_string_list(sub_project_dirs);
@@ -4664,6 +4710,7 @@ int main(int argc, char *argv[])
   Free(generatorCommandOutput);
   free_string2_list(target_placement_list);
   free_string2_list(required_configs);
+  Free(makefileScript);
 
   Free(other_files);
   if (tpd_processed == TPD_SUCCESS) {
diff --git a/compiler2/xpather.cc b/compiler2/xpather.cc
index d1cbef00863a87feae76305836f832676cdb2823..005fe3abbcf0dc8b2d8644f7924473d6382c502a 100644
--- a/compiler2/xpather.cc
+++ b/compiler2/xpather.cc
@@ -1218,7 +1218,7 @@ static tpd_result process_tpd_internal(const char *p_tpd_name, char* tpdName, co
   struct string_list* linkerlibs, struct string_list* additionalObjects, struct string_list* linkerlibsearchp, boolean Vflag, boolean Dflag,
   boolean *p_Zflag, boolean *p_Hflag, char** generatorCommandOutput, struct string2_list* target_placement_list, boolean prefix_workdir, 
   struct string2_list* run_command_list, map<cstring, int>& seen_tpd_files, struct string2_list* required_configs, struct string_list** profiled_file_list,
-  const char **search_paths, size_t n_search_paths, struct config_struct * const all_configs);
+  const char **search_paths, size_t n_search_paths, char** makefileScript, struct config_struct * const all_configs);
 
 extern "C" tpd_result process_tpd(const char *p_tpd_name, const char *actcfg,
   const char *file_list_path, int *p_argc, char ***p_argv,
@@ -1238,7 +1238,7 @@ extern "C" tpd_result process_tpd(const char *p_tpd_name, const char *actcfg,
   string_list* linkerlibs, string_list* additionalObjects, string_list* linkerlibsearchp, boolean Vflag, boolean Dflag, boolean *p_Zflag,
   boolean *p_Hflag, char** generatorCommandOutput, struct string2_list* target_placement_list, boolean prefix_workdir,
   struct string2_list* run_command_list, struct string2_list* required_configs, struct string_list** profiled_file_list,
-  const char **search_paths, size_t n_search_paths) {
+  const char **search_paths, size_t n_search_paths, char** makefileScript) {
 
   map<cstring, int> seen_tpd_files;
   char *tpdName = NULL;
@@ -1267,7 +1267,7 @@ extern "C" tpd_result process_tpd(const char *p_tpd_name, const char *actcfg,
       linkerlibs, additionalObjects, linkerlibsearchp, Vflag, Dflag, p_Zflag,
       p_Hflag, generatorCommandOutput, target_placement_list, prefix_workdir, 
       run_command_list, seen_tpd_files, required_configs, profiled_file_list,
-      search_paths, n_search_paths, all_configs);
+      search_paths, n_search_paths, makefileScript, all_configs);
   
   if (success == TPD_SUCCESS) {
     struct config_list* tmp_configs = NULL;
@@ -1295,7 +1295,7 @@ extern "C" tpd_result process_tpd(const char *p_tpd_name, const char *actcfg,
       linkerlibs, additionalObjects, linkerlibsearchp, Vflag, Dflag, p_Zflag,
       p_Hflag, generatorCommandOutput, target_placement_list, prefix_workdir, 
       run_command_list, seen_tpd_files, required_configs, profiled_file_list,
-      search_paths, n_search_paths, all_configs);
+      search_paths, n_search_paths, makefileScript, all_configs);
   }
   if (TPD_FAILED == success){
     exit(EXIT_FAILURE);
@@ -1347,7 +1347,7 @@ static tpd_result process_tpd_internal(const char *p_tpd_name, char *tpdName, co
   string_list* linkerlibs, string_list* additionalObjects, string_list* linkerlibsearchp, boolean Vflag, boolean Dflag, boolean *p_Zflag,
   boolean *p_Hflag, char** generatorCommandOutput, struct string2_list* target_placement_list, boolean prefix_workdir,
   struct string2_list* run_command_list, map<cstring, int>& seen_tpd_files, struct string2_list* required_configs, struct string_list** profiled_file_list,
-  const char **search_paths, size_t n_search_paths, struct config_struct * const all_configs)
+  const char **search_paths, size_t n_search_paths, char** makefileScript, struct config_struct * const all_configs)
 {
   tpd_result result = TPD_SUCCESS;
   // read-only non-pointer aliases
@@ -1933,6 +1933,27 @@ static tpd_result process_tpd_internal(const char *p_tpd_name, char *tpdName, co
       }
     }
   }
+  
+  // Extract the makefileScript only for top level
+  // In the recursive case the subsequent makefile calls will process the 
+  // makefileScript
+  if (local_argc != 0)
+  {
+    char *makefileScriptXpath = mprintf(
+      "/TITAN_Project_File_Information/Configurations/Configuration[@name='%s']"
+      "/ProjectProperties/LocalBuildSettings/MakefileScript/text()",
+      actcfg);
+    XPathObject makefileScriptObj(run_xpath(xpathCtx, makefileScriptXpath));
+    Free(makefileScriptXpath);
+    if (makefileScriptObj->nodesetval && makefileScriptObj->nodesetval->nodeNr > 0) {
+      const char* file_path = (const char*)makefileScriptObj->nodesetval->nodeTab[0]->content;
+      expstring_t rel_file_dir = get_dir_from_path(file_path);
+      expstring_t file_name = get_file_from_path(file_path);
+      expstring_t abs_dir_path = get_absolute_dir(rel_file_dir, abs_tpd_dir, TRUE);
+      expstring_t abs_file_name = compose_path_name(abs_dir_path, file_name);
+      *makefileScript = mcopystr(abs_file_name);
+    }
+  }
 
   // Extract the default target option
   // if it is not defined as a command line argument
@@ -2826,7 +2847,7 @@ static tpd_result process_tpd_internal(const char *p_tpd_name, char *tpdName, co
           solspeclibs, sol8speclibs, linuxspeclibs, freebsdspeclibs, win32speclibs,
           ttcn3prep, linkerlibs, additionalObjects, linkerlibsearchp, Vflag, FALSE, &my_Zflag, 
           &my_Hflag, NULL, NULL, prefix_workdir, run_command_list, seen_tpd_files, required_configs, profiled_file_list,
-          search_paths, n_search_paths, all_configs);
+          search_paths, n_search_paths, makefileScript, all_configs);
         
         autostring sub_proj_abs_work_dir_as(sub_proj_abs_work_dir); // ?!
 
diff --git a/compiler2/xpather.h b/compiler2/xpather.h
index b54b37324fe422d11654cd0e8c79a8780c6759fd..860e7644fb3b73e6ac11ad6a83ce5b4f60efe447 100644
--- a/compiler2/xpather.h
+++ b/compiler2/xpather.h
@@ -246,6 +246,7 @@ void free_string2_list(struct string2_list* act_elem);
  * @param run_command_list contains the working directories and the makefilegen commands to be called there
  * @param search_paths contains the paths that can be tried if a file is not found
  * @param n_search_paths contains the size of relative_prefixes
+ * @param makefileScript contains the script that can modify the makefile
  * @return TPD_SUCCESS if parsing successful, TPD_SKIPPED if the tpd
  *         was seen already, or TPD_FAILED on error.
  */
@@ -275,6 +276,6 @@ tpd_result process_tpd(const char *p_tpd_name, const char *actcfg,
   struct string_list* linuxspeclibs, struct string_list* freebsdspeclibs, struct string_list* win32speclibs,
   char** ttcn3preprocessor, struct string_list* linkerlibs, struct string_list* additionalObjects, struct string_list* linkerlibsearchpath, boolean Vflag, boolean Dflag,
   boolean *Zflag, boolean *Hflag, char** generatorCommandOutput, struct string2_list* target_placement_list, boolean prefix_workdir, struct string2_list* run_command_list,
-  struct string2_list* required_configs, struct string_list** profiled_file_list, const char **search_paths, size_t n_search_paths);
+  struct string2_list* required_configs, struct string_list** profiled_file_list, const char **search_paths, size_t n_search_paths, char** makefileScript);
 
 #endif /* XPATHER_H_ */
diff --git a/regression_test/compileonly/mfgen-tpd/Makefile b/regression_test/compileonly/mfgen-tpd/Makefile
index 889a5a2992ad5de0326b92340bfe8ddd758ca0c0..937389b4ffa641ee3e0ac2eba9c809b45e6bf330 100644
--- a/regression_test/compileonly/mfgen-tpd/Makefile
+++ b/regression_test/compileonly/mfgen-tpd/Makefile
@@ -31,7 +31,8 @@ MAKEPROG := ${MAKE}
 
 DIRLIST := buildconfig_param invalid_buildconfig_param invalid_buildconfig_tpd \
 	HP79745 HQ56829 HQ56834 HQ56848 library HR30356 flagTest HR30365 dependency_check \
-	required_config required_config_v2 required_config_v3 disablePredefinedExternalFolder
+	required_config required_config_v2 required_config_v3 disablePredefinedExternalFolder \
+	makefileScript
 
 # The default target.
 ifeq ($(findstring c,$(MFGEN_FLAGS)),) # no -c
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/ImprovedLinking/Makefile b/regression_test/compileonly/mfgen-tpd/makefileScript/ImprovedLinking/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..92e3effb163d53a52ed7efab41e239fcf896d040
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/ImprovedLinking/Makefile
@@ -0,0 +1,45 @@
+##############################################################################
+# Copyright (c) 2000-2016 Ericsson Telecom AB
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#   Szabo, Bence Janos
+#
+##############################################################################
+TOPDIR := ../../../..
+include $(TOPDIR)/Makefile.regression
+
+ifdef LCOV
+COVERAGE_FLAG := -C
+endif
+
+# ${MAKEPROG} has the same content as the built-in ${MAKE},
+# except the special handling of ${MAKE} does not apply.
+# If we used ${MAKE} in the rules below, 'make -n' would succeed once,
+# then fail on every subsequent invocation until a 'make clean' is done. 
+
+
+MAKEPROG := ${MAKE}
+
+all: CheckTpd
+
+BuildTpd:
+	$(TTCN3_DIR)/bin/ttcn3_makefilegen -F $(MFGEN_FLAGS) $(COVERAGE_FLAG) \
+	-t a.tpd -WrZH
+
+CheckTpd: BuildTpd
+	if [ ! -f "./a_bin/Makefile" ] || [ `grep -c "SCRIPTFLAG=ImprovedLinkingA" ./a_bin/Makefile` -lt 1 ]; \
+	then echo "Makefilegen MakefileScript test ImprovedLinking failed: Overall verdict: fail" && exit 1; fi
+	if [ ! -f "./b_bin/Makefile" ] || [ `grep -c "SCRIPTFLAG=ImprovedLinkingB" ./b_bin/Makefile` -lt 1 ]; \
+	then echo "Makefilegen MakefileScript test ImprovedLinking failed: Overall verdict: fail" && exit 1; fi
+
+clean:
+	-rm -rf a_bin b_bin
+
+distclean: clean
+	-rm -f *.out
+
+.PHONY: all clean distclean BuildTpd CheckTpd
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/ImprovedLinking/Scripts/a_command.sh b/regression_test/compileonly/mfgen-tpd/makefileScript/ImprovedLinking/Scripts/a_command.sh
new file mode 100755
index 0000000000000000000000000000000000000000..f314fd7b8a2b1e4551bfda5776890a543be81c81
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/ImprovedLinking/Scripts/a_command.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+editcmd='/COMPILER_FLAGS/a SCRIPTFLAG=ImprovedLinkingA'
+
+sed -e "$editcmd" <$1 >$2
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/ImprovedLinking/Scripts/b_command.sh b/regression_test/compileonly/mfgen-tpd/makefileScript/ImprovedLinking/Scripts/b_command.sh
new file mode 100755
index 0000000000000000000000000000000000000000..33bba0e10d719b8f5bc2b306df3d208f368da519
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/ImprovedLinking/Scripts/b_command.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+editcmd='/COMPILER_FLAGS/a SCRIPTFLAG=ImprovedLinkingB'
+
+sed -e "$editcmd" <$1 >$2
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/ImprovedLinking/a.tpd b/regression_test/compileonly/mfgen-tpd/makefileScript/ImprovedLinking/a.tpd
new file mode 100644
index 0000000000000000000000000000000000000000..a292e9d3243810272b7fea9564f341dff2b8934a
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/ImprovedLinking/a.tpd
@@ -0,0 +1,32 @@
+<!--
+ Copyright (c) 2000-2016 Ericsson Telecom AB
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+  Szabo, Bence Janos – initial implementation
+-->
+<TITAN_Project_File_Information version="1.0">
+  <ProjectName>a</ProjectName>
+    <ReferencedProjects>
+    <ReferencedProject name="b" projectLocationURI="b.tpd"/>
+  </ReferencedProjects>
+  <ActiveConfiguration>Default</ActiveConfiguration>
+  <Configurations>
+    <Configuration name="Default">
+      <ProjectProperties>
+        <MakefileSettings>
+          <GNUMake>true</GNUMake>
+          <targetExecutable>bin</targetExecutable>
+          <disablePredefinedExternalFolder>false</disablePredefinedExternalFolder>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <MakefileScript>Scripts/a_command.sh</MakefileScript>
+          <workingDirectory>bin</workingDirectory>
+        </LocalBuildSettings>
+      </ProjectProperties>
+    </Configuration>
+  </Configurations>
+</TITAN_Project_File_Information>
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/ImprovedLinking/b.tpd b/regression_test/compileonly/mfgen-tpd/makefileScript/ImprovedLinking/b.tpd
new file mode 100644
index 0000000000000000000000000000000000000000..0c972d4820626f58925706a8399ce6155fa0695e
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/ImprovedLinking/b.tpd
@@ -0,0 +1,29 @@
+<!--
+ Copyright (c) 2000-2016 Ericsson Telecom AB
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+  Szabo, Bence Janos – initial implementation
+-->
+<TITAN_Project_File_Information version="1.0">
+  <ProjectName>b</ProjectName>
+  <ActiveConfiguration>Default</ActiveConfiguration>
+  <Configurations>
+    <Configuration name="Default">
+      <ProjectProperties>
+        <MakefileSettings>
+          <GNUMake>true</GNUMake>
+          <targetExecutable>bin</targetExecutable>
+          <disablePredefinedExternalFolder>false</disablePredefinedExternalFolder>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <MakefileScript>Scripts/b_command.sh</MakefileScript>
+          <workingDirectory>bin</workingDirectory>
+        </LocalBuildSettings>
+      </ProjectProperties>
+    </Configuration>
+  </Configurations>
+</TITAN_Project_File_Information>
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/Makefile b/regression_test/compileonly/mfgen-tpd/makefileScript/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..fa86ecf67b64cd845f318b1556e1d99927f8ee6b
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/Makefile
@@ -0,0 +1,24 @@
+##############################################################################
+# Copyright (c) 2000-2016 Ericsson Telecom AB
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#   Szabo, Bence Janos – initial implementation
+#
+##############################################################################
+TOPDIR := ../../..
+include $(TOPDIR)/Makefile.regression
+
+CODIRS := Normal WithReqConfig WithMakefileName WithMakefileDir \
+		WithMakefilePath WithScriptDiffDir RecursiveHierarchy \
+		OneMakefileWithAllFiles ImprovedLinking
+
+
+# All dirs have a test in them. The dir's makefile will check the
+# generated makefile if the script inserted a line into it.
+
+all dep clean distclean:
+	for dir in $(CODIRS); do $(MAKE) -C $$dir $@ || exit; done
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/Normal/Makefile b/regression_test/compileonly/mfgen-tpd/makefileScript/Normal/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..2122fc8d643d8cb0923489b504a7f49e6f198162
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/Normal/Makefile
@@ -0,0 +1,44 @@
+##############################################################################
+# Copyright (c) 2000-2016 Ericsson Telecom AB
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#   Szabo, Bence Janos
+#
+##############################################################################
+TOPDIR := ../../../..
+include $(TOPDIR)/Makefile.regression
+
+ifdef LCOV
+COVERAGE_FLAG := -C
+endif
+
+# ${MAKEPROG} has the same content as the built-in ${MAKE},
+# except the special handling of ${MAKE} does not apply.
+# If we used ${MAKE} in the rules below, 'make -n' would succeed once,
+# then fail on every subsequent invocation until a 'make clean' is done. 
+
+
+MAKEPROG := ${MAKE}
+
+all: CheckTpd
+
+BuildTpd:
+	$(TTCN3_DIR)/bin/ttcn3_makefilegen -f $(MFGEN_FLAGS) $(COVERAGE_FLAG) \
+	-t a.tpd
+
+CheckTpd: BuildTpd
+	if [ ! -f "./bin/Makefile" ] || [ `grep -c "SCRIPTFLAG=Normal" ./bin/Makefile` -lt 1 ]; \
+	then echo "Makefilegen MakefileScript test Normal failed: Overall verdict: fail" && exit 1; fi
+
+clean:
+	-rm -rf bin
+
+distclean: clean
+	-rm -f *.out
+
+.PHONY: all clean distclean BuildTpd CheckTpd
+
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/Normal/a.tpd b/regression_test/compileonly/mfgen-tpd/makefileScript/Normal/a.tpd
new file mode 100644
index 0000000000000000000000000000000000000000..ab0a45b79f3a3263c30e3ee9b4dd6798ddf71a11
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/Normal/a.tpd
@@ -0,0 +1,29 @@
+<!--
+ Copyright (c) 2000-2016 Ericsson Telecom AB
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+  Szabo, Bence Janos – initial implementation
+-->
+<TITAN_Project_File_Information version="1.0">
+  <ProjectName>a</ProjectName>
+  <ActiveConfiguration>Default</ActiveConfiguration>
+  <Configurations>
+    <Configuration name="Default">
+      <ProjectProperties>
+        <MakefileSettings>
+          <GNUMake>true</GNUMake>
+          <targetExecutable>bin</targetExecutable>
+          <disablePredefinedExternalFolder>false</disablePredefinedExternalFolder>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <MakefileScript>command.sh</MakefileScript>
+          <workingDirectory>bin</workingDirectory>
+        </LocalBuildSettings>
+      </ProjectProperties>
+    </Configuration>
+  </Configurations>
+</TITAN_Project_File_Information>
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/Normal/command.sh b/regression_test/compileonly/mfgen-tpd/makefileScript/Normal/command.sh
new file mode 100755
index 0000000000000000000000000000000000000000..e4155ae13afcb3bd55e76cc2afa33d35d04252ce
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/Normal/command.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+editcmd='/COMPILER_FLAGS/a SCRIPTFLAG=Normal'
+
+sed -e "$editcmd" <$1 >$2
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/OneMakefileWithAllFiles/Makefile b/regression_test/compileonly/mfgen-tpd/makefileScript/OneMakefileWithAllFiles/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..7f9d2b5e3171df11f5c9e1a8e5335f7338ef0289
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/OneMakefileWithAllFiles/Makefile
@@ -0,0 +1,43 @@
+##############################################################################
+# Copyright (c) 2000-2016 Ericsson Telecom AB
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#   Szabo, Bence Janos
+#
+##############################################################################
+TOPDIR := ../../../..
+include $(TOPDIR)/Makefile.regression
+
+ifdef LCOV
+COVERAGE_FLAG := -C
+endif
+
+# ${MAKEPROG} has the same content as the built-in ${MAKE},
+# except the special handling of ${MAKE} does not apply.
+# If we used ${MAKE} in the rules below, 'make -n' would succeed once,
+# then fail on every subsequent invocation until a 'make clean' is done. 
+
+
+MAKEPROG := ${MAKE}
+
+all: CheckTpd
+
+BuildTpd:
+	$(TTCN3_DIR)/bin/ttcn3_makefilegen -f $(MFGEN_FLAGS) $(COVERAGE_FLAG) \
+	-t a.tpd
+
+CheckTpd: BuildTpd
+	if [ ! -f "./bin/Makefile" ] || [ `grep -c "SCRIPTFLAG=OneMakefileWithAllFiles" ./bin/Makefile` -lt 1 ]; \
+	then echo "Makefilegen MakefileScript test OneMakefileWithAllFiles failed: Overall verdict: fail" && exit 1; fi
+
+clean:
+	-rm -rf bin
+
+distclean: clean
+	-rm -f *.out
+
+.PHONY: all clean distclean BuildTpd CheckTpd
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/OneMakefileWithAllFiles/Scripts/a_command.sh b/regression_test/compileonly/mfgen-tpd/makefileScript/OneMakefileWithAllFiles/Scripts/a_command.sh
new file mode 100755
index 0000000000000000000000000000000000000000..66452bffe7a401ef4eb92a8bf5d7599b5e5401b3
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/OneMakefileWithAllFiles/Scripts/a_command.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+editcmd='/COMPILER_FLAGS/a SCRIPTFLAG=OneMakefileWithAllFilesA'
+
+sed -e "$editcmd" <$1 >$2
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/OneMakefileWithAllFiles/Scripts/b_command.sh b/regression_test/compileonly/mfgen-tpd/makefileScript/OneMakefileWithAllFiles/Scripts/b_command.sh
new file mode 100755
index 0000000000000000000000000000000000000000..8510fd3ea3ef08f714e9d78d07a46d45f32b1418
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/OneMakefileWithAllFiles/Scripts/b_command.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+editcmd='/COMPILER_FLAGS/a SCRIPTFLAG=OneMakefileWithAllFilesB'
+
+sed -e "$editcmd" <$1 >$2
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/OneMakefileWithAllFiles/a.tpd b/regression_test/compileonly/mfgen-tpd/makefileScript/OneMakefileWithAllFiles/a.tpd
new file mode 100644
index 0000000000000000000000000000000000000000..a292e9d3243810272b7fea9564f341dff2b8934a
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/OneMakefileWithAllFiles/a.tpd
@@ -0,0 +1,32 @@
+<!--
+ Copyright (c) 2000-2016 Ericsson Telecom AB
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+  Szabo, Bence Janos – initial implementation
+-->
+<TITAN_Project_File_Information version="1.0">
+  <ProjectName>a</ProjectName>
+    <ReferencedProjects>
+    <ReferencedProject name="b" projectLocationURI="b.tpd"/>
+  </ReferencedProjects>
+  <ActiveConfiguration>Default</ActiveConfiguration>
+  <Configurations>
+    <Configuration name="Default">
+      <ProjectProperties>
+        <MakefileSettings>
+          <GNUMake>true</GNUMake>
+          <targetExecutable>bin</targetExecutable>
+          <disablePredefinedExternalFolder>false</disablePredefinedExternalFolder>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <MakefileScript>Scripts/a_command.sh</MakefileScript>
+          <workingDirectory>bin</workingDirectory>
+        </LocalBuildSettings>
+      </ProjectProperties>
+    </Configuration>
+  </Configurations>
+</TITAN_Project_File_Information>
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/OneMakefileWithAllFiles/b.tpd b/regression_test/compileonly/mfgen-tpd/makefileScript/OneMakefileWithAllFiles/b.tpd
new file mode 100644
index 0000000000000000000000000000000000000000..0c972d4820626f58925706a8399ce6155fa0695e
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/OneMakefileWithAllFiles/b.tpd
@@ -0,0 +1,29 @@
+<!--
+ Copyright (c) 2000-2016 Ericsson Telecom AB
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+  Szabo, Bence Janos – initial implementation
+-->
+<TITAN_Project_File_Information version="1.0">
+  <ProjectName>b</ProjectName>
+  <ActiveConfiguration>Default</ActiveConfiguration>
+  <Configurations>
+    <Configuration name="Default">
+      <ProjectProperties>
+        <MakefileSettings>
+          <GNUMake>true</GNUMake>
+          <targetExecutable>bin</targetExecutable>
+          <disablePredefinedExternalFolder>false</disablePredefinedExternalFolder>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <MakefileScript>Scripts/b_command.sh</MakefileScript>
+          <workingDirectory>bin</workingDirectory>
+        </LocalBuildSettings>
+      </ProjectProperties>
+    </Configuration>
+  </Configurations>
+</TITAN_Project_File_Information>
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/RecursiveHierarchy/Makefile b/regression_test/compileonly/mfgen-tpd/makefileScript/RecursiveHierarchy/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..f86b14fb617f1a483fcd74d753a943f5f8aac69e
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/RecursiveHierarchy/Makefile
@@ -0,0 +1,45 @@
+##############################################################################
+# Copyright (c) 2000-2016 Ericsson Telecom AB
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#   Szabo, Bence Janos
+#
+##############################################################################
+TOPDIR := ../../../..
+include $(TOPDIR)/Makefile.regression
+
+ifdef LCOV
+COVERAGE_FLAG := -C
+endif
+
+# ${MAKEPROG} has the same content as the built-in ${MAKE},
+# except the special handling of ${MAKE} does not apply.
+# If we used ${MAKE} in the rules below, 'make -n' would succeed once,
+# then fail on every subsequent invocation until a 'make clean' is done. 
+
+
+MAKEPROG := ${MAKE}
+
+all: CheckTpd
+
+BuildTpd:
+	$(TTCN3_DIR)/bin/ttcn3_makefilegen -F $(MFGEN_FLAGS) $(COVERAGE_FLAG) \
+	-t a.tpd -rWc
+
+CheckTpd: BuildTpd
+	if [ ! -f "./a_bin/Makefile" ] || [ `grep -c "SCRIPTFLAG=RecursiveHierarchyA" ./a_bin/Makefile` -lt 1 ]; \
+	then echo "Makefilegen MakefileScript test RecursiveHierarchy failed: Overall verdict: fail" && exit 1; fi
+	if [ ! -f "./b_bin/Makefile" ] || [ `grep -c "SCRIPTFLAG=RecursiveHierarchyB" ./b_bin/Makefile` -lt 1 ]; \
+	then echo "Makefilegen MakefileScript test RecursiveHierarchy failed: Overall verdict: fail" && exit 1; fi
+
+clean:
+	-rm -rf a_bin b_bin
+
+distclean: clean
+	-rm -f *.out
+
+.PHONY: all clean distclean BuildTpd CheckTpd
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/RecursiveHierarchy/Scripts/a_command.sh b/regression_test/compileonly/mfgen-tpd/makefileScript/RecursiveHierarchy/Scripts/a_command.sh
new file mode 100755
index 0000000000000000000000000000000000000000..aacc8b1d8d6195ae640861433e5ee16c0c51acdb
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/RecursiveHierarchy/Scripts/a_command.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+editcmd='/COMPILER_FLAGS/a SCRIPTFLAG=RecursiveHierarchyA'
+
+sed -e "$editcmd" <$1 >$2
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/RecursiveHierarchy/Scripts/b_command.sh b/regression_test/compileonly/mfgen-tpd/makefileScript/RecursiveHierarchy/Scripts/b_command.sh
new file mode 100755
index 0000000000000000000000000000000000000000..1e53bcc1f471acdf0021628e8934e180e89bb63b
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/RecursiveHierarchy/Scripts/b_command.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+editcmd='/COMPILER_FLAGS/a SCRIPTFLAG=RecursiveHierarchyB'
+
+sed -e "$editcmd" <$1 >$2
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/RecursiveHierarchy/a.tpd b/regression_test/compileonly/mfgen-tpd/makefileScript/RecursiveHierarchy/a.tpd
new file mode 100644
index 0000000000000000000000000000000000000000..a292e9d3243810272b7fea9564f341dff2b8934a
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/RecursiveHierarchy/a.tpd
@@ -0,0 +1,32 @@
+<!--
+ Copyright (c) 2000-2016 Ericsson Telecom AB
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+  Szabo, Bence Janos – initial implementation
+-->
+<TITAN_Project_File_Information version="1.0">
+  <ProjectName>a</ProjectName>
+    <ReferencedProjects>
+    <ReferencedProject name="b" projectLocationURI="b.tpd"/>
+  </ReferencedProjects>
+  <ActiveConfiguration>Default</ActiveConfiguration>
+  <Configurations>
+    <Configuration name="Default">
+      <ProjectProperties>
+        <MakefileSettings>
+          <GNUMake>true</GNUMake>
+          <targetExecutable>bin</targetExecutable>
+          <disablePredefinedExternalFolder>false</disablePredefinedExternalFolder>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <MakefileScript>Scripts/a_command.sh</MakefileScript>
+          <workingDirectory>bin</workingDirectory>
+        </LocalBuildSettings>
+      </ProjectProperties>
+    </Configuration>
+  </Configurations>
+</TITAN_Project_File_Information>
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/RecursiveHierarchy/b.tpd b/regression_test/compileonly/mfgen-tpd/makefileScript/RecursiveHierarchy/b.tpd
new file mode 100644
index 0000000000000000000000000000000000000000..0c972d4820626f58925706a8399ce6155fa0695e
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/RecursiveHierarchy/b.tpd
@@ -0,0 +1,29 @@
+<!--
+ Copyright (c) 2000-2016 Ericsson Telecom AB
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+  Szabo, Bence Janos – initial implementation
+-->
+<TITAN_Project_File_Information version="1.0">
+  <ProjectName>b</ProjectName>
+  <ActiveConfiguration>Default</ActiveConfiguration>
+  <Configurations>
+    <Configuration name="Default">
+      <ProjectProperties>
+        <MakefileSettings>
+          <GNUMake>true</GNUMake>
+          <targetExecutable>bin</targetExecutable>
+          <disablePredefinedExternalFolder>false</disablePredefinedExternalFolder>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <MakefileScript>Scripts/b_command.sh</MakefileScript>
+          <workingDirectory>bin</workingDirectory>
+        </LocalBuildSettings>
+      </ProjectProperties>
+    </Configuration>
+  </Configurations>
+</TITAN_Project_File_Information>
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefileDir/Makefile b/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefileDir/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..067d622b36d2930be596b76bc39d8f13cc259a68
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefileDir/Makefile
@@ -0,0 +1,45 @@
+##############################################################################
+# Copyright (c) 2000-2016 Ericsson Telecom AB
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#   Szabo, Bence Janos
+#
+##############################################################################
+TOPDIR := ../../../..
+include $(TOPDIR)/Makefile.regression
+
+ifdef LCOV
+COVERAGE_FLAG := -C
+endif
+
+# ${MAKEPROG} has the same content as the built-in ${MAKE},
+# except the special handling of ${MAKE} does not apply.
+# If we used ${MAKE} in the rules below, 'make -n' would succeed once,
+# then fail on every subsequent invocation until a 'make clean' is done. 
+
+
+MAKEPROG := ${MAKE}
+
+all: CheckTpd
+
+BuildTpd:
+	mkdir tmp; \
+	$(TTCN3_DIR)/bin/ttcn3_makefilegen -f $(MFGEN_FLAGS) $(COVERAGE_FLAG) \
+	-t a.tpd -b 1 -o ../tmp
+	
+CheckTpd: BuildTpd
+	if [ ! -f "./tmp/Makefile" ] || [ `grep -c "SCRIPTFLAG=WithMakefileDir" ./tmp/Makefile` -lt 1 ]; \
+	then echo "Makefilegen MakefileScript test WithMakefileDir failed: Overall verdict: fail" && exit 1; fi
+
+clean:
+	-rm -rf bin1 tmp
+
+distclean: clean
+	-rm -f *.out
+
+.PHONY: all clean distclean BuildTpd CheckTpd
+
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefileDir/a.tpd b/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefileDir/a.tpd
new file mode 100644
index 0000000000000000000000000000000000000000..da4ff8095c2eb4f1e6fecf9025e45c7bfbeef85f
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefileDir/a.tpd
@@ -0,0 +1,41 @@
+<!--
+ Copyright (c) 2000-2016 Ericsson Telecom AB
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+  Szabo, Bence Janos – initial implementation
+-->
+<TITAN_Project_File_Information version="1.0">
+  <ProjectName>a</ProjectName>
+  <ActiveConfiguration>Default</ActiveConfiguration>
+  <Configurations>
+    <Configuration name="Default">
+      <ProjectProperties>
+        <MakefileSettings>
+          <GNUMake>true</GNUMake>
+          <targetExecutable>bin</targetExecutable>
+          <disablePredefinedExternalFolder>false</disablePredefinedExternalFolder>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <workingDirectory>bin</workingDirectory>
+        </LocalBuildSettings>
+      </ProjectProperties>
+    </Configuration>
+    <Configuration name="1">
+      <ProjectProperties>
+        <MakefileSettings>
+          <GNUMake>true</GNUMake>
+          <targetExecutable>bin1</targetExecutable>
+          <disablePredefinedExternalFolder>false</disablePredefinedExternalFolder>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <MakefileScript>command.sh</MakefileScript>
+          <workingDirectory>bin1</workingDirectory>
+        </LocalBuildSettings>
+      </ProjectProperties>
+    </Configuration>
+  </Configurations>
+</TITAN_Project_File_Information>
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefileDir/command.sh b/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefileDir/command.sh
new file mode 100755
index 0000000000000000000000000000000000000000..0c09898ff8fc074183bb307b6f8a8bbde727c405
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefileDir/command.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+editcmd='/COMPILER_FLAGS/a SCRIPTFLAG=WithMakefileDir'
+
+sed -e "$editcmd" <$1 >$2
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefileName/Makefile b/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefileName/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..f5f4a08441f03c1507e753fa818d26c270e80fe0
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefileName/Makefile
@@ -0,0 +1,44 @@
+##############################################################################
+# Copyright (c) 2000-2016 Ericsson Telecom AB
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#   Szabo, Bence Janos
+#
+##############################################################################
+TOPDIR := ../../../..
+include $(TOPDIR)/Makefile.regression
+
+ifdef LCOV
+COVERAGE_FLAG := -C
+endif
+
+# ${MAKEPROG} has the same content as the built-in ${MAKE},
+# except the special handling of ${MAKE} does not apply.
+# If we used ${MAKE} in the rules below, 'make -n' would succeed once,
+# then fail on every subsequent invocation until a 'make clean' is done. 
+
+
+MAKEPROG := ${MAKE}
+
+all: CheckTpd
+
+BuildTpd:
+	$(TTCN3_DIR)/bin/ttcn3_makefilegen -f $(MFGEN_FLAGS) $(COVERAGE_FLAG) \
+	-t a.tpd -b 1 -o NotMakefile
+
+CheckTpd: BuildTpd
+	if [ ! -f "./bin1/NotMakefile" ] || [ `grep -c "SCRIPTFLAG=WithMakefileName" ./bin1/NotMakefile` -lt 1 ]; \
+	then echo "Makefilegen MakefileScript test WithMakefileName failed: Overall verdict: fail" && exit 1; fi
+
+clean:
+	-rm -rf bin1
+
+distclean: clean
+	-rm -f *.out
+
+.PHONY: all clean distclean BuildTpd CheckTpd
+
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefileName/a.tpd b/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefileName/a.tpd
new file mode 100644
index 0000000000000000000000000000000000000000..da4ff8095c2eb4f1e6fecf9025e45c7bfbeef85f
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefileName/a.tpd
@@ -0,0 +1,41 @@
+<!--
+ Copyright (c) 2000-2016 Ericsson Telecom AB
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+  Szabo, Bence Janos – initial implementation
+-->
+<TITAN_Project_File_Information version="1.0">
+  <ProjectName>a</ProjectName>
+  <ActiveConfiguration>Default</ActiveConfiguration>
+  <Configurations>
+    <Configuration name="Default">
+      <ProjectProperties>
+        <MakefileSettings>
+          <GNUMake>true</GNUMake>
+          <targetExecutable>bin</targetExecutable>
+          <disablePredefinedExternalFolder>false</disablePredefinedExternalFolder>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <workingDirectory>bin</workingDirectory>
+        </LocalBuildSettings>
+      </ProjectProperties>
+    </Configuration>
+    <Configuration name="1">
+      <ProjectProperties>
+        <MakefileSettings>
+          <GNUMake>true</GNUMake>
+          <targetExecutable>bin1</targetExecutable>
+          <disablePredefinedExternalFolder>false</disablePredefinedExternalFolder>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <MakefileScript>command.sh</MakefileScript>
+          <workingDirectory>bin1</workingDirectory>
+        </LocalBuildSettings>
+      </ProjectProperties>
+    </Configuration>
+  </Configurations>
+</TITAN_Project_File_Information>
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefileName/command.sh b/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefileName/command.sh
new file mode 100755
index 0000000000000000000000000000000000000000..05ee12cf42572493677fcf169fc4bacc6d873422
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefileName/command.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+editcmd='/COMPILER_FLAGS/a SCRIPTFLAG=WithMakefileName'
+
+sed -e "$editcmd" <$1 >$2
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefilePath/Makefile b/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefilePath/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..516638ad3f944c6aa4034a90bfcc19eec030ecd6
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefilePath/Makefile
@@ -0,0 +1,45 @@
+##############################################################################
+# Copyright (c) 2000-2016 Ericsson Telecom AB
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#   Szabo, Bence Janos
+#
+##############################################################################
+TOPDIR := ../../../..
+include $(TOPDIR)/Makefile.regression
+
+ifdef LCOV
+COVERAGE_FLAG := -C
+endif
+
+# ${MAKEPROG} has the same content as the built-in ${MAKE},
+# except the special handling of ${MAKE} does not apply.
+# If we used ${MAKE} in the rules below, 'make -n' would succeed once,
+# then fail on every subsequent invocation until a 'make clean' is done. 
+
+
+MAKEPROG := ${MAKE}
+
+all: CheckTpd
+
+BuildTpd:
+	mkdir tmp; \
+	$(TTCN3_DIR)/bin/ttcn3_makefilegen -f $(MFGEN_FLAGS) $(COVERAGE_FLAG) \
+	-t a.tpd -b 1 -o ../tmp/NewMakefile
+	
+CheckTpd: BuildTpd
+	if [ ! -f "./tmp/NewMakefile" ] || [ `grep -c "SCRIPTFLAG=WithMakefilePath" ./tmp/NewMakefile` -lt 1 ]; \
+	then echo "Makefilegen MakefileScript test WithMakefilePath failed: Overall verdict: fail" && exit 1; fi
+
+clean:
+	-rm -rf bin1 tmp
+
+distclean: clean
+	-rm -f *.out
+
+.PHONY: all clean distclean BuildTpd CheckTpd
+
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefilePath/a.tpd b/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefilePath/a.tpd
new file mode 100644
index 0000000000000000000000000000000000000000..da4ff8095c2eb4f1e6fecf9025e45c7bfbeef85f
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefilePath/a.tpd
@@ -0,0 +1,41 @@
+<!--
+ Copyright (c) 2000-2016 Ericsson Telecom AB
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+  Szabo, Bence Janos – initial implementation
+-->
+<TITAN_Project_File_Information version="1.0">
+  <ProjectName>a</ProjectName>
+  <ActiveConfiguration>Default</ActiveConfiguration>
+  <Configurations>
+    <Configuration name="Default">
+      <ProjectProperties>
+        <MakefileSettings>
+          <GNUMake>true</GNUMake>
+          <targetExecutable>bin</targetExecutable>
+          <disablePredefinedExternalFolder>false</disablePredefinedExternalFolder>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <workingDirectory>bin</workingDirectory>
+        </LocalBuildSettings>
+      </ProjectProperties>
+    </Configuration>
+    <Configuration name="1">
+      <ProjectProperties>
+        <MakefileSettings>
+          <GNUMake>true</GNUMake>
+          <targetExecutable>bin1</targetExecutable>
+          <disablePredefinedExternalFolder>false</disablePredefinedExternalFolder>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <MakefileScript>command.sh</MakefileScript>
+          <workingDirectory>bin1</workingDirectory>
+        </LocalBuildSettings>
+      </ProjectProperties>
+    </Configuration>
+  </Configurations>
+</TITAN_Project_File_Information>
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefilePath/command.sh b/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefilePath/command.sh
new file mode 100755
index 0000000000000000000000000000000000000000..48758f393fe6d1c19bcbda3279d0591bc344258a
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/WithMakefilePath/command.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+editcmd='/COMPILER_FLAGS/a SCRIPTFLAG=WithMakefilePath'
+
+sed -e "$editcmd" <$1 >$2
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/WithReqConfig/Makefile b/regression_test/compileonly/mfgen-tpd/makefileScript/WithReqConfig/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..8b16f4044f8c1eb53dedc28f23aadad6ebc6599e
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/WithReqConfig/Makefile
@@ -0,0 +1,44 @@
+##############################################################################
+# Copyright (c) 2000-2016 Ericsson Telecom AB
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#   Szabo, Bence Janos
+#
+##############################################################################
+TOPDIR := ../../../..
+include $(TOPDIR)/Makefile.regression
+
+ifdef LCOV
+COVERAGE_FLAG := -C
+endif
+
+# ${MAKEPROG} has the same content as the built-in ${MAKE},
+# except the special handling of ${MAKE} does not apply.
+# If we used ${MAKE} in the rules below, 'make -n' would succeed once,
+# then fail on every subsequent invocation until a 'make clean' is done. 
+
+
+MAKEPROG := ${MAKE}
+
+all: CheckTpd
+
+BuildTpd:
+	$(TTCN3_DIR)/bin/ttcn3_makefilegen -f $(MFGEN_FLAGS) $(COVERAGE_FLAG) \
+	-t a.tpd -b 1
+
+CheckTpd: BuildTpd
+	if [ ! -f "./bin1/Makefile" ] || [ `grep -c "SCRIPTFLAG=WithReqConfig" ./bin1/Makefile` -lt 1 ]; \
+	then echo "Makefilegen MakefileScript test WithReqConfig failed: Overall verdict: fail" && exit 1; fi
+
+clean:
+	-rm -rf bin1
+
+distclean: clean
+	-rm -f *.out
+
+.PHONY: all clean distclean BuildTpd CheckTpd
+
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/WithReqConfig/a.tpd b/regression_test/compileonly/mfgen-tpd/makefileScript/WithReqConfig/a.tpd
new file mode 100644
index 0000000000000000000000000000000000000000..da4ff8095c2eb4f1e6fecf9025e45c7bfbeef85f
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/WithReqConfig/a.tpd
@@ -0,0 +1,41 @@
+<!--
+ Copyright (c) 2000-2016 Ericsson Telecom AB
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+  Szabo, Bence Janos – initial implementation
+-->
+<TITAN_Project_File_Information version="1.0">
+  <ProjectName>a</ProjectName>
+  <ActiveConfiguration>Default</ActiveConfiguration>
+  <Configurations>
+    <Configuration name="Default">
+      <ProjectProperties>
+        <MakefileSettings>
+          <GNUMake>true</GNUMake>
+          <targetExecutable>bin</targetExecutable>
+          <disablePredefinedExternalFolder>false</disablePredefinedExternalFolder>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <workingDirectory>bin</workingDirectory>
+        </LocalBuildSettings>
+      </ProjectProperties>
+    </Configuration>
+    <Configuration name="1">
+      <ProjectProperties>
+        <MakefileSettings>
+          <GNUMake>true</GNUMake>
+          <targetExecutable>bin1</targetExecutable>
+          <disablePredefinedExternalFolder>false</disablePredefinedExternalFolder>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <MakefileScript>command.sh</MakefileScript>
+          <workingDirectory>bin1</workingDirectory>
+        </LocalBuildSettings>
+      </ProjectProperties>
+    </Configuration>
+  </Configurations>
+</TITAN_Project_File_Information>
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/WithReqConfig/command.sh b/regression_test/compileonly/mfgen-tpd/makefileScript/WithReqConfig/command.sh
new file mode 100755
index 0000000000000000000000000000000000000000..47680bd8a426e290d5673fd1399a5105eacfd82e
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/WithReqConfig/command.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+editcmd='/COMPILER_FLAGS/a SCRIPTFLAG=WithReqConfig'
+
+sed -e "$editcmd" <$1 >$2
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/WithScriptDiffDir/Makefile b/regression_test/compileonly/mfgen-tpd/makefileScript/WithScriptDiffDir/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..d52393c98fb2ab0a2b2a5820cc4f84bb27026c89
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/WithScriptDiffDir/Makefile
@@ -0,0 +1,44 @@
+##############################################################################
+# Copyright (c) 2000-2016 Ericsson Telecom AB
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#   Szabo, Bence Janos
+#
+##############################################################################
+TOPDIR := ../../../..
+include $(TOPDIR)/Makefile.regression
+
+ifdef LCOV
+COVERAGE_FLAG := -C
+endif
+
+# ${MAKEPROG} has the same content as the built-in ${MAKE},
+# except the special handling of ${MAKE} does not apply.
+# If we used ${MAKE} in the rules below, 'make -n' would succeed once,
+# then fail on every subsequent invocation until a 'make clean' is done. 
+
+
+MAKEPROG := ${MAKE}
+
+all: CheckTpd
+
+BuildTpd:
+	$(TTCN3_DIR)/bin/ttcn3_makefilegen -f $(MFGEN_FLAGS) $(COVERAGE_FLAG) \
+	-t a.tpd -b 1
+	
+CheckTpd: BuildTpd
+	if [ ! -f "./bin1/Makefile" ] || [ `grep -c "SCRIPTFLAG=WithScriptDiffDir" ./bin1/Makefile` -lt 1 ]; \
+	then echo "Makefilegen MakefileScript test WithScriptDiffDir failed: Overall verdict: fail" && exit 1; fi
+
+clean:
+	-rm -rf bin1
+
+distclean: clean
+	-rm -f *.out
+
+.PHONY: all clean distclean BuildTpd CheckTpd
+
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/WithScriptDiffDir/Script/command.sh b/regression_test/compileonly/mfgen-tpd/makefileScript/WithScriptDiffDir/Script/command.sh
new file mode 100755
index 0000000000000000000000000000000000000000..2bb656b2de684b068a7fc5fe34b596de831b438e
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/WithScriptDiffDir/Script/command.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+editcmd='/COMPILER_FLAGS/a SCRIPTFLAG=WithScriptDiffDir'
+
+sed -e "$editcmd" <$1 >$2
diff --git a/regression_test/compileonly/mfgen-tpd/makefileScript/WithScriptDiffDir/a.tpd b/regression_test/compileonly/mfgen-tpd/makefileScript/WithScriptDiffDir/a.tpd
new file mode 100644
index 0000000000000000000000000000000000000000..6f5d6e890bfcbfb44a7a80a82c0a514c6aee7f82
--- /dev/null
+++ b/regression_test/compileonly/mfgen-tpd/makefileScript/WithScriptDiffDir/a.tpd
@@ -0,0 +1,41 @@
+<!--
+ Copyright (c) 2000-2016 Ericsson Telecom AB
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+  Szabo, Bence Janos – initial implementation
+-->
+<TITAN_Project_File_Information version="1.0">
+  <ProjectName>a</ProjectName>
+  <ActiveConfiguration>Default</ActiveConfiguration>
+  <Configurations>
+    <Configuration name="Default">
+      <ProjectProperties>
+        <MakefileSettings>
+          <GNUMake>true</GNUMake>
+          <targetExecutable>bin</targetExecutable>
+          <disablePredefinedExternalFolder>false</disablePredefinedExternalFolder>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <workingDirectory>bin</workingDirectory>
+        </LocalBuildSettings>
+      </ProjectProperties>
+    </Configuration>
+    <Configuration name="1">
+      <ProjectProperties>
+        <MakefileSettings>
+          <GNUMake>true</GNUMake>
+          <targetExecutable>bin1</targetExecutable>
+          <disablePredefinedExternalFolder>false</disablePredefinedExternalFolder>
+        </MakefileSettings>
+        <LocalBuildSettings>
+          <MakefileScript>Script/command.sh</MakefileScript>
+          <workingDirectory>bin1</workingDirectory>
+        </LocalBuildSettings>
+      </ProjectProperties>
+    </Configuration>
+  </Configurations>
+</TITAN_Project_File_Information>
diff --git a/usrguide/referenceguide.doc b/usrguide/referenceguide.doc
index 9ae39dedb43b55bb49d5490589ff1c84148f4f83..0a3604404866e300a3ff696e024f2fa314733c7a 100644
Binary files a/usrguide/referenceguide.doc and b/usrguide/referenceguide.doc differ