2 * udibuild - UDI Compilation Utility
3 * - By John Hodge (thePowersGang)
10 #include <unistd.h> // getopt
12 #include <string.h> // strrchr
14 #include "include/common.h"
15 #include "include/build.h"
16 #include "include/inifile.h"
17 #include "include/udiprops.h"
20 #define CONFIG_FILE "/Acess/Conf/UDI/udibuild.ini"
22 #define CONFIG_FILE "/etc/udi/udibuild.ini"
26 int main(int argc, char *argv[]);
27 int ParseArguments(int argc, char *argv[]);
28 void Usage(const char *progname);
31 const char *gsOpt_ConfigFile;
32 const char *gsOpt_WorkingDir;
33 const char *gsOpt_UdipropsFile;
34 const char *gsOpt_ABIName = "ia32";
36 tUdiprops *gpUdipropsBuild;
39 int main(int argc, char *argv[])
41 if( ParseArguments(argc, argv) ) {
45 // Locate udibuild.ini
47 if( !gsOpt_ConfigFile ) {
48 //if( file_exists("./udibuild.ini") )
50 // gsOpt_ConfigFile = "udibuild.ini";
53 // 2. Check program dir (if not invoked from PATH)
54 if( !gsOpt_ConfigFile && (argv[0][0] == '.' || argv[0][0] == '/') ) {
55 char *last_slash = strrchr(argv[0], '/');
57 gsOpt_ConfigFile = mkstr("%.*s/udibuild.ini",
58 last_slash-argv[0], argv[0]);
60 //if( !file_exists(gsOpt_ConfigFile) ) {
61 // free(gsOpt_ConfigFile);
62 // gsOpt_ConfigFile = NULL;
65 // 3. Check ~/.config/udi/udibuild.ini
66 // 4. Check CONFIGNAME
69 if( !gsOpt_ConfigFile ) {
70 fprintf(stderr, "Can't locate udibuild.ini file, please specify using '-c'\n");
75 gpOptions = IniFile_Load(gsOpt_ConfigFile);
78 // Change to working directory (-C <dir>)
79 if( gsOpt_WorkingDir )
81 chdir(gsOpt_WorkingDir);
85 gpUdipropsBuild = Udiprops_LoadBuild( gsOpt_UdipropsFile ? gsOpt_UdipropsFile : "udiprops.txt" );
86 assert(gpUdipropsBuild);
87 assert(gpUdipropsBuild->SourceFiles);
90 for( int i = 0; i < gpUdipropsBuild->nSourceFiles; i ++ )
92 int rv = Build_CompileFile(gpOptions, gsOpt_ABIName, gpUdipropsBuild,
93 gpUdipropsBuild->SourceFiles[i]);
95 fprintf(stderr, "*** Exit status: %i\n", rv);
99 Build_LinkObjects(gpOptions, gsOpt_ABIName, gpUdipropsBuild);
104 int ParseArguments(int argc, char *argv[])
107 while( (opt = getopt(argc, argv, "hC:c:f:a:")) != -1 )
115 gsOpt_WorkingDir = optarg;
118 gsOpt_ConfigFile = optarg;
121 gsOpt_UdipropsFile = optarg;
124 gsOpt_ABIName = optarg;
130 fprintf(stderr, "BUG: Unhandled optarg %i '%c'\n", opt, opt);
137 void Usage(const char *progname)
139 fprintf(stderr, "Usage: %s [-C workingdir] [-c udibuild.ini] [-f udiprops.txt] [-a abiname]\n",
142 "-C workingdir : Change to the specified directory before looking for udiprops.txt\n"
143 "-c udibuild.ini : Override the default udibuild config file\n"
144 "-f udiprops.txt : Override the default udiprops file\n"
145 "-a abiname : Select a different ABI\n"
149 char *mkstr(const char *fmt, ...)
153 size_t len = vsnprintf(NULL, 0, fmt, args);
156 char *ret = malloc(len+1);
157 vsnprintf(ret, len+1, fmt, args);