Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1033 lines
25 KiB

  1. /*
  2. * MkClnMkf - generates the makefile to cleanse the VC++ v7.0 CRTL sources
  3. * in preparation for a Microsoft-internal build of the CRTL. Those
  4. * cleansed sources will also be used for the publicly-released CRTL
  5. * source as a part of the VC++ 7.0 retail product.
  6. *
  7. * Programmed by Steve Salisbury, 1994-12-07 Wed
  8. *
  9. * This program takes 7 arguments:
  10. * prefixSrc - path to the raw VC++ 7.0 CRTL sources
  11. * prefixDst - path to the partly cleansed VC++ 7.0 CRTL sources
  12. * prefixDst2 - path to the final cleansed VC++ 7.0 CRTL sources
  13. * inputRaw - a list of raw input files
  14. * inputCln - a list of the input files that must be cleansed
  15. * output - name of the first output file (may not already exist)
  16. * outputRel - name of the second output file (may not already exist)
  17. *
  18. * Modified by Steve Salisbury, 1994-12-15 Thu
  19. * Restore the crtw32/ and fpw32/ subdirectories
  20. * Automate the generation of the directory list
  21. *
  22. * Modified 1995-01-16 Mon - take directory list from an input file, too.
  23. *
  24. * Modified 1995-01-17 Tue - many changes to make things work when removing
  25. * crtw32/ and fpw32/ directories from the target filename paths.
  26. *
  27. * Modified 1995-01-18 Wed - The 3 files cleansed with bldmkf.sed should
  28. * have that file as an explicit dependency.
  29. *
  30. * Modified 1995-01-23 Mon - Add a second output file
  31. *
  32. * Modified 1996-06-27 Thu - Fix off by 1 error in list allocation
  33. *
  34. * Modified 1997-08-14 Thu (Jamie) - Revved version strings from 4.0 => 6.0
  35. *
  36. * Modified 1999-05-16 Sun (PhilipLu) - Removed MAC support
  37. *
  38. * Modified 1999-08-02 Mon (PhilipLu) - Revved version strings from 6.0 => 7.0
  39. *
  40. * Modified 1999-08-06 Fri (PhilipLu) - Set .RC file names by cmdline switches
  41. *
  42. * Modified 1999-10-17 Sun (PhilipLu) - Add -noclean options
  43. */
  44. /*-
  45. * Build Version Options
  46. -*/
  47. /* define KEEPDIRS */
  48. /*-
  49. * Include Header Files
  50. -*/
  51. #include <stdio.h>
  52. #include <stdlib.h>
  53. #include <string.h>
  54. #include <time.h>
  55. /*-
  56. * Define Constants
  57. -*/
  58. #define MAXARGLEN 128
  59. #define CRTW32 "crtw32\\"
  60. #define FPW32 "fpw32\\"
  61. /*-
  62. * Define VERBOSE to get verbose output makefiles
  63. -*/
  64. #ifdef VERBOSE
  65. #define AT ""
  66. #else
  67. #define AT "@"
  68. #endif
  69. #if defined(_BUILD_IA64)
  70. #define TOOLDIR "..\\libw32\\tools\\i386"
  71. #define CPUDIR "ia64"
  72. #elif defined(_BUILD_ALPHA64)
  73. #define TOOLDIR "..\\libw32\\tools\\alpha"
  74. #define CPUDIR "alpha64"
  75. #elif defined(_M_IA64)
  76. #define TOOLDIR "..\\libw32\\tools\\ia64"
  77. #define CPUDIR "ia64"
  78. #elif defined(_M_ALPHA64)
  79. #define TOOLDIR "..\\libw32\\tools\\alpha64"
  80. #define CPUDIR "alpha64"
  81. #elif defined(_M_IX86)
  82. #define TOOLDIR "..\\libw32\\tools\\i386"
  83. #define CPUDIR "intel"
  84. #elif defined(_M_ALPHA)
  85. #define TOOLDIR "..\\libw32\\tools\\alpha"
  86. #define CPUDIR "alpha"
  87. #elif defined(_M_MRX000)
  88. #define TOOLDIR "..\\libw32\\tools\\mips"
  89. #define CPUDIR "mips"
  90. #elif defined(_M_PPC)
  91. #define TOOLDIR "..\\libw32\\tools\\ppc"
  92. #define CPUDIR "ppc"
  93. #endif
  94. #define INTEL_DIR "intel"
  95. /*-
  96. * Define Global Variables (Constants)
  97. -*/
  98. #ifndef KEEPDIRS
  99. char fmtRaw2 [ ] =
  100. "%s%s: %s%s %ssrcrel\\bldmkf.sed\n"
  101. "\t" AT "echo Copying %s from %s to %s. (using SED.EXE)\n"
  102. "\t" AT "if exist %s%s attrib -r %s%s\n"
  103. "\t" AT "sed -f %ssrcrel\\bldmkf.sed %s%s > %s%s\n"
  104. "\t" AT "attrib +r %s%s\n"
  105. "\n" ;
  106. #endif /* KEEPDIRS */
  107. char fmtRaw [ ] =
  108. "%s%s: %s%s\n"
  109. "\t" AT "echo Copying %s from %s to %s.\n"
  110. "\t" AT "if exist %s%s attrib -r %s%s\n"
  111. "\t" AT "copy /b %s%s %s%s >nul\n"
  112. "\t" AT "attrib +r %s%s\n"
  113. "\n" ;
  114. char fmtCln2 [ ] =
  115. "%s%s: %s%s %ssrcrel\\msvc40.if\n"
  116. "\t" AT "echo Cleansing %s%s\n"
  117. "\t" AT "if exist %s%s attrib -r %s%s\n"
  118. "\t" AT TOOLDIR "\\detab < %s%s | " TOOLDIR "\\trailing > %s%s\n"
  119. "\t" AT "rem *\n"
  120. "\t" AT "rem * IFSTRIP is NOT used on .INC assembler include files!\n"
  121. "\t" AT "rem *\n"
  122. "\t" AT "rem " TOOLDIR "\\ifstrip -z -c -t -x.TMP -f %ssrcrel\\msvc40.if %s%s\n"
  123. "\t" AT "rem del %s%s\n"
  124. "\t" AT "rem ren %s%s.TMP *%s\n"
  125. "\t" AT TOOLDIR "\\striphdr -r %s%s\n"
  126. "\t" AT "del %s%s\n"
  127. "\t" AT "ren %s%s.NEW *%s\n"
  128. "\t" AT "attrib +r %s%s\n"
  129. "\n" ;
  130. char fmtCln [ ] =
  131. "%s%s: %s%s %ssrcrel\\msvc40.if\n"
  132. "\t" AT "echo Cleansing %s%s\n"
  133. "\t" AT "if exist %s%s attrib -r %s%s\n"
  134. "\t" AT TOOLDIR "\\detab < %s%s | " TOOLDIR "\\trailing > %s%s\n"
  135. "\t" AT TOOLDIR "\\ifstrip -z -c -t -x.TMP -f %ssrcrel\\msvc40.if %s%s\n"
  136. "\t" AT "del %s%s\n"
  137. "\t" AT "ren %s%s.TMP *%s\n"
  138. "\t" AT TOOLDIR "\\striphdr -r %s%s\n"
  139. "\t" AT "del %s%s\n"
  140. "\t" AT "ren %s%s.NEW *%s\n"
  141. "\t" AT "attrib +r %s%s\n"
  142. "\n" ;
  143. const char prefixSrc [ ] = "$(SRC)\\" ;
  144. const char prefixDst [ ] = "$(DST)\\" ;
  145. char * * DirList ;
  146. const char * szRcFiles [ 2 ] [ 2 ] [ 3 ] =
  147. {
  148. {
  149. { "msvcirt.rc" , "msvcprt.rc" , "msvcrt.rc" } ,
  150. { "msvcir64.rc" , "msvcpr64.rc" , "msvcrt64.rc" }
  151. } ,
  152. {
  153. { "sysirt.rc" , "sysprt.rc" , "syscrt.rc" } ,
  154. { "sysirt64.rc" , "sysprt64.rc" , "syscrt64.rc" }
  155. }
  156. } ;
  157. /*-
  158. * Function Declarations (Prototypes)
  159. -*/
  160. int main ( int argc , char * * argv ) ;
  161. void Usage ( void ) ;
  162. char * fgetsNL ( char * lineBuf , int lineSize , FILE * fileInput ) ;
  163. void Progress ( int prefix , char * string , int suffix ) ;
  164. char * SkipFirstDir ( char * string ) ;
  165. /*-
  166. * Function Definitions (Implementations)
  167. -*/
  168. int main ( int argc , char * * argv )
  169. {
  170. FILE * inputRaw ;
  171. FILE * inputCln ;
  172. FILE * inputDir ;
  173. FILE * output ;
  174. FILE * output2 ;
  175. char lineRaw [ MAXARGLEN ] ;
  176. char lineCln [ MAXARGLEN ] ;
  177. char * rvRaw ;
  178. char * rvCln ;
  179. char * defaultSrc ;
  180. char * defaultDst ;
  181. char * defaultDst2 ;
  182. char * lineSkip ;
  183. char * * pDirs ;
  184. time_t timestamp ;
  185. struct tm localt ;
  186. char * * nextArg ;
  187. int fSysCrt = 0;
  188. int fCrt64 = 0;
  189. int fNoClean = 0;
  190. nextArg = ++ argv ;
  191. while ( * nextArg != NULL && * * nextArg == '-' )
  192. {
  193. if ( strcmp ( * nextArg , "-sys" ) == 0 )
  194. {
  195. fSysCrt = 1 ;
  196. }
  197. else if ( strcmp ( * nextArg , "-64" ) == 0 )
  198. {
  199. fCrt64 = 1 ;
  200. }
  201. else if ( strcmp ( * nextArg , "-noclean" ) == 0 )
  202. {
  203. fNoClean = 1 ;
  204. }
  205. else
  206. {
  207. Usage ( ) ;
  208. exit ( 1 ) ;
  209. }
  210. nextArg = ++ argv ;
  211. -- argc ;
  212. }
  213. if ( -- argc != 8 )
  214. {
  215. Usage ( ) ;
  216. exit ( 1 ) ;
  217. }
  218. defaultSrc = * nextArg ;
  219. ++ nextArg ;
  220. defaultDst = * nextArg ;
  221. ++ nextArg ;
  222. defaultDst2 = * nextArg ;
  223. ++ nextArg ;
  224. if ( ( inputRaw = fopen ( * nextArg , "rt" ) ) == NULL )
  225. {
  226. fprintf ( stderr , "mkclnmkf: cannot open input file \"%s\"\n" ,
  227. * nextArg ) ;
  228. exit ( 1 ) ;
  229. }
  230. ++ nextArg ;
  231. if ( ( inputCln = fopen ( * nextArg , "rt" ) ) == NULL )
  232. {
  233. fprintf ( stderr , "mkclnmkf: cannot open input file \"%s\"\n" ,
  234. * nextArg ) ;
  235. exit ( 1 ) ;
  236. }
  237. ++ nextArg ;
  238. if ( ( inputDir = fopen ( * nextArg , "rt" ) ) == NULL )
  239. {
  240. fprintf ( stderr , "mkclnmkf: cannot open input file \"%s\"\n" ,
  241. * nextArg ) ;
  242. exit ( 1 ) ;
  243. }
  244. ++ nextArg ;
  245. if ( ( output = fopen ( * nextArg , "rb" ) ) != NULL )
  246. {
  247. fprintf ( stderr , "mkclnmkf: first output file already exists: \"%s\"\n" ,
  248. * nextArg ) ;
  249. exit ( 1 ) ;
  250. }
  251. if ( ( output = fopen ( * nextArg , "wt" ) ) == NULL )
  252. {
  253. fprintf ( stderr , "mkclnmkf: cannot open first output file: \"%s\"\n" ,
  254. * nextArg ) ;
  255. exit ( 1 ) ;
  256. }
  257. ++ nextArg ;
  258. if ( ( output2 = fopen ( * nextArg , "rb" ) ) != NULL )
  259. {
  260. fprintf ( stderr , "mkclnmkf: second output file already exists: \"%s\"\n" ,
  261. * nextArg ) ;
  262. exit ( 1 ) ;
  263. }
  264. if ( ( output2 = fopen ( * nextArg , "wt" ) ) == NULL )
  265. {
  266. fprintf ( stderr , "mkclnmkf: cannot open second output file: \"%s\"\n" ,
  267. * nextArg ) ;
  268. exit ( 1 ) ;
  269. }
  270. ++ nextArg ;
  271. /*-
  272. * Read in the list of directories
  273. -*/
  274. {
  275. int numDirs = 0 ;
  276. int maxNumDirs = 0 ;
  277. char nextDir [ MAXARGLEN ] ;
  278. char * pDir ;
  279. pDir = fgetsNL ( nextDir , sizeof ( nextDir ) , inputDir ) ;
  280. while ( pDir )
  281. {
  282. if ( numDirs + 1 >= maxNumDirs )
  283. {
  284. maxNumDirs += 16 ;
  285. if ( ! ( DirList = ( char * * ) realloc ( DirList ,
  286. sizeof ( char * ) * maxNumDirs ) ) )
  287. {
  288. fprintf ( stderr ,
  289. "mkclnmkf: realloc failed (maxNumDirs=%d)\n" ,
  290. maxNumDirs ) ;
  291. exit ( 1 ) ;
  292. }
  293. }
  294. DirList [ numDirs ] = _strdup ( nextDir ) ;
  295. if ( ! DirList [ numDirs ] )
  296. {
  297. fprintf ( stderr ,
  298. "mkclnmkf: strdup failed (nextDir=\"%s\")\n" ,
  299. nextDir ) ;
  300. exit ( 1 ) ;
  301. }
  302. ++ numDirs ;
  303. pDir = fgetsNL ( nextDir , sizeof ( nextDir ) , inputDir ) ;
  304. }
  305. DirList [ numDirs ] = NULL ;
  306. {
  307. int i ;
  308. fprintf ( stderr , "Reading in directory list...\n" ) ;
  309. for ( i = 0 ; DirList [ i ] ; ++ i )
  310. Progress ( '(' , DirList [ i ] , ')' ) ;
  311. Progress ( '(' , NULL , ')' ) ;
  312. }
  313. }
  314. if ( fclose ( inputDir ) )
  315. {
  316. fprintf ( stderr ,
  317. "mkclnmkf: error closing input file \"%s\"\n" ,
  318. * nextArg ) ;
  319. }
  320. /*
  321. * Generate MAKEFILE header comment
  322. */
  323. time ( & timestamp ) ;
  324. localt = * localtime ( & timestamp ) ;
  325. fprintf ( output ,
  326. "########\n"
  327. "#\n"
  328. "# This is a program-generated Makefile, the purpose of which is to\n"
  329. "# copy Visual C++ v7.0 C Run-Time Library Source files from the raw\n"
  330. "# source tree to a directory structure suitable for end user usage\n"
  331. "# in debugging and modification. Not all of the VC++ 7.0 CRTL srcs\n"
  332. "# are provided to end users, but the ones that are 'cleansed' using\n"
  333. "# an automated process. Another makefile will copy these cleansed\n"
  334. "# files to their final directory lay-out.\n"
  335. "#\n"
  336. "# This Makefile was generated on\n"
  337. "#\t\t%.3s %2d %4d at %02d:%02d:%02d\n"
  338. "#\n"
  339. "# The program that generated this Makefile was compiled on\n"
  340. "#\t\t" __DATE__ " at " __TIME__ "\n"
  341. "\n"
  342. "!if \"$(SRC)\"==\"\"\n"
  343. "SRC=%s\n"
  344. "!endif\n"
  345. "\n"
  346. "!if \"$(DST)\"==\"\"\n"
  347. "DST=%s\n"
  348. "!endif\n"
  349. "\n"
  350. "all:\tdirs files\n"
  351. "\n"
  352. "files: \\\n" ,
  353. localt . tm_mon * 3 + "JanFebMarAprMayJunJulAugSepOctNovDec" ,
  354. localt . tm_mday , localt . tm_year + 1900 ,
  355. localt . tm_hour , localt . tm_min , localt . tm_sec ,
  356. defaultSrc , defaultDst ) ;
  357. fprintf ( output2 ,
  358. "########\n"
  359. "#\n"
  360. "# This is a program-generated Makefile, the purpose of which is to\n"
  361. "# copy the cleansed Visual C++ v7.0 C Run-Time Library Source files\n"
  362. "# to their directory lay-out which will be received by end users.\n"
  363. "#\n"
  364. "# This Makefile was generated on\n"
  365. "#\t\t%.3s %2d %4d at %02d:%02d:%02d\n"
  366. "#\n"
  367. "# The program that generated this Makefile was compiled on\n"
  368. "#\t\t" __DATE__ " at " __TIME__ "\n"
  369. "\n"
  370. "!if \"$(SRC)\"==\"\"\n"
  371. "SRC=%s\n"
  372. "!endif\n"
  373. "\n"
  374. "!if \"$(DST)\"==\"\"\n"
  375. "DST=%s\n"
  376. "!endif\n"
  377. "\n"
  378. "all:\tdirs files\n"
  379. "\n"
  380. "dirs:\n"
  381. "\t" AT "if not exist %s" CPUDIR "\\NUL mkdire %s" CPUDIR "\n"
  382. #if defined(_BUILD_IA64)
  383. "\t" AT "if not exist %s" INTEL_DIR "\\NUL mkdire %s" INTEL_DIR "\n"
  384. #endif
  385. "\t" AT "if not exist %ssys\\NUL mkdire %ssys\n"
  386. "\t" AT "if not exist %sbuild\\NUL mkdire %sbuild\n"
  387. "\t" AT "if not exist %sbuild\\" CPUDIR "\\NUL mkdire %sbuild\\" CPUDIR "\n"
  388. "\n"
  389. "files: \\\n"
  390. "\t%s%s \\\n"
  391. "\t%smakefile \\\n"
  392. "\t%smakefile.inc \\\n"
  393. "\t%smakefile.sub \\\n" ,
  394. localt . tm_mon * 3 + "JanFebMarAprMayJunJulAugSepOctNovDec" ,
  395. localt . tm_mday , localt . tm_year + 1900 ,
  396. localt . tm_hour , localt . tm_min , localt . tm_sec ,
  397. defaultDst , defaultDst2 ,
  398. /* if not exist ... CPUDIR */
  399. prefixDst , prefixDst ,
  400. #if defined(_BUILD_IA64)
  401. /* if not exist intel */
  402. prefixDst , prefixDst ,
  403. #endif
  404. /* if not exist sys */
  405. prefixDst , prefixDst ,
  406. /* if not exist build ... */
  407. prefixDst , prefixDst ,
  408. prefixDst , prefixDst ,
  409. /* RC files... */
  410. prefixDst , szRcFiles [ fSysCrt ] [ fCrt64 ] [ 1 ] ,
  411. prefixDst ,
  412. /* makefile.{,inc,sub} */
  413. prefixDst , prefixDst , prefixDst ) ;
  414. /*
  415. * Generate default ("all") dependecy
  416. */
  417. /*-
  418. * First, files that are just copied
  419. -*/
  420. rvRaw = fgetsNL ( lineRaw , sizeof ( lineRaw ) , inputRaw ) ;
  421. while ( rvRaw )
  422. {
  423. lineSkip = lineRaw ;
  424. #ifndef KEEPDIRS
  425. if ( ! strncmp ( "crtw32\\" , lineSkip , 7 ) )
  426. lineSkip += 7 ;
  427. else if ( ! strncmp ( "fpw32\\" , lineSkip , 6 ) )
  428. lineSkip += 6 ;
  429. #endif /* KEEPDIRS */
  430. fprintf ( output , "\t%s%s \\\n" ,
  431. prefixDst , lineSkip ) ;
  432. if ( ! memcmp ( lineSkip , "stdcpp\\" , 7 )
  433. || ! memcmp ( lineSkip , "stdhpp\\" , 7 ) )
  434. {
  435. /*
  436. * Files in the stdcpp / stdhpp directories are
  437. * special cases -- they are not cleansed but are
  438. * copied to the crt/src/ directory.
  439. */
  440. fprintf ( output2 , "\t%s%s \\\n" ,
  441. prefixDst , lineSkip + 7 ) ;
  442. }
  443. rvRaw = fgetsNL ( lineRaw , sizeof ( lineRaw ) , inputRaw ) ;
  444. }
  445. /*-
  446. * Second, files that have be cleansed
  447. -*/
  448. rvCln = fgetsNL ( lineCln , sizeof ( lineCln ) , inputCln ) ;
  449. while ( rvCln )
  450. {
  451. lineSkip = lineCln ;
  452. #ifndef KEEPDIRS
  453. if ( ! strncmp ( "crtw32\\" , lineSkip , 7 ) )
  454. lineSkip += 7 ;
  455. else if ( ! strncmp ( "fpw32\\" , lineSkip , 6 ) )
  456. lineSkip += 6 ;
  457. #endif /* KEEPDIRS */
  458. fprintf ( output , "\t%s%s \\\n" ,
  459. prefixDst , lineSkip ) ;
  460. fprintf ( output2 , "\t%s%s \\\n" ,
  461. prefixDst , SkipFirstDir ( lineSkip ) ) ;
  462. rvCln = fgetsNL ( lineCln , sizeof ( lineCln ) , inputCln ) ;
  463. }
  464. fprintf ( output ,
  465. "\n\n# Directory Dependencies:\n\ndirs:\n"
  466. "\t" AT "if not exist %sbuild\\NUL mkdire %sbuild\n" ,
  467. prefixDst , prefixDst ) ;
  468. #ifdef BLDROOTDIR
  469. /*
  470. * Create Root Directory Component by Component
  471. * NOTE: this code assumes prefixDst resembles:
  472. * \msdev\crt\src\
  473. */
  474. {
  475. char temp [ MAXARGLEN ] ;
  476. char * prefixSlash ;
  477. char * prefixNext ;
  478. int len ;
  479. strcpy ( temp , prefixDst ) ;
  480. len = strlen ( temp ) ;
  481. if ( temp [ len - 1 ] == '\\' )
  482. temp [ len - 1 ] == '\0' ;
  483. prefixNext = prefixDst + 1 ;
  484. while ( prefixSlash = strchr ( prefixNext , '\\' ) )
  485. {
  486. temp [ prefixSlash - prefixDst ] = '\0' ;
  487. fprintf ( output ,
  488. "\t" AT "if not exist %s\\NUL mkdire %s\n" ,
  489. temp , temp ) ;
  490. prefixNext = prefixSlash + 1 ;
  491. temp [ prefixSlash - prefixDst ] = '\\' ;
  492. }
  493. }
  494. #endif /* BLDROOTDIR */
  495. /*
  496. * Create Directories
  497. */
  498. for ( pDirs = DirList ; * pDirs ; ++ pDirs )
  499. {
  500. char * targetDir ;
  501. targetDir = * pDirs ;
  502. #ifndef KEEPDIRS
  503. if ( ! strcmp ( "crtw32" , targetDir )
  504. || ! strcmp ( "fpw32" , targetDir ) )
  505. continue ;
  506. if ( ! strncmp ( "crtw32\\" , targetDir , 7 ) )
  507. targetDir += 7 ;
  508. else if ( ! strncmp ( "fpw32\\" , targetDir , 6 ) )
  509. targetDir += 6 ;
  510. #endif /* KEEPDIRS */
  511. fprintf ( output ,
  512. "\t" AT "if not exist %s%s\\NUL mkdire %s%s\n" ,
  513. prefixDst , targetDir ,
  514. prefixDst , targetDir ,
  515. prefixDst , targetDir ) ;
  516. }
  517. fprintf ( output , "\n\n#\n# Individual Dependencies:\n#\n\n" ) ;
  518. /*
  519. * Second output makefile has some special targets
  520. */
  521. fprintf ( output2 , "\n\n#\n# Individual Dependencies:\n#\n\n" ) ;
  522. {
  523. static char * listMkf [ ] =
  524. {
  525. "makefile" , "makefile.inc" , "makefile.sub" , NULL
  526. } ;
  527. static const char * listSpc [ ] =
  528. {
  529. "msvcprt.rc" , NULL
  530. } ;
  531. int i ;
  532. listSpc [ 0 ] = szRcFiles [ fSysCrt ] [ fCrt64 ] [ 0 ] ;
  533. listSpc [ 1 ] = szRcFiles [ fSysCrt ] [ fCrt64 ] [ 1 ] ;
  534. listSpc [ 2 ] = szRcFiles [ fSysCrt ] [ fCrt64 ] [ 2 ] ;
  535. for ( i = 0 ; listSpc [ i ] ; ++ i )
  536. fprintf ( output2 ,
  537. "%s%s: %slibw32\\%s\n"
  538. "\t" AT "echo Copying %s from %s to %s.\n"
  539. "\t" AT "if exist %s%s attrib -r %s%s\n"
  540. "\t" AT "copy /b $** $@ >NUL\n"
  541. "\t" AT "attrib +r %s%s\n"
  542. "\n" ,
  543. /* %s%s: %slibw32\\%s */
  544. prefixDst , listSpc [ i ] ,
  545. prefixSrc , listSpc [ i ] ,
  546. /* echo Copying %s from %s to %s. */
  547. listSpc [ i ] , prefixSrc , prefixDst ,
  548. /* if exist %s%s attrib -r %s%s */
  549. prefixDst , listSpc [ i ] ,
  550. prefixDst , listSpc [ i ] ,
  551. /* copy /b $** $@ >NUL */
  552. /* attrib +r %s%s */
  553. prefixDst , listSpc [ i ] ) ;
  554. for ( i = 0 ; listMkf [ i ] ; ++ i )
  555. fprintf ( output2 ,
  556. "%s%s: %s%s relmkf.sed\n"
  557. "\t" AT "echo Copying %s from %s to %s. (using SED)\n"
  558. "\t" AT "if exist %s%s attrib -r %s%s\n"
  559. "\t" AT "sed -f relmkf.sed %s%s > $@\n"
  560. "\t" AT "attrib +r %s%s\n"
  561. "\n" ,
  562. /* %s%s: %slibw32\\%s */
  563. prefixDst , listMkf [ i ] ,
  564. prefixSrc , listMkf [ i ] ,
  565. /* echo Copying %s from %s to %s. */
  566. listMkf [ i ] , prefixSrc , prefixDst ,
  567. /* if exist %s%s attrib -r %s%s */
  568. prefixDst , listMkf [ i ] ,
  569. prefixDst , listMkf [ i ] ,
  570. /* sed -f relmkf.sed %s%s > $@ */
  571. prefixSrc , listMkf [ i ] ,
  572. /* attrib +r %s%s */
  573. prefixDst , listMkf [ i ] ) ;
  574. }
  575. /*
  576. * Reset input files for another pass: individual dependencies
  577. */
  578. if ( fseek ( inputRaw , 0L , SEEK_SET )
  579. || fseek ( inputCln , 0L , SEEK_SET ) )
  580. {
  581. fprintf ( stderr , "mkclnmkf: cannot reset input file(s)\n" ) ;
  582. exit ( 1 ) ;
  583. }
  584. /*
  585. * Generate individual dependecies for files that are copied as-is
  586. */
  587. fprintf ( stderr , "Producing copied file dependencies...\n" ) ;
  588. fprintf ( output , "# Copied File Dependencies:\n\n" ) ;
  589. rvRaw = fgetsNL ( lineRaw , sizeof ( lineRaw ) , inputRaw ) ;
  590. while ( rvRaw )
  591. {
  592. lineSkip = lineRaw ;
  593. #ifndef KEEPDIRS
  594. /*
  595. * strip crtw32\ and fpw32\ from the input string
  596. */
  597. if ( ! strncmp ( "crtw32\\" , lineSkip , 7 ) )
  598. lineSkip += 7 ;
  599. else if ( ! strncmp ( "fpw32\\" , lineSkip , 6 ) )
  600. lineSkip += 6 ;
  601. if ( ( lineRaw [ 0 ] != 'f'
  602. || strcmp ( lineSkip + strlen ( lineSkip ) - 9 , "\\lsources" ) )
  603. && strcmp ( "makefile" , lineRaw ) )
  604. #endif /* KEEPDIRS */
  605. fprintf ( output , fmtRaw ,
  606. /* %s%s: %s%s */
  607. prefixDst , lineSkip , prefixSrc , lineRaw ,
  608. /* echo Copying %s from %s to %s */
  609. lineSkip , prefixSrc , prefixDst ,
  610. /* if exist %s%s attrib -r %s%s */
  611. prefixDst , lineSkip , prefixDst , lineSkip ,
  612. /* copy /b %s%s %s%s */
  613. prefixSrc , lineRaw , prefixDst , lineSkip ,
  614. /* attrib +r %s%s */
  615. prefixDst , lineSkip ) ;
  616. #ifndef KEEPDIRS
  617. else
  618. fprintf ( output , fmtRaw2 ,
  619. /* %s%s: %s%s %ssrcrel\\bldmkf.sed */
  620. prefixDst , lineSkip ,
  621. prefixSrc , lineRaw , prefixSrc ,
  622. /* echo Copying %s from %s to %s */
  623. lineSkip , prefixSrc , prefixDst ,
  624. /* if exist %s%s attrib -r %s%s */
  625. prefixDst , lineSkip , prefixDst , lineSkip ,
  626. /* sed -f %ssrcrel\\bldmkf.sed %s%s > %s%s */
  627. prefixSrc ,
  628. prefixSrc , lineRaw , prefixDst , lineSkip ,
  629. /* attrib +r %s%s */
  630. prefixDst , lineSkip ) ;
  631. #endif /* KEEPDIRS */
  632. if ( ! memcmp ( lineSkip , "stdcpp\\" , 7 )
  633. || ! memcmp ( lineSkip , "stdhpp\\" , 7 ) )
  634. {
  635. /*
  636. * Files in the stdcpp / stdhpp directories are
  637. * special cases -- they are not cleansed but are
  638. * copied to the crt/src/ directory.
  639. */
  640. fprintf ( output2 , "%s%s: %s%s\n"
  641. "\t" AT "echo Copying %s from %s to %s.\n"
  642. "\t" AT "if exist %s%s attrib -r %s%s\n"
  643. "\t" AT "copy /b %s%s %s%s\n"
  644. "\t" AT "attrib +r %s%s\n"
  645. "\n" ,
  646. prefixDst , lineSkip + 7 ,
  647. prefixSrc , lineSkip ,
  648. lineRaw , prefixSrc , prefixDst ,
  649. prefixDst , lineSkip + 7 ,
  650. prefixDst , lineSkip + 7 ,
  651. prefixSrc , lineSkip ,
  652. prefixDst , lineSkip + 7 ,
  653. prefixDst , lineSkip + 7 ) ;
  654. }
  655. Progress ( '[' , lineRaw , ']' ) ;
  656. rvRaw = fgetsNL ( lineRaw , sizeof ( lineRaw ) , inputRaw ) ;
  657. }
  658. Progress ( '[' , NULL , ']' ) ;
  659. /*
  660. * Generate individual dependecies for files that are cleansed
  661. */
  662. fprintf ( stderr , "Producing cleansed file dependencies...\n" ) ;
  663. fprintf ( output , "# Cleansed File Dependencies:\n\n" ) ;
  664. rvCln = fgetsNL ( lineCln , sizeof ( lineCln ) , inputCln ) ;
  665. while ( rvCln )
  666. {
  667. char * pExt ;
  668. char pNoExt [ MAXARGLEN ] ;
  669. lineSkip = lineCln ;
  670. #ifndef KEEPDIRS
  671. /*
  672. * strip crtw32\ and fpw32\ from the input string
  673. */
  674. if ( ! strncmp ( "crtw32\\" , lineSkip , 7 ) )
  675. lineSkip += 7 ;
  676. else if ( ! strncmp ( "fpw32\\" , lineSkip , 6 ) )
  677. lineSkip += 6 ;
  678. #endif /* KEEPDIRS */
  679. pExt = strrchr ( lineSkip , '.' ) ;
  680. if ( ! pExt )
  681. {
  682. fprintf ( stderr ,
  683. "Warning: filename has no extension: %s\n" ,
  684. lineCln ) ;
  685. pExt = lineSkip + strlen ( pExt ) ;
  686. }
  687. strcpy ( pNoExt , lineSkip ) ;
  688. pNoExt [ pExt - lineSkip ] = '\0' ;
  689. if ( !fNoClean )
  690. /*
  691. * .INC files do not get ifstripped - use fmtCln2 for them
  692. */
  693. fprintf ( output ,
  694. strcmp ( ".inc" , pExt ) ? fmtCln : fmtCln2 ,
  695. /* %s%s: %scrtw32\%s %ssrcrel\msvc40.if */
  696. prefixDst , lineSkip , prefixSrc , lineCln , prefixSrc ,
  697. /* echo Cleansing %scrtw32\%s */
  698. prefixDst , lineSkip ,
  699. /* if exist %s%s attrib -r %s%s */
  700. prefixDst , lineSkip , prefixDst , lineSkip ,
  701. /* detab < %scrtw32\%s | trailing > ... */
  702. prefixSrc , lineCln , prefixDst , lineSkip ,
  703. /* ifstrip %s\srcrel\msvc40.if %s%s */
  704. prefixSrc , prefixDst , lineSkip ,
  705. /* del %s%s */
  706. prefixDst , lineSkip ,
  707. /* ren %s%s.TMP *%s */
  708. prefixDst , pNoExt , pExt ,
  709. /* striphdr -r %s%s */
  710. prefixDst , lineSkip ,
  711. /* del %s%s */
  712. prefixDst , lineSkip ,
  713. /* ren %s%s.NEW *%s */
  714. prefixDst , pNoExt , pExt ,
  715. /* attrib +r %s%s */
  716. prefixDst , lineSkip ) ;
  717. else
  718. /*
  719. * -noclean: Just copy, don't cleanse, for development builds
  720. */
  721. fprintf ( output , fmtRaw ,
  722. /* %s%s: %s%s */
  723. prefixDst , lineSkip , prefixSrc , lineCln ,
  724. /* echo Copying %s from %s to %s */
  725. lineSkip , prefixSrc , prefixDst ,
  726. /* if exist %s%s attrib -r %s%s */
  727. prefixDst , lineSkip , prefixDst , lineSkip ,
  728. /* copy /b %s%s %s%s */
  729. prefixSrc , lineCln , prefixDst , lineSkip ,
  730. /* attrib +r %s%s */
  731. prefixDst , lineSkip ) ;
  732. /*
  733. * Secondary makefile
  734. */
  735. if ( memcmp ( "libw32" , lineCln , 6 ) )
  736. {
  737. char * lineSkipFirst = SkipFirstDir ( lineSkip ) ;
  738. if ( ! strcmp ( ".asm" , pExt ) &&
  739. ( ! memcmp ( "mbstring" , lineSkip , 8 )
  740. || ! strcmp ( "memmove.asm" , pExt - 7 )
  741. || ! strcmp ( "strcspn.asm" , pExt - 7 )
  742. || ! strcmp ( "strpbrk.asm" , pExt - 7 ) )
  743. || ! strcmp ( ".c" , pExt ) &&
  744. ( ! strcmp ( "mbscat.c" , pExt - 6 )
  745. || ! strcmp ( "mbsdup.c" , pExt - 6 ) ) )
  746. fprintf ( output2 ,
  747. "%s%s: %s%s asmfile.sed\n"
  748. "\t" AT "echo Copying %s from %s to %s. (using SED.EXE)\n"
  749. "\t" AT "if exist %s%s attrib -r %s%s\n"
  750. "\t" AT "sed -f asmfile.sed %s%s > $@\n"
  751. "\t" AT "attrib +r %s%s\n"
  752. "\n" ,
  753. /* %s%s: %s%s asmfile.sed */
  754. prefixDst , lineSkipFirst ,
  755. prefixSrc , lineSkip ,
  756. /* echo Copying %s from %s to %s... */
  757. lineSkip , prefixSrc , prefixDst ,
  758. /* if exist %s%s attrib -r %s%s */
  759. prefixDst , lineSkipFirst ,
  760. prefixDst , lineSkipFirst ,
  761. /* sed -f asmfile.sed %s%s > $@ */
  762. prefixSrc , lineSkip ,
  763. /* attrib +r %s%s */
  764. prefixDst , lineSkipFirst ) ;
  765. else
  766. fprintf ( output2 ,
  767. "%s%s: %s%s\n"
  768. "\t" AT "echo Copying %s from %s to %s.\n"
  769. "\t" AT "if exist %s%s attrib -r %s%s\n"
  770. "\t" AT "copy /b $** $@ >NUL\n"
  771. "\t" AT "attrib +r %s%s\n"
  772. "\n" ,
  773. /* %s%s: %s%s */
  774. prefixDst , lineSkipFirst ,
  775. prefixSrc , lineSkip ,
  776. /* Copying %s from %s to %s */
  777. lineSkip , prefixSrc , prefixDst ,
  778. /* if exist %s%s attrib -r %s%s */
  779. prefixDst , lineSkipFirst ,
  780. prefixDst , lineSkipFirst ,
  781. /* copy /b $** $@ >NUL */
  782. /* attrib +r %s%s */
  783. prefixDst , lineSkipFirst ) ;
  784. }
  785. /*
  786. * Show Progress
  787. */
  788. Progress ( '{' , lineSkip , '}' ) ;
  789. rvCln = fgetsNL ( lineCln , sizeof ( lineCln ) , inputCln ) ;
  790. }
  791. Progress ( '{' , NULL , '}' ) ;
  792. return 0 ;
  793. }
  794. /*
  795. * Usage - print message explaining the arguments to this program
  796. */
  797. void Usage ( void )
  798. {
  799. fprintf ( stderr ,
  800. "Usage: mkclnmkf [opts] prefIn prefOut prefOut2 fRaw fCln dirList mkfOut mkfOut2\n"
  801. "where\tprefIn is the input prefix (such as \"\\crt\")\n"
  802. "\tprefOut is the primary output prefix (such as \"\\msdev\\crt\\prebuild\")\n"
  803. "\tprefOut2 is the secondary output prefix (such as \"\\msdev\\crt\\src\")\n"
  804. "\tfRaw is a list of files to be copied as-is\n"
  805. "\tfCln is a list of files to be cleansed\n"
  806. "\tdirList is a list of the directories to be created\n"
  807. "\tmkfOut is the primary output makefile (it may not already exist)\n"
  808. "\tmkfOut2 is the secondary output makefile (it may not already exist)\n\n"
  809. "\tOptions:\n"
  810. "\t -sys\t\tuse system CRT filenames\n"
  811. "\t -64\t\tuse Win64 CRT filenames\n"
  812. "\t -noclean\tdon't cleanse source files\n"
  813. ) ;
  814. }
  815. /*
  816. * fgetsNL - same as fgets except final newline character is deleted
  817. * Upon EOF or error, make sure the buffer is set to the empty string.
  818. */
  819. char * fgetsNL ( char * lineBuf , int lineSize , FILE * fileInput )
  820. {
  821. char * retval = fgets ( lineBuf , lineSize , fileInput ) ;
  822. if ( retval )
  823. {
  824. int len = strlen ( lineBuf ) ;
  825. if ( len < 1 && lineBuf [ len - 1 ] != '\n' )
  826. {
  827. fprintf ( stderr , "mkclnmkf: malformed input line:\n\t%s\n" , lineBuf ) ;
  828. }
  829. else
  830. lineBuf [ len - 1 ] = '\0' ;
  831. }
  832. else
  833. lineBuf [ 0 ] = '\0' ;
  834. return retval ;
  835. }
  836. void Progress ( int prefix , char * string , int suffix )
  837. {
  838. static int prevlen = 0 ;
  839. static int counter = 0 ;
  840. if ( string == NULL )
  841. {
  842. fprintf ( stderr , "%*s\n" , prevlen + 3 , " " ) ;
  843. prevlen = 0 ;
  844. counter = 0 ;
  845. }
  846. else if ( ++ counter % 100 == 1 )
  847. {
  848. int length = strlen ( string ) ;
  849. fprintf ( stderr , "%c%s%c%*s\r" ,
  850. prefix , string , suffix ,
  851. prevlen > length ? prevlen - length : 1 ,
  852. " " ) ;
  853. prevlen = length ;
  854. }
  855. }
  856. char * SkipFirstDir ( char * string )
  857. {
  858. char * pFile = string ;
  859. while ( * pFile ++ != '\\' )
  860. if ( ! * pFile )
  861. {
  862. fprintf ( stderr ,
  863. "mkclnmkf: no \\ in \"%s\"\n" , string ) ;
  864. exit ( 1 ) ;
  865. }
  866. return pFile ;
  867. }