First off I would like to thank the author of the Makefile article in the wiki http://wiki.osdev.org/Makefile. I am using this as a reference for my own makefile for a little project I have just started (not OS development). Here is the makefile,
Code: Select all
CC := gcc
RM := rm
CFLAGS := -Iinclude/ -g -std=c99 -Wall
RMFLAGS := -rf
EXT_LIBS := -lc -lssl
PROJDIRS := dir1 dir2
SRCFILES := $(shell find $(PROJDIRS) -type f -name "*.c")
HDRFILES := $(shell find $(PROJDIRS) -type f -name "*.h")
OBJFILES := $(patsubst %.c,%.o,$(SRCFILES))
DEPFILES := $(patsubst %.c,%.d,$(SRCFILES))
EXECUTABLE := my_exec
.PHONY: all clean
all: $(EXECUTABLE)
$(EXECUTABLE): $(OBJFILES)
@$(CC) -o $(EXECUTABLE) $? $(EXT_LIBS)
%.o: %.c Makefile
@$(CC) $(CFLAGS) -MD -MP -c $< -o $@
-include $(DEPFILES)
clean:
-@$(RM) $(RMFLAGS) $(OBJFILES) $(DEPFILES) $(EXECUTABLE)
Code: Select all
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [my_exec] Error 1
TIA