@@ -354,6 +354,21 @@ source files (not headers), and more importantly, it is used as the
354354 searched for in <code>DocumentationDirectory</code> (even though they
355355 may not have been autogenerated).
356356 </item>
357+ <item><strong>InstallationDomain</strong>
358+ May be used to specify where the documentation is to be installed,
359+ so that relative references to documentation in other projects can
360+ be used (otherwise references to other docuentation will use the
361+ absolute loacation of that documentation in the filesystem).
362+ By default this is the LOCAL domain, but it can also be set to
363+ SYSTEM, NETWORK, or USER.
364+ </item>
365+ <item><strong>InstallDir</strong>
366+ This is used to enable generation of HTML output with relative links
367+ to documentation created for other projects. The value of this must
368+ be the relative path at which this documentation will be installed
369+ within the installation domain (see -InstallationDomain) used.
370+ Relative links will not work until the documentation is installed.
371+ </item>
357372 <item><strong>Files</strong>
358373 Specifies the name of a file containing a list of file names as
359374 a property list array <em>(name1,name2,...)</em> format. If this
@@ -623,16 +638,42 @@ standard PropertyList format (not the XML format of OS X), using
623638#import " GNUstepBase/NSString+GNUstepBase.h"
624639#import " GNUstepBase/NSMutableString+GNUstepBase.h"
625640
641+ static NSString *
642+ commonRoot (NSString *s1, NSString *s2)
643+ {
644+ NSString *s;
645+ unsigned l;
646+
647+ if (nil == s1) return s2;
648+
649+ s = [s1 commonPrefixWithString: s2 options: NSLiteralSearch];
650+ l = [s length ];
651+ while (l > 0 && [s characterAtIndex: l - 1 ] != ' /' )
652+ {
653+ l--;
654+ }
655+ if (0 == l)
656+ {
657+ NSLog (@" Unable to make relative links because projects '%@ ' and '%@ '"
658+ @" share no common prefix." , s1, s2);
659+ exit (1 );
660+ }
661+ return [s substringToIndex: l];
662+ }
663+
626664int
627665main (int argc, char **argv, char **env)
628666{
629667 NSProcessInfo *proc;
630668 unsigned i;
669+ NSString *str;
631670 NSMutableDictionary *safe;
632671 NSDictionary *argsRecognized;
633672 NSUserDefaults *defs;
634673 NSFileManager *mgr;
635674 NSString *documentationDirectory;
675+ int installationDomain = 0 ;
676+ NSString *installDir;
636677 NSString *declared;
637678 NSString *headerDirectory;
638679 NSString *project;
@@ -779,6 +820,10 @@ standard PropertyList format (not the XML format of OS X), using
779820 @" search for gsdoc files" ,
780821 @" DocumentationDirectory" ,
781822 @" \t\t\t STR\t (\"\" )\n\t name of file containing filenames to document" ,
823+ @" InstallationDomain" ,
824+ @" \t\t\t STR\t (LOCAL)\n\t for relative links, the expected installation domain" ,
825+ @" InstallDir" ,
826+ @" \t\t\t STR\t (\"\" )\n\t for relative links, location within domain" ,
782827 @" Files" ,
783828 @" \t\t\t BOOL\t (NO)\n\t remove all generated files" ,
784829 @" Clean" ,
@@ -940,6 +985,25 @@ standard PropertyList format (not the XML format of OS X), using
940985 error: NULL ];
941986 }
942987
988+ str = [[defs stringForKey: @" InstallationlDomain" ] uppercaseString ];
989+ if ([str isEqualToString: @" SYSTEM" ])
990+ installationDomain = NSSystemDomainMask;
991+ else if ([str isEqualToString: @" LOCAL" ])
992+ installationDomain = NSLocalDomainMask;
993+ else if ([str isEqualToString: @" NETWORK" ])
994+ installationDomain = NSNetworkDomainMask;
995+ else if ([str isEqualToString: @" USER" ])
996+ installationDomain = NSUserDomainMask;
997+ else if (nil == str)
998+ installationDomain = NSLocalDomainMask;
999+ else
1000+ {
1001+ NSLog (@" Bad value for -InstallationDomain. If specified this must be one of SYSTEM, LOCAL, NETWORK, or USER" );
1002+ exit (1 );
1003+ }
1004+
1005+ installDir = [defs stringForKey: @" InstallDir" ];
1006+
9431007 symbolDeclsFile = [documentationDirectory
9441008 stringByAppendingPathComponent: @" OrderedSymbolDeclarations.plist" ];
9451009
@@ -1781,6 +1845,7 @@ standard PropertyList format (not the XML format of OS X), using
17811845 NSMutableDictionary *projects;
17821846 NSString *systemProjects;
17831847 NSString *localProjects;
1848+ NSString *installRoot = nil ;
17841849 CREATE_AUTORELEASE_POOL (pool);
17851850
17861851 localProjects = [defs stringForKey: @" LocalProjects" ];
@@ -1833,6 +1898,8 @@ standard PropertyList format (not the XML format of OS X), using
18331898 val
18341899 = [systemProjects stringByAppendingPathComponent: val];
18351900 [projects setObject: val forKey: key];
1901+ if (installDir)
1902+ installRoot = commonRoot (installRoot, key);
18361903 }
18371904 }
18381905 }
@@ -1876,6 +1943,8 @@ standard PropertyList format (not the XML format of OS X), using
18761943 val = [file stringByDeletingLastPathComponent ];
18771944 val = [localProjects stringByAppendingPathComponent: val];
18781945 [projects setObject: val forKey: key];
1946+ if (installDir)
1947+ installRoot = commonRoot (installRoot, key);
18791948 }
18801949 }
18811950 }
@@ -1889,6 +1958,46 @@ standard PropertyList format (not the XML format of OS X), using
18891958 NSEnumerator *e = [projects keyEnumerator ];
18901959 NSMutableArray *merged;
18911960 NSString *k;
1961+ NSString *relative = @" " ;
1962+ unsigned installLength = 0 ;
1963+
1964+ if (installDir)
1965+ {
1966+ NSString *base;
1967+ NSString *file;
1968+ NSString *path;
1969+
1970+ base = [NSSearchPathForDirectoriesInDomains (
1971+ NSDocumentationDirectory, installationDomain, NO ) lastObject ];
1972+ base = [base stringByAppendingPathComponent: installDir];
1973+ base = [base stringByStandardizingPath ];
1974+ file = [project stringByAppendingPathExtension: @" html" ];
1975+ path = [base stringByAppendingPathComponent: file];
1976+ installRoot = commonRoot (installRoot, path);
1977+ installLength = [installRoot length ];
1978+ if ([base length ] < installLength)
1979+ {
1980+ /* All referenced project documentation is relative to the
1981+ * directory that this project will be installed in.
1982+ */
1983+ relative = @" " ;
1984+ }
1985+ else
1986+ {
1987+ unsigned c;
1988+
1989+ base = [base substringFromIndex: installLength];
1990+
1991+ /* Build the prefix to get from the package being generated
1992+ * up to the documentation installation root.
1993+ */
1994+ c = [[base componentsSeparatedByString: @" /" ] count ];
1995+ while (c--)
1996+ {
1997+ relative = [relative stringByAppendingString: @" ../" ];
1998+ }
1999+ }
2000+ }
18922001
18932002 merged = [NSMutableArray arrayWithCapacity: [projects count ]];
18942003 while ((k = [e nextObject ]) != nil )
@@ -1923,6 +2032,14 @@ standard PropertyList format (not the XML format of OS X), using
19232032 {
19242033 p = [k stringByDeletingLastPathComponent ];
19252034 }
2035+ if (installRoot)
2036+ {
2037+ /* Replace the root part with the prefix
2038+ * to make the path relative.
2039+ */
2040+ p = [p substringFromIndex: installLength];
2041+ p = [relative stringByAppendingString: p];
2042+ }
19262043 [tmp setDirectory: p];
19272044 [globalRefs mergeRefs: [tmp refs ] override: YES ];
19282045 RELEASE (tmp);
0 commit comments