Skip to main content

[LINUX] Hiding the source file and Linking the objects file

In order to prepare the exercise for students in RTEMS on Raspberry Pi, I dig into Makefile (which is auto generated by automake) this week.
(The way to build up the example in RTEMS on Raspberry Pi : here)

The perspective of exercise is to let the students adopt our library to design a simpler real-time application.
However, I want to hide the source code of library, but let the framework of makefile still work well.
That is, we have to exclude the data dependency from the auto generated makefile.

Assume we already compile the essential object as the library and place it at Source code directory, i.e., "...../rtems-gpio/testsuites/samples/SEMAPHORE_TEST".
If we open Build directory, i.e., "build-rtems-rpi-gpio/arm-rtems4.11/c/raspberrypi/testsuites/samples/SEMAPHORE_TEST", we can find a Makefile that is generated by using automake with Makefile.am in Source code directory.

As the typical rule in Makefile framework, all the dependencies of object will be denoted like this:

Pibrella.o:\
 ../../../../../../../rtems-gpio/c/src/../../testsuites/samples/SEMAPHORE_TEST/Pibrella.c \
../config.h \
... so on.

However, we cannot directly find this kind of information from Makefile in Build directory.

Lets trace the file by bottom-up (This example is called SEMAPHORE_TEST):

...
SEMAPHORE_TEST$(EXEEXT): $(SEMAPHORE_TEST_OBJECTS) $(SEMAPHORE_TEST_DEPENDENCIES)
        @rm -f GPIO_Pibrella$(EXEEXT)
        $(make-exe) 
...

You can find the same rule here and the dependent files are defined with the object.

...
am_SEMAPHORE_TEST_OBJECTS = init.$(OBJEXT) Pibrella.$(OBJEXT) \
        tasks.$(OBJEXT)
SEMAPHORE_TEST_OBJECTS = $(am_SEMAPHORE_TEST_OBJECTS)

Here OBJEXT is ".o".
...
include ./$(DEPDIR)/Pibrella.Po
include ./$(DEPDIR)/init.Po
include ./$(DEPDIR)/tasks.Po
...
Behind the implicit keyword, .SUFFIXES:, we can find the include line as include ./$(DEPDIR)/Pibrella.Po, which is used to reveal the dependency of Pibrella.o generated by automake.
DEPDIR here is an invisible directory called .desp in Source code directory.

By marking this line, we can exclude the checking of dependent file and keep the assumed object file with the source codes of example.
Therefore, we reach our perspective.

------------BTW, one of my friends ask me that how to enable math library in RTEMS compilation:
For example, it is a question like this:
https://lists.rtems.org/pipermail/users/2006-March/014215.html

Ad-hoc way is to open Makefile.am in the same folder:
LINK_LIBS = $(NXT_LDLIBS) 
add -lm at the end of line.
LINK_LIBS = $(NXT_LDLIBS) -lm

Comments

Popular posts from this blog

RSB+RTEMS 5/6 with QEMU-SMP (ARM realview_pbx_a9_qemu as example)

Since I got a request regarding this blog  written in 2016, summarizing again the complete flow with the latest version of RTEMS could be a good idea. Prepare a suitable workspace according to the adopted operating system on your host ( https://docs.rtems.org/branches/master/user/hosts/index.html ):  sudo apt-get build-dep build-essential gcc-defaults g++ gdb git unzip pax bison flex texinfo unzip python3-dev libpython-dev libncurses5-dev zlib1g-dev Checkout RSB and build: git clone git://git.rtems.org/rtems-source-builder.git rsb change directory to rsb/rtems/ and type ../source-builder/sb-set-builder --prefix=<the path you like to store the built toolchains> <the name of bsp> For example, to use QEMU, I need toolchains for ARM, so: ../source-builder/sb-set-builder --prefix=/home/kh.chen/respository/build/. 6/rtems-arm This will take a while. Please ensure your connection is reliable. Add the built folder into your PATH. For example, you can add one line in ~/.bas...

[LEGO nxt] Install the Enhanced NXT firmware and Upload the OSEK excutable file with Ubuntu 64bits 14.04 in 2015

This tutorial is referred from Install the Enhanced NXT firmware on NXT . I think this is the critical part to capture the idea from the tutorial for Windows. I have tried many ways to conquer the problem of libnxt3.0, however, I still have some problems on the compilation of fwflash or something else. Though the tutorial for Windows is doable, my preference is to build up everything with Linux environment. Fortunately, I notice that NxTTool in the tutorial for Windows is really powerful. We can handle the firmware updating by using NxTTool in Linux as well! I also refer to this Japanese Blog , which inspire me a lot. As usual, install the required packages: sudo apt-get install libusb-dev:i386 libusb-0.1-4 subversion fpc Please note, here is the case for 64bits user that I change libusb-dev to libusb-dev:i386 comparing to the original tutorial. Instead of using libnxt to do the uploading, here I follow that JP Blog to get the latest version of bricxcc: (The url in blog i...

Virtualenv experience or alternatives

Today I have a project which requires several packages on my python. However, due to whatever reason, I have a lot of different versions of python. Before I thought, it was fine to just install and maintain each by each. Maybe it is time to learn how to use virtualenv. (alternatively, you can use module). I first got some quick ideas from here: https://stackoverflow.com/questions/10763440/how-to-install-python3-version-of-package-via-pip-on-ubuntu The magic virtualenv does is that, it copies a series of your python binaries, include, pip, etc., into a folder. The prepared activate script does that, add the export folder into the general variable PATH at its beginning. By doing so, the targeted version of python will be the first target that will be executed. To enable virtualenv, source the position of the above folder/bin/activate To leave the virtualenv, just type deactivate, as it is defined when you load the activate script. For example, I call virtualenv in my home ...