Makefile 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. $(info Starting building process)
  2. # include configurations
  3. include Makefile.conf
  4. $(info - Makefile.conf loaded)
  5. # find project files
  6. H_FILES := $(shell find -L ./$(INC_DIRECTORY) -name '*.h' -exec dirname {} \; | sed 's/ /\\ /g' | uniq)
  7. C_FILES := $(shell find ./$(SRC_DIRECTORY) -name '*.c' -type f | sed 's/ /\\ /g' | uniq)
  8. CXX_FILES := $(shell find ./$(SRC_DIRECTORY) -name '*.cpp' -type f | sed 's/ /\\ /g' | uniq)
  9. O_FILES := $(C_FILES:.c=.o)
  10. O_FILES += $(CXX_FILES:.cpp=.o)
  11. H_FILES := $(notdir $(H_FILES))
  12. C_FILES := $(notdir $(C_FILES))
  13. CXX_FILES := $(notdir $(CXX_FILES))
  14. INCLUDES := $(H_FILES:%=-I%)
  15. $(info - Project Files Loaded)
  16. ifeq ($(DEBUG),yes)
  17. $(info - Debug flag added [makefile.conf DEBUG = yes])
  18. CFLAGS := -g $(CFLAGS)
  19. endif
  20. ifeq ($(IS_LIBRARY),yes)
  21. $(info - Set Parameters for Shared Library build process)
  22. ALL_PARAMETERS = lib$(PROJECT_NAME).so.$(PROJECT_VERSION) clean
  23. ALL_TYPE = lib$(PROJECT_NAME).so.$(PROJECT_VERSION): $(O_FILES)
  24. LIBFLAGS = -shared -Wl,-soname,lib$(PROJECT_NAME).so
  25. CFLAGS := -fPIC $(CFLAGS)
  26. CXXFLAGS := -fPIC $(CXXFLAGS)
  27. else
  28. $(info - Set Parameters for Application build process)
  29. ALL_PARAMETERS = $(PROJECT_NAME) clean
  30. ALL_TYPE = $(PROJECT_NAME): $(O_FILES)
  31. LIBFLAGS =
  32. endif
  33. # Build Process
  34. all: $(ALL_PARAMETERS)
  35. $(ALL_TYPE)
  36. @echo - [OUTPUT][CXX] $@ @[$(BIN_DIRECTORY)]
  37. @$(CXX) $(CFLAGS) $(INCLUDES) $(LDFLAGS) $(LIBFLAGS) -o $(BIN_DIRECTORY)/$@ $^ $(LDLIBS)
  38. %.o: %.c
  39. @echo - [CC] $@
  40. @$(CC) $(CFLAGS) -c $(INCLUDES) -o $@ $< $(LFLAGS)
  41. %.o: %.cpp
  42. @echo - [CXX] $@
  43. @$(CXX) $(CXXFLAGS) -c $(INCLUDES) -o $@ $< $(LFLAGS)
  44. # Clear Objects
  45. clean:
  46. $(info - Remove all .o [object] files)
  47. @find . -name \*.o -type f -delete
  48. # Clear Objects & Executables
  49. cleanall:
  50. $(info - Remove all .o [object] files)
  51. @find . -name \*.o -type f -delete
  52. $(info - Remove all files in $(BIN_DIRECTORY))
  53. @find $(BIN_DIRECTORY) -name \*.* -type f -delete