xref: /openbmc/u-boot/scripts/kconfig/lkc.h (revision 3eceff64)
10a9064fbSMasahiro Yamada /*
20a9064fbSMasahiro Yamada  * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
30a9064fbSMasahiro Yamada  * Released under the terms of the GNU GPL v2.0.
40a9064fbSMasahiro Yamada  */
50a9064fbSMasahiro Yamada 
60a9064fbSMasahiro Yamada #ifndef LKC_H
70a9064fbSMasahiro Yamada #define LKC_H
80a9064fbSMasahiro Yamada 
90a9064fbSMasahiro Yamada #include "expr.h"
100a9064fbSMasahiro Yamada 
110a9064fbSMasahiro Yamada #ifndef KBUILD_NO_NLS
120a9064fbSMasahiro Yamada # include <libintl.h>
130a9064fbSMasahiro Yamada #else
gettext(const char * txt)140a9064fbSMasahiro Yamada static inline const char *gettext(const char *txt) { return txt; }
textdomain(const char * domainname)150a9064fbSMasahiro Yamada static inline void textdomain(const char *domainname) {}
bindtextdomain(const char * name,const char * dir)160a9064fbSMasahiro Yamada static inline void bindtextdomain(const char *name, const char *dir) {}
bind_textdomain_codeset(const char * dn,char * c)170a9064fbSMasahiro Yamada static inline char *bind_textdomain_codeset(const char *dn, char *c) { return c; }
180a9064fbSMasahiro Yamada #endif
190a9064fbSMasahiro Yamada 
200a9064fbSMasahiro Yamada #ifdef __cplusplus
210a9064fbSMasahiro Yamada extern "C" {
220a9064fbSMasahiro Yamada #endif
230a9064fbSMasahiro Yamada 
240a9064fbSMasahiro Yamada #include "lkc_proto.h"
250a9064fbSMasahiro Yamada 
260a9064fbSMasahiro Yamada #define SRCTREE "srctree"
270a9064fbSMasahiro Yamada 
280a9064fbSMasahiro Yamada #ifndef PACKAGE
290a9064fbSMasahiro Yamada #define PACKAGE "linux"
300a9064fbSMasahiro Yamada #endif
310a9064fbSMasahiro Yamada 
320a9064fbSMasahiro Yamada #define LOCALEDIR "/usr/share/locale"
330a9064fbSMasahiro Yamada 
340a9064fbSMasahiro Yamada #define _(text) gettext(text)
350a9064fbSMasahiro Yamada #define N_(text) (text)
360a9064fbSMasahiro Yamada 
370a9064fbSMasahiro Yamada #ifndef CONFIG_
380a9064fbSMasahiro Yamada #define CONFIG_ "CONFIG_"
390a9064fbSMasahiro Yamada #endif
CONFIG_prefix(void)400a9064fbSMasahiro Yamada static inline const char *CONFIG_prefix(void)
410a9064fbSMasahiro Yamada {
420a9064fbSMasahiro Yamada 	return getenv( "CONFIG_" ) ?: CONFIG_;
430a9064fbSMasahiro Yamada }
440a9064fbSMasahiro Yamada #undef CONFIG_
450a9064fbSMasahiro Yamada #define CONFIG_ CONFIG_prefix()
460a9064fbSMasahiro Yamada 
470a9064fbSMasahiro Yamada #define TF_COMMAND	0x0001
480a9064fbSMasahiro Yamada #define TF_PARAM	0x0002
490a9064fbSMasahiro Yamada #define TF_OPTION	0x0004
500a9064fbSMasahiro Yamada 
510a9064fbSMasahiro Yamada enum conf_def_mode {
520a9064fbSMasahiro Yamada 	def_default,
530a9064fbSMasahiro Yamada 	def_yes,
540a9064fbSMasahiro Yamada 	def_mod,
550a9064fbSMasahiro Yamada 	def_no,
560a9064fbSMasahiro Yamada 	def_random
570a9064fbSMasahiro Yamada };
580a9064fbSMasahiro Yamada 
590a9064fbSMasahiro Yamada #define T_OPT_MODULES		1
600a9064fbSMasahiro Yamada #define T_OPT_DEFCONFIG_LIST	2
610a9064fbSMasahiro Yamada #define T_OPT_ENV		3
620a9064fbSMasahiro Yamada #define T_OPT_ALLNOCONFIG_Y	4
630a9064fbSMasahiro Yamada 
640a9064fbSMasahiro Yamada struct kconf_id {
65*e91610daSEugeniu Rosca 	const char *name;
660a9064fbSMasahiro Yamada 	int token;
670a9064fbSMasahiro Yamada 	unsigned int flags;
680a9064fbSMasahiro Yamada 	enum symbol_type stype;
690a9064fbSMasahiro Yamada };
700a9064fbSMasahiro Yamada 
71*e91610daSEugeniu Rosca extern int yylineno;
720a9064fbSMasahiro Yamada void zconfdump(FILE *out);
730a9064fbSMasahiro Yamada void zconf_starthelp(void);
740a9064fbSMasahiro Yamada FILE *zconf_fopen(const char *name);
750a9064fbSMasahiro Yamada void zconf_initscan(const char *name);
760a9064fbSMasahiro Yamada void zconf_nextfile(const char *name);
770a9064fbSMasahiro Yamada int zconf_lineno(void);
780a9064fbSMasahiro Yamada const char *zconf_curname(void);
790a9064fbSMasahiro Yamada 
800a9064fbSMasahiro Yamada /* confdata.c */
810a9064fbSMasahiro Yamada const char *conf_get_configname(void);
820a9064fbSMasahiro Yamada const char *conf_get_autoconfig_name(void);
830a9064fbSMasahiro Yamada char *conf_get_default_confname(void);
840a9064fbSMasahiro Yamada void sym_set_change_count(int count);
850a9064fbSMasahiro Yamada void sym_add_change_count(int count);
860a9064fbSMasahiro Yamada bool conf_set_all_new_symbols(enum conf_def_mode mode);
870a9064fbSMasahiro Yamada void set_all_choice_values(struct symbol *csym);
880a9064fbSMasahiro Yamada 
890a9064fbSMasahiro Yamada /* confdata.c and expr.c */
xfwrite(const void * str,size_t len,size_t count,FILE * out)900a9064fbSMasahiro Yamada static inline void xfwrite(const void *str, size_t len, size_t count, FILE *out)
910a9064fbSMasahiro Yamada {
920a9064fbSMasahiro Yamada 	assert(len != 0);
930a9064fbSMasahiro Yamada 
940a9064fbSMasahiro Yamada 	if (fwrite(str, len, count, out) != count)
950a9064fbSMasahiro Yamada 		fprintf(stderr, "Error in writing or end of file.\n");
960a9064fbSMasahiro Yamada }
970a9064fbSMasahiro Yamada 
980a9064fbSMasahiro Yamada /* menu.c */
990a9064fbSMasahiro Yamada void _menu_init(void);
1000a9064fbSMasahiro Yamada void menu_warn(struct menu *menu, const char *fmt, ...);
1010a9064fbSMasahiro Yamada struct menu *menu_add_menu(void);
1020a9064fbSMasahiro Yamada void menu_end_menu(void);
1030a9064fbSMasahiro Yamada void menu_add_entry(struct symbol *sym);
1040a9064fbSMasahiro Yamada void menu_add_dep(struct expr *dep);
1050a9064fbSMasahiro Yamada void menu_add_visibility(struct expr *dep);
1060a9064fbSMasahiro Yamada struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep);
1070a9064fbSMasahiro Yamada void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep);
1080a9064fbSMasahiro Yamada void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep);
1090a9064fbSMasahiro Yamada void menu_add_option(int token, char *arg);
1100a9064fbSMasahiro Yamada void menu_finalize(struct menu *parent);
1110a9064fbSMasahiro Yamada void menu_set_type(int type);
1120a9064fbSMasahiro Yamada 
1130a9064fbSMasahiro Yamada /* util.c */
1140a9064fbSMasahiro Yamada struct file *file_lookup(const char *name);
1150a9064fbSMasahiro Yamada int file_write_dep(const char *name);
1160a9064fbSMasahiro Yamada void *xmalloc(size_t size);
1170a9064fbSMasahiro Yamada void *xcalloc(size_t nmemb, size_t size);
118*e91610daSEugeniu Rosca void *xrealloc(void *p, size_t size);
119*e91610daSEugeniu Rosca char *xstrdup(const char *s);
1200a9064fbSMasahiro Yamada 
1210a9064fbSMasahiro Yamada struct gstr {
1220a9064fbSMasahiro Yamada 	size_t len;
1230a9064fbSMasahiro Yamada 	char  *s;
1240a9064fbSMasahiro Yamada 	/*
1250a9064fbSMasahiro Yamada 	* when max_width is not zero long lines in string s (if any) get
1260a9064fbSMasahiro Yamada 	* wrapped not to exceed the max_width value
1270a9064fbSMasahiro Yamada 	*/
1280a9064fbSMasahiro Yamada 	int max_width;
1290a9064fbSMasahiro Yamada };
1300a9064fbSMasahiro Yamada struct gstr str_new(void);
1310a9064fbSMasahiro Yamada void str_free(struct gstr *gs);
1320a9064fbSMasahiro Yamada void str_append(struct gstr *gs, const char *s);
1330a9064fbSMasahiro Yamada void str_printf(struct gstr *gs, const char *fmt, ...);
1340a9064fbSMasahiro Yamada const char *str_get(struct gstr *gs);
1350a9064fbSMasahiro Yamada 
1360a9064fbSMasahiro Yamada /* symbol.c */
1370a9064fbSMasahiro Yamada extern struct expr *sym_env_list;
1380a9064fbSMasahiro Yamada 
1390a9064fbSMasahiro Yamada void sym_init(void);
1400a9064fbSMasahiro Yamada void sym_clear_all_valid(void);
1410a9064fbSMasahiro Yamada struct symbol *sym_choice_default(struct symbol *sym);
1420a9064fbSMasahiro Yamada const char *sym_get_string_default(struct symbol *sym);
1430a9064fbSMasahiro Yamada struct symbol *sym_check_deps(struct symbol *sym);
1440a9064fbSMasahiro Yamada struct property *prop_alloc(enum prop_type type, struct symbol *sym);
1450a9064fbSMasahiro Yamada struct symbol *prop_get_symbol(struct property *prop);
1460a9064fbSMasahiro Yamada struct property *sym_get_env_prop(struct symbol *sym);
1470a9064fbSMasahiro Yamada 
sym_get_tristate_value(struct symbol * sym)1480a9064fbSMasahiro Yamada static inline tristate sym_get_tristate_value(struct symbol *sym)
1490a9064fbSMasahiro Yamada {
1500a9064fbSMasahiro Yamada 	return sym->curr.tri;
1510a9064fbSMasahiro Yamada }
1520a9064fbSMasahiro Yamada 
1530a9064fbSMasahiro Yamada 
sym_get_choice_value(struct symbol * sym)1540a9064fbSMasahiro Yamada static inline struct symbol *sym_get_choice_value(struct symbol *sym)
1550a9064fbSMasahiro Yamada {
1560a9064fbSMasahiro Yamada 	return (struct symbol *)sym->curr.val;
1570a9064fbSMasahiro Yamada }
1580a9064fbSMasahiro Yamada 
sym_set_choice_value(struct symbol * ch,struct symbol * chval)1590a9064fbSMasahiro Yamada static inline bool sym_set_choice_value(struct symbol *ch, struct symbol *chval)
1600a9064fbSMasahiro Yamada {
1610a9064fbSMasahiro Yamada 	return sym_set_tristate_value(chval, yes);
1620a9064fbSMasahiro Yamada }
1630a9064fbSMasahiro Yamada 
sym_is_choice(struct symbol * sym)1640a9064fbSMasahiro Yamada static inline bool sym_is_choice(struct symbol *sym)
1650a9064fbSMasahiro Yamada {
1660a9064fbSMasahiro Yamada 	return sym->flags & SYMBOL_CHOICE ? true : false;
1670a9064fbSMasahiro Yamada }
1680a9064fbSMasahiro Yamada 
sym_is_choice_value(struct symbol * sym)1690a9064fbSMasahiro Yamada static inline bool sym_is_choice_value(struct symbol *sym)
1700a9064fbSMasahiro Yamada {
1710a9064fbSMasahiro Yamada 	return sym->flags & SYMBOL_CHOICEVAL ? true : false;
1720a9064fbSMasahiro Yamada }
1730a9064fbSMasahiro Yamada 
sym_is_optional(struct symbol * sym)1740a9064fbSMasahiro Yamada static inline bool sym_is_optional(struct symbol *sym)
1750a9064fbSMasahiro Yamada {
1760a9064fbSMasahiro Yamada 	return sym->flags & SYMBOL_OPTIONAL ? true : false;
1770a9064fbSMasahiro Yamada }
1780a9064fbSMasahiro Yamada 
sym_has_value(struct symbol * sym)1790a9064fbSMasahiro Yamada static inline bool sym_has_value(struct symbol *sym)
1800a9064fbSMasahiro Yamada {
1810a9064fbSMasahiro Yamada 	return sym->flags & SYMBOL_DEF_USER ? true : false;
1820a9064fbSMasahiro Yamada }
1830a9064fbSMasahiro Yamada 
1840a9064fbSMasahiro Yamada #ifdef __cplusplus
1850a9064fbSMasahiro Yamada }
1860a9064fbSMasahiro Yamada #endif
1870a9064fbSMasahiro Yamada 
1880a9064fbSMasahiro Yamada #endif /* LKC_H */
189