mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 09:24:36 +00:00
169 lines
3.0 KiB
Cheetah
169 lines
3.0 KiB
Cheetah
#? stdtmpl(subsChar='?') | standard
|
|
#proc generateMakefile(c: ConfigData): string =
|
|
# result = "# Generated from niminst\n" &
|
|
# "# Template is in tools/niminst/makefile.tmpl\n" &
|
|
# "# To regenerate run ``niminst csource`` or ``koch csource``\n"
|
|
|
|
CC = gcc
|
|
LINKER = gcc
|
|
COMP_FLAGS = $(CPPFLAGS) $(CFLAGS) ?{c.ccompiler.flags}
|
|
LINK_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
|
|
LINK_FLAGS += -ldl -lm
|
|
endif
|
|
ifeq ($(uos),dragonfly)
|
|
myos = freebsd
|
|
LINK_FLAGS += -lm
|
|
endif
|
|
ifeq ($(uos),freebsd)
|
|
myos= freebsd
|
|
CC = clang
|
|
LINKER = clang
|
|
LINK_FLAGS += -lm
|
|
endif
|
|
ifeq ($(uos),openbsd)
|
|
myos = openbsd
|
|
LINK_FLAGS += -lm
|
|
endif
|
|
ifeq ($(uos),netbsd)
|
|
myos = netbsd
|
|
LINK_FLAGS += -lm
|
|
endif
|
|
ifeq ($(uos),darwin)
|
|
myos = macosx
|
|
CC = clang
|
|
LINKER = clang
|
|
LINK_FLAGS += -ldl -lm
|
|
ifeq ($HOSTTYPE,x86_64)
|
|
ucpu = amd64
|
|
endif
|
|
endif
|
|
ifeq ($(uos),aix)
|
|
myos = aix
|
|
LINK_FLAGS += -dl -lm
|
|
endif
|
|
ifeq ($(uos),solaris)
|
|
myos = solaris
|
|
LINK_FLAGS += -ldl -lm -lsocket -lnsl
|
|
endif
|
|
ifeq ($(uos),sun)
|
|
myos = solaris
|
|
LINK_FLAGS += -ldl -lm -lsocket -lnsl
|
|
endif
|
|
ifeq ($(uos),haiku)
|
|
myos = haiku
|
|
endif
|
|
ifndef uos
|
|
@echo "Error: unknown operating system: $(uos)"
|
|
@exit 1
|
|
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),ppc64)
|
|
mycpu = powerpc64
|
|
ifeq ($(myos),linux)
|
|
COMP_FLAGS += -m64
|
|
LINK_FLAGS += -m64
|
|
endif
|
|
endif
|
|
ifeq ($(ucpu),powerpc)
|
|
mycpu = powerpc
|
|
endif
|
|
ifeq ($(ucpu),ppc)
|
|
mycpu = ppc
|
|
endif
|
|
ifeq ($(ucpu),mips)
|
|
mycpu = mips
|
|
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
|
|
ifndef ucpu
|
|
@echo "Error: unknown processor : $(ucpu)"
|
|
@exit 1
|
|
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)),)
|
|
@echo "Error: no C code generated for: [$(myos): $(mycpu)]"
|
|
@exit 1
|
|
endif
|
|
|
|
%.o: %.c
|
|
$(CC) $(COMP_FLAGS) -Ic_code -c $< -o $@
|
|
|
|
?{"$(binDir)/" & toLowerAscii(c.name)}: $(oFiles)
|
|
@mkdir -p $(binDir)
|
|
$(LINKER) -o $@ $^ $(LINK_FLAGS)
|
|
@echo "SUCCESS"
|
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
|
rm -f $(oFiles) ?{"$(binDir)/" & toLowerAscii(c.name)}
|