|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the tools applications of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 #include "cesdkhandler.h" |
|
42 #include <QtCore/QStringList> |
|
43 #include <QtCore/QFile> |
|
44 #include <QtCore/QDir> |
|
45 #include <QtCore/QDebug> |
|
46 |
|
47 void usage() |
|
48 { |
|
49 printf("SDK Scanner - Convenience Tool to setup your environment\n"); |
|
50 printf(" for crosscompilation to Windows CE\n"); |
|
51 printf("Options:\n"); |
|
52 printf("-help This output\n"); |
|
53 printf("-list List all available SDKs\n"); |
|
54 printf("-sdk <name> Select specified SDK.\n"); |
|
55 printf(" Note: SDK names with spaces need to be\n"); |
|
56 printf(" specified in parenthesis\n"); |
|
57 printf(" default: Windows Mobile 5.0 Pocket PC SDK (ARMV4I)\n"); |
|
58 printf("-script <file> Create a script file which can be launched\n"); |
|
59 printf(" to setup your environment for specified SDK\n"); |
|
60 } |
|
61 |
|
62 int main(int argc, char **argv) |
|
63 { |
|
64 if (argc == 1) { |
|
65 usage(); |
|
66 return 0; |
|
67 } |
|
68 QString sdkName; |
|
69 bool operationList = false; |
|
70 QString scriptFile; |
|
71 |
|
72 QStringList arguments; |
|
73 for (int i=0; i < argc; ++i) |
|
74 arguments.append(QLatin1String(argv[i])); |
|
75 for (int i=1; i < arguments.size(); ++i) { |
|
76 if (arguments[i].toLower() == QLatin1String("-help")) { |
|
77 usage(); |
|
78 return 0; |
|
79 } else if (arguments[i].toLower() == QLatin1String("-list")) { |
|
80 operationList = true; |
|
81 } else if (arguments[i].toLower() == QLatin1String("-sdk")) { |
|
82 if (i+1 >= arguments.size()) { |
|
83 qWarning("No SDK specified."); |
|
84 return -1; |
|
85 } |
|
86 sdkName = arguments[++i]; |
|
87 } else if (arguments[i].toLower() == QLatin1String("-script")) { |
|
88 if (i+1 >= arguments.size()) { |
|
89 qWarning("No scriptfile specified."); |
|
90 return -1; |
|
91 } |
|
92 scriptFile = arguments[++i]; |
|
93 } else { |
|
94 qWarning("Unknown option:%s", qPrintable(arguments[i])); |
|
95 usage(); |
|
96 return -1; |
|
97 } |
|
98 } |
|
99 |
|
100 CeSdkHandler handler; |
|
101 if (!handler.parse()) { |
|
102 qWarning("Could not find any installed SDK, aborting!"); |
|
103 return -1; |
|
104 } |
|
105 |
|
106 QList<CeSdkInfo> list = handler.listAll(); |
|
107 |
|
108 if (operationList) { |
|
109 printf("Available SDKs:\n"); |
|
110 for (QList<CeSdkInfo>::iterator it = list.begin(); it != list.end(); ++it) { |
|
111 printf("SDK Name: "); |
|
112 printf(qPrintable(it->name())); |
|
113 printf("\n"); |
|
114 } |
|
115 return 0; |
|
116 } |
|
117 |
|
118 // Check for SDK Name, otherwise use Windows Mobile as default |
|
119 if (sdkName.isEmpty()) { |
|
120 qWarning("No SDK specified: Defaulting to Windows Mobile 5.0 Pocket PC SDK"); |
|
121 sdkName = QString::fromLatin1("Windows Mobile 5.0 Pocket PC SDK (ARMV4I)"); |
|
122 } |
|
123 |
|
124 // finally find the given SDK and prompt out the environment to be set |
|
125 for (QList<CeSdkInfo>::iterator it = list.begin(); it != list.end(); ++it ) { |
|
126 if (sdkName == it->name()) { |
|
127 if (!it->isValid()) { |
|
128 qWarning("Selected SDK is not valid!"); |
|
129 return -1; |
|
130 } else if (!it->isSupported()) { |
|
131 qWarning("Selected SDK is not officially supported and might not work"); |
|
132 } |
|
133 QString binPath, includePath, libPath; |
|
134 binPath = QString::fromLatin1("PATH=") + it->binPath(); |
|
135 includePath = QString::fromLatin1("INCLUDE=") + it->includePath(); |
|
136 libPath = QString::fromLatin1("LIB=") + it->libPath(); |
|
137 if (scriptFile.isEmpty()) { |
|
138 printf("Please set up your environment with the following paths:\n"); |
|
139 printf(qPrintable(binPath)); |
|
140 printf("\n"); |
|
141 printf(qPrintable(includePath)); |
|
142 printf("\n"); |
|
143 printf(qPrintable(libPath)); |
|
144 printf("\n"); |
|
145 return 0; |
|
146 } else { |
|
147 QFile file(scriptFile); |
|
148 if (!file.open(QIODevice::WriteOnly)) { |
|
149 qWarning("Could not open target script file"); |
|
150 return -1; |
|
151 } |
|
152 QString content; |
|
153 content += QLatin1String("@echo off\n"); |
|
154 content += QLatin1String("echo Environment Selection:") + sdkName + QLatin1String("\n"); |
|
155 content += QLatin1String("set ") + binPath + QLatin1String("\n"); |
|
156 content += QLatin1String("set ") + includePath + QLatin1String("\n"); |
|
157 content += QLatin1String("set ") + libPath + QLatin1String("\n"); |
|
158 file.write(content.toLatin1()); |
|
159 return 0; |
|
160 } |
|
161 } |
|
162 } |
|
163 qWarning("Could not find specified SDK: %s" , qPrintable(sdkName)); |
|
164 return -1; |
|
165 } |