# Manual makefile to go with Eclipse # NOTE: enviornment variables must be set to find linker & compiler. # NOTE: runs with GNU Make. Might also run with Microsoft nmake with tweaks. # # This Makefile will compile any .c file in the current directory and link the # objects into a .hex file to load into the robot. # # Rename this file "makefile" and put in your C source code folder. # # The OBJFILES variable is filled with .o targets using the wildcard # command and patsubst. The $(wildcard *.c) will retrieve any .c # file in the current directory and store it in a variable. The patsubstr # functions is used to convert a file from one format to another. In # this case each .c file is converted into a .o extension and then # stored into OBJFILES. This variable is then used to compile each .c file. # The rule %.o: %.c rebuilds any .o file if the cooresponding .c file has changed. # In the compile line you will see two variables $@ and $<. # $@ will match the target and the $< will match the dependency. So, for # example, $< will contain main.c whenever $@ contains main.o. # Note: makefiles are counterintuitive in that the rules don't run in the order # listed in the file, but instead run whenever they are matched. Also be careful # with tabs and spaces. Rules need a tab (not spaces) before each action. #RENAME AS NEEDED PROJECT=HasCamera #del for windows, rm for unix RM := del /F LIB_PATH=c:\PROGRA~1\mcc18\lib LINKER = mplink CC = mcc18 PICFLAG=-p=18F8520 CFLAGS = -i"C:PROGRA~1\mcc18\h" -nw=2066 DEFINES = -D_FRC_BOARD -D_PRIORY_CAMERA #optimization parameters (default = full optimization) OPT_ENABLE_ALL= OPT_DEBUG=-Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa- OPT=$(OPT_ENABLE_ALL) #make a list of object files that match all C files OBJFILES := $(patsubst %.c,%.o,$(wildcard *.c)) COMPILE=$(CC) $(PICFLAG) $< -fo=$@ $(CFLAGS) $(DEFINES) $(OPT) all: $(PROJECT).hex #re-link if any object file changed $(PROJECT).hex: $(OBJFILES) $(LINKER) "18f8520user.lkr" $(OBJFILES) "FRC_library.lib" /l $(LIB_PATH) /m $(PROJECT).map /o $(PROJECT).hex # Recompile a file if it's c-file changes, # OR recompile everything if ANY header file changes %.o: %.c *.h $(COMPILE) #delete all the build files so you can start from scratch. clean: -$(RM) $(OBJFILES) -$(RM) $(PROJECT).hex -$(RM) $(PROJECT).map -$(RM) $(PROJECT).lst -$(RM) $(PROJECT).cod