about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--Makefile125
-rw-r--r--README.md10
-rw-r--r--doc/build.md48
3 files changed, 112 insertions, 71 deletions
diff --git a/Makefile b/Makefile
index 9deee797..8f6f0089 100644
--- a/Makefile
+++ b/Makefile
@@ -1,93 +1,88 @@
-NIMC = nim c
-OBJDIR = .obj
-FLAGS = -o:cha -d:curlLibName:$(CURLLIBNAME)
-FILES = src/main.nim
-prefix = /usr/local
-manprefix = /usr/local/share/man
-manprefix1 = $(manprefix)/man1
-manprefix5 = $(manprefix)/man5
+NIMC ?= nim c
+OBJDIR ?= .obj
+OUTDIR ?= target
+PREFIX ?= /usr/local
+MANPREFIX ?= $(PREFIX)/share/man
+MANPREFIX1 ?= $(MANPREFIX)/man1
+MANPREFIX5 ?= $(MANPREFIX)/man5
+TARGET ?= release
+
+ifeq ($(TARGET),debug)
+FLAGS += --debugger:native
+else ifeq ($(TARGET),release)
+FLAGS += -d:strip, -d:lto
+else ifeq ($(TARGET),release0)
+FLAGS += -d:release --stacktrace:on
+else ifeq ($(TARGET),release1)
+FLAGS += -d:release --debugger:native
+endif
+
+$(OUTDIR)/$(TARGET)/bin/cha: lib/libquickjs.a src/*.nim src/**/*.nim res/* res/**/*
+	@mkdir -p "$(OUTDIR)/$(TARGET)/bin"
+	$(NIMC) -d:curlLibName:$(CURLLIBNAME) -o:"$(OUTDIR)/$(TARGET)/bin/cha" \
+		--nimcache:"$(OBJDIR)/$(TARGET)" -d:$(TARGET) src/main.nim
+	ln -sf "$(OUTDIR)/$(TARGET)/bin/cha" cha
+
+CFLAGS = -g -Wall -O2 -DCONFIG_VERSION=\"$(shell cat lib/quickjs/VERSION)\" \
+	-DCONFIG_BIGNUM=1
 QJSOBJ = $(OBJDIR)/quickjs
-CFLAGS = -g -Wall -O2 -DCONFIG_VERSION=\"$(shell cat lib/quickjs/VERSION)\" -DCONFIG_BIGNUM=1
-
-.PHONY: debug
-debug: lib/libquickjs.a $(OBJDIR)/debug/
-	$(NIMC) $(FLAGS) --nimcache:$(OBJDIR)/debug --debugger:native -d:debug $(FILES)
-
-.PHONY: debug0
-debug0: lib/libquickjs.a $(OBJDIR)/debug0/
-	$(NIMC) $(FLAGS) --nimcache:$(OBJDIR)/debug0 -d:debug --stacktrace:off --linetrace:off --opt:speed $(FILES)
-
-.PHONY: release
-release: lib/libquickjs.a $(OBJDIR)/release/
-	$(NIMC) $(FLAGS) --nimcache:$(OBJDIR)/release -d:release -d:strip -d:lto $(FILES)
-
-.PHONY: release0
-release0: lib/libquickjs.a $(OBJDIR)/release0/
-	$(NIMC) $(FLAGS) --nimcache:$(OBJDIR)/release0 -d:release --stacktrace:on $(FILES)
-
-.PHONY: release1
-release1: lib/libquickjs.a $(OBJDIR)/release1/
-	$(NIMC) $(FLAGS) --nimcache:$(OBJDIR)/release1 --debugger:native -d:release $(FILES)
-
-.PHONY: profile
-profile: lib/libquickjs.a $(OBJDIR)/profile/
-	$(NIMC) $(FLAGS) --nimcache:$(OBJDIR)/profile --profiler:on --stacktrace:on -d:profile $(FILES)
-
-.PHONY: profile0
-profile0: lib/libquickjs.a $(OBJDIR)/profile0/
-	$(NIMC) $(FLAGS) --nimcache:$(OBJDIR)/profile0 -d:release --passC:"-pg" --passL:"-pg" $(FILES)
-
-$(OBJDIR)/%/:
-	mkdir -p $@
-
-$(QJSOBJ)/%.o: lib/quickjs/%.c | $(QJSOBJ)/
+$(QJSOBJ)/%.o: lib/quickjs/%.c
+	@mkdir -p "$(QJSOBJ)"
 	$(CC) $(CFLAGS) -c -o $@ $<
 
 lib/libquickjs.a: $(QJSOBJ)/quickjs.o $(QJSOBJ)/libregexp.o \
 		$(QJSOBJ)/libunicode.o $(QJSOBJ)/cutils.o \
