Skip to content

Commit

Permalink
Added awk, ruby 1.8, crystal, C (static compiled/linked with MUSL), c…
Browse files Browse the repository at this point in the history
…rystal (with musl), dart, nodejs, and quickjs. Added some notes and results from my intel i7 laptop.
  • Loading branch information
Greg Orlowski committed Nov 28, 2020
1 parent 3f503ad commit 9033d59
Show file tree
Hide file tree
Showing 8 changed files with 364 additions and 18 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
C
C_MUSL
Crystal
Crystal_MUSL
C++
Cython
Cython3
D
Dart
Go
Go_GCC
Haskell
Expand All @@ -18,3 +22,8 @@ Rust
*.exe
*.hi
*.o
*.swp
hello-world.rb18
hello-world.mrb
hello-world.qjs
hello-world.djs
84 changes: 78 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
COMPILED_LANGS := C C++ Cython Cython3 D Go Go_GCC Haskell OCaml Pascal Rust
INTERPRETED_LANGS := Bash CShell Lua Perl PHP Python-S Python Python3-S Python3 PyPy Ruby Shell ZShell
# EXTRA_COMPILED_LANGS and EXTRA_INTERPRETED_LANGS are not in debian or ubuntu (as of 2020).
# Include them only if they already exist on this system:
EXTRA_COMPILED_LANGS := Crystal Crystal_MUSL Dart
EXTRA_INTERPRETED_LANGS := QJS Ruby18

lc = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1))))))))))))))))))))))))))

OTHER_COMPILED_LANGS := $(foreach lang,$(EXTRA_COMPILED_LANGS),\
$(if $(shell which $(call lc,$(lang))),$(lang),))

OTHER_INTERPRETED_LANGS := $(foreach lang,$(EXTRA_INTERPRETED_LANGS),\
$(if $(shell which $(call lc,$(lang))),$(lang),))

COMPILED_LANGS := C C_MUSL C++ Cython Cython3 D Go Go_GCC Haskell OCaml Pascal Rust $(OTHER_COMPILED_LANGS)
INTERPRETED_LANGS := Awk Bash CShell DuktapeJS Lua MRuby NodeJS Perl PHP Python-S Python Python3-S Python3 PyPy Ruby Shell ZShell $(OTHER_INTERPRETED_LANGS)

GENERATED_SCRIPT_LANGUAGES := qjs djs rb18 mrb
GENERATED_INTERPRETED_SCRIPTS := $(foreach script,$(GENERATED_SCRIPT_LANGUAGES), hello-world.$(script))

Bash_EXT := bash
CShell_EXT := csh
Expand All @@ -12,16 +28,24 @@ Python3_EXT := py3
Python3-S_EXT := py3-S
PyPy_EXT := pypy
Ruby_EXT := rb
Ruby18_EXT := rb18
MRuby_EXT := mrb
Shell_EXT := sh
ZShell_EXT := zsh
Awk_EXT := awk
NodeJS_EXT := js
QJS_EXT := qjs
DuktapeJS_EXT := djs

C_COMPILER := gcc
C_MUSL_COMPILER := musl-gcc
C++_COMPILER := g++
Csharp_COMPILER := mcs
Cython_COMPILER := cython
Cython3_COMPILER := cython3
MONO := $(shell which mono)
D_COMPILER := gdc
Dart_COMPILER := dart2native
Go_COMPILER := go
Go_GCC_COMPILER := gccgo
Haskell_COMPILER := ghc
Expand All @@ -30,18 +54,31 @@ Java_COMPILER := javac
Pascal_COMPILER := fpc
Rust_COMPILER := rustc
Scala_COMPILER := scalac
Crystal_COMPILER := crystal
Crystal_MUSL_COMPILER := crystal_musl

MACHINE_ARCH := $(shell uname -m)
MUSL_VERSION := $(shell /lib/ld-musl-$(MACHINE_ARCH).so.1 2>&1 |grep '^Version' |cut -d" " -f2)

