Changeset 2689 for trunk/emx/src/emxomf/emxomfld.c
- Timestamp:
- Apr 1, 2006, 3:21:13 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/emx/src/emxomf/emxomfld.c
r2673 r2689 253 253 } 254 254 255 /* Opens a response file. */ 256 257 static void open_response_file(void) 258 { 259 int fd; 260 261 if (response_file) 262 return; 263 264 /* Complain if we are not allowed to use a response 265 file. */ 266 267 if (!response_flag) 268 { 269 fprintf (stderr, "emxomfld: command line too long\n"); 270 exit (2); 271 } 272 273 /* Choose a unique file name and create the response 274 file. */ 275 276 strcpy (response_fname, "ldXXXXXX"); 277 fd = mkstemp (response_fname); 278 if (fd < 0) 279 { 280 perror ("emxomfld"); 281 exit (2); 282 } 283 close(fd); 284 response_file = fopen (response_fname, "wt"); 285 if (response_file == NULL) 286 { 287 perror ("emxomfld"); 288 exit (2); 289 } 290 291 /* Add the name of the response file to the command 292 line. */ 293 294 command_line[line_len++] = ' '; 295 command_line[line_len++] = '@'; 296 strcpy (command_line+line_len, response_fname); 297 if (!stricmp (linker_type, "WLINK")) 298 strcat (command_line, "."); 299 300 if (force_response_file) 301 force_response_file = FALSE; 302 } 255 303 256 304 /* Replace forward slashes `/' in NAME with backslashes `\'. The linkers … … 348 396 349 397 if (response_file == NULL) 350 { 351 int fd; 352 353 /* Complain if we are not allowed to use a response 354 file. */ 355 356 if (!response_flag) 357 { 358 fprintf (stderr, "emxomfld: command line too long\n"); 359 exit (2); 360 } 361 362 /* Choose a unique file name and create the response 363 file. */ 364 365 strcpy (response_fname, "ldXXXXXX"); 366 fd = mkstemp (response_fname); 367 if (fd < 0) 368 { 369 perror ("emxomfld"); 370 exit (2); 371 } 372 close(fd); 373 response_file = fopen (response_fname, "wt"); 374 if (response_file == NULL) 375 { 376 perror ("emxomfld"); 377 exit (2); 378 } 379 380 /* Add the name of the response file to the command 381 line. */ 382 383 command_line[line_len++] = ' '; 384 command_line[line_len++] = '@'; 385 strcpy (command_line+line_len, response_fname); 386 387 if (force_response_file) 388 force_response_file = FALSE; 389 } 398 open_response_file(); 390 399 else if (line_len != 0) 391 400 { … … 1242 1251 } 1243 1252 1253 /* converts a def file statement to watcom responsfile lingo. */ 1254 1255 static def_2_watcom(struct _md *md, const _md_stmt *stmt, _md_token token, void *arg) 1256 { 1257 switch (token) 1258 { 1259 case _MD_BASE: 1260 fprintf (response_file, "OPTION OFFSET=%#lx\n", stmt->base.addr); 1261 break; 1262 1263 case _MD_CODE: 1264 break; 1265 1266 case _MD_DATA: 1267 break; 1268 1269 case _MD_DESCRIPTION: 1270 fprintf (response_file, "OPTION DESCRIPTION '%s'\n", stmt->descr.string); 1271 break; 1272 1273 case _MD_EXETYPE: 1274 break; 1275 1276 case _MD_EXPORTS: 1277 fprintf (response_file, "EXPORT '%s'", stmt->export.entryname); 1278 if (stmt->export.flags & _MDEP_ORDINAL) 1279 fprintf (response_file, ".%d", stmt->export.ordinal); 1280 if (stmt->export.internalname[0]) 1281 fprintf (response_file, "='%s'", stmt->export.internalname); 1282 if (stmt->export.flags & _MDEP_RESIDENTNAME) 1283 fprintf (response_file, " RESIDENT", stmt->export.internalname); 1284 /** @todo _MDEP_NONAME */ 1285 fprintf (response_file, "\n"); 1286 break; 1287 1288 case _MD_HEAPSIZE: 1289 fprintf (response_file, "OPTION HEAPSIZE=%#lx\n", stmt->heapsize.size); 1290 break; 1291 1292 case _MD_IMPORTS: 1293 fprintf (response_file, "IMPORT '%s' '%s'", stmt->import.entryname, 1294 stmt->import.modulename); 1295 if (stmt->import.flags & _MDEP_ORDINAL) 1296 fprintf (response_file, ".%d", stmt->import.ordinal); 1297 else if (stmt->import.internalname[0]) 1298 fprintf (response_file, ".'%s'", stmt->import.internalname); 1299 fprintf (response_file, "\n"); 1300 break; 1301 1302 case _MD_LIBRARY: 1303 if (stmt->library.name[0]) 1304 fprintf (response_file, "OPTION MODNAME='%s'\n", stmt->library.name); 1305 break; 1306 1307 case _MD_NAME: 1308 if (stmt->name.name[0]) 1309 fprintf (response_file, "OPTION MODNAME='%s'\n", stmt->name.name); 1310 break; 1311 1312 case _MD_OLD: 1313 fprintf (response_file, "OPTION OLDLIBRARY='%s'\n", stmt->old.name); 1314 break; 1315 1316 case _MD_PROTMODE: 1317 fprintf (response_file, "OPTION PROTMODE\n"); 1318 break; 1319 1320 case _MD_REALMODE: 1321 fprintf (response_file, "OPTION PROTMODE\n"); 1322 break; 1323 1324 case _MD_SEGMENTS: 1325 fprintf (stderr, "emxomfld: ignoring SEGMENTS directive in .def-file\n"); 1326 break; 1327 1328 case _MD_STACKSIZE: 1329 fprintf (response_file, "OPTION STACK=%#ld\n", stmt->stacksize.size); 1330 break; 1331 1332 case _MD_STUB: 1333 fprintf (response_file, "OPTION STUB='%s'\n", stmt->stub.name); 1334 break; 1335 1336 case _MD_VIRTUAL: 1337 case _MD_PHYSICAL: 1338 break; 1339 1340 case _MD_parseerror: 1341 error ("%s (line %ld of %s)", _md_errmsg (stmt->error.code), 1342 _md_get_linenumber (md), def_fname); 1343 break; 1344 1345 default: 1346 abort (); 1347 } 1348 return 0; 1349 } 1350 1244 1351 /* -t output. We dump the commandline and responsefile. */ 1245 1352 static void show_spawn(const char *pszwhat) … … 1386 1493 fputs ("Environment variables:\n" 1387 1494 " EMXOMFLD_TYPE:\n" 1388 " The type of linker we're using. Values: VAC365, VAC308, LINK386 .\n"1495 " The type of linker we're using. Values: VAC365, VAC308, LINK386, WLINK.\n" 1389 1496 " VAC365 ilink.exe from IBM C and C++ Compilers for OS/2 v3.6 or later.\n" 1390 1497 " VAC308 ilink.exe from Visual Age for C++ v3.08.\n" 1391 " LINK386 link386 form OS/2 install or DDK.\n", stderr); 1498 " LINK386 link386 form OS/2 install or DDK.\n" 1499 " WLINK wlink.exe from Open Watcom v1.4 or later. (experimental)\n", stderr); 1392 1500 fputs (" EMXOMFLD_LINKER:\n" 1393 1501 " Name of the linker to use and optionally extra parameters. Spaces in the\n" … … 1445 1553 int main (int argc, char *argv[]) 1446 1554 { 1555 struct stat s; 1447 1556 int c, rc, files; 1448 1557 const char *ext; … … 1687 1796 && stricmp(t, "VAC308") 1688 1797 && stricmp(t, "LINK386") 1798 && stricmp(t, "WLINK") 1689 1799 ) 1690 1800 fprintf (stderr, "emxomfld: warning: '%s' is an invalid value for EMXOMFLD_TYPE.\n", t); … … 1736 1846 arg_init (TRUE); 1737 1847 1738 /*1739 For VAC365 and VAC308 the default options is:1740 1741 /NOFR[EEFORMAT] Use /NOFREEFORMAT to allow a LINK386-compatible1742 command line syntax, in which different types of file1743 are grouped and separated by commas.1744 1745 /DBGPACK If !strip_symbols then we'll add this option, which1746 will cause type tables to be merged into one global1747 table and so eliminating a lot of duplicate info.1748 1749 For VAC365 additional default option is:1750 1751 /STUB:<emxomfld-path>\os2stub.bin1752 Causes this MZ stub to be used when linking the1753 executables instead of the default on for the linker.1754 1755 For LINK386 the default options is:1756 1757 /BATCH Run in batch mode (disable prompting, don't1758 echo response file)1759 1760 The default options for all linkers are:1761 1762 /NOLOGO Don't display sign-on banner1763 1764 /NOEXTDICTIONARY Don't use extended dictionary (redefining1765 library symbols is quite common)1766 1767 /NOIGNORECASE Make symbols case-sensitive1768 1769 /PACKCODE Group neighboring code segments (this is the1770 default unless the SEGMENTS module definition1771 statement is used for a segment of class1772 'CODE'). Not grouping neighboring code1773 segments would break sets1774 1775 For non DLLs targets:1776 1777 /BASE:0x10000 Base the executable an so removing extra fixups.1778 1779 */1780 1781 1848 /* issue commandline */ 1782 1849 put_arg (linker_name, TRUE, FALSE); 1783 1850 1784 /* the next part depends on the linker type. */ 1785 if (!stricmp (linker_type, "LINK386")) 1786 put_arg ("/bat", FALSE, FALSE); 1787 else /* vac3xx: */ 1788 { 1789 put_arg ("/nofree", FALSE, FALSE); 1851 if (stricmp (linker_type, "WLINK")) 1852 { 1853 /* 1854 For VAC365 and VAC308 the default options is: 1855 1856 /NOFR[EEFORMAT] Use /NOFREEFORMAT to allow a LINK386-compatible 1857 command line syntax, in which different types of file 1858 are grouped and separated by commas. 1859 1860 /DBGPACK If !strip_symbols then we'll add this option, which 1861 will cause type tables to be merged into one global 1862 table and so eliminating a lot of duplicate info. 1863 1864 For VAC365 additional default option is: 1865 1866 /STUB:<emxomfld-path>\os2stub.bin 1867 Causes this MZ stub to be used when linking the 1868 executables instead of the default on for the linker. 1869 1870 For LINK386 the default options is: 1871 1872 /BATCH Run in batch mode (disable prompting, don't 1873 echo response file) 1874 1875 The default options for all linkers are: 1876 1877 /NOLOGO Don't display sign-on banner 1878 1879 /NOEXTDICTIONARY Don't use extended dictionary (redefining 1880 library symbols is quite common) 1881 1882 /NOIGNORECASE Make symbols case-sensitive 1883 1884 /PACKCODE Group neighboring code segments (this is the 1885 default unless the SEGMENTS module definition 1886 statement is used for a segment of class 1887 'CODE'). Not grouping neighboring code 1888 segments would break sets 1889 1890 For non DLLs targets: 1891 1892 /BASE:0x10000 Base the executable an so removing extra fixups. 1893 1894 */ 1895 1896 /* the next part depends on the linker type. */ 1897 if (!stricmp (linker_type, "LINK386")) 1898 put_arg ("/bat", FALSE, FALSE); 1899 else /* vac3xx: */ 1900 { 1901 put_arg ("/nofree", FALSE, FALSE); 1902 if (!strip_symbols) 1903 put_arg ("/db", FALSE, FALSE); 1904 if (map_flag) 1905 put_arg ("/map", FALSE, FALSE); 1906 } 1907 put_arg ("/nol", FALSE, FALSE); 1908 put_arg ("/noe", FALSE, FALSE); 1909 put_arg ("/noi", FALSE, FALSE); 1910 put_arg ("/packc", FALSE, FALSE); 1911 1912 1913 /* VAC365: check if we have os2stub.bin. 1914 We must to this after the above stuff else /nol might end up in the 1915 response file and we'll get the component output. */ 1916 1917 if (!stricmp (linker_type, "VAC365")) 1918 { 1919 /* gklayout show that the linker isn't capable of determining a 1920 decent value for this parameter. 32MB makes gklayout link. */ 1921 put_arg ("/ocache:0x02000000", FALSE, FALSE); 1922 1923 _execname (&execname[0], sizeof(execname)); 1924 strcpy (_getname (&execname[0]), "os2stub.bin"); 1925 if (!stat (execname, &s)) 1926 { 1927 sprintf (tmp, "/STUB:%s", &execname[0]); 1928 put_arg (tmp, FALSE, FALSE); 1929 } 1930 } 1931 1932 /* Add the /INFORMATION option if the -i or -t option was given. This is 1933 for debugging. */ 1934 1935 if (opt_t) 1936 put_arg ("/i", FALSE, FALSE); 1937 1938 /* Add the /DEBUG option if the -s option was not given. Without 1939 this, the linker throws away debugging information. */ 1940 1790 1941 if (!strip_symbols) 1791 put_arg ("/db", FALSE, FALSE); 1792 if (map_flag) 1793 put_arg ("/map", FALSE, FALSE); 1794 } 1795 put_arg ("/nol", FALSE, FALSE); 1796 put_arg ("/noe", FALSE, FALSE); 1797 put_arg ("/noi", FALSE, FALSE); 1798 put_arg ("/packc", FALSE, FALSE); 1799 1800 1801 /* VAC365: check if we have os2stub.bin. 1802 We must to this after the above stuff else /nol might end up in the 1803 response file and we'll get the component output. */ 1804 1805 if (!stricmp (linker_type, "VAC365")) 1806 { 1807 struct stat s; 1808 /* gklayout show that the linker isn't capable of determining a 1809 decent value for this parameter. 32MB make gklayout link. */ 1810 put_arg ("/ocache:0x02000000", FALSE, FALSE); 1811 1812 _execname(&execname[0], sizeof(execname)); 1813 strcpy(_getname(&execname[0]), "os2stub.bin"); 1814 if (!stat (execname, &s)) 1815 { 1816 sprintf (tmp, "/STUB:%s", &execname[0]); 1942 put_arg ("/de", FALSE, FALSE); 1943 1944 /* Add the /BASE:n option to set the base address. This specifies 1945 the preferred load address of object 1. The base address being 1946 used is 0x10000 unless a DLL is generated or the -T option was 1947 given. -Tno can be used to suppress the /BASE:n option. */ 1948 1949 if (base == NULL && !dll_flag) 1950 { 1951 struct _md *md; 1952 1953 if (def_fname != NULL) 1954 { 1955 int token; 1956 md = _md_open (def_fname); 1957 if (md == NULL) 1958 { 1959 fprintf (stderr, "emxomfld: cannot open `%s'\n", def_fname); 1960 exit (2); 1961 } 1962 token = _md_next_token (md); 1963 if (token == _MD_LIBRARY || token == _MD_PHYSICAL || token == _MD_VIRTUAL) 1964 dll_flag = TRUE; 1965 _md_close (md); 1966 } 1967 } 1968 if (base == NULL && !dll_flag) 1969 base = "0x10000"; 1970 if (base != NULL && stricmp (base, "no") != 0) 1971 { 1972 sprintf (tmp, "/bas:%s", base); 1817 1973 put_arg (tmp, FALSE, FALSE); 1818 1974 } 1819 } 1820 1821 /* Add the /INFORMATION option if the -i or -t option was given. This is 1822 for debugging. */ 1823 1824 if (opt_t) 1825 put_arg ("/i", FALSE, FALSE); 1826 1827 /* Add the /DEBUG option if the -s option was not given. Without 1828 this, the linker throws away debugging information. */ 1829 1830 if (!strip_symbols) 1831 put_arg ("/de", FALSE, FALSE); 1832 1833 /* Add the /BASE:n option to set the base address. This specifies 1834 the preferred load address of object 1. The base address being 1835 used is 0x10000 unless a DLL is generated or the -T option was 1836 given. -Tno can be used to suppress the /BASE:n option. */ 1837 1838 if (base == NULL && !dll_flag) 1839 { 1840 struct _md *md; 1841 1842 if (def_fname != NULL) 1975 1976 /* Add the /STACK:n option if the -Zstack option was given. */ 1977 1978 if (!dll_flag) 1979 { 1980 sprintf (tmp, "/st:0x%lx", stack_size * 1024); 1981 put_arg (tmp, FALSE, FALSE); 1982 } 1983 1984 /* Add the linker options specified with -O. */ 1985 1986 put_args (options, FALSE); 1987 1988 /* Put the object file names onto the command line. */ 1989 1990 force_response_file = TRUE; /* link386 workaround. */ 1991 put_args (obj_fnames, TRUE); 1992 put_arg (",", FALSE, FALSE); 1993 1994 /* Put the output file name onto the command line. */ 1995 1996 put_arg (output_fname, TRUE, TRUE); 1997 put_arg (",", FALSE, FALSE); 1998 1999 /* Put the map file name onto the command line. */ 2000 2001 put_arg (map_fname, TRUE, TRUE); 2002 put_arg (",", FALSE, FALSE); 2003 2004 /* Put the library file names onto the command line. */ 2005 2006 put_args (lib_fnames, TRUE); 2007 put_arg (",", FALSE, FALSE); 2008 2009 /* Put the name of the module definition file onto the command line. */ 2010 2011 put_arg (def_fname, TRUE, TRUE); 2012 put_arg (";", FALSE, FALSE); 2013 2014 /* Call Linker and abort on failure. */ 2015 } 2016 else /* wlink */ 2017 { 2018 open_response_file (); 2019 2020 /* figure out what format options we're gonna use */ 2021 2022 if (!def_fname && !dll_flag) 2023 fprintf (response_file, "FORMAT OS2 LX PMCompatible\n"); 2024 else if (!def_fname && dll_flag) 2025 fprintf (response_file, "FORMAT OS2 LX DLL INITINSTANCE TERMINSTANCE\n"); 2026 else 1843 2027 { 1844 2028 int token; 1845 md = _md_open (def_fname);1846 if ( md == NULL)2029 struct _md *pMd = _md_open (def_fname); 2030 if (!pMd) 1847 2031 { 1848 2032 fprintf (stderr, "emxomfld: cannot open `%s'\n", def_fname); 1849 2033 exit (2); 1850 2034 } 1851 token = _md_next_token ( md);2035 token = _md_next_token (pMd); 1852 2036 if (token == _MD_LIBRARY || token == _MD_PHYSICAL || token == _MD_VIRTUAL) 1853 2037 dll_flag = TRUE; 1854 _md_close (md); 1855 } 1856 } 1857 if (base == NULL && !dll_flag) 1858 base = "0x10000"; 1859 if (base != NULL && stricmp (base, "no") != 0) 1860 { 1861 sprintf (tmp, "/bas:%s", base); 1862 put_arg (tmp, FALSE, FALSE); 1863 } 1864 1865 /* Add the /STACK:n option if the -Zstack option was given. */ 1866 1867 if (!dll_flag) 1868 { 1869 sprintf (tmp, "/st:0x%lx", stack_size * 1024); 1870 put_arg (tmp, FALSE, FALSE); 1871 } 1872 1873 /* Add the linker options specified with -O. */ 1874 1875 put_args (options, FALSE); 1876 1877 /* Put the object file names onto the command line. */ 1878 1879 force_response_file = TRUE; /* link386 workaround. */ 1880 put_args (obj_fnames, TRUE); 1881 put_arg (",", FALSE, FALSE); 1882 1883 /* Put the output file name onto the command line. */ 1884 1885 put_arg (output_fname, TRUE, TRUE); 1886 put_arg (",", FALSE, FALSE); 1887 1888 /* Put the map file name onto the command line. */ 1889 1890 put_arg (map_fname, TRUE, TRUE); 1891 put_arg (",", FALSE, FALSE); 1892 1893 /* Put the library file names onto the command line. */ 1894 1895 put_args (lib_fnames, TRUE); 1896 put_arg (",", FALSE, FALSE); 1897 1898 /* Put the name of the module definition file onto the command line. */ 1899 1900 put_arg (def_fname, TRUE, TRUE); 1901 put_arg (";", FALSE, FALSE); 2038 if (dll_flag) 2039 { 2040 int fInitInstance = 1; 2041 int fTermInstance = 1; 2042 for (;;) 2043 { 2044 switch (_md_next_token (pMd)) 2045 { 2046 case _MD_INITINSTANCE: fInitInstance = 1; continue; 2047 case _MD_INITGLOBAL: fInitInstance = 0; continue; 2048 case _MD_TERMINSTANCE: fTermInstance = 1; continue; 2049 case _MD_TERMGLOBAL: fTermInstance = 0; continue; 2050 default: break; 2051 } 2052 break; 2053 } 2054 fprintf (response_file, "FORMAT OS2 LX DLL %s %s\n", 2055 fInitInstance ? "INITINSTANCE" : "INITGLOBAL", 2056 fTermInstance ? "TERMINSTANCE" : "TERMGLOBAL"); 2057 } 2058 else 2059 switch (_md_next_token (pMd)) 2060 { 2061 case _MD_WINDOWAPI: 2062 fprintf (response_file, "FORMAT OS2 LX PM\n"); 2063 break; 2064 default: 2065 case _MD_WINDOWCOMPAT: 2066 fprintf (response_file, "FORMAT OS2 LX PMCompatible\n"); 2067 break; 2068 case _MD_NOTWINDOWCOMPAT: 2069 fprintf (response_file, "FORMAT OS2 LX FullScreen\n"); 2070 break; 2071 } 2072 _md_close (pMd); 2073 } 2074 2075 /* output files */ 2076 2077 fprintf (response_file, "NAME '%s'\n", output_fname); 2078 2079 if (map_flag && map_fname) 2080 fprintf (response_file, "OPTION MAP='%s'\n", map_fname); 2081 else if (map_flag) 2082 fprintf (response_file, "OPTION MAP\n", map_fname); 2083 2084 /* standard stuff */ 2085 2086 //if (!strip_symbols) 2087 // put_arg ("debug hll", FALSE, FALSE); 2088 fprintf (response_file, "OPTION QUIET\n"); 2089 fprintf (response_file, "OPTION OSNAME='OS/2 EMX'\n"); 2090 fprintf (response_file, "OPTION CASEEXACT\n"); 2091 if (!dll_flag) 2092 fprintf (response_file, "OPTION STACK=%#lx\n", stack_size * 1024); 2093 if (!dll_flag && !base) 2094 base = "0x10000"; 2095 if (base) 2096 fprintf (response_file, "OPTION OFFSET=%s\n", base); 2097 2098 /* the stub */ 2099 2100 _execname(&execname[0], sizeof(execname)); 2101 strcpy (_getname (&execname[0]), "os2stub.bin"); 2102 if (!stat (execname, &s)) 2103 fprintf (response_file, "OPTION STUB='%s'\n", execname); 2104 2105 /* Add the /INFORMATION option if the -i or -t option was given. This is 2106 for debugging. */ 2107 2108 // if (opt_t) 2109 // put_arg ("/i", FALSE, FALSE); 2110 2111 /* Add the linker options specified with -O. */ 2112 2113 put_args (options, FALSE); 2114 2115 /* Put the object file names onto the command line. */ 2116 2117 for (pcur = obj_fnames; pcur; pcur = pcur->next) 2118 fprintf (response_file, "FILE '%s'\n", pcur->name); 2119 2120 /* Put the library file names onto the command line. */ 2121 2122 for (pcur = lib_fnames; pcur; pcur = pcur->next) 2123 fprintf (response_file, "LIBRARY '%s'\n", pcur->name); 2124 2125 /* Translate the essentials of the module definition file into wlink lingo. */ 2126 if (def_fname) 2127 { 2128 _md_token token; 2129 struct _md *pMd = _md_open (def_fname); 2130 if (!pMd) 2131 { 2132 fprintf (stderr, "emxomfld: cannot open `%s'\n", def_fname); 2133 exit (2); 2134 } 2135 _md_next_token (pMd); 2136 _md_parse (pMd, def_2_watcom, NULL); 2137 _md_close (pMd); 2138 } 2139 } 2140 2141 /* End the arguments and run the linker. */ 2142 1902 2143 arg_end (); 1903 1904 /* Call Linker and abort on failure. */1905 2144 1906 2145 rc = emxomfld_spawn (command_line, "Linker");
Note:
See TracChangeset
for help on using the changeset viewer.