ox

The Ox programming language, compiler and tools (WIP)
Log | Files | Refs | README | LICENSE

makefile (2031B)


      1 # note: needed both gcc and libgccjit
      2 # macOS: brew install gcc libgccjit
      3 # linux: sudo apt-get install build-essential gcc g++ libgccjit-14-dev
      4 # update the prefix if needed
      5 
      6 # Try Homebrew first (macOS)
      7 BREW := $(shell command -v brew 2>/dev/null)
      8 ifneq ($(BREW),)
      9 	LIBGCCJIT_PREFIX := $(shell brew --prefix libgccjit 2>/dev/null)
     10 endif
     11 
     12 UNAME_S := $(shell uname -s)
     13 ifeq ($(UNAME_S),Darwin)
     14 	LIB := -I${LIBGCCJIT_PREFIX}/include -L${LIBGCCJIT_PREFIX}/lib/gcc/current -lgccjit
     15 else
     16 	LIBGCCJIT_PREFIX := $(shell dirname $(shell gcc -print-file-name=libgccjit.so))
     17 	LIB := -I${LIBGCCJIT_PREFIX}/include -L${LIBGCCJIT_PREFIX} -lgccjit
     18 endif
     19 
     20 SRC = */*/*.c */*.c
     21 BIN = oxc
     22 STD = -std=c99
     23 
     24 debug:
     25 	cc ${STD} -g -Wall -Wextra -o ${BIN} ${SRC} ${LIB}
     26 
     27 default:
     28 	cc ${STD} -g -Wall -Wextra -Wno-unused-parameter -Wno-unused-function -fsanitize=address,undefined -o ${BIN} ${SRC} ${LIB} # -Wpedantic -Wshadow -Wconversion
     29 
     30 fast:
     31 	cc ${STD} -O3 -ffast-math -DNDEBUG -march=native -mtune=native -flto -fomit-frame-pointer -fno-plt -fno-semantic-interposition -pipe \
     32 		-fno-trapping-math -Wl,-O3 ${LDFLAGS} -o ${BIN} ${SRC} ${LIB}
     33 	strip ${BIN}
     34 
     35 clean:
     36 	rm -rf ${BIN} ${BIN}.* err.log
     37 
     38 release: clean
     39 	cc ${STD} -O02 -Wall -Wshadow -Wextra -Wpedantic -Werror -o ${BIN} ${SRC} ${LIB}
     40 
     41 check: clean
     42 	cc ${STD} -g -Wall -Wextra -fsanitize=address -fsanitize=undefined -o ${BIN} ${SRC} ${LIB}
     43 
     44 # test: clean fast
     45 # 	+@printf '%s\0' ex*.ox \
     46 # 	| xargs -0 -P100 -n1 sh -c 'printf "%s\n" "$$1" 1>&2; exec ./$(BIN) --quiet "$$1" >/dev/null' sh
     47 
     48 JOBS ?= $(shell nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 16)
     49 
     50 test: clean fast
     51 	+@find . -maxdepth 3 -name 'ex*.ox' -print0 \
     52 	| xargs -0 -r -P$(JOBS) -n1 sh -c 'printf "%s\n" "$$1" 1>&2; exec ./$(BIN) --quiet "$$1" >/dev/null' sh
     53 
     54 test-slow: clean fast
     55 	+@find . -maxdepth 3 -name 'ex*.ox' -print0 \
     56 	| xargs -0 -r -P1 -n1 sh -c 'printf "%s\n" "$$1" 1>&2; exec ./$(BIN) --quiet "$$1" >/dev/null' sh
     57 
     58 test-hmap: clean default
     59 	MallocNanoZone=0 ./oxc --test-hmap
     60 
     61 again: clean default