summaryrefslogtreecommitdiffstats
path: root/development/makedepf90/01-adds-B-PATH-option.patch
blob: f1c217ea0f4649452409fefbb35d19afae9a819b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
From 76a2fc5c3fa8edb17a6e9e15d5ef519768f9ccff Mon Sep 17 00:00:00 2001
From: Jason Graham <jason.graham@jhuapl.edu>
Date: Wed, 18 Nov 2015 01:37:05 -0500
Subject: [PATCH] makedepf90: Adds the '-B PATH' option to mirror src directory
 structure in object PATH.

When working on one of my projects, I wanted to preserve the directory
structure used in the source tree within the objects PATH. The main
issue was naming collisions with the '-b' option, since I have
sub-directories within the source tree and some of the files have the
same name resulting in the same objects within PATH. So '-B' behaves
similarly to '-b', but places resulting objects within PATH using the
same directory structure as the source files. The motivation for this
addition is to be able to have equivalent source file names contained
within different directories and still use the same top level objects
PATH.
---
 global.h     |  3 +++
 main.c       | 31 ++++++++++++++++++++++++-------
 makedepf90.1 | 11 +++++++++--
 utils.c      | 14 ++++++++++----
 utils.h      |  3 ++-
 5 files changed, 48 insertions(+), 14 deletions(-)

diff --git a/global.h b/global.h
index 1704f82..64a627e 100644
--- a/global.h
+++ b/global.h
@@ -1,5 +1,6 @@
 /* 
  * Copyright (C) 2000-2005 Erik Edelmann <Erik.Edelmann@iki.fi>
+ * Copyright (C) 2015 Jason Graham <jason.graham@jhuapl.edu>
  *
  *     This program is free software;  you  can  redistribute  it
  *     and/or modify it under the terms of the GNU General Public
@@ -68,6 +69,8 @@ typedef struct {
     char *link_rule;    
     bool coco;          /* Look for coco set-files */
     bool obj_dir_set;  /* Option -b obj_dir was used */
+    bool obj_dir_mirror;  /* Option -B obj_dir was used; turns on
+			     mirroring of src directory structure */
     char *obj_dir;      /* Directory set by option -b */
     bool src_dep;       /* List the source file in the dependencys */
     bool src_path_set;  /* option -I was used */
diff --git a/main.c b/main.c
index e73bdef..d78f355 100644
--- a/main.c
+++ b/main.c
@@ -1,5 +1,6 @@
 /* 
  * Copyright (C) 2000-2006 Erik Edelmann <Erik.Edelmann@iki.fi>
+ * Copyright (C) 2015 Jason Graham <jason.graham@jhuapl.edu>
  *
  *     This program is free software;  you  can  redistribute  it
  *     and/or modify it under the terms of the GNU General Public
@@ -86,6 +87,8 @@ static const char helpstring[] =
     "\n-coco\tLook for coco set-files.  Implies '-free'.\n"
     "\n-D NAME\tDefine pre-processor symbol 'NAME'\n"
     "\n-b PATH\tAssume object files are placed in PATH.\n"
+    "\n-B PATH\tAssume object files are placed in PATH using the same\n"
+	"\tdirectory structure as the source files.\n"
     "\n-nosrc\tRemove the explicit dependency on the source file\n"
     "\n-I PATH1:PATH2:...\n\tSearch path(s) for source files\n"
     "\n\nReport bugs to erik.edelmann@iki.fi\n";
@@ -143,6 +146,7 @@ int main (int argc, char **argv)
     options.link_rule = (char *)LINK_RULE_DEFAULT;
     options.coco = false;
     options.obj_dir_set = false;
+    options.obj_dir_mirror = false;
     options.obj_dir = "";
     options.src_dep = true;
     options.ignore_mods = NULL;
@@ -276,9 +280,18 @@ int main (int argc, char **argv)
             if (!list_find(macrolist, mac, &macrocmp))
                 macrolist = list_prepend(macrolist, mac);
 
-        } else if (strncmp(argv[i], "-b", 2) == 0) {
+        } else if (strncmp(argv[i], "-b", 2) == 0 ||
+		   strncmp(argv[i], "-B", 2) == 0 ) {
+	
+            /* Construct custom error message */
+            char err_msg[32];
+	    char _argv[3];
+	    
+	    strncpy(_argv,argv[i],2); _argv[2]='\0';
+	    snprintf(err_msg,sizeof(err_msg),"Option '%s' needs argument",_argv);
+
             if (strlen(argv[i]) == 2) {
-                if (i == argc - 1) fatal_error("Option '-b' needs argument");
+                if (i == argc - 1) fatal_error(err_msg);
                 options.obj_dir = xstrdup(argv[++i]);
             } else
                 if (argv[i][2] == '=') {
@@ -292,7 +305,11 @@ int main (int argc, char **argv)
                 strcat(options.obj_dir, "/");
             }
 
