Adding Source Files - Trainraider/gtk3-glade-c-template GitHub Wiki

If you add a new source file, you'll have to let the Make build system know about it.

Adding a .c file with no prerequisite headers

There is an generic target for building any .c files that don't rely on project headers, so they are simpler to add.

  • In config.mk find this line:
OBJ ?= $(BLD)/main.o $(BLD)/version.o $(BLD)/data.o
  • Add an object file corresponding to your c file, e.g.
OBJ ?= $(BLD)/main.o $(BLD)/version.o $(BLD)/data.o $(BLD)/new.o

Adding a .c file that relies on headers within the project

Additional steps are needed if the C file includes any headers within your project that might change later. However, you don't need to do anything more just from including things like library headers that are outside your project.

You'll first need to do the above step within config.mk, and then open makefile There needs to be a custom target for your .c file that lists any included .h files as prerequisites.

  • Find the section labeled with the comment #Specific rules
  • Add a new line that targets an object file and lists the .c and .h files as prerequisites. e.g.
$(BLD)/new.o : $(SRC)/new.c $(SRC)/new.h
  • Now at the end of that new line, add | mkdirs, this boilerplate simply ensures that you never try to build files into the build directory if it doesn't exist yet.
$(BLD)/new.o : $(SRC)/new.c $(SRC)/new.h | mkdirs