Пример #1
0
RULE* bind_builtin( char* name, LIST*(*f)(PARSE*, FRAME*), int flags, char** args )
{
    argument_list* arg_list = 0;
    
    if ( args )
    {
        arg_list = args_new();
        lol_build( arg_list->data, args );
    }

    return new_rule_body( root_module(), name, arg_list,
                          parse_make( f, P0, P0, P0, C0, C0, flags ), 1 );
}
Пример #2
0
Файл: compile.c Проект: aosm/jam
void
compile_builtins()
{
    /* Note that we cannot share the PARSE object between the different */
    /* variants of a given rule name, since we do no know if the Jambase */
    /* or Jamfile will redefine one of the rules and thus free the PARSE */
    /* object. */

    bindrule( "Always" )->procedure = 
        parse_make( builtin_flags, P0, P0, C0, C0, L0, L0, T_FLAG_TOUCHED );
    bindrule( "ALWAYS" )->procedure = 
        parse_make( builtin_flags, P0, P0, C0, C0, L0, L0, T_FLAG_TOUCHED );

    bindrule( "Depends" )->procedure = 
        parse_make( builtin_depends, P0, P0, C0, C0, L0, L0, T_DEPS_DEPENDS );
    bindrule( "DEPENDS" )->procedure = 
        parse_make( builtin_depends, P0, P0, C0, C0, L0, L0, T_DEPS_DEPENDS );

    bindrule( "Echo" )->procedure = 
        parse_make( builtin_echo, P0, P0, C0, C0, L0, L0, 0 );
    bindrule( "ECHO" )->procedure = 
        parse_make( builtin_echo, P0, P0, C0, C0, L0, L0, 0 );

    bindrule( "Exit" )->procedure = 
        parse_make( builtin_exit, P0, P0, C0, C0, L0, L0, 0 );
    bindrule( "EXIT" )->procedure = 
        parse_make( builtin_exit, P0, P0, C0, C0, L0, L0, 0 );

    bindrule( "Includes" )->procedure = 
        parse_make( builtin_depends, P0, P0, C0, C0, L0, L0, T_DEPS_INCLUDES );
    bindrule( "INCLUDES" )->procedure = 
        parse_make( builtin_depends, P0, P0, C0, C0, L0, L0, T_DEPS_INCLUDES );

    bindrule( "Leaves" )->procedure = 
        parse_make( builtin_flags, P0, P0, C0, C0, L0, L0, T_FLAG_LEAVES );
    bindrule( "LEAVES" )->procedure = 
        parse_make( builtin_flags, P0, P0, C0, C0, L0, L0, T_FLAG_LEAVES );

    bindrule( "NoCare" )->procedure = 
        parse_make( builtin_flags, P0, P0, C0, C0, L0, L0, T_FLAG_NOCARE );
    bindrule( "NOCARE" )->procedure = 
        parse_make( builtin_flags, P0, P0, C0, C0, L0, L0, T_FLAG_NOCARE );

    bindrule( "NOTIME" )->procedure = 
        parse_make( builtin_flags, P0, P0, C0, C0, L0, L0, T_FLAG_NOTFILE );
    bindrule( "NotFile" )->procedure = 
        parse_make( builtin_flags, P0, P0, C0, C0, L0, L0, T_FLAG_NOTFILE );
    bindrule( "NOTFILE" )->procedure = 
        parse_make( builtin_flags, P0, P0, C0, C0, L0, L0, T_FLAG_NOTFILE );

    bindrule( "NoUpdate" )->procedure = 
        parse_make( builtin_flags, P0, P0, C0, C0, L0, L0, T_FLAG_NOUPDATE );
    bindrule( "NOUPDATE" )->procedure = 
        parse_make( builtin_flags, P0, P0, C0, C0, L0, L0, T_FLAG_NOUPDATE );

    bindrule( "Temporary" )->procedure = 
        parse_make( builtin_flags, P0, P0, C0, C0, L0, L0, T_FLAG_TEMP );
    bindrule( "TEMPORARY" )->procedure = 
        parse_make( builtin_flags, P0, P0, C0, C0, L0, L0, T_FLAG_TEMP );
}
Пример #3
0
int 
	main(int argc, char **argv)
{
	struct makefile		*Makefile; 

	FILE				*rw_to = NULL;

	char				*contents = NULL;
	char				*conv_str = NULL;

	char				byte[CHAR_BIT]; 

	int					error_code;
	int					i, c, x;

	int					run_flag = 0;
	int					comp_flag = 0;
	
	// Attempt to find BFMakefile
	if ((rw_to = fopen("BFMakefile", "r")) == NULL)
	{	
		// No BFMakefile found :(
		(void) fprintf(stderr, "[ERROR] BFMakefile was not found\nCreating...\n\n");

		// Attempt creation of BFMakefle
		if ((rw_to = fopen("BFMakefile", "w")) == NULL)

			// Creation failed
			(void) fprintf(stderr, "[ERROR] Unable to create BFMakefile\nExiting\n");

		// Creation successful, close the _file stream
		else
		{
			(void) fclose(rw_to);
			(void) fprintf(stderr, "[INFO] BFMakefile has been created\n");
		}

		error_code = errno;
		return error_code;
	}

		
	// Get contents of makefile, NULL if fail
	if ((contents = read_file(rw_to)) == NULL)
		return MALLOC_ERR;

	(void) fclose(rw_to);

	// Check if number of bits is correct
	if ((i = strlen(contents) % 8))
	{
		(void) fprintf(stderr, "[ERROR] Incorrect length\nExcess Length: %d", i);
		return NO_MAKE;
	}

	// Allocate 8 "bits" to a char, so divide by 8 +1 for NT
	if ((conv_str = (char *) malloc(sizeof(char) * (strlen(contents) / 8) + 1)) == NULL)
	{
		(void) fprintf(stderr, "[ERROR] Malloc of conv_str failed\n\n");
		(void) fprintf(stderr, "File: %s\n", __FILE__);
		(void) fprintf(stderr, "Line: %d\n", __LINE__);

		return MALLOC_ERR;
	}

	for (c = 0, i = 0, x = 0; contents[c] != '\0'; ++c, ++x) 
	{ 
		byte[x] = contents[c]; 
		
		if (x + 1 == CHAR_BIT) 
		{ 
			conv_str[i++] = bin_str(byte, NULL);
			x = 0; 
			++c;
		}
	}
	
	free(contents);

	(void) fprintf(rw_to, "\n\n\n");
	(void) fclose(rw_to);

	// Terminate string
	conv_str[i] = '\0';

	// Allocate space for Makefile, NULL if fail
	if ((Makefile = (struct makefile *) malloc(sizeof(struct makefile))) == NULL)
	{
		(void) fprintf(stderr, "[ERROR] Malloc of Makefile failed\n\n");
		(void) fprintf(stderr, "File: %s\n", __FILE__);
		(void) fprintf(stderr, "Line: %d\n", __LINE__);

		return MALLOC_ERR;
	}

	else
		if (parse_make(conv_str, Makefile))
			return BAD_MAKE;

	free(conv_str);

	if (src_hdr_write(Makefile->src_files, Makefile->src_count, SRC_MODE))
	{
		(void) fprintf(stderr, "[ERROR] Failed to handle Makefile->src_files correctly\n");
		return EXIT_FAILURE;
	}

	free(Makefile->src_files);
	(void) printf("\nMakefile->src_files successfully handled\n");


	if (src_hdr_write(Makefile->hdr_files, Makefile->hdr_count, HDR_MODE))
	{
		(void) fprintf(stderr, "[ERROR] Failed to handle Makefile->hdr_files correctly\n");
		return EXIT_FAILURE;
	}

	free(Makefile->hdr_files);
	(void) printf("Makefile->hdr_files successfully handled\n");



	if (obj_exc_write(Makefile->obj_files, Makefile->obj_count, OBJ_MODE))
	{
		(void) fprintf(stderr, "[ERROR] Failed to handle Makefile->obj_files correctly\n");
		return EXIT_FAILURE;
	}

	free(Makefile->obj_files);
	(void) printf("Makefile->obj_files successfully handled\n");


	if (obj_exc_write(Makefile->exc_name, 1, EXC_MODE))
	{
		(void) fprintf(stderr, "[ERROR] Failed to handle Makefile->exc_name correctly\n");
		return EXIT_FAILURE;
	}

	(void) printf("Makefile->exc_name successfully handled\n\n");
	

	for (i = 1; i < argc; ++i)
	{
		if (!strcmp(argv[i], "--make"))
			comp_flag = 1;

		if (!strcmp(argv[i], "--run"))
			run_flag = 1;
	}

	if (comp_flag)
		if (system("make"))
			return EXIT_FAILURE;

	(void) printf("\n\n");

	if (run_flag)
	{
		if ((Makefile->exc_name = (char*) realloc(Makefile->exc_name, sizeof(char) * Makefile->exc_len + strlen(EXC_EXT) + 1)) == NULL)
		{
			(void) fprintf(stderr, "[ERROR] Realloc of Makefile->exc_name failed\n");
			return EXIT_FAILURE;
		}

		(void) system(strcat(Makefile->exc_name, EXC_EXT));
	}

	free(Makefile->exc_name);
	free(Makefile);

	return EXIT_SUCCESS;
}
Пример #4
0
void
load_builtins()
{
    bindrule( "Always" )->procedure =
    bindrule( "ALWAYS" )->procedure =
	parse_make( builtin_flags, P0, P0, P0, C0, C0, T_FLAG_TOUCHED );

    bindrule( "Depends" )->procedure =
    bindrule( "DEPENDS" )->procedure =
	parse_make( builtin_depends, P0, P0, P0, C0, C0, 0 );

    bindrule( "echo" )->procedure =
    bindrule( "Echo" )->procedure =
    bindrule( "ECHO" )->procedure =
	parse_make( builtin_echo, P0, P0, P0, C0, C0, 0 );

    bindrule( "exit" )->procedure =
    bindrule( "Exit" )->procedure =
    bindrule( "EXIT" )->procedure =
	parse_make( builtin_exit, P0, P0, P0, C0, C0, 0 );

    bindrule( "Glob" )->procedure =
    bindrule( "GLOB" )->procedure =
	parse_make( builtin_glob, P0, P0, P0, C0, C0, 0 );

    bindrule( "Includes" )->procedure =
    bindrule( "INCLUDES" )->procedure =
	parse_make( builtin_depends, P0, P0, P0, C0, C0, 1 );

    bindrule( "Leaves" )->procedure =
    bindrule( "LEAVES" )->procedure =
	parse_make( builtin_flags, P0, P0, P0, C0, C0, T_FLAG_LEAVES );

    bindrule( "Match" )->procedure =
    bindrule( "MATCH" )->procedure =
	parse_make( builtin_match, P0, P0, P0, C0, C0, 0 );

    bindrule( "ForceCare" )->procedure =
	parse_make( builtin_flags_forcecare, P0, P0, P0, C0, C0, T_FLAG_FORCECARE );

    bindrule( "NoCare" )->procedure =
    bindrule( "NOCARE" )->procedure =
	parse_make( builtin_flags_nocare, P0, P0, P0, C0, C0, T_FLAG_NOCARE );

    bindrule( "NOTIME" )->procedure =
    bindrule( "NotFile" )->procedure =
    bindrule( "NOTFILE" )->procedure =
	parse_make( builtin_flags, P0, P0, P0, C0, C0, T_FLAG_NOTFILE );

    bindrule( "NoUpdate" )->procedure =
    bindrule( "NOUPDATE" )->procedure =
	parse_make( builtin_flags, P0, P0, P0, C0, C0, T_FLAG_NOUPDATE );

#ifdef OPT_BUILTIN_SUBST_EXT
	bindrule( "Subst" )->procedure =
		parse_make( builtin_subst, P0, P0, P0, C0, C0, 0 );
	bindrule( "SubstLiteralize" )->procedure =
		parse_make( builtin_subst_literalize, P0, P0, P0, C0, C0, 0 );
#endif

    bindrule( "Temporary" )->procedure =
    bindrule( "TEMPORARY" )->procedure =
	parse_make( builtin_flags, P0, P0, P0, C0, C0, T_FLAG_TEMP );

#ifdef OPT_MULTIPASS_EXT
    bindrule( "QueueJamfile" )->procedure =
	parse_make( builtin_queuejamfile, P0, P0, P0, C0, C0, 0 );
#endif

#ifdef OPT_BUILTIN_MD5_EXT
    bindrule( "MD5" )->procedure =
	parse_make( builtin_md5, P0, P0, P0, C0, C0, 0 );
    bindrule( "MD5File" )->procedure =
	parse_make( builtin_md5file, P0, P0, P0, C0, C0, 0 );
#endif /* OPT_BUILTIN_MD5_EXT */
#ifdef OPT_BUILTIN_MATH_EXT
    bindrule( "Math" )->procedure =
	parse_make( builtin_math, P0, P0, P0, C0, C0, 0 );
#endif
#ifdef NT
#ifdef OPT_BUILTIN_W32_GETREG_EXT
	bindrule( "W32_GETREG" )->procedure =
		parse_make( builtin_w32_getreg, P0, P0, P0, C0, C0, 0 );
#endif
#ifdef OPT_BUILTIN_W32_GETREG64_EXT
	bindrule( "W32_GETREG64" )->procedure =
		parse_make( builtin_w32_getreg64, P0, P0, P0, C0, C0, 0 );
#endif
#ifdef OPT_BUILTIN_W32_SHORTNAME_EXT
	bindrule( "W32_SHORTNAME" )->procedure =
		parse_make( builtin_w32_shortname, P0, P0, P0, C0, C0, 0 );
#endif
#endif

#ifdef OPT_HEADER_CACHE_EXT
    bindrule( "UseDepCache" )->procedure =
 parse_make( builtin_usedepcache, P0, P0, P0, C0, C0, T_FLAG_USEDEPCACHE );
#endif

#ifdef OPT_BUILTIN_MD5CACHE_EXT
    bindrule( "UseFileCache" )->procedure =
 parse_make( builtin_usefilecache, P0, P0, P0, C0, C0, T_FLAG_USEFILECACHE );

    bindrule( "OptionalFileCache" )->procedure =
 parse_make( builtin_usefilecache, P0, P0, P0, C0, C0, T_FLAG_USEFILECACHE | T_FLAG_OPTIONALFILECACHE );

    bindrule( "UseCommandLine" )->procedure =
	parse_make( builtin_usecommandline, P0, P0, P0, C0, C0, T_FLAG_USECOMMANDLINE );

    bindrule( "ScanContents" )->procedure =
    bindrule( "SCANCONTENTS" )->procedure =
	parse_make( builtin_flags, P0, P0, P0, C0, C0, T_FLAG_SCANCONTENTS );
#endif

#ifdef OPT_BUILTIN_NEEDS_EXT
    bindrule( "MightNotUpdate" )->procedure =
    	parse_make( builtin_flags, P0, P0, P0, C0, C0, T_FLAG_MIGHTNOTUPDATE );

    bindrule( "Needs" )->procedure =
    bindrule( "NEEDS" )->procedure =
	parse_make( builtin_depends, P0, P0, P0, C0, C0, 2 );
#endif

#ifdef OPT_BUILTIN_LUA_SUPPORT_EXT
    bindrule( "LuaString" )->procedure =
	parse_make( builtin_luastring, P0, P0, P0, C0, C0, 0 );

    bindrule( "LuaFile" )->procedure =
	parse_make( builtin_luafile, P0, P0, P0, C0, C0, 0 );

    bindrule( "UseMD5Callback" )->procedure =
	parse_make( builtin_usemd5callback, P0, P0, P0, C0, C0, 0 );
#endif
#ifdef OPT_SERIAL_OUTPUT_EXT
    bindrule( "Shell" )->procedure =
	parse_make( builtin_shell, P0, P0, P0, C0, C0, 0 );
#endif

#ifdef OPT_BUILTIN_GROUPBYVAR_EXT
	bindrule( "GroupByVar" )->procedure =
		parse_make( builtin_groupbyvar, P0, P0, P0, C0, C0, 0 );
#endif

#ifdef OPT_BUILTIN_SPLIT_EXT
	bindrule( "Split" )->procedure =
		parse_make( builtin_split, P0, P0, P0, C0, C0, 0 );
#endif

	bindrule( "ExpandFileList" )->procedure =
		parse_make( builtin_expandfilelist, P0, P0, P0, C0, C0, 0 );
	bindrule( "ListSort" )->procedure =
		parse_make( builtin_listsort, P0, P0, P0, C0, C0, 0 );
}