-		$(QJSOBJ)/libbf.o | $(QJSOBJ)/
+		$(QJSOBJ)/libbf.o
+	@mkdir -p "$(QJSOBJ)"
 	$(AR) rcs $@ $^
 
-.PHONY: clean
-clean:
-	rm -f cha
-	rm -rf $(OBJDIR)
-	rm -f lib/libquickjs.a
-
-$(OBJDIR)/man/cha-%.md: doc/%.md | $(OBJDIR)/man/
+$(OBJDIR)/man/cha-%.md: doc/%.md
+	@mkdir -p "$(OBJDIR)/man"
 	./md2manpreproc $< > $@
 
-$(OBJDIR)/man/cha-%.5: $(OBJDIR)/man/cha-%.md | $(OBJDIR)/man/
+$(OBJDIR)/man/cha-%.5: $(OBJDIR)/man/cha-%.md
 	pandoc --standalone --to man $< -o $@
 
-$(OBJDIR)/man/cha.1: doc/cha.1 | $(OBJDIR)/man/
+$(OBJDIR)/man/cha.1: doc/cha.1
+	@mkdir -p "$(OBJDIR)/man"
 	cp doc/cha.1 "$(OBJDIR)/man/cha.1"
 
+.PHONY: clean
+clean:
+	rm -rf "$(OUTDIR)"
+	rm -rf "$(OBJDIR)"
+	rm -f lib/libquickjs.a
+
 .PHONY: manpage
-manpage:  $(OBJDIR)/man/cha-config.5 $(OBJDIR)/man/cha-mailcap.5 \
+manpage: $(OBJDIR)/man/cha-config.5 $(OBJDIR)/man/cha-mailcap.5 \
 	$(OBJDIR)/man/cha-mime.types.5 $(OBJDIR)/man/cha-localcgi.5 \
 	$(OBJDIR)/man/cha-urimethodmap.5 \
 	$(OBJDIR)/man/cha.1
 
 .PHONY: install
 install:
-	mkdir -p "$(DESTDIR)$(prefix)/bin"
-	install -m755 cha "$(DESTDIR)$(prefix)/bin"
+	mkdir -p "$(DESTDIR)$(PREFIX)/bin"
+	install -m755 "$(OUTDIR)/$(TARGET)/bin/cha" "$(DESTDIR)$(PREFIX)/bin"
 	if test -d "$(OBJDIR)/man"; then \
-	mkdir -p "$(DESTDIR)$(manprefix5)"; \
-	mkdir -p "$(DESTDIR)$(manprefix1)"; \
-	install -m644 "$(OBJDIR)/man/cha-config.5" "$(DESTDIR)$(manprefix5)"; \
-	install -m644 "$(OBJDIR)/man/cha-mailcap.5" "$(DESTDIR)$(manprefix5)"; \
-	install -m644 "$(OBJDIR)/man/cha-mime.types.5" "$(DESTDIR)$(manprefix5)"; \
-	install -m644 "$(OBJDIR)/man/cha-localcgi.5" "$(DESTDIR)$(manprefix5)"; \
-	install -m644 "$(OBJDIR)/man/cha-urimethodmap.5" "$(DESTDIR)$(manprefix5)"; \
-	install -m644 "$(OBJDIR)/man/cha.1" "$(DESTDIR)$(manprefix1)"; \
+	mkdir -p "$(DESTDIR)$(MANPREFIX5)"; \
+	mkdir -p "$(DESTDIR)$(MANPREFIX1)"; \
+	install -m644 "$(OBJDIR)/man/cha-config.5" "$(DESTDIR)$(MANPREFIX5)"; \
+	install -m644 "$(OBJDIR)/man/cha-mailcap.5" "$(DESTDIR)$(MANPREFIX5)"; \
+	install -m644 "$(OBJDIR)/man/cha-mime.types.5" "$(DESTDIR)$(MANPREFIX5)"; \
+	install -m644 "$(OBJDIR)/man/cha-localcgi.5" "$(DESTDIR)$(MANPREFIX5)"; \
+	install -m644 "$(OBJDIR)/man/cha-urimethodmap.5" "$(DESTDIR)$(MANPREFIX5)"; \
+	install -m644 "$(OBJDIR)/man/cha.1" "$(DESTDIR)$(MANPREFIX1)"; \
 	fi
 
 .PHONY: uninstall
 uninstall:
