25 #include <gwenhywfar/gwenhywfar.h> 26 #include <gwenhywfar/cgui.h> 27 #include <gwenhywfar/debug.h> 28 #include <gwenhywfar/args.h> 29 #include <gwenhywfar/i18n.h> 30 #include <gwenhywfar/text.h> 31 #include <gwenhywfar/directory.h> 41 #define I18N(msg) GWEN_I18N_Translate(PACKAGE, msg) 45 #define ARGS_COMMAND_SETUP 0x0001 46 #define ARGS_COMMAND_PREPARE 0x0002 47 #define ARGS_COMMAND_BUILD 0x0004 48 #define ARGS_COMMAND_REPEAT_SETUP 0x0008 49 #define ARGS_COMMAND_INSTALL 0x0010 50 #define ARGS_COMMAND_CLEAN 0x0020 51 #define ARGS_COMMAND_DIST 0x0040 56 static int _handleStringArgument(
int argc,
char **argv,
int *pIndex,
const char *sArg,
const char *sArgId,
65 # ifdef _POSIX_C_SOURCE 66 struct sigaction sigActionChild;
70 void _signalHandler(
int s) {
72 #ifdef _POSIX_C_SOURCE 78 fprintf(stderr,
"Received unhandled signal %d\n", s);
81 signal(s, _signalHandler);
87 int _setSingleSignalHandler(
struct sigaction *sa,
int sig)
89 sa->sa_handler=_signalHandler;
90 sigemptyset(&sa->sa_mask);
92 if (sigaction(sig, sa, 0)) {
93 DBG_ERROR(
NULL,
"Could not setup signal handler for signal %d", sig);
102 int _setSignalHandlers() {
103 #ifdef _POSIX_C_SOURCE 106 rv=_setSingleSignalHandler(&sigActionChild, SIGCHLD);
121 int main(
int argc,
char **argv)
130 #if defined(HAVE_SIGNAL_H) && defined(_POSIX_C_SOURCE) 131 signal(SIGCHLD, _signalHandler);
137 fprintf(stderr,
"Could not initialize Gwenhywfar.\n");
178 fprintf(stderr,
"ERROR: Error on setup build environment.\n");
186 fprintf(stderr,
"ERROR: Error on repeating setup.\n");
194 fprintf(stderr,
"ERROR: Error on preparing build environment.\n");
202 fprintf(stderr,
"ERROR: Error on building.\n");
210 fprintf(stderr,
"ERROR: Error on installing.\n");
218 fprintf(stderr,
"ERROR: Error on creating dist file.\n");
226 fprintf(stderr,
"ERROR: Error on cleaning generated files.\n");
235 "WARNING: Could not deinitialize Gwenhywfar.\n");
280 fprintf(stderr,
"Specifying build target not yet supported.\n");
287 if (strncmp(s,
"-O", 2)==0) {
292 if (strncmp(s,
"-B", 2)==0) {
297 if (strncmp(s,
"-L", 2)==0) {
302 if (strncmp(s,
"-C", 2)==0) {
307 else if (strcmp(s,
"--dump")==0)
309 else if (strcmp(s,
"--static")==0)
311 else if (strcmp(s,
"--help")==0) {
315 else if (strcmp(s,
"-p")==0)
317 else if (strcmp(s,
"-s")==0) {
323 else if (strcmp(s,
"-r")==0)
325 else if (strcmp(s,
"-b")==0)
327 else if (strcmp(s,
"-i")==0)
329 else if (strcmp(s,
"-c")==0)
331 else if (strcmp(s,
"-d")==0)
333 else if (strncmp(s,
"-j", 2)==0) {
344 if (1!=sscanf(s,
"%d", &val)) {
371 "Building a project (e.g. compiling and linking) is done in multiple steps.\n" 373 "1. Setup Build Environment\n" 374 "-------------------------\n" 375 "A. Create files named 0BUILD inside your project (see project AqFinance for\n" 377 "B. Create an empty folder and change into it (all next commands are run\n" 379 "You might want to use a folder like 'build' inside the source tree of\n" 382 " gwbuild -s PATH_TO_SOURCE_TREE\n" 383 "e.g. gwbuild -s ..\n" 385 "2. Prepare Buidling\n" 386 "-------------------\n" 388 "This is only needed if your project uses typemaker2 to generate c-sources from\n" 390 "This command makes typemaker2 create its derived type description files needed\n" 392 "typemaker2 generated types inside another typemaker2 generated type.\n" 394 "3. Build All Targets\n" 395 "--------------------------\n" 397 "This command builds typemaker2 source files first (if needed) and then all\n" 399 "A single process is used to compile and link the project files.\n" 400 "If you have multiple processor cores/threads you can build multiple files in\n" 403 "This command uses 14 processes in parallel.\n" 404 "The step can be repeated as often as needed. It will automatically check for\n" 405 "changed files and try to only re-compile/link those modified files and others\n" 406 "which depend on them.\n" 407 "If you change a 0BUILD file gwbuild will automatically call the setup step\n" 409 "arguments given to the last setup command (-s). This typically leads to all\n" 410 "files being re-build.\n" 414 "-s FOLDER setup build environment (arg: source folder path)\n" 415 "-p run preparation commands (needed e.g. if typemaker2 is used)\n" 418 "-c cleanup; delete generated files\n" 419 "-r repeat setup command using the same arguments given to last setup\n" 420 "-d make distribution folder (you need to run tar yourself for now)\n" 421 "-Oname=value specify options (can occur multiple times)\n" 422 "-Bname Only run commands for the given build (mostly used with\n" 424 "-Lname Set loglevel (debug, info, notice, warn, error)\n" 425 "-Cname Crosscompile for given environment (e-g- 'x86_64-w64-mingw32')\n" 426 "-jvalue Use the given number of parallel process for building\n" 427 "--static Generate static libs for InstallLibrary targets\n" #define GWEN_DB_FLAGS_OVERWRITE_VARS
#define ARGS_COMMAND_CLEAN
int GWB_Setup(GWEN_DB_NODE *dbArgs)
struct GWEN_DB_NODE GWEN_DB_NODE
int GWB_RepeatLastSetup(const char *fileName)
#define GWEN_ERROR_INVALID
void GWEN_Logger_SetLevel(const char *logDomain, GWEN_LOGGER_LEVEL l)
#define ARGS_COMMAND_REPEAT_SETUP
#define GWBUILD_FILE_INSTALLFILES
#define ARGS_COMMAND_SETUP
GWEN_LOGGER_LEVEL GWEN_Logger_Name2Level(const char *name)
#define ARGS_COMMAND_DIST
#define ARGS_COMMAND_INSTALL
int GWB_Build(GWEN_DB_NODE *dbArgs)
#define GWBUILD_FILE_ARGS
int GWB_Clean(const char *fname)
#define GWEN_ERROR_GENERIC
const char * GWEN_DB_GetCharValue(GWEN_DB_NODE *n, const char *path, int idx, const char *defVal)
#define GWBUILD_FILE_FILES
int GWEN_Logger_Open(const char *logDomain, const char *ident, const char *file, GWEN_LOGGER_LOGTYPE logtype, GWEN_LOGGER_FACILITY facility)
#define DBG_ERROR(dbg_logger, format, args...)
int GWB_Prepare(GWEN_UNUSED GWEN_DB_NODE *dbArgs)
#define ARGS_COMMAND_PREPARE
int GWEN_DB_SetCharValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, const char *val)
#define ARGS_COMMAND_BUILD
int main(int argc, char **argv)
#define DBG_INFO(dbg_logger, format, args...)
static int _readArgsIntoDb(int argc, char **argv, GWEN_DB_NODE *db)
int GWEN_DB_GetIntValue(GWEN_DB_NODE *n, const char *path, int idx, int defVal)
GWEN_DB_NODE * GWEN_DB_Group_new(const char *name)
int GWEN_DB_SetIntValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, int val)
#define GWENHYWFAR_VERSION_FULL_STRING
void GWEN_Gui_SetGui(GWEN_GUI *gui)
GWEN_GUI * GWEN_Gui_CGui_new(void)
int GWB_InstallFiles(const char *fileName, const char *destDir)
static void _printHelpScreen()
static int _handleStringArgument(int argc, char **argv, int *pIndex, const char *sArg, const char *sArgId, const char *sVarName, GWEN_DB_NODE *db)
#define GWEN_DB_FLAGS_DEFAULT