c_src.mk 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Copyright (c) 2014, Loïc Hoguin <essen@ninenines.eu>
  2. # This file is part of erlang.mk and subject to the terms of the ISC License.
  3. .PHONY: clean-c_src
  4. # todo
  5. # Configuration.
  6. C_SRC_DIR = $(CURDIR)/c_src
  7. C_SRC_ENV ?= $(C_SRC_DIR)/env.mk
  8. C_SRC_OPTS ?=
  9. C_SRC_OUTPUT ?= $(CURDIR)/priv/$(PROJECT).so
  10. # System type and C compiler/flags.
  11. UNAME_SYS := $(shell uname -s)
  12. ifeq ($(UNAME_SYS), Darwin)
  13. CC ?= cc
  14. CFLAGS ?= -O3 -std=c99 -arch x86_64 -flat_namespace -undefined suppress -finline-functions -Wall -Wmissing-prototypes
  15. else ifeq ($(UNAME_SYS), FreeBSD)
  16. CC ?= cc
  17. CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes
  18. else ifeq ($(UNAME_SYS), Linux)
  19. CC ?= gcc
  20. CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes
  21. endif
  22. # Verbosity.
  23. c_src_verbose_0 = @echo " C_SRC " $(?F);
  24. c_src_verbose = $(appsrc_verbose_$(V))
  25. # Targets.
  26. ifeq ($(wildcard $(C_SRC_DIR)/Makefile),)
  27. app:: $(C_SRC_ENV)
  28. @mkdir -p priv/
  29. $(c_src_verbose) $(CC) $(CFLAGS) $(C_SRC_DIR)/*.c -fPIC -shared -o $(C_SRC_OUTPUT) \
  30. -I $(ERTS_INCLUDE_DIR) $(C_SRC_OPTS)
  31. $(C_SRC_ENV):
  32. erl -noshell -noinput -eval "file:write_file(\"$(C_SRC_ENV)\", \
  33. io_lib:format(\"ERTS_INCLUDE_DIR ?= ~s/erts-~s/include/\", \
  34. [code:root_dir(), erlang:system_info(version)])), \
  35. init:stop()."
  36. -include $(C_SRC_ENV)
  37. else
  38. ifneq ($(wildcard $(C_SRC_DIR),))
  39. app::
  40. $(MAKE) -C $(C_SRC_DIR)
  41. clean::
  42. $(MAKE) -C $(C_SRC_DIR) clean
  43. endif
  44. endif
  45. clean:: clean-c_src
  46. clean-c_src:
  47. $(gen_verbose) rm -f $(C_SRC_ENV) $(C_SRC_OUTPUT)