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 bool gbTraceEnabled = false;
33 const char *gsRuntimeDir = RUNTIME_DIR;
34 const char *gsOpt_ConfigFile;
35 const char *gsOpt_WorkingDir;
36 const char *gsOpt_UdipropsFile;
37 const char *gsOpt_ABIName = "ia32";
39 tUdiprops *gpUdipropsBuild;
42 int main(int argc, char *argv[])
44 if( ParseArguments(argc, argv) ) {
48 // Locate udibuild.ini
50 if( !gsOpt_ConfigFile ) {
51 //if( file_exists("./udibuild.ini") )
53 // gsOpt_ConfigFile = "udibuild.ini";
56 // 2. Check program dir (if not invoked from PATH)
57 if( !gsOpt_ConfigFile && (argv[0][0] == '.' || argv[0][0] == '/') ) {
58 char *last_slash = strrchr(argv[0], '/');
60 gsOpt_ConfigFile = mkstr("%.*s/%s",
61 last_slash-argv[0], argv[0], CONFIG_FILENAME);
63 //if( !file_exists(gsOpt_ConfigFile) ) {
64 // free(gsOpt_ConfigFile);
65 // gsOpt_ConfigFile = NULL;
68 // 3. Check ~/.config/udi/udibuild.ini
69 // 4. Check RUNTIME_DIR/udibuild.ini
72 if( !gsOpt_ConfigFile ) {
73 fprintf(stderr, "Can't locate "CONFIG_FILENAME" file, please specify using '-c'\n");
78 gpOptions = IniFile_Load(gsOpt_ConfigFile);
81 // Change to working directory (-C <dir>)
82 if( gsOpt_WorkingDir )
84 chdir(gsOpt_WorkingDir);
88 gpUdipropsBuild = Udiprops_LoadBuild( gsOpt_UdipropsFile ? gsOpt_UdipropsFile : "udiprops.txt" );
89 assert(gpUdipropsBuild);
90 assert(gpUdipropsBuild->SourceFiles);
93 for( int i = 0; i < gpUdipropsBuild->nSourceFiles; i ++ )
95 int rv = Build_CompileFile(gpOptions, gsOpt_ABIName, gpUdipropsBuild,
96 gpUdipropsBuild->SourceFiles[i]);
98 fprintf(stderr, "*** Exit status: %i\n", rv);
102 // Create file with `.udiprops` section
104 //Build_CreateUdiprops(gpOptions, gsOpt_ABIName, gpUdipropsBuild);
106 Build_LinkObjects(gpOptions, gsOpt_ABIName, gpUdipropsBuild);
111 int ParseArguments(int argc, char *argv[])
114 while( (opt = getopt(argc, argv, "hC:c:f:a:")) != -1 )
122 gsOpt_WorkingDir = optarg;
125 gsOpt_ConfigFile = optarg;
128 gsOpt_UdipropsFile = optarg;
131 gsOpt_ABIName = optarg;
137 fprintf(stderr, "BUG: Unhandled optarg %i '%c'\n", opt, opt);
144 void Usage(const char *progname)
146 fprintf(stderr, "Usage: %s [-C workingdir] [-c udibuild.ini] [-f udiprops.txt] [-a abiname]\n",
149 "-C workingdir : Change to the specified directory before looking for udiprops.txt\n"
150 "-c udibuild.ini : Override the default udibuild config file\n"
151 "-f udiprops.txt : Override the default udiprops file\n"
152 "-a abiname : Select a different ABI\n"
156 char *mkstr(const char *fmt, ...)
160 size_t len = vsnprintf(NULL, 0, fmt, args);
163 char *ret = malloc(len+1);
164 vsnprintf(ret, len+1, fmt, args);