Awk_VERSION = ($(shell awk --version | head -n 1 | cut -f1 -d","))
Bash_VERSION = $(shell bash --version | head -n 1 | cut -d " " -f 4 | sed 's/-release$$//')
C_VERSION = $(shell $(C_COMPILER) --version | head -n 1 | cut -d " " -f 4)
C_MUSL_VERSION = $(shell $(C_COMPILER) --version | head -n 1 | cut -d " " -f 4) / musl $(MUSL_VERSION)
C++_VERSION = $(shell $(C++_COMPILER) --version | head -n 1 | cut -d " " -f 4)
Csharp_VERSION = $(shell $(Csharp_COMPILER) --version | head -n 1 | cut -d " " -f 5)
CShell_VERSION = $(shell dpkg-query --showformat='$${Version}' --show csh | sed 's/-[a-z0-9~.]\+$$//')
Crystal_VERSION = $(shell $(Crystal_COMPILER) --version |head -n 1 | cut -d " " -f 2)
Crystal_MUSL_VERSION = $(shell $(Crystal_MUSL_COMPILER) --version |head -n 1 | cut -d " " -f 2) / musl $(MUSL_VERSION)
Cython_VERSION = $(shell $(Cython_COMPILER) --version 2>&1 | head -n 1 | cut -d " " -f 3)
Cython3_VERSION = $(shell $(Cython3_COMPILER) --version 2>&1 | head -n 1 | cut -d " " -f 3)
D_VERSION = $(shell $(D_COMPILER) --version | head -n 1 | cut -d " " -f 4)
Dart_VERSION = $(shell dart --version 2>&1 |sed -n 's/.*\([0-9]\+[.][0-9]\+[.][0-9]\+\).*/\1/p')
Go_VERSION = $(shell $(Go_COMPILER) version | head -n 1 | cut -d " " -f 3)
Go_GCC_VERSION = $(shell $(Go_GCC_COMPILER) --version | head -n 1 | cut -d " " -f 4)
Haskell_VERSION = $(shell $(Haskell_COMPILER) --version | head -n 1 | cut -d " " -f 8)
NodeJS_VERSION = $(shell /usr/bin/nodejs --version)
QJS_VERSION = (quickjs $(shell qjs -h |head -n1 |cut -d" " -f3))
DuktapeJS_VERSION = (duktape js $(shell duk -e 'var maj=Math.floor(Duktape.version / 10000), min=Math.floor(Duktape.version % 10000 / 100); pat=(Duktape.version % 100); console.log([maj,min,pat].join("."))'))
Lua_VERSION = $(shell lua -v 2>&1 | head -n 1 | cut -d " " -f 2)
Java_VERSION = $(shell $(Java_COMPILER) -version 2>&1 | head -n 1 | cut -d " " -f 2)
OCaml_VERSION = $(shell $(OCaml_COMPILER) -version)
Expand All @@ -53,7 +90,9 @@ Python-S_VERSION = $(Python_VERSION)
Python3_VERSION = $(shell python3 --version 2>&1 | head -n 1 | cut -d " " -f 2)
Python3-S_VERSION = $(Python3_VERSION)
PyPy_VERSION = $(shell pypy --version 2>&1 | tail -n 1 | cut -d " " -f 2)
Ruby_VERSION = $(shell ruby --version | head -n 1 | cut -d " " -f 2)
Ruby_VERSION = $(shell /usr/bin/ruby --version | head -n 1 | cut -d " " -f 2)
Ruby18_VERSION = $(shell ruby18 --version | head -n 1 | cut -d " " -f 2)
MRuby_VERSION = $(shell /usr/bin/mruby --version | head -n 1 | cut -d " " -f 2)
Rust_VERSION = $(shell $(Rust_COMPILER) --version | head -n 1 | cut -d " " -f 2)
Scala_VERSION = $(shell $(Scala_COMPILER) -version 2>&1 | head -n 1 | cut -d " " -f 4)
Shell_VERSION = $(shell printf "(%s %s)" $(shell readlink /bin/sh) $(shell dpkg-query --showformat='$${Version}' --show $(shell readlink /bin/sh) | sed 's/-.*$$//'))
Expand Down Expand Up @@ -86,6 +125,7 @@ PACKAGES := \
cython \
cython3 \
default-jdk \
duktape \
fp-compiler \
gcc \
gccgo \
Expand All @@ -94,6 +134,8 @@ PACKAGES := \
golang \
lua5.2 \
mono-mcs \
musl \
nodejs \
ocaml-nox \
perl-base \
php-cli \
Expand All @@ -106,12 +148,18 @@ PACKAGES := \
zsh \
$(NULL)

