makefile.nimf 3.3 KB

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