1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - tools - makelcf
3 File: makelcf.c
4
5 Copyright 2003-2008 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Date:: 2008-09-17#$
14 $Rev: 8556 $
15 $Author: okubata_ryoma $
16 *---------------------------------------------------------------------------*/
17 #include <stdio.h>
18 #include <stdlib.h> // atoi()
19 #include <ctype.h>
20 #include <getopt.h> // getopt()
21 #include "makelcf.h"
22 #include "defval.h"
23 #include "misc.h"
24
25 extern const unsigned long SDK_DATE_OF_LATEST_FILE;
26
27 /*---------------------------------------------------------------------------*
28 * MAIN
29 *---------------------------------------------------------------------------*/
30
main(int argc,char * argv[])31 int main(int argc, char *argv[])
32 {
33 int n;
34 int narg;
35 int t;
36
37 while ((n = getopt(argc, argv, "hdD:M:V:")) != -1)
38 {
39 switch (n)
40 {
41 case 'h':
42 goto usage;
43
44 case 'd':
45 DebugMode = TRUE;
46 break;
47
48 case 'D':
49 AddDefVal(optarg);
50 break;
51
52 case 'M':
53 if (!AddDefValFromFile(optarg))
54 {
55 fprintf(stderr, "Stop.\n");
56 return 1;
57 }
58 break;
59
60 case 'V':
61 t = atoi(optarg);
62 if (t >= 1)
63 {
64 char str[128];
65 sprintf(str, "NITRO_LCFSPEC=%d", t); // NITRO_LCFSPEC is defined
66 AddDefVal(str);
67 }
68 else
69 {
70 fprintf(stderr, "Unknown version number [%s]. Stop.\n", optarg);
71 return 1;
72 }
73 break;
74
75 default:
76 break;
77 }
78 }
79
80 narg = argc - optind;
81
82 if (narg == 2 || narg == 3)
83 {
84 if (ParseSpecFile(argv[optind]))
85 {
86 fprintf(stderr, "Stop.\n");
87 return 1;
88 }
89
90 if (ParseTlcfFile(argv[optind + 1]))
91 {
92 fprintf(stderr, "Stop.\n");
93 return 1;
94 }
95
96 if (CreateLcfFile(narg == 3 ? argv[optind + 2] : NULL))
97 {
98 fprintf(stderr, "Stop.\n");
99 return 1;
100 }
101 return 0;
102 }
103
104 usage:
105 {
106 fprintf(stderr,
107 "NITRO-SDK Development Tool - makelcf - Make linker command file\n"
108 "Build %lu\n\n"
109 "Usage: makelcf [-DNAME=VALUE...] [-MDEFINES_FILE] [-V1|-V2] SPECFILE LCF-TEMPALTE [LCFILE]\n\n",
110 SDK_DATE_OF_LATEST_FILE);
111 }
112 return 2;
113 }
114