
#C makefile for multiple files how to
I can do the linking by causing all header files to be dependencies of the target, but I cannot figure out how to make the C files be invalidated when their included header files are newer. What I want is for only the C files that include the header file I change to be rebuilt, and for the entire project to be linked again. I can fix this quite easily by having all of my header files be dependencies for all of my C files, but that would effectively cause a complete rebuild of the project any time I changed/added a header file, which would not be very graceful. My main issue with this makefile is that when I modify a header file that one or more C files include, the C files aren’t rebuilt. AS = nasmĬFLAGS = -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions \ĬFILES = $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))Ĭ:/python26/python.exe concat.py stage1 stage2 pad.bin core.elf floppy.img Its from scratch and I’m learning about the process, so its not perfect, but I think its powerful enough at this point for my level of experience writing makefiles.
#C makefile for multiple files code
The project code includes "delay.h".I have the following makefile that I use to build a program (a kernel, actually) that I’m working on. Here I'm trying to link with the delay.o object file. Test(.text+0xbe):delay.c:70: first defined here Test(.text+0x5c):delay.c:13: first defined hereĭelay.o(.text+0圆c): In function `delay_ms':ĭelay.c:70: multiple definition of `delay_ms' Test(.text+0x54):delay.c:64: first defined hereĭelay.o(.text+0xa): In function `delay_us':ĭelay.c:13: multiple definition of `delay_us' Test(.text+0x52):delay.c:7: first defined hereĭelay.o(.text+0x2): In function `poll_overflow':ĭelay.c:64: multiple definition of `poll_overflow' gstabs -ID:\WaterMon\libraries -O0 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=test -std=gnu99 -Wp,-M,-MP,-MT,test.o,-MF.dep/ test delay.o -output test.elf -Wl,-Map=test.map,-cref -lm delay.o o file to the current directory I get the following error:Īvr-gcc -Wl,-Map=test.map,-cref -lm delay.o test.o -o testĪvr-gcc -mmcu=atmega163 -I. The trouble is, when I run "make" after having copied the. PHONY : all begin finish end sizebefore sizeafter gccversion \ %.o : $(MSG_COMPILING) $/dev/null) $(wildcard. # Compile: create object files from C source files. %.elf: $(MSG_LINKING) $(ALL_CFLAGS) $(OBJ) -output $(LDFLAGS) %.sym: $(MSG_SYMBOL_TABLE) -n $ Link: create ELF output file from object files. # Build the CFLAGS variable that gets passed to gcc:ĬFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enumsĬFLAGS += -Wa,-adhlns=$( Create a symbol table from ELF output file. # Values below this line should not need to be changed, EVER. # Section Divider Section Divider Section Divider # # C99 standards are not fully implemented yet: # What C Standard are we following? gnu99 is the most flexible, anlthough the # list all the directories you want includes to come from (over and above # what's the debugging format to produce? Can be stabs or dwarf-2:

# The output format (can be srec, ihex, binary) These can be changed by setting vars to be "volatile". Note that wierd things can happen if you're using interrupts # what level of optimisation to use? Can be 0,1,2,3,s. Technically these are not libraries, just #what's the target filename? (without any extensions) # until you reach the section divider below: # Make sure the following variables are present and correct, # controller binaries, not Server side binaries.

# More specifically, this Makefile is intended for micro # This is the MakeFile used for WaterMon project binaries.
