diff --git a/makefile b/makefile index 9d2748d9..fd8f342b 100644 --- a/makefile +++ b/makefile @@ -1,34 +1,115 @@ -MAKEFLAGS=--no-print-directory -J=-j4 +SHELL = /usr/bin/env bash +MAKEFLAGS+= --no-print-directory o3: - @$(MAKE) $(J) -C obj/o3 o3 -o3n: - @$(MAKE) $(J) -C obj/o3n o3n + @${MAKE} t=o3 b o3g: - @$(MAKE) $(J) -C obj/o3g o3g -debug: - @$(MAKE) -C obj/debug debug + @${MAKE} t=o3g b +o3n: + @${MAKE} t=o3n b rtperf: - @$(MAKE) $(J) -C obj/rtperf rtperf -heapverify: - @$(MAKE) $(J) -C obj/heapverify heapverify + @${MAKE} t=rtperf b rtverify: - @$(MAKE) $(J) -C obj/rtverify rtverify + @${MAKE} t=rtverify b +debug: + @${MAKE} t=debug b +debug1: + @${MAKE} t=debug1 b +heapverify: + @${MAKE} t=heapverify b +c: # custom + @${MAKE} t=${t} FLAGS.${t}="${f}" b -o3-clean: - @$(MAKE) -C obj/o3 clean -o3n-clean: - @$(MAKE) -C obj/o3n clean -o3g-clean: - @$(MAKE) -C obj/o3g clean -debug-clean: - @$(MAKE) -C obj/debug clean -rtperf-clean: - @$(MAKE) -C obj/rtperf clean -heapverify-clean: - @$(MAKE) -C obj/heapverify clean -rtverify-clean: - @$(MAKE) -C obj/rtverify clean +b: gen -clean: o3-clean o3n-clean o3g-clean debug-clean rtperf-clean heapverify-clean rtverify-clean + + + +# compiler setup +CC = clang +ifeq ($(CC),gcc) +CCFLAGS = -Wno-parentheses +else +CCFLAGS = -Wno-microsoft-anon-tag +endif +CMD = $(CC) -std=gnu11 -Wall -Wno-unused-function -fms-extensions ${CCFLAGS} $(FLAGS) -fPIE -MMD -MP -MF + +# `if` to allow `make clean` alone to clean everything, but `make t=debug clean` to just clean obj/debug +ifeq ($(MAKECMDGOALS),clean) +t = * +else ifeq ($(t),) +t = o3 +endif + +ifneq (${t},debug1) +# don't make makefile cry about something idk +ifeq (${MAKECMDGOALS},b) + MAKEFLAGS += -j4 +endif +endif + + + + +# per-type flags +FLAGS.o3 := -O3 +FLAGS.o3n := -O3 -march=native +FLAGS.o3g := -O3 -g +FLAGS.debug := -g -DDEBUG +FLAGS.debug1 := -g -DDEBUG +FLAGS.rtperf := -O3 -DRT_PERF +FLAGS.heapverify := -DDEBUG -g -DHEAP_VERIFY +FLAGS.rtverify := -DDEBUG -O3 -DRT_VERIFY +FLAGS = ${FLAGS.${t}} +bd = obj/${t} + + + + +gen: builtins core base jit utils # build the final binary + @$(CC) -no-pie -o BQN ${bd}/*.o -lm + @echo + +builddir: # create the build directory. makefiles are stupid + @mkdir -p ${bd} + +# build individual object files +core: builddir ${addprefix ${bd}/, i32arr.o c32arr.o f64arr.o harr.o fillarr.o stuff.o derv.o mm.o heap.o} +${bd}/%.o: src/core/%.c + @echo $< | cut -c 5- + @$(CMD) $@.d -o $@ -c $< + +base: builddir ${addprefix ${bd}/, load.o main.o rtwrap.o vm.o ns.o nfns.o} +${bd}/%.o: src/%.c + @echo $< | cut -c 5- + @$(CMD) $@.d -o $@ -c $< + +utils: builddir ${addprefix ${bd}/, utf.o hash.o file.o mut.o} +${bd}/%.o: src/utils/%.c + @echo $< | cut -c 5- + @$(CMD) $@.d -o $@ -c $< + +jit: builddir ${addprefix ${bd}/, nvm.o} +${bd}/%.o: src/jit/%.c + @echo $< | cut -c 5- + @$(CMD) $@.d -o $@ -c $< + +builtins: builddir ${addprefix ${bd}/, arithm.o arithd.o cmp.o sfns.o sort.o md1.o md2.o fns.o sysfn.o internal.o} +${bd}/%.o: src/builtins/%.c + @echo $< | cut -c 5- + @$(CMD) $@.d -o $@ -c $< + + + +src/gen/customRuntime: + @echo "Copying precompiled bytecode from the bytecode branch" + git checkout remotes/origin/bytecode src/gen/{compiler,formatter,runtime0,runtime1,src} + git reset src/gen/{compiler,formatter,runtime0,runtime1,src} +${bd}/load.o: src/gen/customRuntime + +-include $(bd)/*.d + + +clean: + rm -f ${bd}/*.o + rm -f ${bd}/*.d \ No newline at end of file diff --git a/obj/debug/makefile b/obj/debug/makefile deleted file mode 120000 index 26ebd524..00000000 --- a/obj/debug/makefile +++ /dev/null @@ -1 +0,0 @@ -../subMakefile \ No newline at end of file diff --git a/obj/heapverify/makefile b/obj/heapverify/makefile deleted file mode 120000 index 26ebd524..00000000 --- a/obj/heapverify/makefile +++ /dev/null @@ -1 +0,0 @@ -../subMakefile \ No newline at end of file diff --git a/obj/o3/makefile b/obj/o3/makefile deleted file mode 120000 index 26ebd524..00000000 --- a/obj/o3/makefile +++ /dev/null @@ -1 +0,0 @@ -../subMakefile \ No newline at end of file diff --git a/obj/o3g/makefile b/obj/o3g/makefile deleted file mode 120000 index 26ebd524..00000000 --- a/obj/o3g/makefile +++ /dev/null @@ -1 +0,0 @@ -../subMakefile \ No newline at end of file diff --git a/obj/o3n/makefile b/obj/o3n/makefile deleted file mode 120000 index 26ebd524..00000000 --- a/obj/o3n/makefile +++ /dev/null @@ -1 +0,0 @@ -../subMakefile \ No newline at end of file diff --git a/obj/rtperf/makefile b/obj/rtperf/makefile deleted file mode 120000 index 26ebd524..00000000 --- a/obj/rtperf/makefile +++ /dev/null @@ -1 +0,0 @@ -../subMakefile \ No newline at end of file diff --git a/obj/rtverify/makefile b/obj/rtverify/makefile deleted file mode 120000 index 26ebd524..00000000 --- a/obj/rtverify/makefile +++ /dev/null @@ -1 +0,0 @@ -../subMakefile \ No newline at end of file diff --git a/obj/subMakefile b/obj/subMakefile deleted file mode 100644 index e8d849ff..00000000 --- a/obj/subMakefile +++ /dev/null @@ -1,67 +0,0 @@ -SHELL=/usr/bin/env bash -CC=clang -ifeq ($(CC),gcc) -CCFLAGS=-Wno-parentheses -else -CCFLAGS=-Wno-microsoft-anon-tag -endif - -CMD=$(CC) -std=gnu11 -Wall -Wno-unused-function -fms-extensions ${CCFLAGS} $(FLAGS) -fPIE -MMD -MP -MF - -o3: FLAGS=-O3 -o3: gen -o3n: FLAGS=-O3 -march=native -o3n: gen -o3g: FLAGS=-O3 -g -o3g: gen -debug: FLAGS=-g -DDEBUG -debug: gen -rtperf: FLAGS=-O3 -DRT_PERF -rtperf: gen -heapverify: FLAGS=-DDEBUG -g -DHEAP_VERIFY -heapverify: gen -rtverify: FLAGS=-DDEBUG -O3 -DRT_VERIFY -rtverify: gen - -gen: builtins core base jit utils - @$(CC) -no-pie -o BQN *.o -lm - @mv BQN ../../BQN - @echo - -core: i32arr.o c32arr.o f64arr.o harr.o fillarr.o stuff.o derv.o mm.o heap.o -%.o: ../../src/core/%.c - @echo $< | cut -c 11- - @$(CMD) $@.d -c $< - -../../src/gen/customRuntime: - @echo "Copying precompiled bytecode from the bytecode branch" - git checkout remotes/origin/bytecode ../../src/gen/{compiler,formatter,runtime0,runtime1,src} - git reset ../../src/gen/{compiler,formatter,runtime0,runtime1,src} -load.o: ../../src/gen/customRuntime - -base: load.o main.o rtwrap.o vm.o ns.o nfns.o -%.o: ../../src/%.c - @echo $< | cut -c 11- - @$(CMD) $@.d -c $< - -utils: utf.o hash.o file.o mut.o -%.o: ../../src/utils/%.c - @echo $< | cut -c 11- - @$(CMD) $@.d -c $< - -jit: nvm.o -%.o: ../../src/jit/%.c - @echo $< | cut -c 11- - @$(CMD) $@.d -c $< - -builtins: arithm.o arithd.o cmp.o sfns.o sort.o md1.o md2.o fns.o sysfn.o internal.o -%.o: ../../src/builtins/%.c - @echo $< | cut -c 11- - @$(CMD) $@.d -c $< - --include *.d - - -clean: - @rm -f *.o - @rm -f *.d