![]() In either case, don't use autoconf, please. However, if you want to change the name of the generated executable, libraries, or compiler flags, you can just modify the variables. h files in the current directory, meaning when you add new code files to your directory, you won't have to update the Makefile. It uses the wildcard and patsubst features of the make utility to automatically include. PRECIOUS: $(TARGET) $(OBJECTS) $(TARGET): $(OBJECTS) $(CC) $(OBJECTS) -Wall $(LIBS) -o clean: -rm -f *.o -rm -f $(TARGET) PHONY: default all clean default: $(TARGET) all: default OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c)) HEADERS = $(wildcard *.h) %.o: %.c $(HEADERS) $(CC) $(CFLAGS) -c $< -o. In the structure above, it is critical that the on the third line is actually a tab character.In a makefile, lines preceded with a hash symbol are comments, and will be ignored by the utility. Feel free to use it: TARGET = prog LIBS = -lm CC = gcc CFLAGS = -g -Wall. Compile an executable named yourProgram from yourProgram.c all: yourProgram.c gcc -g -Wall -o yourProgram yourProgram.c.Here's the Makefile I like to use for C source. If you're interested in figuring that out, I hope I've given you a good start on that. The short answer of how to use that makefile is this: Change the line that says SRCFILES so that the right-hand side of the equals sign is a list of all the. I tried to make this as simple as possible by omitting variables like $(CC) and $(CFLAGS) that are usually seen in makefiles. ![]() ![]() Thus, to improve: HEADERS = program.h headers.h OBJECTS = program.o default: program %.o: %.c $(HEADERS) gcc -c $< -o program: $(OBJECTS) gcc $(OBJECTS) -o clean: -rm -f $(OBJECTS) -rm -f program ![]() However, to support more C files, you'd have to make new rules for each of them. (bear in mind that make requires tab instead of space indentation, so be sure to fix that when copying) Interesting, I didn't know make would default to using the C compiler given rules regarding source files.Īnyway, a simple solution that demonstrates simple Makefile concepts would be: HEADERS = program.h headers.h default: program program.o: program.c $(HEADERS) gcc -c program.c -o program.o program: program.o gcc program.o -o program clean: -rm -f program.o -rm -f program ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |