Makefile 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # ex: set ts=8 noet:
  2. MODULE_NAME := nx
  3. OS := $(shell sh -c 'uname -s 2>/dev/null || echo not')
  4. ifeq ($(OS),Linux)
  5. DIR := linux
  6. DIRARCH := linux
  7. else ifeq ($(OS),Darwin)
  8. DIR := osx
  9. DIRARCH := osx-amd64
  10. else
  11. $(error OS unrecognized ($OS))
  12. endif
  13. CSOURCES := $(DIR)/nxstring.c $(DIR)/nxuri.c $(DIR)/nxdata.c $(DIR)/nxsemaphore.c $(DIRARCH)/nxonce.c $(DIR)/nxpath.c $(DIR)/nxcondition.c $(DIR)/nxthread.c $(DIR)/nxfile.c $(DIR)/nxsleep.c
  14. CPPSOURCES := $(DIR)/NXFileObject.cpp $(DIR)/NXFileProgressiveDownloader.cpp
  15. LIBRARY_FILENAME := lib$(MODULE_NAME).so
  16. OUTPUT_PATH := ../build/$(MODULE_NAME)
  17. ARCHIVE_PATH := ../build/lib
  18. LIBRARY_FILEPATH := ../build/lib/$(LIBRARY_FILENAME)
  19. CPPOBJS := $(patsubst %.cpp,$(OUTPUT_PATH)/%.o,$(CPPSOURCES))
  20. CPPDEPS := $(patsubst %.o,$(OUTPUT_PATH)/%.d,$(CPPOBJS))
  21. COBJS := $(patsubst %.c,$(OUTPUT_PATH)/%.o,$(CSOURCES))
  22. CDEPS := $(patsubst %.o,$(OUTPUT_PATH)/%.d,$(COBJS))
  23. OBJS := $(CPPOBJS) $(COBJS)
  24. DEPS := $(CPPDEPS) $(CDEPS)
  25. CFLAGS= -I.. -DREPLICANT_NO_ICY -DREPLICANT_NO_ULTRAVOX -DREPLICANT_NO_HTTP -D_LARGEFILE64_SOURCE -fPIC #-fvisibility=hidden
  26. CPPFLAGS := ${CFLAGS}
  27. CFLAGS += -std=gnu99 # C but not CPP, sneaky
  28. LDFLAGS =-lc -lpthread -lz #-fvisibility=hidden
  29. ifeq ($(OS),Linux)
  30. LDFLAGS += -lrt
  31. endif
  32. ifeq ($(OS),Darwin)
  33. CFLAGS += -F /System/Library/Frameworks/CoreServices.framework/Frameworks
  34. LDFLAGS += -framework CoreFoundation -framework CoreServices
  35. endif
  36. build: build-dir $(LIBRARY_FILEPATH)
  37. build-dir:
  38. @mkdir -p $(OUTPUT_PATH)/$(DIR) > /dev/null 2> /dev/null
  39. @mkdir -p $(OUTPUT_PATH)/$(DIRARCH) > /dev/null 2> /dev/null
  40. @mkdir -p $(OUTPUT_PATH) > /dev/null 2> /dev/null
  41. @mkdir -p $(ARCHIVE_PATH) > /dev/null 2> /dev/null
  42. dep:
  43. @rm ${DEPS}
  44. $(OUTPUT_PATH)/%.o: %.cpp
  45. #@echo Compiling $*.cpp
  46. @$(CXX) $(CPPFLAGS) -MMD -MF $(OUTPUT_PATH)/$*.d -MT $(OUTPUT_PATH)/$*.o -c $*.cpp -o $(OUTPUT_PATH)/$*.o
  47. $(OUTPUT_PATH)/$(DIR)/%.o: %.cpp
  48. #@echo Compiling $*.cpp
  49. @$(CXX) $(CPPFLAGS) -MMD -MF $(OUTPUT_PATH)/$(DIR)/$*.d -MT $(OUTPUT_PATH)/$(DIR)/$*.o -c $*.cpp -o $(OUTPUT_PATH)/$(DIR)/$*.o
  50. $(OUTPUT_PATH)/%.o: %.c
  51. #@echo Compiling $*.c
  52. @$(CC) $(CFLAGS) -MMD -MF $(OUTPUT_PATH)/$*.d -MT $(OUTPUT_PATH)/$*.o -c $*.c -o $(OUTPUT_PATH)/$*.o
  53. $(OUTPUT_PATH)/.*/%.o: %.c
  54. #@echo Compiling $*.c
  55. @$(CC) $(CFLAGS) -MMD -MF $(OUTPUT_PATH)/$*.d -MT $(OUTPUT_PATH)/$*.o -c $*.c -o $(OUTPUT_PATH)/$(DIR)/$*.o
  56. ifeq ($(OS),Darwin)
  57. LIBLDFLAGS = -Wl,-install_name,libnx.so
  58. else
  59. LIBLDFLAGS = -Wl,-soname,libnx.so
  60. endif
  61. $(LIBRARY_FILEPATH): ${OBJS}
  62. $(MAKE) -C ../nu
  63. $(MAKE) -C ../jnetlib
  64. @$(CXX) -Wl,-L,'../build/lib' -shared $(LIBLDFLAGS) -o $(LIBRARY_FILEPATH) ${OBJS} ${LDFLAGS} -lnu -ljnet
  65. clean:
  66. -rm -f ${OBJS} $(LIBRARY_FILENAME) ${DEPS}
  67. -include $(DEPS)