Exemplo n.º 1
0
Arquivo: conf.c Projeto: krzk/linux
int main(int ac, char **av)
{
	const char *progname = av[0];
	int opt;
	const char *name, *defconfig_file = NULL /* gcc uninit */;
	struct stat tmpstat;

	tty_stdio = isatty(0) && isatty(1);

	while ((opt = getopt_long(ac, av, "s", long_opts, NULL)) != -1) {
		if (opt == 's') {
			conf_set_message_callback(NULL);
			continue;
		}
		input_mode = (enum input_mode)opt;
		switch (opt) {
		case syncconfig:
			sync_kconfig = 1;
			break;
		case defconfig:
		case savedefconfig:
			defconfig_file = optarg;
			break;
		case randconfig:
		{
			struct timeval now;
			unsigned int seed;
			char *seed_env;

			/*
			 * Use microseconds derived seed,
			 * compensate for systems where it may be zero
			 */
			gettimeofday(&now, NULL);
			seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1));

			seed_env = getenv("KCONFIG_SEED");
			if( seed_env && *seed_env ) {
				char *endp;
				int tmp = (int)strtol(seed_env, &endp, 0);
				if (*endp == '\0') {
					seed = tmp;
				}
			}
			fprintf( stderr, "KCONFIG_SEED=0x%X\n", seed );
			srand(seed);
			break;
		}
		case oldaskconfig:
		case oldconfig:
		case allnoconfig:
		case allyesconfig:
		case allmodconfig:
		case alldefconfig:
		case listnewconfig:
		case olddefconfig:
			break;
		case '?':
			conf_usage(progname);
			exit(1);
			break;
		}
	}
	if (ac == optind) {
		fprintf(stderr, "%s: Kconfig file missing\n", av[0]);
		conf_usage(progname);
		exit(1);
	}
	name = av[optind];
	conf_parse(name);
	//zconfdump(stdout);
	if (sync_kconfig) {
		name = conf_get_configname();
		if (stat(name, &tmpstat)) {
			fprintf(stderr, "***\n"
				"*** Configuration file \"%s\" not found!\n"
				"***\n"
				"*** Please run some configurator (e.g. \"make oldconfig\" or\n"
				"*** \"make menuconfig\" or \"make xconfig\").\n"
				"***\n", name);
			exit(1);
		}
	}

	switch (input_mode) {
	case defconfig:
		if (!defconfig_file)
			defconfig_file = conf_get_default_confname();
		if (conf_read(defconfig_file)) {
			fprintf(stderr,
				"***\n"
				  "*** Can't find default configuration \"%s\"!\n"
				  "***\n",
				defconfig_file);
			exit(1);
		}
		break;
	case savedefconfig:
	case syncconfig:
	case oldaskconfig:
	case oldconfig:
	case listnewconfig:
	case olddefconfig:
		conf_read(NULL);
		break;
	case allnoconfig:
	case allyesconfig:
	case allmodconfig:
	case alldefconfig:
	case randconfig:
		name = getenv("KCONFIG_ALLCONFIG");
		if (!name)
			break;
		if ((strcmp(name, "") != 0) && (strcmp(name, "1") != 0)) {
			if (conf_read_simple(name, S_DEF_USER)) {
				fprintf(stderr,
					"*** Can't read seed configuration \"%s\"!\n",
					name);
				exit(1);
			}
			break;
		}
		switch (input_mode) {
		case allnoconfig:	name = "allno.config"; break;
		case allyesconfig:	name = "allyes.config"; break;
		case allmodconfig:	name = "allmod.config"; break;
		case alldefconfig:	name = "alldef.config"; break;
		case randconfig:	name = "allrandom.config"; break;
		default: break;
		}
		if (conf_read_simple(name, S_DEF_USER) &&
		    conf_read_simple("all.config", S_DEF_USER)) {
			fprintf(stderr,
				"*** KCONFIG_ALLCONFIG set, but no \"%s\" or \"all.config\" file found\n",
				name);
			exit(1);
		}
		break;
	default:
		break;
	}

	if (sync_kconfig) {
		if (conf_get_changed()) {
			name = getenv("KCONFIG_NOSILENTUPDATE");
			if (name && *name) {
				fprintf(stderr,
					"\n*** The configuration requires explicit update.\n\n");
				return 1;
			}
		}
	}

	switch (input_mode) {
	case allnoconfig:
		conf_set_all_new_symbols(def_no);
		break;
	case allyesconfig:
		conf_set_all_new_symbols(def_yes);
		break;
	case allmodconfig:
		conf_set_all_new_symbols(def_mod);
		break;
	case alldefconfig:
		conf_set_all_new_symbols(def_default);
		break;
	case randconfig:
		/* Really nothing to do in this loop */
		while (conf_set_all_new_symbols(def_random)) ;
		break;
	case defconfig:
		conf_set_all_new_symbols(def_default);
		break;
	case savedefconfig:
		break;
	case oldaskconfig:
		rootEntry = &rootmenu;
		conf(&rootmenu);
		input_mode = oldconfig;
		/* fall through */
	case oldconfig:
	case listnewconfig:
	case syncconfig:
		/* Update until a loop caused no more changes */
		do {
			conf_cnt = 0;
			check_conf(&rootmenu);
		} while (conf_cnt);
		break;
	case olddefconfig:
	default:
		break;
	}

	if (sync_kconfig) {
		/* syncconfig is used during the build so we shall update autoconf.
		 * All other commands are only used to generate a config.
		 */
		if (conf_get_changed() && conf_write(NULL)) {
			fprintf(stderr, "\n*** Error during writing of the configuration.\n\n");
			exit(1);
		}
		if (conf_write_autoconf()) {
			fprintf(stderr, "\n*** Error during update of the configuration.\n\n");
			return 1;
		}
	} else if (input_mode == savedefconfig) {
		if (conf_write_defconfig(defconfig_file)) {
			fprintf(stderr, "n*** Error while saving defconfig to: %s\n\n",
				defconfig_file);
			return 1;
		}
	} else if (input_mode != listnewconfig) {
		if (conf_write(NULL)) {
			fprintf(stderr, "\n*** Error during writing of the configuration.\n\n");
			exit(1);
		}
	}
	return 0;
}
Exemplo n.º 2
0
int main(int ac, char **av)
{
	const char *progname = av[0];
	int opt;
	const char *name, *defconfig_file = NULL /* gcc uninit */;
	struct stat tmpstat;

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);

	while ((opt = getopt_long(ac, av, "", long_opts, NULL)) != -1) {
		input_mode = (enum input_mode)opt;
		switch (opt) {
		case silentoldconfig:
			sync_kconfig = 1;
			break;
		case defconfig:
		case savedefconfig:
			defconfig_file = optarg;
			break;
		case randconfig:
		{
			struct timeval now;
			unsigned int seed;

			/*
			 * Use microseconds derived seed,
			 * compensate for systems where it may be zero
			 */
			gettimeofday(&now, NULL);

			seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1));
			srand(seed);
			break;
		}
		case oldaskconfig:
		case oldconfig:
		case allnoconfig:
		case allyesconfig:
		case allmodconfig:
		case alldefconfig:
		case listnewconfig:
		case oldnoconfig:
			break;
		case '?':
			conf_usage(progname);
			exit(1);
			break;
		}
	}
	if (ac == optind) {
		printf(_("%s: Kconfig file missing\n"), av[0]);
		conf_usage(progname);
		exit(1);
	}
	name = av[optind];
	conf_parse(name);
	//zconfdump(stdout);
	if (sync_kconfig) {
		name = conf_get_configname();
		if (stat(name, &tmpstat)) {
			fprintf(stderr, _("***\n"
				"*** Configuration file \"%s\" not found!\n"
				"***\n"
				"*** Please run some configurator (e.g. \"make oldconfig\" or\n"
				"*** \"make menuconfig\" or \"make xconfig\").\n"
				"***\n"), name);
			exit(1);
		}
	}

	switch (input_mode) {
	case defconfig:
		if (!defconfig_file)
			defconfig_file = conf_get_default_confname();
		if (conf_read(defconfig_file)) {
			printf(_("***\n"
				"*** Can't find default configuration \"%s\"!\n"
				"***\n"), defconfig_file);
			exit(1);
		}
                name = getenv("KCONFIG_SELINUX");
                printf("KCONFIG_SELINUX(%s)\n", name);
                if (name) {
                        if (conf_read_simple(name, S_DEF_USER, false)) {
                                printf(_("***\n"
                                        "*** Can't find selinux configuration \"%s\"!\n"
                                        "***\n"), name);
                                exit(1);
                        }
                }
                name = getenv("KCONFIG_LOG_SELINUX");
                printf("KCONFIG_LOG_SELINUX(%s)\n", name);
                if (name) {
                        if (conf_read_simple(name, S_DEF_USER, false)) {
                                printf(_("***\n"
                                        "*** Can't find selinux log configuration \"%s\"!\n"
                                        "***\n"), name);
                                exit(1);
                        }
                }
                name = getenv("KCONFIG_TIMA");
                printf("KCONFIG_TIMA(%s)\n", name);
                if (name) {
                        if (conf_read_simple(name, S_DEF_USER, false)) {
                                printf(_("***\n"
                                        "*** Can't find tima log configuration \"%s\"!\n"
                                        "***\n"), name);
                                exit(1);
                        }
                }
		name = getenv("KCONFIG_VARIANT");
		printf("KCONFIG_VARIANT(%s)\n", name);
		if (name) {
			if (conf_read_simple(name, S_DEF_USER, false)) {
				printf(_("***\n"
					"*** Can't find variant configuration \"%s\"!\n"
					"***\n"), name);
				exit(1);
			}
		}
		name = getenv("KCONFIG_DEBUG");
		printf("KCONFIG_DEBUG(%s)\n", name);
		if (name) {
			if (conf_read_simple(name, S_DEF_USER, false)) {
				printf(_("***\n"
					"*** Can't find debug configuration \"%s\"!\n"
					"***\n"), name);
				exit(1);
			}
		}
		break;
	case savedefconfig:
	case silentoldconfig:
	case oldaskconfig:
	case oldconfig:
	case listnewconfig:
	case oldnoconfig:
		conf_read(NULL);
		break;
	case allnoconfig:
	case allyesconfig:
	case allmodconfig:
	case alldefconfig:
	case randconfig:
		name = getenv("KCONFIG_ALLCONFIG");
		if (name && !stat(name, &tmpstat)) {
			conf_read_simple(name, S_DEF_USER, true);
			break;
		}
		switch (input_mode) {
		case allnoconfig:	name = "allno.config"; break;
		case allyesconfig:	name = "allyes.config"; break;
		case allmodconfig:	name = "allmod.config"; break;
		case alldefconfig:	name = "alldef.config"; break;
		case randconfig:	name = "allrandom.config"; break;
		default: break;
		}
		if (!stat(name, &tmpstat))
			conf_read_simple(name, S_DEF_USER, true);
		else if (!stat("all.config", &tmpstat))
			conf_read_simple("all.config", S_DEF_USER, true);
		break;
	default:
		break;
	}

	if (sync_kconfig) {
		if (conf_get_changed()) {
			name = getenv("KCONFIG_NOSILENTUPDATE");
			if (name && *name) {
				fprintf(stderr,
					_("\n*** The configuration requires explicit update.\n\n"));
				return 1;
			}
		}
		valid_stdin = isatty(0) && isatty(1) && isatty(2);
	}

	switch (input_mode) {
	case allnoconfig:
		conf_set_all_new_symbols(def_no);
		break;
	case allyesconfig:
		conf_set_all_new_symbols(def_yes);
		break;
	case allmodconfig:
		conf_set_all_new_symbols(def_mod);
		break;
	case alldefconfig:
		conf_set_all_new_symbols(def_default);
		break;
	case randconfig:
		conf_set_all_new_symbols(def_random);
		break;
	case defconfig:
		conf_set_all_new_symbols(def_default);
		break;
	case savedefconfig:
		break;
	case oldaskconfig:
		rootEntry = &rootmenu;
		conf(&rootmenu);
		input_mode = silentoldconfig;
		/* fall through */
	case oldconfig:
	case listnewconfig:
	case oldnoconfig:
	case silentoldconfig:
		/* Update until a loop caused no more changes */
		do {
			conf_cnt = 0;
			check_conf(&rootmenu);
		} while (conf_cnt &&
			 (input_mode != listnewconfig &&
			  input_mode != oldnoconfig));
		break;
	}

	if (sync_kconfig) {
		/* silentoldconfig is used during the build so we shall update autoconf.
		 * All other commands are only used to generate a config.
		 */
		if (conf_get_changed() && conf_write(NULL)) {
			fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n"));
			exit(1);
		}
		if (conf_write_autoconf()) {
			fprintf(stderr, _("\n*** Error during update of the configuration.\n\n"));
			return 1;
		}
	} else if (input_mode == savedefconfig) {
		if (conf_write_defconfig(defconfig_file)) {
			fprintf(stderr, _("n*** Error while saving defconfig to: %s\n\n"),
			        defconfig_file);
			return 1;
		}
	} else if (input_mode != listnewconfig) {
		if (conf_write(NULL)) {
			fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n"));
			exit(1);
		}
	}
	return 0;
}
Exemplo n.º 3
0
int main(int ac, char **av)
{
	int opt;
	const char *name;
	struct stat tmpstat;

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);

 	while ((opt = getopt(ac, av, "osbBdD:nmyrh")) != -1) {
		switch (opt) {
		case 'o':
			input_mode = ask_silent;
			break;
		case 's':
			input_mode = ask_silent;
			sync_kconfig = 1;
			break;
		case 'b':
			input_mode = dont_ask;
			break;
		case 'B':
			input_mode = dont_ask_dont_tell;
			break;
		case 'd':
			input_mode = set_default;
			break;
		case 'D':
			input_mode = set_default;
			defconfig_file = optarg;
			break;
		case 'n':
			input_mode = set_no;
			break;
		case 'm':
			input_mode = set_mod;
			break;
		case 'y':
			input_mode = set_yes;
			break;
		case 'r':
		{
			struct timeval now;
			unsigned int seed;

			/*
			 * Use microseconds derived seed,
			 * compensate for systems where it may be zero
			 */
			gettimeofday(&now, NULL);

			seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1));
			srand(seed);

			input_mode = set_random;
			break;
		}
		case 'h':
			printf(_("See README for usage info\n"));
			exit(0);
			break;
		default:
			fprintf(stderr, _("See README for usage info\n"));
			exit(1);
		}
	}
	if (ac == optind) {
		printf(_("%s: Kconfig file missing\n"), av[0]);
		exit(1);
	}
	name = av[optind];
	conf_parse(name);
	//zconfdump(stdout);
	if (sync_kconfig) {
		name = conf_get_configname();
		if (stat(name, &tmpstat)) {
			fprintf(stderr, _("***\n"
				"*** You have not yet configured your kernel!\n"
				"*** (missing kernel config file \"%s\")\n"
				"***\n"
				"*** Please run some configurator (e.g. \"make oldconfig\" or\n"
				"*** \"make menuconfig\" or \"make xconfig\").\n"
				"***\n"), name);
			exit(1);
		}
	}

	switch (input_mode) {
	case set_default:
		if (!defconfig_file)
			defconfig_file = conf_get_default_confname();
		if (conf_read(defconfig_file)) {
			printf(_("***\n"
				"*** Can't find default configuration \"%s\"!\n"
				"***\n"), defconfig_file);
			exit(1);
		}
		break;
	case ask_silent:
	case ask_all:
	case ask_new:
	case dont_ask:
	case dont_ask_dont_tell:
		conf_read(NULL);
		break;
	case set_no:
	case set_mod:
	case set_yes:
	case set_random:
		name = getenv("KCONFIG_ALLCONFIG");
		if (name && !stat(name, &tmpstat)) {
			conf_read_simple(name, S_DEF_USER);
			break;
		}
		switch (input_mode) {
		case set_no:	 name = "allno.config"; break;
		case set_mod:	 name = "allmod.config"; break;
		case set_yes:	 name = "allyes.config"; break;
		case set_random: name = "allrandom.config"; break;
		default: break;
		}
		if (!stat(name, &tmpstat))
			conf_read_simple(name, S_DEF_USER);
		else if (!stat("all.config", &tmpstat))
			conf_read_simple("all.config", S_DEF_USER);
		break;
	default:
		break;
	}

	if (sync_kconfig) {
		if (conf_get_changed()) {
			name = getenv("KCONFIG_NOSILENTUPDATE");
			if (name && *name) {
				fprintf(stderr,
					_("\n*** Kernel configuration requires explicit update.\n\n"));
				return 1;
			}
		}
		valid_stdin = isatty(0) && isatty(1) && isatty(2);
	}

	switch (input_mode) {
	case set_no:
		conf_set_all_new_symbols(def_no);
		break;
	case set_yes:
		conf_set_all_new_symbols(def_yes);
		break;
	case set_mod:
		conf_set_all_new_symbols(def_mod);
		break;
	case set_random:
		conf_set_all_new_symbols(def_random);
		break;
	case set_default:
		conf_set_all_new_symbols(def_default);
		break;
	case ask_new:
	case ask_all:
		rootEntry = &rootmenu;
		conf(&rootmenu);
		input_mode = ask_silent;
		/* fall through */
	case dont_ask:
	case dont_ask_dont_tell:
	case ask_silent:
		/* Update until a loop caused no more changes */
		do {
			conf_cnt = 0;
			check_conf(&rootmenu);
		} while (conf_cnt &&
			 (input_mode != dont_ask &&
			  input_mode != dont_ask_dont_tell));
		break;
	}

	if (sync_kconfig) {
		/* silentoldconfig is used during the build so we shall update autoconf.
		 * All other commands are only used to generate a config.
		 */
		if (conf_get_changed() && conf_write(NULL)) {
			fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
			exit(1);
		}
		if (conf_write_autoconf()) {
			fprintf(stderr, _("\n*** Error during update of the kernel configuration.\n\n"));
			return 1;
		}
	} else {
		if (conf_write(NULL)) {
			fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
			exit(1);
		}
	}
	return return_value;
}
Exemplo n.º 4
0
int main(int ac, char **av)
{
	int opt;
	const char *name;
	struct stat tmpstat;

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);

	while ((opt = getopt_long(ac, av, "", long_opts, NULL)) != -1) {
		input_mode = (enum input_mode)opt;
		switch (opt) {
		case silentoldconfig:
			sync_kconfig = 1;
			break;
		case defconfig:
		case savedefconfig:
			defconfig_file = optarg;
			break;
		case randconfig:
		{
			struct timeval now;
			unsigned int seed;

			/*
			 * Use microseconds derived seed,
			 * compensate for systems where it may be zero
			 */
			gettimeofday(&now, NULL);

			seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1));
			srand(seed);
			break;
		}
		case '?':
			fprintf(stderr, _("See README for usage info\n"));
			exit(1);
			break;
		}
	}
	if (ac == optind) {
		printf(_("%s: Kconfig file missing\n"), av[0]);
		exit(1);
	}
	name = av[optind];
	conf_parse(name);
	//zconfdump(stdout);
	if (sync_kconfig) {
		name = conf_get_configname();
		if (stat(name, &tmpstat)) {
			fprintf(stderr, _("***\n"
				"*** Configuration file \"%s\" not found!\n"
				"***\n"
				"*** Please run some configurator (e.g. \"make oldconfig\" or\n"
				"*** \"make menuconfig\" or \"make xconfig\").\n"
				"***\n"), name);
			exit(1);
		}
	}

	switch (input_mode) {
	case defconfig:
		if (!defconfig_file)
			defconfig_file = conf_get_default_confname();
		if (conf_read(defconfig_file)) {
			printf(_("***\n"
				"*** Can't find default configuration \"%s\"!\n"
				"***\n"), defconfig_file);
			exit(1);
		}
		break;
	case savedefconfig:
	case silentoldconfig:
	case oldaskconfig:
	case oldconfig:
	case listnewconfig:
	case oldnoconfig:
		conf_read(NULL);
		break;
	case allnoconfig:
	case allyesconfig:
	case allmodconfig:
	case alldefconfig:
	case randconfig:
		name = getenv("KCONFIG_ALLCONFIG");
		if (name && !stat(name, &tmpstat)) {
			conf_read_simple(name, S_DEF_USER);
			break;
		}
		switch (input_mode) {
		case allnoconfig:	name = "allno.config"; break;
		case allyesconfig:	name = "allyes.config"; break;
		case allmodconfig:	name = "allmod.config"; break;
		case alldefconfig:	name = "alldef.config"; break;
		case randconfig:	name = "allrandom.config"; break;
		default: break;
		}
		if (!stat(name, &tmpstat))
			conf_read_simple(name, S_DEF_USER);
		else if (!stat("all.config", &tmpstat))
			conf_read_simple("all.config", S_DEF_USER);
		break;
	default:
		break;
	}

	if (sync_kconfig) {
		if (conf_get_changed()) {
			name = getenv("KCONFIG_NOSILENTUPDATE");
			if (name && *name) {
				fprintf(stderr,
					_("\n*** The configuration requires explicit update.\n\n"));
				return 1;
			}
		}
		valid_stdin = isatty(0) && isatty(1) && isatty(2);
	}

	switch (input_mode) {
	case allnoconfig:
		conf_set_all_new_symbols(def_no);
		break;
	case allyesconfig:
		conf_set_all_new_symbols(def_yes);
		break;
	case allmodconfig:
		conf_set_all_new_symbols(def_mod);
		break;
	case alldefconfig:
		conf_set_all_new_symbols(def_default);
		break;
	case randconfig:
		conf_set_all_new_symbols(def_random);
		break;
	case defconfig:
		conf_set_all_new_symbols(def_default);
		break;
	case savedefconfig:
		break;
	case oldaskconfig:
		rootEntry = &rootmenu;
		conf(&rootmenu);
		input_mode = silentoldconfig;
		/* fall through */
	case oldconfig:
	case listnewconfig:
	case oldnoconfig:
	case silentoldconfig:
		/* Update until a loop caused no more changes */
		do {
			conf_cnt = 0;
			check_conf(&rootmenu);
		} while (conf_cnt &&
			 (input_mode != listnewconfig &&
			  input_mode != oldnoconfig));
		break;
	}

	if (sync_kconfig) {
		/* silentoldconfig is used during the build so we shall update autoconf.
		 * All other commands are only used to generate a config.
		 */
		if (conf_get_changed() && conf_write(NULL)) {
			fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n"));
			exit(1);
		}
		if (conf_write_autoconf()) {
			fprintf(stderr, _("\n*** Error during update of the configuration.\n\n"));
			return 1;
		}
	} else if (input_mode == savedefconfig) {
		if (conf_write_defconfig(defconfig_file)) {
			fprintf(stderr, _("n*** Error while saving defconfig to: %s\n\n"),
			        defconfig_file);
			return 1;
		}
	} else if (input_mode != listnewconfig) {
		if (conf_write(NULL)) {
			fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n"));
			exit(1);
		}
	}
	/* This is for Intel Media SOC Gen3 Support, creates "include/linux/autoconf.h" link to be consistent with kernel versions earlier than 2.6.35
	#ifdef CONFIG_ARCH_GEN3
	*/
	if (access("include/linux/autoconf.h",0)&&(symlink("../generated/autoconf.h","include/linux/autoconf.h")))
	{
			fprintf(stderr, _("\n*** can not symlink include/generated/autoconf.h to include/linux/autoconf.h.\n\n"));
	}

	return 0;
}
Exemplo n.º 5
0
int main(int ac, char **av)
{
	int opt;
	const char *name;
	struct stat tmpstat;

	setlocale(LC_ALL, "");
	bindtextdomain(OPENCONF_PACKAGE, OPENCONF_LOCALEDIR);
	textdomain(OPENCONF_PACKAGE);

	while ((opt = getopt(ac, av, "osdD:nmyrh")) != -1) {
		switch (opt) {
		case 'o':
			input_mode = ask_silent;
			break;
		case 's':
			input_mode = ask_silent;
			sync_kconfig = 1;
			break;
		case 'd':
			input_mode = set_default;
			break;
		case 'D':
			input_mode = set_default;
			defconfig_file = optarg;
			break;
		case 'n':
			input_mode = set_no;
			break;
		case 'm':
			input_mode = set_mod;
			break;
		case 'y':
			input_mode = set_yes;
			break;
		case 'r':
			input_mode = set_random;
			srand(time(NULL));
			break;
		case 'h':
			printf("See README for usage info\n");
			exit(0);
			break;
		default:
			fprintf(stderr, "See README for usage info\n");
			exit(1);
		}
	}
	if (ac == optind) {
		printf(_("%s: Kconfig file missing\n"), av[0]);
		exit(1);
	}
	name = av[optind];
	conf_parse(name);
	//zconfdump(stdout);
	if (sync_kconfig) {
		name = getenv(OPENCONF_CONFIG_ENVNAME);
		if (stat(name, &tmpstat)) {
			fprintf(stderr, "***\n"
				"*** You have not yet configured!\n"
				"*** (missing " OPENCONF_CONFIG_DEFAULT " file)\n"
				"***\n"
				"*** Please run some configurator (e.g. \"make oldconfig\" or\n"
				"*** \"make menuconfig\" or \"make xconfig\").\n"
				"***\n");
			exit(1);
		}
	}

	switch (input_mode) {
	case set_default:
		if (!defconfig_file)
			defconfig_file = conf_get_default_confname();
		if (conf_read(defconfig_file)) {
			printf("***\n"
				"*** Can't find default configuration \"%s\"!\n"
				"***\n", defconfig_file);
			exit(1);
		}
		break;
	case ask_silent:
	case ask_all:
	case ask_new:
		conf_read(NULL);
		break;
	case set_no:
	case set_mod:
	case set_yes:
	case set_random:
		name = getenv(OPENCONF_ALLCONFIG_ENVNAME);
		if (name && !stat(name, &tmpstat)) {
			conf_read_simple(name, S_DEF_USER);
			break;
		}
		switch (input_mode) {
		case set_no:	 name = OPENCONF_ALLCONFIG_ALLNO; break;
		case set_mod:	 name = OPENCONF_ALLCONFIG_ALLMOD; break;
		case set_yes:	 name = OPENCONF_ALLCONFIG_ALLYES; break;
		case set_random: name = OPENCONF_ALLCONFIG_ALLRANDOM; break;
		default: break;
		}
		if (!stat(name, &tmpstat))
			conf_read_simple(name, S_DEF_USER);
		else if (!stat(OPENCONF_ALLCONFIG_ALL, &tmpstat))
			conf_read_simple(OPENCONF_ALLCONFIG_ALL, S_DEF_USER);
		break;
	default:
		break;
	}

	if (sync_kconfig) {
		if (conf_get_changed()) {
			name = getenv(OPENCONF_NOSILENTUPDATE_ENVNAME);
			if (name && *name) {
				fprintf(stderr,
					"\n*** configuration requires explicit update.\n\n");
				return 1;
			}
		}
		valid_stdin = isatty(0) && isatty(1) && isatty(2);
	}

	switch (input_mode) {
	case set_no:
		conf_set_all_new_symbols(def_no);
		break;
	case set_yes:
		conf_set_all_new_symbols(def_yes);
		break;
	case set_mod:
		conf_set_all_new_symbols(def_mod);
		break;
	case set_random:
		conf_set_all_new_symbols(def_random);
		break;
	case set_default:
		conf_set_all_new_symbols(def_default);
		break;
	case ask_new:
	case ask_all:
		rootEntry = &rootmenu;
		conf(&rootmenu);
		input_mode = ask_silent;
		/* fall through */
	case ask_silent:
		/* Update until a loop caused no more changes */
		do {
			conf_cnt = 0;
			check_conf(&rootmenu);
		} while (conf_cnt);
		break;
	}

	if (sync_kconfig) {
		/* silentoldconfig is used during the build so we shall update autoconf.
		 * All other commands are only used to generate a config.
		 */
		if (conf_get_changed() && conf_write(NULL)) {
			fprintf(stderr, "\n*** Error during writing of the configuration.\n\n");
			exit(1);
		}
		if (conf_write_autoconf()) {
			fprintf(stderr, "\n*** Error during update of the configuration.\n\n");
			return 1;
		}
	} else {
		if (conf_write(NULL)) {
			fprintf(stderr, "\n*** Error during writing of the configuration.\n\n");
			exit(1);
		}
	}
	return 0;
}
Exemplo n.º 6
0
/* Write out the Linux configuration files, setting all configuration
 * variables to yes.
 */
