From 06e308526e9c612eaf6e36c36f2213bb915038e4 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 10 Jun 2014 07:08:27 -0700 Subject: 2014-06-10 Kaz Kylheku * Makefile (PROG): Removing ./ prefix from variable name; adding it to invocations of $(PROG) in some rules. (txr.o): Pass several strings as macros on the command line: TXR_REL_PATH, EXE_SUFF and PROG_NAME. * configure (bindir, datadir, mandir): These variables become just relative paths from the prefix. * txr.c (sysroot): Use the TXR_REL_PATH, EXE_SUFF and PROG_NAME preprocessor symbols defined on the command line to avoid hard-coding strings like "bin/txr" and "bin/txr.exe" which actually should reflect the value of the bindir variable. --- ChangeLog | 15 +++++++++++++++ Makefile | 16 +++++++++++----- configure | 32 +++++++++++++++++++------------- txr.c | 8 ++++---- 4 files changed, 49 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4af53990..025aed8f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2014-06-10 Kaz Kylheku + + * Makefile (PROG): Removing ./ prefix from variable name; adding it + to invocations of $(PROG) in some rules. + (txr.o): Pass several strings as macros on the command line: + TXR_REL_PATH, EXE_SUFF and PROG_NAME. + + * configure (bindir, datadir, mandir): These variables become + just relative paths from the prefix. + + * txr.c (sysroot): Use the TXR_REL_PATH, EXE_SUFF and PROG_NAME + preprocessor symbols defined on the command line to avoid + hard-coding strings like "bin/txr" and "bin/txr.exe" which + actually should reflect the value of the bindir variable. + 2014-06-10 Kaz Kylheku * txr.c (get_self_path): Fix spelling of GetModuleFileName. diff --git a/Makefile b/Makefile index 780f1659..9c47ddcc 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,7 @@ MPI_OBJS := $(addprefix mpi-$(mpi_version)/,$(MPI_OBJ_BASE)) OBJS += $(MPI_OBJS) -PROG := ./txr +PROG := txr $(PROG): $(OBJS) $(OBJS-y) $(CC) $(CFLAGS) -o $@ $^ -lm $(LEXLIB) @@ -73,6 +73,12 @@ y.tab.c y.tab.h: parser.y # Bison-generated parser also tests for this lint define. y.tab.o: CFLAGS += -Dlint +# txr.c needs to know the relative datadir path to do some sysroot +# calculations. + +txr.o: CFLAGS += -DTXR_REL_PATH=\"$(bindir_rel)/$(PROG)$(EXE)\" +txr.o: CFLAGS += -DEXE_SUFF=\"$(EXE)\" -DPROG_NAME=\"$(PROG)\" + $(MPI_OBJS): CFLAGS += -DXMALLOC=chk_malloc -DXREALLOC=chk_realloc $(MPI_OBJS): CFLAGS += -DXCALLOC=chk_calloc -DXFREE=free @@ -132,13 +138,13 @@ tests/011/%: TXR_DBG_OPTS := %.ok: %.txr mkdir -p $(dir $@) $(if $(TXR_SCRIPT_ON_CMDLINE),\ - $(PROG) $(TXR_DBG_OPTS) $(TXR_OPTS) -c "$$(cat $^)" \ + ./$(PROG) $(TXR_DBG_OPTS) $(TXR_OPTS) -c "$$(cat $^)" \ $(TXR_ARGS) > $(@:.ok=.out),\ - $(PROG) $(TXR_DBG_OPTS) $(TXR_OPTS) $^ $(TXR_ARGS) > $(@:.ok=.out)) + ./$(PROG) $(TXR_DBG_OPTS) $(TXR_OPTS) $^ $(TXR_ARGS) > $(@:.ok=.out)) diff -u $(^:.txr=.expected) $(@:.ok=.out) %.expected: %.txr - $(PROG) $(TXR_OPTS) $^ $(TXR_ARGS) > $@ + ./$(PROG) $(TXR_OPTS) $^ $(TXR_ARGS) > $@ # # Installation macro. @@ -178,7 +184,7 @@ install-tests: # Generate web page from man page # txr-manpage.html: txr.1 genman.txr - man2html $< | $(PROG) genman.txr - > $@ + man2html $< | ./$(PROG) genman.txr - > $@ config.make config.h: @echo "$@ missing: you didn't run ./configure" diff --git a/configure b/configure index d5afb432..86e17c26 100755 --- a/configure +++ b/configure @@ -76,11 +76,11 @@ help= # # config # -prefix=/usr/local +prefix='/usr/local' install_prefix= -bindir='$(prefix)/bin' -datadir='$(prefix)/share/txr' -mandir='$(prefix)/share/man' +bindir='bin' +datadir='share/txr' +mandir='share/man' make= cross= compiler_prefix= @@ -244,15 +244,18 @@ install-prefix [$install_prefix] bindir [$bindir] - Specifies where the program executable will be installed. + Specifies where the program executable will be installed, as a relative + path from the prefix. datadir [$datadir] - Specifies where read-only program data is to be stored. + Specifies where read-only program data is to be stored, as a relative + path from the prefix. mandir [$mandir] - Specifies the directory where to install man pages. + Specifies the directory where to install man pages, as a relative + path from the prefix. cross [$cross] @@ -467,9 +470,9 @@ fi printf "Checking installation paths:\n" -for name in prefix bindir datadir mandir; do - eval path="\$install_prefix\${$name}" - printf "\$(install_prefix)\$(%s)=%s ... " $name "$path" +for name in bindir datadir mandir; do + eval path="\$install_prefix\$prefix/\${$name}" + printf "\$(install_prefix)\$(prefix)/\$%s=%s ... " $name "$path" test_access=y case "$path" in " "* | *" "* | *" " ) @@ -574,14 +577,17 @@ prefix := $prefix # e.g. for an operating system distro. DESTDIR := $install_prefix +# relative path from prefix to datadir +bindir_rel := $bindir + # executable directory -bindir := $bindir +bindir := \$(prefix)/\$(bindir_rel) # read-only data directory -datadir := $datadir +datadir := \$(prefix)/$datadir # man page directory -mandir := $mandir +mandir := \$(prefix)/$mandir # cross compiler toolchain root directory cross := $cross diff --git a/txr.c b/txr.c index 22bc8c4d..d46a2d67 100644 --- a/txr.c +++ b/txr.c @@ -217,10 +217,10 @@ static val sysroot_helper(val exepart, val target) static val sysroot(val target) { uses_or2; - return or4(sysroot_helper(lit("bin/txr"), target), - sysroot_helper(lit("bin/txr.exe"), target), - sysroot_helper(lit("txr"), target), - sysroot_helper(lit("txr.exe"), target)); + return or4(sysroot_helper(lit(TXR_REL_PATH), target), + sysroot_helper(lit(TXR_REL_PATH EXE_SUFF), target), + sysroot_helper(lit(PROG_NAME), target), + sysroot_helper(lit(PROG_NAME EXE_SUFF), target)); } static void sysroot_init(void) -- cgit v1.2.3