Wink Saville’s Blog

March 7, 2008

make – need VPATH for non-local files if implicit rules are used

Filed under: linux, programming — wink @ 5:31 pm

Ran into a strange problem today, for some reason if a file isn’t in the current directory I need to have VPATH defined so that it points to the directory that contains the file(s) if the rule is implicit. For example, with the following structure where the Makefile is in a subdirectory below the location of the source file:

wink.c
x/Makefile

and the Makefile file is:cat x/Makefile is:

wink@ic2d1:$ cat x/Makefile
#VPATH=../
wink.o: ../wink.c
clean:
      rm *.o

If I now go into x and do a make –debug the we see the following:

wink@ic2d1:$ make --debug
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for x86_64-pc-linux-gnu
Reading makefiles...
Updating goal targets....
 File `wink.o' does not exist.
Must remake target `wink.o'.
Successfully remade target file `wink.o'.
make: Nothing to be done for `wink.o'.

So it knows it needs to”remake target ‘wink.o’” but then says “Successfully remade …” but it didn’t, wink.o isn’t built. If I now enable VPATH and Makefile is:

wink@ic2d1:$ cat x/Makefile
VPATH=../
wink.o: ../wink.c
clean:
      rm *.o

Now make –debug does build wink.o and the output is:

wink@ic2d1:$ make --debug
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for x86_64-pc-linux-gnu
Reading makefiles...
Updating goal targets....
 File `wink.o' does not exist.
Must remake target `wink.o'.
cc    -c -o wink.o ../wink.c
Successfully remade target file `wink.o'.

If you have an explicit rule everything works as expected as well:

wink@ic2d1:$ cat Makefile
#VPATH=../
wink.o: ../wink.c
	$(CC) $(CFLAGS) -c -o $@ $<
clean:
      rm *.o

Now make –debug also builds wink.o and the output is:

wink@ic2d1:$ make --debug
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for x86_64-pc-linux-gnu
Reading makefiles...
Updating goal targets....
 File `wink.o' does not exist.
Must remake target `wink.o'.
cc    -c -o wink.o ../wink.c
Successfully remade target file `wink.o'.

Another solution is don’t use Gnu Make but use pmake. Of course if the makefile isn’t compatible with pmake then this won’t work. On Ubuntu install the bin86 package via synaptic or “apt-get install pmake”.

March 3, 2008

PXE – Booting via network cards

Filed under: linux, programming, pxe — wink @ 2:08 pm

To get PXE there are several resources on the web, here and here. The sources for pxelinux.0 is in syslinux. Anyway, here’s what I did; First, to use PXE you need to have a more capable DHCP server, so I switched to dhcpd3-server on my linux:

wink@saville-server:/etc/dhcp3$ cat my-dhcpd.conf
ddns-update-style interim;
option domain-name "saville.com";
option domain-name-servers 68.87.76.178, 66.240.49.9;
default-lease-time 600;max-lease-time 7200;

log-facility local7;
subnet 192.168.0.0 netmask 255.255.255.0 {
   range 192.168.0.100 192.168.0.149;
   option routers 192.168.0.2;
}

host test1 {
   hardware ethernet 00:1D:7D:00:A3:0B;
   fixed-address 192.168.0.148;
   option host-name "test1";
   filename "pxelinux.0";
   next-server 192.168.0.99;
}

The “host” section is the important part for PXE and in particular “hardware” identifies the card via its ethernet id, “filename” defines the file that will be requested and “next-server” defines the IP address of the server that will server the file to the “test1″ client via tftp.

So the next step was to get tftp working, I did the following but obviously synaptic works also:

apt-get install tftpd-hpa

I the config file for tftpd needs a little doctoring. The defaults is not running as a daemon and the directory is /var/log/tftpboot. You need it to run as a daemon and you may want to change the directory, here is what I have:

#Defaults for tftpd-hpa
RUN_DAEMON="yes"
OPTIONS="-l -s /tftpboot"

To start/test manually run “sudo /etc/init.d/tftpd-hpa start”. You should be able to see tftp using netstat:

wink@ic2d1:$ netstat netstat -apu
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
udp        0      0 *:32769                 *:*                                -
udp        0      0 *:32772                 *:*                                -
udp        0      0 ic2d1.local:netbios-ns  *:*                                -
udp        0      0 *:netbios-ns            *:*                                -
udp        0      0 ic2d1.local:netbios-dgm *:*                                -
udp        0      0 *:netbios-dgm           *:*                                -
udp        0      0 *:946                   *:*                                -
udp        0      0 *:tftp                  *:*                                -       
udp        0      0 *:mdns                  *:*                                -
udp        0      0 *:sunrpc                *:*                                -
udp        0      0 ic2d1.local:ntp         *:*                                -
udp        0      0 localhost:ntp           *:*                                -
udp        0      0 *:ntp                   *:*                                -
udp6       0      0 fe80::217:31ff:fee1:ntp *:*                                -
udp6       0      0 ip6-localhost:ntp       *:*                                -
udp6       0      0 *:ntp                   *:*                                -

You should now be able to add files to the directory /tftpboot such as pxelinux.0.

February 24, 2008

Ajax – responses must have Content-Length

Filed under: Ajax, firefox — wink @ 2:30 pm

When responding to an AJAX request, actually when responding to any HTTP/1.1 request that is going to be kept alive you need to have a Content-Length header field even if the the content length is 0.

February 23, 2008

Java – sources in jar’s

Filed under: java — wink @ 7:33 pm

While debugging Ajax support for AMC I learned that to debug class files that java libraries (aka. jar files) all you need to do is include the java files in the jar files.

February 22, 2008

Firefox/Apache – debug server side php code

Filed under: Apache, firefox — wink @ 11:10 am

To apache debug server-side scripts the typical solution is to usr print statements back to the browser. But that won’t work for AJAX as there isn’t any place to view the output.

The other method is to log to a file

$fp = fopen(’debug.php’, ‘ab’);
fwrite($fp, “debug data …”);
// Then eventually close
fclose($fp);

Filed under: firefox — wink @ 11:03 am

Debugging Firefox:

*) DOM Inspector:

By default on Ubuntu the firefox DOM inspector isn’t enabled and when reading “Programmin Firefox” it is one of the recommended tools

But it isn’t enabled by default, apparently this is the case for Windows also where you need to do a custom install to get it. For Ubuntu I installed it via synaptic as firefox-dom-inspector I also added firefox-dbg and firefox-dev. Interesting, it wasn’t available right away and I needed to reboot the system, although there may be other ways.

*) Java script parsing bugs

At the moment, 20070602, I don’t see parsing errors for java script files I create?

*) Java script runtime debugging:

Method one: run FF from the command line with the -console option: wink@ic2d1:~$ firefox -console & and then use “dump” commands to print strings to the console.

Method two: use Venkman debugger. Again, wasn’t available by default, I used Toos->Add-on and navigated to “Web and developer tools” and searched for debugger, the Venkman debugger was the first choice. Seleting this and the “Install Now” button installed it.

*) Venkman debugger:

To get Venkman to debug my overlay I had to enable browser files: Goto menu item “Debug/Exclude Browser Files” and be sure it is not checked. The list of files will then expand and my script “sl.js” was visible. A break point could then be set.

Firefox – Adding preferences

Filed under: firefox — wink @ 10:54 am

Adding preferences isn’t too hard. I followed the instructions here. I had several problems of my own making plus one in the example code. The example code problem was:

var gMyPrefs = new PrefsWrapper(”extensions.myextension.”);

PrefsWrapper needed a number “1″ appended:

var gMyPrefs = new PrefsWrapper1(”extensions.myextension.”);

The other minor problem was “myextension” and “yourextension” needs to be “sparkrocket”.

The problems of my own making were a miss-understanding of javascript. At first I added the example code at the global scope but nothing would happen. After a little while of adding debug I figured out I needed to not have the example code at the global scope, but it needed to be in sr_initialize. I could then execute the code from prefsutils.js.

Also, the prompt service described here is similar but different from “prompt()” builtin function which also prompts for input but I couldn’t find the docs for it so I used the prompt service.

Finally, after adding the setUnicharPref I couldn’t unset it, at first I thought it would replace the defaults/preferences/extensions.js value for user.name. But no, that is just the default, the value is actually stored in ~/.mozilla/firefox/fbgu8siq.default/prefs.js and can be modified by going to the url “about:config”.

Firefox – building an extension

Filed under: firefox — wink @ 10:34 am

Here’s an update to this post 7/6/2008:

