lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Mar 4, 2013 at 4:56 PM, Steve Litt <slitt@troubleshooters.com> wrote:
> On Sun, 3 Mar 2013 17:36:17 -0500
> Rena <hyperhacker@gmail.com> wrote:
>
>> So, I've been developing some small applications in Lua, and one issue
>> that's come to light is once my app is installed, if it's made up of
>> more than one script, the main 'executable' script needs to know where
>> to find the other scripts.
>> It's enough to use os.getenv('PWD') .. arg[0] during testing, but that
>> won't work if the script is in the $PATH. Unfortunately my
>> understanding is there's no standard way to determine the current path
>> of the executable.
>>
>> I'm also not sure what is the best practice when it comes to
>> installing a program that consists of several files (the main
>> executable and several sub-scripts it includes) on a Linux system.
>
> Hi Rena,
>
> What I'm going to talk about won't be very popular, and it's neither
> Unixly-correct nor Windowsly-correct, but I see a couple people have
> already suggested it.
>
> Having computed in the DOS era, I'm a big fan of the "everything in one
> tree" paradigm. An install is just an tar xzvf, and an uninstall is just
> rm -rf. Your app needs to know about few other facilities, and other
> facilities needn't know anything about your app.
>
> The easiest way I've found to do this is, if your app is myapp.lua, put
> it in an arbitrary directory along with the other files (or the other
> files can be in subdirectories), and then in the same directory put
> myapp.sh, whose first few lines look like this:
>
> =====================
> #!/bin/bash
> cd /whatever/myapp
> export ENVARG1=WHATEVER1
> export ENVARG2=WHATEVER2
> ./myapp.lua $1 $2 $3 $4 $5 $6 $7
> =====================
> The last task is to, within /usr/local/bin or wherever on the path, put
> a symlink to myapp.sh.
>
> If you want your app to truly be standalone, this is an effective way
> to do it.
>
> SteveT
>
> Steve Litt                *  http://www.troubleshooters.com/
> Troubleshooting Training  *  Human Performance
>

Thanks for all the feedback.

This is the makefile I came up with:
PROGRAM=imgview
INSTALLDIR=/usr/local/share/$(PROGRAM)
.PHONY: all install uninstall

all:
	@echo This program does not need to be compiled, just run \`make install\`.

install:
	mkdir -p $(INSTALLDIR)
	ln -fs $(PROGRAM).lua /usr/local/bin/$(PROGRAM)
	find . -name '*.lua' -not -name '$(PROGRAM).lua' \
		-exec ln -fs {} $(INSTALLDIR)/{} \;
	find ./data -type d -not -name '.*' -exec mkdir -p $(INSTALLDIR)/{} \;
	find ./data -type f -not -name '.*' -exec ln -fs {} $(INSTALLDIR)/{} \;

uninstall:
	rm /usr/local/bin/$(PROGRAM)
	rm -r $(INSTALLDIR)

I'll update it to embed the install path in the executable as well. I
like the idea of the actual "executable" being a symlink and putting
all of the app's actual scripts in one directory.

The one thing I don't like about this method is you can change
INSTALLDIR on the command line, but not where the executable itself is
placed. That's easy enough to fix, but I wonder what to call that
variable... no doubt there's standards I'm not aware of for that, too.
Is this makefile up to spec?

-- 
Sent from my Game Boy.