OK, here's a revised Makefile template that embraces some of the things discussed:
If you fill in the "gaps" (which I hope will be obvious from the comments!) then this pretty much ought to Just Work.
################ template makefile ##############
# Set up the paths to the folders we will read files from
PATH_1 := /path/to/some/files
PATH_2 := /path/to/other/files
# Where is the fltk-config we plan to use?
FLTK_CNF := /full/path/to/my/fltk-config
# We don't know what compiler to use to build fltk on this machine - but fltk-config does...
CC := $(shell $(FLTK_CNF) --cc)
CXX := $(shell $(FLTK_CNF) --cxx)
# Set the flags for compiler: fltk-config knows the basic settings, then we can add our own...
CFLAGS := $(shell $(FLTK_CNF) --cflags) -Wall -O3 -I$(PATH_1) -I$(PATH_2)
CXXFLAGS := $(shell $(FLTK_CNF) --cxxflags) -Wall -O3 -I$(PATH_1) -I$(PATH_2)
# We don't know what libraries to link with: fltk-config does... Throw in the kitchen sink...
LINKFLTK := $(shell $(FLTK_CNF) --use-gl --use-images --ldstaticflags)
# Possible steps to run after linking...
STRIP := strip
POSTBUILD := $(FLTK_CNF) --post # May be required on OSX (does nothing on other platforms, so safe to call)
# Define what your target application is called
TARGET := MyApp
# What objects go into the target application
OBJECTS := file1.o file2.o
all: $(TARGET)
# Define how to build the various object files...
file1.o: $(PATH_1)/file1.c $(PATH_1)/file1.h # a "plain" C file from PATH_1
$(CC) -c $< -o $@ $(CCFLAGS)
file2.o: $(PATH_2)/file2.cxx $(PATH_2)/file2.h $(PATH_1)/file1.h # a C++ source file from PATH_2
$(CXX) -c $< -o $@ $(CXXFLAGS)
# Now define how to link the final app
MyApp: $(OBJECTS)
$(CXX) -o $@ $(OBJECTS) $(LINKFLTK)
$(STRIP) $@
$(POSTBUILD) $@ # only required on OSX, but we call it anyway for portability
clean:
rm -f $(TARGET)
rm -f $(OBJECTS)
############### end #################