-            options.obj_dir_set = true;
+	    options.obj_dir_set = true;
+	    /* Have to compare with '_argv' since 'i' may be modified above */
+	    if(strncmp(_argv, "-B", 2) == 0) {
+		    options.obj_dir_mirror = true;
+	    }
 
         } else if (strncmp(argv[i], "-I", 2) == 0) {
             int jp;
@@ -383,7 +400,7 @@ int main (int argc, char **argv)
         printf("FOBJ=");
         for (h1 = obj; h1; h1 = h1->next)
             if (options.obj_dir_set)
-                printf("%s ", set_path(h1->data, options.obj_dir));
+	        printf("%s ", set_path(h1->data, options.obj_dir, options.obj_dir_mirror));
             else
                 printf("%s ", (char *)h1->data);
         printf("\n\n%s: $(FOBJ)\n\t%s\n\n", options.exe_name,options.link_rule);
@@ -402,8 +419,8 @@ int main (int argc, char **argv)
         /* Targets */
         for (h2 = dep->targets; h2; h2 = h2->next)  
             if (options.obj_dir_set)
-                printf("%s ", set_path(h2->data, options.obj_dir));
-            else
+	        printf("%s ", set_path(h2->data, options.obj_dir, options.obj_dir_mirror));
+	    else
                 printf("%s ", (char *)h2->data);
 
         printf(": ");;
@@ -430,7 +447,7 @@ int main (int argc, char **argv)
                 } else {
                     if (options.obj_dir_set)
                         printf("%s ", 
-                               set_path(mod->modfile_name, options.obj_dir));
+                            set_path(mod->modfile_name, options.obj_dir, options.obj_dir_mirror));
                     else
                         printf("%s ", mod->modfile_name);
                 }
diff --git a/makedepf90.1 b/makedepf90.1
index 49bcfb7..738ce66 100644
--- a/makedepf90.1
+++ b/makedepf90.1
@@ -1,5 +1,6 @@
 .\"
 .\"    Copyright (C) 2000--2003 Erik Edelmann <eedelman@acclab.helsinki.fi>
+.\"    Copyright (C) 2015 Jason Graham <jason.graham@jhuapl.edu>
 .\"
 .\"    This program is free software;  you  can  redistribute  it
 .\"    and/or modify it under the terms of the GNU General Public
@@ -18,7 +19,7 @@
 .\"    Boston, MA  02111-1307  USA
 .\"
 .\" $Format: ".TH makedepf90 1 \"$Date$\""$
-.TH makedepf90 1 "Thu, 06 Dec 2001 23:28:54 +0200"
+.TH makedepf90 1 "Tue, 17 Nov 2015 23:21:02 -0500"
 
 .SH NAME
 makedepf90 \- creates Makefile dependency list for Fortran source files.
@@ -45,7 +46,7 @@ makedepf90 \- creates Makefile dependency list for Fortran source files.
 .RB [ \-coco ]
 .RB [ \-D
 .IR NAME ]
-.RB [ \-b
+.RB [ \-b | \-B
 .IR "path" ]
 .RB [ \-I
 .IR "PATH1:PATH2:..." ]
@@ -211,6 +212,12 @@ Dependency tree and link rule will assume objects are placed in \fIpath\fP.
 This is useful if the build places object files in a different directory than
 the source files.
 .TP
+.BI \-B " path"
+Dependency tree and link rule will assume objects are placed in \fIpath\fP using
+the same directory structure as the source files. This is useful if the build
+places object files in a different directory than the source files and the
+source directory structure is needed to avoid object name collisions.
+.TP
 .BI \-I " list-of-paths"
 Look for source/include files in the \fIlist-of-paths\fP, if not found in
 current working directory.  Here, \fIlist-of-paths\fP is a colon separated
diff --git a/utils.c b/utils.c
index 08f6905..e5d3aff 100644
--- a/utils.c
+++ b/utils.c
@@ -1,5 +1,6 @@
 /* 
  * Copyright (C) 2000-2005 Erik Edelmann <Erik.Edelmann@iki.fi>
+ * Copyright (C) 2015 Jason Graham <jason.graham@jhuapl.edu>
  *
  *     This program is free software;  you  can  redistribute  it
  *     and/or modify it under the terms of the GNU General Public
@@ -70,22 +71,27 @@ char *replace_suffix(const char *filename, const char *new_suffix)
 
 
 /* If filename has no path, append 'path' to the beginning of the filename,
- * else replace the existing path (everything before the first '/') with 'path'.
+ * else replace the existing path if 'mirror=false' (everything before the first '/') with 'path' or
+ * prepend 'path' in the case that 'mirror=true'
  */
 
-char *set_path(const char *filename, const char *path)
+char *set_path(const char *filename, const char *path, const bool mirror)
 {
     char *rs;
     int fl, n, pl, nl;
 
     pl = strlen(path);
 
+
     fl = n = strlen(filename);
-    while (filename[n] != '/' && n >= 0)  n--;
+    if( !mirror )
+        while (filename[n] != '/' && n >= 0)  n--;
+    else
+        n=-1;
     nl = fl - n - 1;
 
     if (n == -1) {
-        /* if there was no '/' */
+        /* if there was no '/' or 'mirror=true' */
         rs = (char *)xmalloc((fl+pl+2)*sizeof(char));
         strcpy(rs, path);
         strcat(rs, filename);
diff --git a/utils.h b/utils.h
index 643d276..ca932ef 100644
--- a/utils.h
+++ b/utils.h
@@ -1,5 +1,6 @@
 /* 
  * Copyright (C) 2000-2005 Erik Edelmann <Erik.Edelmann@iki.fi>
+ * Copyright (C) 2015 Jason Graham <jason.graham@jhuapl.edu>
  *
  *     This program is free software;  you  can  redistribute  it
  *     and/or modify it under the terms of the GNU General Public
@@ -21,7 +22,7 @@
 #define UTILS_H_
 
 char *replace_suffix (const char *filename, const char *new_suffix);
-char *set_path (const char *filename, const char *path);
+char *set_path (const char *filename, const char *path, const bool mirror);
 char *remove_citation (const char *s);
 char *expand_rule(const char *rule, const char *srcfile);
 FILE *open_src_file (const char *fname, const List *path);
-- 
1.8.4