-	rm -f "$(DESTDIR)$(prefix)/bin/cha"
-
+	rm -f "$(DESTDIR)$(PREFIX)/bin/cha"
+	rm -f "$(DESTDIR)$(MANPREFIX5)/cha-config.5"
+	rm -f "$(DESTDIR)$(MANPREFIX5)/cha-mailcap.5"
+	rm -f "$(DESTDIR)$(MANPREFIX5)/cha-mime.types.5"
+	rm -f "$(DESTDIR)$(MANPREFIX5)/cha-localcgi.5"
+	rm -f "$(DESTDIR)$(MANPREFIX5)/cha-urimethodmap.5"
+	rm -f "$(DESTDIR)$(MANPREFIX1)/cha.1"
 
 .PHONY: submodule
 submodule:
diff --git a/README.md b/README.md
index d7b33218..88b142cb 100644
--- a/README.md
+++ b/README.md
@@ -28,12 +28,10 @@ supported yet.)
 	  in PATH)
 	* If you are using a system where the default make program is not
 	  GNU make (e.g. BSD), install gmake and use it in the following steps.
-4. Download parts of Chawan found in other repositories:
-	* `make submodule`
-5. Use one of the following:
-	* `make release` - optimized release build
-	* `make` - debug build (slow, for development)
-6. If you want manpages: `make manpage`
+4. Download parts of Chawan found in other repositories: `make submodule`
+5. Run `make`. (By default, this will build in release mode for development,
+   use `make TARGET=debug`. For details, see [doc/build.md](doc/build.md).)
+6. If you want manpages, run `make manpage`.
 7. Finally, install using `make install` (e.g. `sudo make install`)
 
 Then, try:
diff --git a/doc/build.md b/doc/build.md
new file mode 100644
index 00000000..d04c290a
--- /dev/null
+++ b/doc/build.md
@@ -0,0 +1,48 @@
+# Building Chawan
+
+Chawan uses GNU make for builds.
+
+## Variables
+
+Following is a list of variables which may be safely overridden. You can
+also override them by setting an environment variable with the same name.
+
+* `TARGET`: the build target. By default, this is `release`; for development,
+  `debug` is recommended.<br>
+  This variable changes flags passed to the Nim compiler as follows:
+	- `debug`: Generate a debug build, with --debugger:native (embedded
+	  debugging symbols) enabled. This is useful for debugging, but
+	  generates huge and slow executables.
+	- `release`: This is the default target. We use LTO and strip the
+	  final binary.
+	- `release0`: A release build with stack traces enabled. Useful when
+	  you need to debug a crash that needs a lot of processing to manifest.
+	  Note: this does not enable line traces, so you only get the function
+	  name in stack traces.
+	- `release1`: A release build with --debugger:native enabled. May
+	  be useful for profiling with cachegrind, or debugging a release
+	  build with with gdb.
+* `OUTDIR`: where to output the files.
+* `NIMC`: path to the Nim compiler. Note that you need to include the flag
+  for compilation; by default it is set to `nim c`.
+* `OBJDIR`: directory to output compilation artifacts. By default, it is
+  set to `.obj`.<br>
+  You may be able to speed up compilation somewhat by setting it to an
+  in-memory file system.
+* `PREFIX`: installation prefix, by default it is `/usr/local`.
+* `DESTDIR`: directory prepended to `$(PREFIX)`. e.g. we can set it to
+  `/tmp`, so that `make install` installs the binary to the path
+  `/tmp/usr/local/bin/cha`.
+* `MANPREFIX`, `MANPREFIX1`, `MANPREFIX5`: prefixes for the installation of
+  man pages. The default setting expands to `/usr/local/share/man/man1`, etc.
+* `CURLLIBNAME`: Change the name of the libcurl shared object file.
+
+## Phony targets
+
+* `clean`: remove OBJDIR, OUTDIR, and the QuickJS library
+* `manpage`: build man pages
+* `install`: install the `cha` binary, and if man pages were generated,
+  those as well
+* `uninstall`: remove the `cha` binary and Chawan man pages
+* `submodule`: download the submodules required for the browser to build
+  (for those of us who keep forgetting the corresponding git command :)