Use this link from firefox and in particular Setup the Development Environment.

—-

I used this link as a model for creating an extension which put a button on FF’s address bar: Building an extension

I more or less followed those instructions: Firefox user interface is written as a .xul file, pronounced “zool”. As explained in Building an extension in the “Chrome URI’s” section you can even execute the browser ui in the browser. Place “chrome://browser/content/browser.xul” in the browser address bar.

To add a new user interface element you create an overlay and basicly dynamically modify the browser.xul file. An overlay is an .xul file which defines a location where the new interface element is to be located and then what it is to do. Finding the location to insert isn’t difficult, the main UI document on my Ubuntu system it is located at at /usr/share/firefox/chrome/browser/content/browser/browser.xul

In the example they modified the status line which is can be found in browser.xul by searching for “statusbar”. Since I wanted to modify the address url I looked around and found that there is a texbox with the id=”urlbar”. So the prgs/fx/sl/chrome/content/sample.xul file contains the following:

<textbox id=”urlbar”>
<button insertafter=”page-proxy-dec” id=”my-button” label=”sl”
oncommand=”alert(’You pressed me!’); return false;”/>
</texbox>

Which adds a button with the label “sl” to the address bar and when pressed displays an allert with “You pressed me!”. So the following steps will get you the same thing:

1) Created my “extension” in ~/prgs/fx/sl which have the following 3 files:

chrome.manifest
install.rdf
chrome/content/sl.xul

2) The content of the files are:

wink@ic2d1:~/prgs/fx/sl$ cat chrome.manifest
content sl chrome/content/
overlay chrome://browser/content/browser.xul chrome://sl/content/sl.xul

 

wink@ic2d1:~/prgs/fx/sl$ cat install.rdf
<?xml version=”1.0″?>
<RDF xmlns=”http://www.w3.org/1999/02/22-rdf-syntax-ns#”
xmlns:em=”http://www.mozilla.org/2004/em-rdf#”>

<Description about=”urn:mozilla:install-manifest”>
<em:id>sl@saville.com</em:id>
<em:version>1.0</em:version>
<em:type>2</em:type>

<!– Target Application this extension can install into,
with minimum and maximum supported versions. –>
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>1.5</em:minVersion>
<em:maxVersion>2.0.0.*</em:maxVersion>
</Description>
</em:targetApplication>

<!– Front End MetaData –>
<em:name>sl</em:name>
<em:description>Shared link<em:description>
<em:creator>Wink Saville</em:creator>
<em:homepageURL>http://www.saville.com/</em:homepageURL>
</Description>
</RDF>

wink@ic2d1:~/prgs/fx/sl$ cat chrome/content/sl.xul
<?xml version=”1.0″?>
<overlay id=”sample”
xmlns=”http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul”>
<textbox id=”urlbar”>
<button id=”my-button” label=”sl”
oncommand=”alert(’You pressed me!’); return false;”/>
</texbox>
</overlay>

3) To install the extension added sample@foo.net to the extensions directory:

wink@ic2d1:~/prgs/fx/sl$ cat ~/.mozilla/firefox/fbgu8siq.default/extensions/sl@saville.com
/home/wink/prgs/fx/sl

 

This is just the path to my extension

 

4) To actually get the url of the current page, this looks like the definitive source. and it says the best is window.content.location.href. I also tried document.getElementById(’urlbar’).value which also looks to have worked.

February 17, 2008

git – applying patches

Filed under: linux, scm — wink @ 3:49 pm

Today learned some things about git and applying patches. First when applying my trec/ace/kshmem patches to 2.6.25-rc2 they wouldn’t apply because now there only an x86 architecture (arch/x86) instead of two architectures i386 and x86_64. That was to be expected actually and there’s going to be some hand work in doing that.

To do this hand work I really need to see what my current patches look like and there isn’t quite enough context in the patch file to do that, at least for me. So I cloned the current linux-2.6 tree into a new directory linux-2.6-x and did a checkout of 2.6.21-rc6 which is what my patches should apply against.

Well almost, there was still some need for a little tweaking; First git am will take my series of patches which were generated using git format-patch and apply them extracting from the email the commit message and the patch. It then creates a commit. But if there is a problem in a series only those that applied cleanly will be committed.

The first patch that fails won’t be applied at all, for example:

