How to process custom arguments ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Scconfig first processes the known arguments (defined in the table in default/arg.c). Unknown (custom) arguments are assumed to be project-specific and are passed to hook_custom_arg(), defined in your hooks.c: int hook_custom_arg(const char *key, const char *value) {} If the user argument was --foo=bar, this function gets "foo" as key and "bar" as value. There are multiple options on parsing the arguments. 1. Classic C Just write a bunch of if (strcmp(key, "foo") == 0) { } statements, e.g.: if (strcmp(key, "prefix") == 0) { report("Setting prefix to '%s'\n", value); put("/local/prefix", strclone(value)); return 1; } if (strcmp(key, "debug") == 0) { put("/local/pcb/debug", strue); pup_set_debug(strue); return 1; } The code is free to do anything upon detecting arguments; the typical behavior is to set tree nodes to affect the generated files later. Return 1 means the argument has been accepted. Return 0 will tell scconfig to report an error and exit. 2. Semi-automatic, using arg_auto_set #include "util/arg_auto_set.h" const arg_auto_set_t disable_libs[] = { {"enable-bison", "/local/pcb/want_bison", arg_true, "$enable generating language files"}, {"disable-bison", "/local/pcb/want_bison", arg_false, "$disable generating language files"}, {"enable-dmalloc", "/local/pcb/want_dmalloc", arg_true, "$compile with lib dmalloc"}, {"disable-dmalloc", "/local/pcb/want_dmalloc", arg_false, "$compile without lib dmalloc"}, {"disable-gd", "libs/gui/gd", arg_lib_nodes, "$do not use gd (many exporters need it)"}, {NULL, NULL, NULL, NULL} }; int hook_custom_arg(const char *key, const char *value) { return arg_auto_set(key, value, disable_libs); } Function arg_auto_set() searches the table for a matching key in the first column. When found, it executes the instructions in the 3rd column on the subtree specified in the 2nd column. Instruction arg_true and arg_false will assume the subtree path points to a leaf and sets it to hardwired strue or sfalse. arg_lib_nodes disables a library, setting the present-string to sfalse and making ldflags and cflags empty under the subtree - this will inhibit detection of the library as scconfig will think the library already got detected and was not found. (The user can specify application-local instructions; see also: src/util/arg_auto_set.[ch]; a "$" in the second column of an arg_auto_set_node_t table will set the given node to the value supplied by the user in the CLI argument). An user readable help can be generated from the dable using arg_auto_print_options(). The 4th column is the help text. If it starts with '$', the '$' is replaced by the first column and padding spaces as needed to have a tabular output: --enable-bison enable generating language files --disable-bison disable generating language files --enable-dmalloc compile with lib dmalloc --disable-dmalloc compile without lib dmalloc --disable-gd do not use gd (many exporters need it) 3. The two methods can be used in parallel In such setup hook_custom_arg() starts with a bunch of if (strcmp()) statements and the final statement is a return arg_auto_set(key, value, table_name);