makefile.nimf 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #? stdtmpl(subsChar='?') | standard
  2. #proc generateMakefile(c: ConfigData): string =
  3. # result = "# Generated from niminst\n" &
  4. # "# Template is in tools/niminst/makefile.nimf\n" &
  5. # "# To regenerate run ``niminst csource`` or ``koch csource``\n"
  6. CC ??= gcc
  7. CFLAGS += -Ic_code ?{c.ccompiler.flags}
  8. LDFLAGS += ?{c.linker.flags}
  9. binDir = ?{firstBinPath(c).toUnix}
  10. koch := $(shell sh -c 'test -s ../koch.nim && echo "yes"')
  11. ifeq ($(koch),yes)
  12. binDir = ../bin
  13. endif
  14. target := ?{"$(binDir)/" & toLowerAscii(c.name)}
  15. ucpu := $(shell sh -c 'uname -m | tr "[:upper:]" "[:lower:]"')
  16. ifeq ($(OS),Windows_NT)
  17. uos := windows
  18. else
  19. uos := $(shell sh -c 'uname | tr "[:upper:]" "[:lower:]"')
  20. endif
  21. ifeq ($(uos),linux)
  22. myos = linux
  23. LDFLAGS += -ldl -lm
  24. endif
  25. ifeq ($(uos),dragonfly)
  26. myos = freebsd
  27. LDFLAGS += -lm
  28. endif
  29. ifeq ($(uos),freebsd)
  30. myos= freebsd
  31. CC = clang
  32. LDFLAGS += -lm
  33. endif
  34. ifeq ($(uos),openbsd)
  35. myos = openbsd
  36. LDFLAGS += -lm
  37. endif
  38. ifeq ($(uos),netbsd)
  39. myos = netbsd
  40. LDFLAGS += -lm
  41. endif
  42. ifeq ($(uos),darwin)
  43. myos = macosx
  44. CC = clang
  45. LDFLAGS += -ldl -lm
  46. ifeq ($(HOSTTYPE),x86_64)
  47. ucpu = amd64
  48. endif
  49. endif
  50. ifeq ($(uos),aix)
  51. myos = aix
  52. LDFLAGS += -dl -lm
  53. endif
  54. ifeq ($(uos),solaris)
  55. myos = solaris
  56. LDFLAGS += -ldl -lm -lsocket -lnsl
  57. endif
  58. ifeq ($(uos),sun)
  59. myos = solaris
  60. LDFLAGS += -ldl -lm -lsocket -lnsl
  61. endif
  62. ifeq ($(uos),haiku)
  63. myos = haiku
  64. endif
  65. ifeq ($(uos),windows)
  66. myos = windows
  67. target := $(target).exe
  68. endif
  69. ifndef myos
  70. $(error unknown operating system: $(uos))
  71. endif
  72. ifeq ($(ucpu),i386)
  73. mycpu = i386
  74. endif
  75. ifeq ($(ucpu),i486)
  76. mycpu = i386
  77. endif
  78. ifeq ($(ucpu),i586)
  79. mycpu = i386
  80. endif
  81. ifeq ($(ucpu),i686)
  82. mycpu = i386
  83. endif
  84. ifeq ($(ucpu),bepc)
  85. mycpu = i386
  86. endif
  87. ifeq ($(ucpu),i86pc)
  88. mycpu = i386
  89. endif
  90. ifeq ($(ucpu),amd64)
  91. mycpu = amd64
  92. endif
  93. ifeq ($(ucpu),x86-64)
  94. mycpu = amd64
  95. endif
  96. ifeq ($(ucpu),x86_64)
  97. mycpu = amd64
  98. endif
  99. ifeq ($(ucpu),sparc)
  100. mycpu = sparc
  101. endif
  102. ifeq ($(ucpu),sun)
  103. mycpu = sparc
  104. endif
  105. ifeq ($(ucpu),ppc64le)
  106. mycpu = powerpc64el
  107. endif
  108. ifeq ($(ucpu),ppc64)
  109. mycpu = powerpc64
  110. ifeq ($(myos),linux)
  111. CFLAGS += -m64
  112. LDFLAGS += -m64
  113. endif
  114. endif
  115. ifeq ($(ucpu),powerpc)
  116. mycpu = powerpc
  117. ifeq ($(myos),freebsd)
  118. mycpu = $(shell sh -c 'uname -p | tr "[:upper:]" "[:lower:]"')
  119. CFLAGS += -m64
  120. LDFLAGS += -m64
  121. endif
  122. endif
  123. ifeq ($(ucpu),ppc)
  124. mycpu = ppc
  125. endif
  126. ifneq (,$(filter $(ucpu), mips mips64))
  127. mycpu = $(shell /bin/sh -c '"$(CC)" -dumpmachine | sed "s/-.*//"')
  128. ifeq (,$(filter $(mycpu), mips mipsel mips64 mips64el))
  129. $(error unknown MIPS target: $(mycpu))
  130. endif
  131. endif
  132. ifeq ($(ucpu),arm)
  133. mycpu = arm
  134. endif
  135. ifeq ($(ucpu),armeb)
  136. mycpu = arm
  137. endif
  138. ifeq ($(ucpu),armel)
  139. mycpu = arm
  140. endif
  141. ifeq ($(ucpu),armv6l)
  142. mycpu = arm
  143. endif
  144. ifeq ($(ucpu),armv7l)
  145. mycpu = arm
  146. endif
  147. ifeq ($(ucpu),armv7hl)
  148. mycpu = arm
  149. endif
  150. ifeq ($(ucpu),aarch64)
  151. mycpu = arm64
  152. endif
  153. ifeq ($(ucpu),riscv64)
  154. mycpu = riscv64
  155. endif
  156. ifndef mycpu
  157. $(error unknown processor: $(ucpu))
  158. endif
  159. # for osA in 1..c.oses.len:
  160. ifeq ($(myos),?{c.oses[osA-1]})
  161. # for cpuA in 1..c.cpus.len:
  162. ifeq ($(mycpu),?{c.cpus[cpuA-1]})
  163. # var oFiles = ""
  164. # for ff in c.cfiles[osA][cpuA].items:
  165. # oFiles.add(" " & changeFileExt(ff.toUnix, "o"))
  166. # end for
  167. oFiles =?oFiles
  168. endif
  169. # end for
  170. endif
  171. # end for
  172. ifeq ($(strip $(oFiles)),)
  173. $(error no C code generated for: [$(myos): $(mycpu)])
  174. endif
  175. $(target): $(oFiles)
  176. @mkdir -p $(binDir)
  177. $(CC) -o $@ $^ $(LDFLAGS)
  178. @echo "SUCCESS"
  179. .PHONY: clean
  180. clean:
  181. rm -f $(oFiles) ?{"$(binDir)/" & toLowerAscii(c.name)}