Index: /trunk/src/kmk/kmkbuiltin/install.c
===================================================================
--- /trunk/src/kmk/kmkbuiltin/install.c	(revision 2475)
+++ /trunk/src/kmk/kmkbuiltin/install.c	(revision 2476)
@@ -123,8 +123,9 @@
 static gid_t gid;
 static uid_t uid;
-static int dobackup, docompare, dodir, dopreserve, dostrip, nommap, safecopy, verbose;
+static int dobackup, docompare, dodir, dopreserve, dostrip, nommap, safecopy, verbose, mode_given;
 static mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
 static const char *suffix = BACKUP_SUFFIX;
 static int ignore_perm_errors;
+static int hard_link_files_when_possible;
 
 static struct option long_options[] =
@@ -134,4 +135,6 @@
     { "ignore-perm-errors",   				no_argument, 0, 263 },
     { "no-ignore-perm-errors",				no_argument, 0, 264 },
+    { "hard-link-files-when-possible",			no_argument, 0, 265 },
+    { "no-hard-link-files-when-possible",		no_argument, 0, 266 },
     { 0, 0,	0, 0 },
 };
@@ -169,6 +172,7 @@
         gid = 0;
         uid = 0;
-        dobackup = docompare = dodir = dopreserve = dostrip = nommap = safecopy = verbose = 0;
+        dobackup = docompare = dodir = dopreserve = dostrip = nommap = safecopy = verbose = mode_given = 0;
 	ignore_perm_errors = geteuid() != 0;
+        hard_link_files_when_possible = 0;
 
         /* reset getopt and set progname. */
@@ -220,4 +224,5 @@
 			mode = bsd_getmode(set, 0);
 			free(set);
+			mode_given = 1;
 			break;
 		case 'o':
@@ -247,4 +252,10 @@
 			ignore_perm_errors = 0;
 			break;
+                case 265:
+                        hard_link_files_when_possible = 1;
+                        break;
+                case 266:
+                        hard_link_files_when_possible = 0;
+                        break;
 		case '?':
 		default:
@@ -385,7 +396,7 @@
 	    || (   stricmp(from_name, _PATH_DEVNULL)
 		&& stricmp(from_name, "nul")
-#ifdef __EMX__
+# ifdef __EMX__
 		&& stricmp(from_name, "/dev/nul")
-#endif
+# endif
 	       )
 #else
@@ -422,4 +433,47 @@
 	/* Only copy safe if the target exists. */
 	tempcopy = safecopy && target;
+
+	/* Try hard linking if wanted and possible. */
+	if (hard_link_files_when_possible)
+	{
+		const char *why_not = NULL;
+		if (devnull) {
+			why_not = "/dev/null";
+		} else if (dostrip) {
+			why_not = "strip (-s)";
+		} else if (docompare) {
+			why_not = "compare (-C)";
+		} else if (dobackup) {
+			why_not = "backup (-b/-B)";
+		} else if (safecopy) {
+			why_not = "safe copy (-S)";
+		} else if (mode_given && mode != (from_sb.st_mode & ALLPERMS)) {
+			why_not = "mode mismatch";
+		} else if (uid != (uid_t)-1 && gid != from_sb.st_uid) {
+			why_not = "uid mismatch";
+		} else if (gid != (gid_t)-1 && gid != from_sb.st_gid) {
+			why_not = "gid mismatch";
+		} else {
+			int rcLink = link(from_name, to_name);
+			if (rcLink != 0 && errno == EEXIST) {
+			    unlink(to_name);
+			    rcLink = link(from_name, to_name);
+			}
+			if (rcLink == 0) {
+			    if (verbose)
+				    printf("install: %s -> %s (hardlinked)\n", from_name, to_name);
+			    goto l_done;
+			}
+			if (verbose)
+				printf("install: hard linking '%s' to '%s' failed: %s\n",
+				       to_name, from_name, strerror(errno));
+			why_not = NULL;
+		}
+		if (verbose && why_not)
+		    printf("install: not hard linking '%s' to '%s' because: %s\n",
+			   to_name, from_name, why_not);
+
+		/* Can't hard link or we failed, continue as nothing happend. */
+	}
 
 	if (!devnull && (from_fd = open(from_name, O_RDONLY | O_BINARY, 0)) < 0)
@@ -973,5 +1027,6 @@
 {
 	fprintf(pf,
-"usage: %s [-bCcpSsv] [--[no-]ignore-perm-errors] [-B suffix] [-f flags]\n"
+"usage: %s [-bCcpSsv] [--[no-]hard-link-files-when-possible]\n"
+"            [--[no-]ignore-perm-errors] [-B suffix] [-f flags]\n"
 "            [-g group] [-m mode] [-o owner] file1 file2\n"
 "   or: %s [-bCcpSsv] [--[no-]ignore-perm-errors] [-B suffix] [-f flags]\n"
Index: /trunk/src/kmk/kmkbuiltin/mscfakes.c
===================================================================
--- /trunk/src/kmk/kmkbuiltin/mscfakes.c	(revision 2475)
+++ /trunk/src/kmk/kmkbuiltin/mscfakes.c	(revision 2476)
@@ -158,4 +158,7 @@
         case ERROR_FILENAME_EXCED_RANGE:    errno = ENOENT; break;
         case ERROR_NESTING_NOT_ALLOWED:     errno = EAGAIN; break;
+#ifdef EMLINK
+        case ERROR_TOO_MANY_LINKS:          errno = EMLINK; break;
+#endif
     }
 
@@ -258,7 +261,7 @@
 int link(const char *pszDst, const char *pszLink)
 {
-    errno = ENOSYS;
-    err(1, "link() is not implemented on windows!");
-    return -1;
+    if (CreateHardLink(pszDst, pszLink, NULL))
+        return 0;
+    return msc_set_errno(GetLastError());
 }
 
