Makefile, bin/ -> src/: Substitute scripts rather than chasing symlinks.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 19 Dec 2018 12:39:59 +0000 (12:39 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 22 Dec 2018 09:30:31 +0000 (09:30 +0000)
Move the original scripts to `src/' and leave placeholders, and have the
Makefile do seddery on them to create the `bin/' versions.

.gitignore
Makefile
src/crosstool.in [moved from bin/crosstool with 100% similarity, mode: 0644]
src/mdw-cross.in [moved from bin/mdw-cross with 77% similarity, mode: 0644]

index 047b29a..339c3b3 100644 (file)
@@ -1,3 +1,4 @@
+/bin/
 /inst.*/
 /etc/*-setup.sh
 
index 055b40c..1411e61 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,6 +3,8 @@
 .SECONDEXPANSION: #sorry
 all::
 
+CROSSDIR               := $(shell pwd)
+
 FLAVOURS               += linux-cross
 linux-cross_ARCHS       = linux-armel linux-armhf linux-arm64
 linux-armel_ARCH        = arm-linux-gnueabi
@@ -43,6 +45,14 @@ $(SETUPS): etc/%-setup.sh: $$(call setup-flavour,$$*)-setup.sh.in Makefile
        $(call v_tag,SED)sed 's/@arch@/$($*_ARCH)/g' $< >$@.new && \
                mv $@.new $@
 
+SCRIPTS                         = mdw-cross crosstool
+BINSCRIPTS              = $(addprefix bin/,$(SCRIPTS))
+TARGETS                        += $(BINSCRIPTS)
+$(BINSCRIPTS): bin/%: src/%.in
+       $(V_AT)mkdir -p $(dir $@)
+       $(call v_tag,SED)sed 's\a@crossdir@\a$(CROSSDIR)\a' $< >$@.new && \
+               chmod +x $@.new && mv $@.new $@
+
 all:: $(TARGETS)
 
 CLEANFILES             += $(TARGETS)
old mode 100755 (executable)
new mode 100644 (file)
similarity index 100%
rename from bin/crosstool
rename to src/crosstool.in
old mode 100755 (executable)
new mode 100644 (file)
similarity index 77%
rename from bin/mdw-cross
rename to src/mdw-cross.in
index 16ba6f7..f7ea08a
@@ -8,22 +8,7 @@ case $# in
   0) set -- "$SHELL" ;;
 esac
 
-case ${CROSSDIR+t} in
-  t) ;;
-  *)
-    dir=$(pwd)
-    p=$0
-    while :; do
-      case $p in */*) f=${p##*/} p=${p%/*};; *) f=$p p=. ;; esac
-      cd $p
-      if ! [ -L "$f" ]; then break; fi
-      p=$(readlink "$f")
-    done
-    p=$(pwd)
-    CROSSDIR=${p%/bin}; export CROSSDIR
-    cd "$dir"
-    ;;
-esac
+: ${CROSSDIR=@crossdir@}; export CROSSDIR
 
 if ! [ -f "$CROSSDIR/etc/$env-setup.sh" ]; then
   echo 2>&1 "${0##*/}: cross environment \`$env' unknown"; exit 2