parent
d89c815c41
commit
b5448bf25c
15 changed files with 23 additions and 15 deletions
180
tools/niminst/makefile.nimf
Normal file
180
tools/niminst/makefile.nimf
Normal file
|
|
@ -0,0 +1,180 @@
|
|||
#? stdtmpl(subsChar='?') | standard
|
||||
#proc generateMakefile(c: ConfigData): string =
|
||||
# result = "# Generated from niminst\n" &
|
||||
# "# Template is in tools/niminst/makefile.nimf\n" &
|
||||
# "# To regenerate run ``niminst csource`` or ``koch csource``\n"
|
||||
|
||||
CC ??= gcc
|
||||
LD ??= gcc
|
||||
CFLAGS += -Ic_code ?{c.ccompiler.flags}
|
||||
LDFLAGS += ?{c.linker.flags}
|
||||
binDir = ?{firstBinPath(c).toUnix}
|
||||
|
||||
koch := $(shell sh -c 'test -s ../koch.nim && echo "yes"')
|
||||
ifeq ($(koch),yes)
|
||||
binDir = ../bin
|
||||
endif
|
||||
|
||||
ucpu := $(shell sh -c 'uname -m | tr "[:upper:]" "[:lower:]"')
|
||||
uos := $(shell sh -c 'uname | tr "[:upper:]" "[:lower:]"')
|
||||
|
||||
ifeq ($(uos),linux)
|
||||
myos = linux
|
||||
LDFLAGS += -ldl -lm
|
||||
endif
|
||||
ifeq ($(uos),dragonfly)
|
||||
myos = freebsd
|
||||
LDFLAGS += -lm
|
||||
endif
|
||||
ifeq ($(uos),freebsd)
|
||||
myos= freebsd
|
||||
CC = clang
|
||||
LD = clang
|
||||
LDFLAGS += -lm
|
||||
endif
|
||||
ifeq ($(uos),openbsd)
|
||||
myos = openbsd
|
||||
LDFLAGS += -lm
|
||||
endif
|
||||
ifeq ($(uos),netbsd)
|
||||
myos = netbsd
|
||||
LDFLAGS += -lm
|
||||
endif
|
||||
ifeq ($(uos),darwin)
|
||||
myos = macosx
|
||||
CC = clang
|
||||
LD = clang
|
||||
LDFLAGS += -ldl -lm
|
||||
ifeq ($(HOSTTYPE),x86_64)
|
||||
ucpu = amd64
|
||||
endif
|
||||
endif
|
||||
ifeq ($(uos),aix)
|
||||
myos = aix
|
||||
LDFLAGS += -dl -lm
|
||||
endif
|
||||
ifeq ($(uos),solaris)
|
||||
myos = solaris
|
||||
LDFLAGS += -ldl -lm -lsocket -lnsl
|
||||
endif
|
||||
ifeq ($(uos),sun)
|
||||
myos = solaris
|
||||
LDFLAGS += -ldl -lm -lsocket -lnsl
|
||||
endif
|
||||
ifeq ($(uos),haiku)
|
||||
myos = haiku
|
||||
endif
|
||||
ifndef myos
|
||||
$(error unknown operating system: $(uos))
|
||||
endif
|
||||
|
||||
ifeq ($(ucpu),i386)
|
||||
mycpu = i386
|
||||
endif
|
||||
ifeq ($(ucpu),i486)
|
||||
mycpu = i386
|
||||
endif
|
||||
ifeq ($(ucpu),i586)
|
||||
mycpu = i386
|
||||
endif
|
||||
ifeq ($(ucpu),i686)
|
||||
mycpu = i386
|
||||
endif
|
||||
ifeq ($(ucpu),bepc)
|
||||
mycpu = i386
|
||||
endif
|
||||
ifeq ($(ucpu),i86pc)
|
||||
mycpu = i386
|
||||
endif
|
||||
ifeq ($(ucpu),amd64)
|
||||
mycpu = amd64
|
||||
endif
|
||||
ifeq ($(ucpu),x86-64)
|
||||
mycpu = amd64
|
||||
endif
|
||||
ifeq ($(ucpu),x86_64)
|
||||
mycpu = amd64
|
||||
endif
|
||||
ifeq ($(ucpu),sparc)
|
||||
mycpu = sparc
|
||||
endif
|
||||
ifeq ($(ucpu),sun)
|
||||
mycpu = sparc
|
||||
endif
|
||||
ifeq ($(ucpu),ppc64le)
|
||||
mycpu = powerpc64el
|
||||
endif
|
||||
ifeq ($(ucpu),ppc64)
|
||||
mycpu = powerpc64
|
||||
ifeq ($(myos),linux)
|
||||
CFLAGS += -m64
|
||||
LDFLAGS += -m64
|
||||
endif
|
||||
endif
|
||||
ifeq ($(ucpu),powerpc)
|
||||
mycpu = powerpc
|
||||
endif
|
||||
ifeq ($(ucpu),ppc)
|
||||
mycpu = ppc
|
||||
endif
|
||||
ifneq (,$(filter $(ucpu), mips mips64))
|
||||
mycpu = $(shell /bin/sh -c '"$(CC)" -dumpmachine | sed "s/-.*//"')
|
||||
ifeq (,$(filter $(mycpu), mips mipsel mips64 mips64el))
|
||||
$(error unknown MIPS target: $(mycpu))
|
||||
endif
|
||||
endif
|
||||
ifeq ($(ucpu),arm)
|
||||
mycpu = arm
|
||||
endif
|
||||
ifeq ($(ucpu),armeb)
|
||||
mycpu = arm
|
||||
endif
|
||||
ifeq ($(ucpu),armel)
|
||||
mycpu = arm
|
||||
endif
|
||||
ifeq ($(ucpu),armv6l)
|
||||
mycpu = arm
|
||||
endif
|
||||
ifeq ($(ucpu),armv7l)
|
||||
mycpu = arm
|
||||
endif
|
||||
ifeq ($(ucpu),armv7hl)
|
||||
mycpu = arm
|
||||
endif
|
||||
ifeq ($(ucpu),aarch64)
|
||||
mycpu = arm64
|
||||
endif
|
||||
ifeq ($(ucpu),riscv64)
|
||||
mycpu = riscv64
|
||||
endif
|
||||
ifndef mycpu
|
||||
$(error unknown processor: $(ucpu))
|
||||
endif
|
||||
|
||||
# for osA in 1..c.oses.len:
|
||||
ifeq ($(myos),?{c.oses[osA-1]})
|
||||
# for cpuA in 1..c.cpus.len:
|
||||
ifeq ($(mycpu),?{c.cpus[cpuA-1]})
|
||||
# var oFiles = ""
|
||||
# for ff in c.cfiles[osA][cpuA].items:
|
||||
# oFiles.add(" " & changeFileExt(ff.toUnix, "o"))
|
||||
# end for
|
||||
oFiles =?oFiles
|
||||
endif
|
||||
# end for
|
||||
endif
|
||||
# end for
|
||||
|
||||
ifeq ($(strip $(oFiles)),)
|
||||
$(error no C code generated for: [$(myos): $(mycpu)])
|
||||
endif
|
||||
|
||||
?{"$(binDir)/" & toLowerAscii(c.name)}: $(oFiles)
|
||||
@mkdir -p $(binDir)
|
||||
$(LD) -o $@ $^ $(LDFLAGS)
|
||||
@echo "SUCCESS"
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
clean:
|
||||
rm -f $(oFiles) ?{"$(binDir)/" & toLowerAscii(c.name)}
|
||||
Loading…
Add table
Add a link
Reference in a new issue