From 36b3a04b9a2a9d52a1db6e28697e7ec3b1118eb1 Mon Sep 17 00:00:00 2001 From: Albert Cervin Date: Tue, 14 May 2024 22:10:34 +0200 Subject: Improve configure with docs and help flag Also make targets dependent on config.mk so that the program is rebuilt when config.mk changes. --- Makefile | 6 +++--- README.md | 10 ++++++++-- configure | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 7d84085..942cbad 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,6 @@ default: dged .PHONY: default clean check run debug debug-tests install format .OBJDIR: ./build -SYNTAX_ENABLE ?= true build: mkdir -p build @@ -14,6 +13,7 @@ build: .endif .include "config.mk" +SYNTAX_ENABLE ?= true HEADERS = src/dged/settings.h src/dged/minibuffer.h src/dged/keyboard.h src/dged/binding.h \ src/dged/buffers.h src/dged/text.h src/dged/display.h src/dged/hashmap.h src/dged/path.h \ @@ -97,12 +97,12 @@ FILES = $(DEPS) \ libdged.a # dependency generation -.c.d: +.c.d: config.mk @mkdir -p $(@D) $(CC) -MM $(CFLAGS) -MT $*.o $< > $@ @sed -i 's,\($*\)\.o[ :]*,\1.o $@ : ,g' $@ -.c.o: +.c.o: config.mk @mkdir -p $(@D) $(CC) $(CFLAGS) -c $< -o $@ diff --git a/README.md b/README.md index 0f5a48e..5b44750 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Contributions are of course welcome. Please open a PR on the Github repository. ## Development Setup -The editor is built using BSD make (specifically bmake) so that needs to be installed. +The editor is built using BSD make so that needs to be installed (preinstalled on BSD and bmake on Linux). To enable syntax highlighting (default) you will also need the tree-sitter library installed. @@ -55,7 +55,13 @@ or $ mkdir -p obj ``` -Then call make +Then call configure (see available options by passing `--help` to `./configure`) + +``` +$ ./configure +``` + +followed by (you guessed it!) make ``` $ bmake diff --git a/configure b/configure index 8cce0d0..63aa2f8 100755 --- a/configure +++ b/configure @@ -1,5 +1,49 @@ #!/bin/sh +_usage="./configure -- configure the DGED build. + +Options: + --[enable|disable]-syntax Enable or disable syntax highlighting support. + --enable-asan Build DGED with address sanitizer enabled. + -h/--help Show this help text. +" + +enable_syntax=1 +enable_asan=0 +while [ "$#" -gt 0 ]; do + case $1 in + --disable-syntax) + enable_syntax=0 + shift 1 + ;; + + --enable-syntax) + enable_syntax=1 + shift 1 + ;; + + --enable-asan) + enable_asan=1 + shift 1 + ;; + + -h|--help) + echo "$_usage" + exit + ;; + + -*) + echo "Unknown flag \"$1\". Usage:" + echo "$_usage" + exit 1 + ;; + *) + shift 1 + ;; + esac +done + + echo "/* Generated by configure */" > src/config.h echo "#ifndef _CONFIG_H" >> src/config.h echo "#define _CONFIG_H" >> src/config.h @@ -19,6 +63,20 @@ else echo "none." fi +if [ "$enable_syntax" -ne 0 ]; then + echo "enabling syntax highlighting" + echo "SYNTAX_ENABLE = true" >> config.mk +else + echo "disabling syntax highlighting" + echo "SYNTAX_ENABLE = false" >> config.mk +fi + +if [ "$enable_asan" -ne 0 ]; then + echo "enabling address sanitizer" + echo "ASAN = true" >> config.mk +fi + + echo "#endif" >> src/config.h echo "wrote src/config.h" echo "wrote config.mk" -- cgit v1.2.3