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:T:")) != -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         case 'T':
76             if (!StaticSetTargetName(optarg))
77             {
78                 fprintf(stderr, "Target Name already specified [%s]. Stop.\n", optarg);
79                 return 1;
80             }
81             break;
82 
83         default:
84             break;
85         }
86     }
87 
88     narg = argc - optind;
89 
90     if (narg == 2 || narg == 3)
91     {
92         if (ParseSpecFile(argv[optind]))
93         {
94             fprintf(stderr, "Stop.\n");
95             return 1;
96         }
97 
98         if (ParseTlcfFile(argv[optind + 1]))
99         {
100             fprintf(stderr, "Stop.\n");
101             return 1;
102         }
103 
104         if (CreateLcfFile(narg == 3 ? argv[optind + 2] : NULL))
105         {
106             fprintf(stderr, "Stop.\n");
107             return 1;
108         }
109         return 0;
110     }
111 
112   usage:
113     {
114         fprintf(stderr,
115                 "NITRO-SDK Development Tool - makelcf - Make linker command file\n"
116                 "Build %lu\n\n"
117                 "Usage:  makelcf [-DNAME=VALUE...] [-MDEFINES_FILE] [-TTARGET_NAME] [-V1|-V2] SPECFILE LCF-TEMPALTE [LCFILE]\n\n",
118                 SDK_DATE_OF_LATEST_FILE);
119     }
120     return 2;
121 }
122