/* ** MakefileData.h ** ** Types & functions related to the makefile data structure. ** ** Written by Peter Sutton ** April 2009 */ #ifndef MAKEFILEDATA_H #define MAKEFILEDATA_H /* Definition structure - stores details of definition lines NAME = VALUE */ typedef struct { char* name; char* value; } Definition; /* Rule structure - stores the arguments in a dependency rule. Note that ** argv[argc] will always be NULL, so that the argv array is suitable for ** passing to execvp. */ typedef struct { int argc; char** argv; } Rule; /* Target structure - stores the name of the file, and what it depends on ** and the rules to be executed to bring it up to date. Each target will have ** 0 or more dependencies and 1 or more rules. Dependencies will be unique. */ typedef struct { char* fileName; int numDependencies; char** dependencies; int numRules; Rule* rules; } Target; /* Toplevel structure */ /* Note that there will be at least one target, and that targets[0] is the ** first target listed in the file. There may be 0 or more definitions. */ typedef struct { int numDefinitions; Definition* definitions; int numTargets; Target* targets; } MakefileData; /****************************** FUNCTIONS ************************************/ /* parse_file() ** ** Read the contents of the given open file and return ** a structure representing our makefile. (Memory is allocated ** within the function for the Makefile structure and its elements. ** This memory can be deallocated using the free_makefile_data() ** function.) If an error occurs, will print an error message to ** standard error and exit with an appropriate exit status. */ MakefileData* parse_file(FILE* fileHandle); /* free_makefile_data() ** ** Free the Makefile structure pointed to by makefilePtr */ void free_makefile_data(MakefileData* makefilePtr); /* print_makefile() ** ** Print the Makefile structure pointed to by makefilePtr */ void print_makefile_data(MakefileData* makefilePtr); /* find_target() ** ** Find the given target in the makefile data structure (or a null ** pointer if it is not found) */ Target* find_target(MakefileData* makefilePtr, char* targetName); /* find_definition() ** ** Find the given definition value in the makefile data structure (or ** a null pointer if it is not found) */ char* find_definition(MakefileData* makefilePtr, char* defName); #endif