error: patch failed: mm/vmalloc.c:469
error: mm/vmalloc.c: patch does not apply
Patch failed at 0002.
When you have resolved this problem run "git-am --resolved".
If you would prefer to skip this patch, instead run "git-am --skip".

At this point I was scratching my head Patch failed at 0002 and when its resolved I can say so, but how to resolve it if its not been applied to the working tree. The solution is to use “git apply”:

git apply --reject --whitespace=fix my-patches/ace2-2.6.21-rc6/0002.patch

By using “git apply” with the –reject it will apply the patch leaving bad files with “xxx.rej” in my case mm/Kconfig.rej was the culprit. I resolved the problem with mm/Kconfig. Next I tried “git am –resolved”:

wink@ic2d1:$ git am --resolved
Applying ACE implementation, conifguration and makefile
No changes - did you forget to use 'git add'?
When you have resolved this problem run "git-am --resolved".
If you would prefer to skip this patch, instead run "git-am --skip"

More head scratching, “did you forget to use ‘git add’?” …. hm Ok so I then used “git gui” to add the files (BUT DID NOT DO A COMMIT) and then did “git am –resolved”:

wink@ic2d1:$ git am --resolved
Applying ACE implementation, conifguration and makefile
Applying ACE modifications to actually use ACE
.dotest/patch:32: trailing whitespace.
warning: 1 line adds whitespace errors.
Applying ACE simple test program
.dotest/patch:130: space before tab in indent.
result ? "true" : "false", i);
.dotest/patch:138: space before tab in indent.
result ? "true" : "false", i);
.dotest/patch:146: space before tab in indent.
result ? "true" : "false", i);
.dotest/patch:233: trailing whitespace.
warning: 4 lines add whitespace errors.

That did it, so no commit was necessary, the “git am –resolved” did the commit and then continued with the other patches. Lean something new everyday!

February 12, 2008

Eclipse – ant and build.xml

Filed under: Android, Ant, Eclipse, java — wink @ 1:31 pm

This week I converted async-msgcomp to use ant for building rather than the internal Eclipse builders because it was the only way I could figure out to get jar files automatically built. After some trial an error I came up with common-build.xml which are common tasks for all sub-project and resides at the root of my build tree. I also created android-build.xml which is in the android sub-directory and is the common Ant tasks for Android. Then within each sub-project is a build.xml, for instance java/debug/build.xml and android/debug/build.xml as well as a global build.xml file in my root. For full disclosure; common-build.xml was based on the build.xml file emitted by:

File -> Export -> General -> Ant Buildfiles

And android-build.xml is based on the build.xml file emitted by running:

android-sdk/tools/activityCreator.py

The build.xml files are then used by executing ant in the appropriate sub directory. By executing ant in the root all of the sub-projects are built. Eclipse is also capable of building using Ant but you have setup the properties for each sub-project, which I’ll try to outline below. Sometimes Eclipse has trouble and either won’t execute saying they are still errors or it won’t execute because the classpath isn’t set properly.

One solution that has helped is to delete all projects and re-import them. Two other important items is that the Run parameters must be setup properly in <Run/Open Run Dialog> must be set properly and Build parameters for must be good.

Anyway, here is an example of setting the project properties so that external Ant files are used for compiling, in the example below I’m setup the sub-project “debug”. We assume there is a build.xml file in the sub-project.

Project -> Properties -> Builders -> new:

Main.Name: = debug-build.xml
Main.Buildfile: = Browse Worksapce => debug/build.xml
Main.Base Directory: = Browse Workspace => debug
Targets.After a “Clean”: = <default target selected>
Targets.Manual Build: = <default target selected>
Targets.Auto Build: = <default target selected>
Targets.During a “Clean”: = clean

Project -> Properties -> Builders = select only debug-build.xml deselect all others
Project -> Propertiers -> java Build Path -> Libraries = Add appropriate Libraries
Project -> Propertiers -> java Build Path -> Order and Export = the Libraries
Project -> Propertiers -> Project References -> Project references for debug: = select appropriate projects

In the Project -> Properties -> Builders where we select only debug-build.xml and deselect all others includes the following if it is an Android sub-project:

Android Resource Manager
Android Pre Compiler
Java Builder
Android Package Builder

If it is “pure java” project than you just deselect Java Builder.

« Newer PostsOlder Posts »

Powered by WordPress