Просто о самом простом Makefile возможно для проекта, как ваше будет что-то вроде этого:
# The name of the source files
SOURCES = hellomain.c hellofunc.c
# The name of the executable
EXE = results
# Flags for compilation (adding warnings are always good)
CFLAGS = -Wall
# Flags for linking (none for the moment)
LDFLAGS =
# Libraries to link with (none for the moment)
LIBS =
# Use the GCC frontend program when linking
LD = gcc
# This creates a list of object files from the source files
OBJECTS = $(SOURCES:%.c=%.o)
# The first target, this will be the default target if none is specified
# This target tells "make" to make the "all" target
default: all
# Having an "all" target is customary, so one could write "make all"
# It depends on the executable program
all: $(EXE)
# This will link the executable from the object files
$(EXE): $(OBJECTS)
$(LD) $(LDFLAGS) $(OBJECTS) -o $(EXE) $(LIBS)
# This is a target that will compiler all needed source files into object files
# We don't need to specify a command or any rules, "make" will handle it automatically
%.o: %.c
# Target to clean up after us
clean:
-rm -f $(EXE) # Remove the executable file
-rm -f $(OBJECTS) # Remove the object files
# Finally we need to tell "make" what source and header file each object file depends on
hellomain.o: hellomain.c helloheader.h
hellofunc.o: hellofunc.c helloheader.h
Это может быть еще проще, но при этом у вас есть некоторая гибкость.
Просто для полноты, это, вероятно, самый простой Makefile можно:
results: hellomain.c hellofunc.c helloheader.h
$(CC) hellomain.c hellofunc.c -o results
Это в основном делает то, что вы уже делаете в командной строке. Он не очень гибкий, и он будет восстанавливать все, если какой-либо файл изменится.
Есть тысячи примеров и руководств по make-файлам. Начните с копирования одного из простых и оттуда. –
Кроме того, вы не должны создавать файл заголовка. –
Я пробовал следовать приведенным здесь примерам: https://www3.ntu.edu.sg/home/ehchua/programming/cpp/gcc_make.html#zz-2.3 Но не смог заставить его работать. –