you're in luck. I made a great makefile that compiles all source files it can find and link then in a final application. Currently it only works for *.cpp file.. I stil haven't added suport to mix *.c files...
here it is
Code:
DIRS := ./ src/
OBJDIR := obj/
EXE = app
#all .cpp/.c
SRC := $(filter %.cpp, $(foreach DIR,$(DIRS),$(wildcard $(DIR)*.cpp) ))
#all headers with matching .cpp/.c
HDR := $(filter $(foreach DIR, $(DIRS),$(wildcard $(DIR)*.h)),$(patsubst %.cpp,%.h,$(SRC)))
#all .o from a .cpp/.c
OBJ := $(foreach FOBJ,$(filter %.o, $(patsubst %.cpp,%.o,$(SRC))),$(OBJDIR)$(FOBJ) )
#all .h with matching .o
HOBJ := $(foreach FOBJ,$(filter %.o, $(patsubst %.h,%.o,$(HDR)) ),$(OBJDIR)$(FOBJ) )
#all .o without matching .h
COBJ := $(filter-out $(HOBJ),$(OBJ))
FLAGS = -Wall
$(EXE): $(OBJ)
$(CXX) $(FLAGS) $(OBJ) -o $(EXE)
$(HOBJ): $(OBJDIR)%.o: %.cpp %.h
-@mkdir -p $(OBJDIR)$(dir $(filter %.cpp, $^))
@touch -a $@
$(CXX) $(FLAGS) -c $(filter %.cpp, $^) -o $@
$(COBJ): $(OBJDIR)%.o: %.cpp
-@mkdir -p $(OBJDIR)$(dir $<)
@touch -a $@
-$(CXX) $(FLAGS) -c $< -o $@
#clean
.PHONY : c clean
c clean:
@echo cleaning temporaries
-@rm -f $(EXE) $(OBJ) $(foreach DIR,$(DIRS),$(DIR)*.bak "$(DIR)*.*~" )
-@rmdir -p --ignore-fail-on-non-empty $(filter-out $(OBJDIR)./,$(foreach DIR,$(DIRS),$(OBJDIR)$(DIR) ))
just save this file as 'makefile' and place it in you source directory.
To compile just write 'make' at the commad prompt.
Add/remove directories to the DIRS variable to mntion where your code is
Change EXE variable to your liking. That's the exeutable final name