Merge pull request #32 from kwwette/depend-phony

Add -MP option for generating phony targets for all dependencies
This commit is contained in:
Olly Betts 2013-04-15 18:24:38 -07:00
commit 28c033dd90
2 changed files with 24 additions and 2 deletions

View file

@ -5,6 +5,12 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.10 (in progress)
============================
2013-04-08: kwwette
Add -MP option to SWIG for generating phony targets for all dependencies.
- Prevents make from complaining if header files have been deleted before
the dependency file has been updated.
- Modelled on similar option in GCC.
2013-04-09: olly
[PHP] Add missing directorin typemap for char* and char[] which
fixes director_string testcase failure.

View file

@ -107,6 +107,7 @@ static const char *usage2 = (const char *) "\
-MM - List dependencies, but omit files in SWIG library\n\
-MMD - Like `-MD', but omit files in SWIG library\n\
-module <name> - Set module name to <name>\n\
-MP - Generate phony targets for all dependencies\n\
-MT <target> - Set the target of the rule emitted by dependency generation\n\
-nocontract - Turn off contract checking\n\
-nocpperraswarn - Do not treat the preprocessor #error statement as #warning\n\
@ -185,6 +186,7 @@ static int dump_classes = 0;
static int werror = 0;
static int depend = 0;
static int depend_only = 0;
static int depend_phony = 0;
static int memory_debug = 0;
static int allkw = 0;
static DOH *cpps = 0;
@ -712,6 +714,9 @@ void SWIG_getoptions(int argc, char *argv[]) {
} else if (strcmp(argv[i], "-MMD") == 0) {
depend = 2;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-MP") == 0) {
depend_phony = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-MT") == 0) {
Swig_mark_arg(i);
if (argv[i + 1]) {
@ -1101,22 +1106,33 @@ int SWIG_main(int argc, char *argv[], Language *l) {
Printf(f_dependencies_file, "%s: ", outfile);
}
List *files = Preprocessor_depend();
List *phony_targets = NewList();
for (int i = 0; i < Len(files); i++) {
int use_file = 1;
if (depend == 2) {
if ((Strncmp(Getitem(files, i), SwigLib, Len(SwigLib)) == 0) || (SwigLibWinUnix && (Strncmp(Getitem(files, i), SwigLibWinUnix, Len(SwigLibWinUnix)) == 0)))
use_file = 0;
}
if (use_file)
Printf(f_dependencies_file, "\\\n %s ", Getitem(files, i));
if (use_file) {
Printf(f_dependencies_file, "\\\n %s ", Getitem(files, i));
if (depend_phony)
Append(phony_targets, Getitem(files, i));
}
}
Printf(f_dependencies_file, "\n");
if (depend_phony) {
for (int i = 0; i < Len(phony_targets); i++) {
Printf(f_dependencies_file, "\n%s:\n", Getitem(phony_targets, i));
}
}
if (f_dependencies_file != stdout)
Delete(f_dependencies_file);
if (depend_only)
SWIG_exit(EXIT_SUCCESS);
Delete(inputfile_filename);
Delete(basename);
Delete(phony_targets);
} else {
Printf(stderr, "Cannot generate dependencies with -nopreprocess\n");
// Actually we could but it would be inefficient when just generating dependencies, as it would be done after Swig_cparse