define generate_script_from_template
@echo "#!$(shell which $(3))" > $(2)
@sed -n '2,$$p' $(1) >> $(2)
@chmod +x $(2)
endef

run_lang = \
@printf "%-25s " "$(1):" $(\n)\
@printf "%-55s " "$(1):" $(\n)\
@$(TIME) $(RUN) $(2) 2>&1 | tr -d '\n'$(\n)\
@printf " ms\n"

all: $(COMPILED_LANGS) hello-world.exe HelloWorld.class HelloWorldScala.class run
all: $(COMPILED_LANGS) $(GENERATED_INTERPRETED_SCRIPTS) hello-world.exe HelloWorld.class HelloWorldScala.class run
@echo 'Run on: $(shell sed -n "s/^model name\t: //p" /proc/cpuinfo | head -n 1) | $(shell . /etc/os-release; echo $$PRETTY_NAME) | $(shell date +%Y-%m-%d)'
$(foreach lang,$(COMPILED_LANGS),$(call run_lang,$(lang) ($($(lang)_COMPILER) $($(lang)_VERSION)),./$(lang))$(\n))
$(foreach lang,$(INTERPRETED_LANGS),$(call run_lang,$(lang) $($(lang)_VERSION),./hello-world.$($(lang)_EXT))$(\n))
Expand All @@ -125,14 +173,17 @@ install:
C: hello-world.c
$(C_COMPILER) $(CFLAGS) -o $@ $^

C_MUSL: hello-world.c
$(C_MUSL_COMPILER) -static $(CFLAGS) -o $@ $^

run: run.c
$(C_COMPILER) $(CFLAGS) -o $@ $^

hello_cython.c: hello.pyx
$(Cython_COMPILER) --embed -o $@ $^

Cython: hello_cython.c
$(C_COMPILER) $(CFLAGS) -o $@ $^ $(shell pkg-config --cflags --libs python-$(shell echo $(Python_VERSION) | cut -d. -f1-2))
$(C_COMPILER) $(CFLAGS) -fno-strict-aliasing -o $@ $^ $(shell pkg-config --cflags --libs python-$(shell echo $(Python_VERSION) | cut -d. -f1-2))

hello_cython3.c: hello.pyx3
$(Cython3_COMPILER) --embed -o $@ $^
Expand All @@ -146,6 +197,27 @@ C++: hello-world.cpp
D: $(wildcard *.d)
$(D_COMPILER) $(DFLAGS) -o $@ $^

hello-world.mrb: hello-world.rb
$(call generate_script_from_template,$^,$@,mruby)

hello-world.rb18: hello-world.rb
$(call generate_script_from_template,$^,$@,ruby18)

hello-world.qjs: hello-world.js
$(call generate_script_from_template,$^,$@,qjs)

hello-world.djs: hello-world.js
$(call generate_script_from_template,$^,$@,duk)

Crystal: hello-world.cr
$(Crystal_COMPILER) build --release -Dno_gc -o $@ $^

Crystal_MUSL: hello-world.cr
$(Crystal_MUSL_COMPILER) build --release -Dno_gc -o $@ $^

Dart: hello-world.dart
$(Dart_COMPILER) -o $@ $^

Go: hello-world.go
$(Go_COMPILER) build -o $@ $^

Expand Down
Loading

0 comments on commit 9033d59

Please sign in to comment.