void write_config(bool (*in_config)(struct symbol *))
{
  char *config_prefix = !bconf_parser ? "CONFIG_" : "";
  struct symbol *sym;
  int i;

  FILE *allvars;
  FILE *conf;
  FILE *autoconf;
  FILE *tristate;
  FILE *header;

  allvars = fopen(".allvars", "w");
  if (!allvars) {
    perror("fopen");
    exit(1);
  }

  conf = fopen(".config", "w");
  if (!conf) {
    perror("fopen");
    exit(1);
  }

  if (mkdir("include/config/", S_IRWXU)) {
    if (EEXIST != errno) {
      perror("mkdir");
      exit(1);
    }
  }

  autoconf = fopen("include/config/auto.conf", "w");
  if (!autoconf) {
    perror("fopen");
    exit(1);
  }

  tristate = fopen("include/config/tristate.conf", "w");
  if (!tristate) {
    perror("fopen");
    exit(1);
  }

  if (mkdir("include/generated/", S_IRWXU)) {
    if (EEXIST != errno) {
      perror("mkdir");
      exit(1);
    }
  }

  if (!bconf_parser)
    header = fopen("include/generated/autoconf.h", "w");
  else
    header = fopen("include/linux/autoconf.h", "w");
  if (!header) {
    perror("fopen");
    exit(1);
  }

  conf_set_all_new_symbols(def_yes);
  for_all_symbols(i, sym) {
    if (!sym)
      continue;
    if (!sym->name)
      continue;
    sym_calc_value(sym);
  }

  for_all_symbols(i, sym) {
    const char *str;

    if (!sym)
      continue;
    if (!sym->name)
      continue;
    if (!is_symbol(sym))
      continue;
    if (!(*in_config)(sym))
      continue;
    if (check_forceoff(sym))
      continue;

    switch (sym->type) {
    case S_OTHER:
    case S_UNKNOWN:
      break;
    case S_STRING:
      str = sym_get_string_value(sym);
      str = sym_escape_string_value(str);
      fprintf(allvars, "%s\n", sym->name);
      fprintf(conf, "%s%s=%s\n", config_prefix, sym->name, str);
      fprintf(autoconf, "%s%s=%s\n", config_prefix, sym->name, str);
      free((void *)str);
      break;
    case S_BOOLEAN:
    case S_TRISTATE:
      fprintf(allvars, "%s\n", sym->name);
      fprintf(conf, "%s%s=y\n", config_prefix, sym->name);
      fprintf(autoconf, "%s%s=y\n", config_prefix, sym->name);
      fprintf(tristate, "%s%s=Y\n", config_prefix, sym->name);
      break;
    default:
      fprintf(allvars, "%s\n", sym->name);
      fprintf(conf, "%s%s=%s\n", config_prefix, sym->name, sym->curr.val);
      fprintf(autoconf, "%s%s=%s\n", config_prefix, sym->name, sym->curr.val);
      break;
    }
  }

  for_all_symbols(i, sym) {
    const char *str;

    if (!sym)
      continue;
    if (!sym->name)
      continue;
    if (!is_symbol(sym))
      continue;
    if (!(*in_config)(sym))
      continue;
    if (check_forceoff(sym))
      continue;

    switch (sym->type) {
    case S_BOOLEAN:
    case S_TRISTATE: {
      fprintf(header, "#define %s%s 1\n", config_prefix, sym->name);
      break;
    }
    case S_HEX: {
      const char *prefix = "";

      str = sym_get_string_value(sym);
      if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X'))
        prefix = "0x";

      fprintf(header, "#define %s%s %s%s\n", config_prefix, sym->name, prefix, str);
      break;
    }
    case S_STRING:
      str = sym_get_string_value(sym);
      str = sym_escape_string_value(str);
      fprintf(header, "#define %s%s %s\n", config_prefix, sym->name, str);
      free((void *)str);
      break;
    case S_INT:
      str = sym_get_string_value(sym);
      fprintf(header, "#define %s%s %s\n", config_prefix, sym->name, str);
      break;
    default:
      break;
    }
  }

  if (fclose(allvars)) {
    perror("fclose");
    exit(1);
  }

  if (fclose(conf)) {
    perror("fclose");
    exit(1);
  }

  if (fclose(autoconf)) {
    perror("fclose");
    exit(1);
  }

  if (fclose(tristate)) {
    perror("fclose");
    exit(1);
  }

  if (fclose(header)) {
    perror("fclose");
    exit(1);
  }
}
Exemplo n.º 7
0
int main(int ac, char **av)
{
    const char *progname = av[0];
    int opt;
    const char *name, *defconfig_file = NULL /* gcc uninit */;
    struct stat tmpstat;

    setlocale(LC_ALL, "");
    bindtextdomain(PACKAGE, LOCALEDIR);
    textdomain(PACKAGE);

    while ((opt = getopt_long(ac, av, "", long_opts, NULL)) != -1) {
        input_mode = (enum input_mode)opt;
        switch (opt) {
        case defconfig:
        case savedefconfig:
            defconfig_file = optarg;
            break;
        case randconfig:
        {
            struct timeval now;
            unsigned int seed;

            /*
             * Use microseconds derived seed,
             * compensate for systems where it may be zero
             */
            gettimeofday(&now, NULL);

            seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1));
            srand(seed);
            break;
        }
        case oldaskconfig:
        case oldconfig:
        case allnoconfig:
        case allyesconfig:
        case allmodconfig:
        case alldefconfig:
        case listnewconfig:
        case oldnoconfig:
            break;
        case '?':
            conf_usage(progname);
            exit(1);
            break;
        }
    }
    if (ac == optind) {
        printf(_("%s: Kconfig file missing\n"), av[0]);
        conf_usage(progname);
        exit(1);
    }
    name = av[optind];
    conf_parse(name);
    //zconfdump(stdout);

    switch (input_mode) {
    case defconfig:
        if (!defconfig_file)
            defconfig_file = conf_get_default_confname();
        if (conf_read(defconfig_file)) {
            printf(_("***\n"
                     "*** Can't find default configuration \"%s\"!\n"
                     "***\n"), defconfig_file);
            exit(1);
        }
        break;
    case savedefconfig:
    case oldaskconfig:
    case oldconfig:
    case listnewconfig:
    case oldnoconfig:
        conf_read(NULL);
        break;
    case allnoconfig:
    case allyesconfig:
    case allmodconfig:
    case alldefconfig:
    case randconfig:
        name = getenv("KCONFIG_ALLCONFIG");
        if (name && !stat(name, &tmpstat)) {
            conf_read_simple(name, S_DEF_USER);
            break;
        }
        switch (input_mode) {
        case allnoconfig:
            name = "allno.config";
            break;
        case allyesconfig:
            name = "allyes.config";
            break;
        case allmodconfig:
            name = "allmod.config";
            break;
        case alldefconfig:
            name = "alldef.config";
            break;
        case randconfig:
            name = "allrandom.config";
            break;
        default:
            break;
        }
        if (!stat(name, &tmpstat))
            conf_read_simple(name, S_DEF_USER);
        else if (!stat("all.config", &tmpstat))
            conf_read_simple("all.config", S_DEF_USER);
        break;
    default:
        break;
    }

    valid_stdin = isatty(0) && isatty(1) && isatty(2);

    switch (input_mode) {
    case allnoconfig:
        conf_set_all_new_symbols(def_no);
        break;
    case allyesconfig:
        conf_set_all_new_symbols(def_yes);
        break;
    case allmodconfig:
        conf_set_all_new_symbols(def_mod);
        break;
    case alldefconfig:
        conf_set_all_new_symbols(def_default);
        break;
    case randconfig:
        conf_set_all_new_symbols(def_random);
        break;
    case defconfig:
        conf_set_all_new_symbols(def_default);
        break;
    case savedefconfig:
        break;
    case oldaskconfig:
        rootEntry = &rootmenu;
        conf(&rootmenu);
        input_mode = oldconfig;
    /* fall through */
    case oldconfig:
    case listnewconfig:
    case oldnoconfig:
        /* Update until a loop caused no more changes */
        do {
            conf_cnt = 0;
            check_conf(&rootmenu);
        } while (conf_cnt &&
                 (input_mode != listnewconfig &&
                  input_mode != oldnoconfig));
        break;
    }

    if (input_mode == savedefconfig) {
        if (conf_write_defconfig(defconfig_file)) {
            fprintf(stderr, _("n*** Error while saving defconfig to: %s\n\n"),
                    defconfig_file);
            return 1;
        }
    } else if (input_mode != listnewconfig) {
        /*
         * build so we shall update autoconf.
         */
        if (conf_write(NULL)) {
            fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n"));
            exit(1);
        }
        if (conf_write_autoconf()) {
            fprintf(stderr, _("\n*** Error during update of the configuration.\n\n"));
            return 1;
        }
    }
    return 0;
}