python.mak 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # -*- make -*-
  2. # This creates a python shared module.
  3. # Input
  4. # $(SOURCE) - The source code to use
  5. # $(MODULE) - The name of the module without module or .so
  6. # All output is writtin to .opic files in the build directory to
  7. # signify the PIC output.
  8. # See defaults.mak for information about LOCAL
  9. # Some local definitions
  10. LOCAL := $(MODULE)module.so
  11. $(LOCAL)-OBJS := $(addprefix $(OBJ)/,$(addsuffix .opic,$(notdir $(basename $(SOURCE)))))
  12. $(LOCAL)-DEP := $(addprefix $(DEP)/,$(addsuffix .opic.d,$(notdir $(basename $(SOURCE)))))
  13. $(LOCAL)-SLIBS := $(SLIBS)
  14. $(LOCAL)-MODULE := $(MODULE)
  15. # Install the command hooks
  16. library: $(LIB)/$(MODULE)module.so
  17. clean: clean/$(LOCAL)
  18. veryclean: veryclean/$(LOCAL)
  19. # Make Directories
  20. MKDIRS += $(OBJ) $(DEP) $(LIB)
  21. # The clean rules
  22. .PHONY: clean/$(LOCAL) veryclean/$(LOCAL)
  23. clean/$(LOCAL):
  24. -rm -f $($(@F)-OBJS) $($(@F)-DEP)
  25. veryclean/$(LOCAL): clean/$(LOCAL)
  26. -rm -f $($(@F)-HEADERS) $(LIB)/$($(@F)-MODULE)module.so*
  27. # The binary build rule.
  28. ifdef PYTHONLIB
  29. ifndef ONLYSTATICLIBS
  30. $(LIB)/$(MODULE)module.so: $($(LOCAL)-OBJS)
  31. -rm -f $(LIB)/$($(@F)-MODULE)module.so* 2> /dev/null
  32. echo Building shared Python module $@
  33. $(CXX) $(CXXSTD) $(CXXFLAGS) $(LDFLAGS) $(PICFLAGS) $(LFLAGS) $(LFLAGS_SO)\
  34. -o $@ -shared \
  35. $(filter %.opic,$^) \
  36. $($(@F)-SLIBS) $(PYTHONLIB)
  37. else
  38. .PHONY: $(LIB)/$(MODULE)module.so
  39. $(LIB)/$(MODULE)module.so:
  40. echo Don't know how to make a python module here, not building $@
  41. endif # ifndef ONLYSTATICLIBS
  42. else
  43. .PHONY: $(LIB)/$(MODULE)module.so
  44. $(LIB)/$(MODULE)module.so:
  45. echo No python support, not building $@
  46. endif # ifdef PYTHONLIB
  47. # Compilation rules
  48. vpath %.cc $(SUBDIRS)
  49. $(OBJ)/%.opic: %.cc
  50. echo Compiling $< to $@
  51. $(CXX) -c $(INLINEDEPFLAG) $(CPPFLAGS) $(CXXSTD) $(CXXFLAGS) $(PICFLAGS) -o $@ '$(abspath $<)'
  52. $(DoDep)
  53. # Include the dependencies that are available
  54. The_DFiles = $(wildcard $($(LOCAL)-DEP))
  55. ifneq ($(words $(The_DFiles)),0)
  56. include $(The_DFiles)
  57. endif