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"
19 #define CONFIG_FILENAME "udibuild.ini"
21 #define RUNTIME_DIR "/Acess/Conf/UDI"
23 #define RUNTIME_DIR "/etc/udi"
27 int main(int argc, char *argv[]);
28 int ParseArguments(int argc, char *argv[]);
29 void Usage(const char *progname);
32 const char *gsRuntimeDir = RUNTIME_DIR;
33 const char *gsOpt_ConfigFile;
34 const char *gsOpt_WorkingDir;
35 const char *gsOpt_UdipropsFile;
36 const char *gsOpt_ABIName = "ia32";
38 tUdiprops *gpUdipropsBuild;
41 int main(int argc, char *argv[])
43 if( ParseArguments(argc, argv) ) {
47 // Locate udibuild.ini
49 if( !gsOpt_ConfigFile ) {
50 //if( file_exists("./udibuild.ini") )
52 // gsOpt_ConfigFile = "udibuild.ini";
55 // 2. Check program dir (if not invoked from PATH)
56 if( !gsOpt_ConfigFile && (argv[0][0] == '.' || argv[0][0] == '/') ) {
57 char *last_slash = strrchr(argv[0], '/');
59 gsOpt_ConfigFile = mkstr("%.*s/%s",
60 last_slash-argv[0], argv[0], CONFIG_FILENAME);
62 //if( !file_exists(gsOpt_ConfigFile) ) {
63 // free(gsOpt_ConfigFile);
64 // gsOpt_ConfigFile = NULL;
67 // 3. Check ~/.config/udi/udibuild.ini
68 // 4. Check RUNTIME_DIR/udibuild.ini
71 if( !gsOpt_ConfigFile ) {
72 fprintf(stderr, "Can't locate "CONFIG_FILENAME" file, please specify using '-c'\n");
77 gpOptions = IniFile_Load(gsOpt_ConfigFile);
80 // Change to working directory (-C <dir>)
81 if( gsOpt_WorkingDir )
83 chdir(gsOpt_WorkingDir);
87 gpUdipropsBuild = Udiprops_LoadBuild( gsOpt_UdipropsFile ? gsOpt_UdipropsFile : "udiprops.txt" );
88 assert(gpUdipropsBuild);
89 assert(gpUdipropsBuild->SourceFiles);
92 for( int i = 0; i < gpUdipropsBuild->nSourceFiles; i ++ )
94 int rv = Build_CompileFile(gpOptions, gsOpt_ABIName, gpUdipropsBuild,
95 gpUdipropsBuild->SourceFiles[i]);
97 fprintf(stderr, "*** Exit status: %i\n", rv);
101 Build_LinkObjects(gpOptions, gsOpt_ABIName, gpUdipropsBuild);
106 int ParseArguments(int argc, char *argv[])
109 while( (opt = getopt(argc, argv, "hC:c:f:a:")) != -1 )
117 gsOpt_WorkingDir = optarg;
120 gsOpt_ConfigFile = optarg;
123 gsOpt_UdipropsFile = optarg;
126 gsOpt_ABIName = optarg;
132 fprintf(stderr, "BUG: Unhandled optarg %i '%c'\n", opt, opt);
139 void Usage(const char *progname)
141 fprintf(stderr, "Usage: %s [-C workingdir] [-c udibuild.ini] [-f udiprops.txt] [-a abiname]\n",
144 "-C workingdir : Change to the specified directory before looking for udiprops.txt\n"
145 "-c udibuild.ini : Override the default udibuild config file\n"
146 "-f udiprops.txt : Override the default udiprops file\n"
147 "-a abiname : Select a different ABI\n"
151 char *mkstr(const char *fmt, ...)
155 size_t len = vsnprintf(NULL, 0, fmt, args);
158 char *ret = malloc(len+1);
159 vsnprintf(ret, len+1, fmt, args);