How to edit Makefile to make it work with NetBeans remote build? - netbeans

I have Makefile like this:
obj-m += some_kernel_module.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
It works when I run make from build machine locally (when my current directory is /home/myaccount/src/some_kernel_module/).
However when I'm trying to compile this remotely in Netbeans I'm getting this error:
/usr/src/linux-headers-3.16.0-6-common/scripts/Makefile.build:44:
/home/myaccount/Makefile: No such file or directory
I guess that's because I have M=$(PWD) in my Makefile, and Netbeans Build Host current directory is my home (/home/myaccount) instead of project directory /home/myaccount/src/some_kernel_module/).
How can I fix that?
I have entered path manually and it works locally and remotely:
obj-m += some_kernel_module.o
all:
make -C /lib/modules/$(shell uname -r)/build M=/home/myaccount/src/some_kernel_module/ modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=/home/myaccount/src/some_kernel_module/ clean
But this is not an answer. I don't want this absolute path in my Makefile.

I found answer here:
How to get current relative directory of your Makefile?
I had to get and store makefile directory like this:
THIS_DIR := $(dir $(abspath $(firstword $(MAKEFILE_LIST))))
And use it instead of PWD (complete Makefile):
obj-m += some_kernel_module.o
THIS_DIR := $(dir $(abspath $(firstword $(MAKEFILE_LIST))))
all:
$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(THIS_DIR) modules
clean:
$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(THIS_DIR) clean
Edit: As https://stackoverflow.com/users/939557/madscientist suggested in comments below I changed make to $(MAKE).

Related

Eclipse Makefile: Make Variables are skipped

I have a project with a Makefile in it, on Unix console it works fine, compiles, builds and I can run the binary at the end.
I imported the project into Eclipse workspace and somehow Makefile module of Eclipse cannot build the project now. It gives the following error:
g++: error: /src/main: No such file or directory
Whereas there should have been
g++ -I $(APR_INCLUDE) -I $(CMS_HOME)/src/main
which uses two make variables. I already put them before this line and define them as :
export APR_INCLUDE=/usr/include/apr-1
export CMS_HOME=~/Desktop/activemq-cpp-library-3.8.4
Same Makefile is fine with console, but not with Eclipse, which is weird.
Any thoughts?
Here is where I put my export lines:
obstacleDetection_cpp: src/obstacleDetection.cpp protoc_middleman
export APR_INCLUDE=/usr/include/apr-1
export CMS_HOME=~/Desktop/activemq-cpp-library-3.8.4
g++ -I $(APR_INCLUDE) -I $(CMS_HOME)/src/main -g -o src/obstacleDetection.o -c src/obstacleDetection.cpp
cd libs && cp $(CMS_HOME)/src/main/.libs/libactivemq-cpp.so.18.0.4 . && ln -sf libactivemq-cpp.so.18.0.4 libactivemq-cpp.so.18
g++ -L $(CMS_HOME)/src/main/.libs/ -g -o bin/obstacleDetection src/obstacleDetection.o src-gen/Point.pb.cc src-gen/Point.pb.h -lactivemq-cpp -lssl -lprotobuf -pthread
#echo "Success. Run the executable from the binary directory with: LD_LIBRARY_PATH=../libs/ ./obstacleDetection"
This is not right:
obstacleDetection_cpp: src/obstacleDetection.cpp protoc_middleman
export APR_INCLUDE=/usr/include/apr-1
export CMS_HOME=~/Desktop/activemq-cpp-library-3.8.4
g++ $(APR_INCLUDE) -I $(CMS_HOME)/src/main ...
All lines in the recipe (that is, lines that are indented with a TAB in a target context like this) are passed to the shell. These are not make variable assignments. There are two things wrong with that:
First, each logical line in the recipe is passed to a new shell. That means any changes to the process context (such as the environment or the working directory) are present only for the duration of that logical line; once the shell processing that line exits, all those changes are lost. So, these lines have no impact: they set an environment variable in the shell, then the shell exits and that setting is gone.
Second, the variable references you make in your compile line, such as $(APR_INCLUDE), are make variable references, not environment variable references. So even if those environment variable assignments still had effect, they would not be used because you're not referring to environment variables here.
You want to create make variable assignments. That can only be done outside of a recipe. Also, you don't need to export them because only make needs to see them (make will expand them before invoking the shell). So, your makefile should look like this:
APR_INCLUDE = /usr/include/apr-1
CMS_HOME = $(HOME)/Desktop/activemq-cpp-library-3.8.4
obstacleDetection_cpp: src/obstacleDetection.cpp protoc_middleman
g++ -I $(APR_INCLUDE) -I $(CMS_HOME)/src/main -g -o src/obstacleDetection.o -c src/obstacleDetection.cpp
cd libs && cp $(CMS_HOME)/src/main/.libs/libactivemq-cpp.so.18.0.4 . && ln -sf libactivemq-cpp.so.18.0.4 libactivemq-cpp.so.18
g++ -L $(CMS_HOME)/src/main/.libs/ -g -o bin/obstacleDetection src/obstacleDetection.o src-gen/Point.pb.cc src-gen/Point.pb.h -lactivemq-cpp -lssl -lprotobuf -pthread
#echo "Success. Run the executable from the binary directory with: LD_LIBRARY_PATH=../libs/ ./obstacleDetection"

rpmbuild no such file or directory

I'm just learning making rpm packages for some custom builds of software that gets compiled from source (some legacy stuff needs this, so I'm trying to learn, as some packages can't use the latest versions), but hitting an error (I'm doing this in Vagrant, and also as root, but typically I'm trying not to use root as I'm aware it has potential for damage, its just this example seems to need some root changes).
sudo rpmbuild -ba testspec.spec --define "_topdir /tmp/"
So far it looks to be using the directory I expected, /tmp/rpmbuild
make[2]: Entering directory `/tmp/rpmbuild/BUILD/exim-4.80.1/build-Linux-x86_64/pdkim'
make[2]: `pdkim.a' is up to date.
make[2]: Leaving directory `/tmp/rpmbu
But then I see these errors...
/usr/lib/rpm/brp-compress: line 8: cd: /tmp/BUILDROOT/custom-exim-4.80.1-1.x86_64: No such file or directory
+ /usr/lib/rpm/brp-strip
find: `/tmp/BUILDROOT/custom-exim-4.80.1-1.x86_64': No such file or directory
+ /usr/lib/rpm/brp-strip-static-archive
find: `/tmp/BUILDROOT/custom-exim-4.80.1-1.x86_64': No such file or directory
+ /usr/lib/rpm/brp-strip-comment-note
So it now seems to be looking in /tmp/BUILDROOT
I'm new to rpmbuild, and don't quite understand some of the process.
My test spec file is at...
%define myversion exim-4.80.1
##%define mybase %{getenv:HOME}
%define mybase /tmp
%define _topdir %{mybase}/rpmbuild
%define _tmppath %{mybase}/rpmbuild/tmp
%define name custom-exim
%define release 1
%define version 4.80.1
%define buildroot %{_topdir}/%{name}-%{version}-root
BuildRoot: %{buildroot}
Summary: %{name}
Name: %{name}
Version: %{version}
Release: %{release}
Source0: ftp://exim.noris.de/exim/exim4/old/exim-4.80.1.tar.gz
License: GPLv1+
Group: Language
AutoReq: no
AutoProv: no
Requires: db4-devel pcre-devel libdb-devel libXt-devel libXaw-devel
%description
Custom Exim Build
%prep
#Do the following manually before building rpm
#mkdir -p /tmp/rpmbuild/BUILD /tmp/rpmbuild/SPECS /tmp/rpmbuild/SOURCES /tmp/rpmbuild/BUILDROOT /tmp/rpmbuild/RPMS /tmp/rpmbuild/SRPMS
#wget ftp://exim.noris.de/exim/exim4/old/exim-4.80.1.tar.gz -O /tmp/rpmbuild/SOURCES/exim-4.80.1.tar.gz
%setup -q -n %{myversion}
grep exim /etc/passwd || useradd -c "Exim" -d /var/spool/exim -m -s /bin/bash exim
%build
# exim needs to config changes before compiling, may do these first and repackage
cp %{mybase}/rpmbuild/BUILD/%{myversion}/src/EDITME %{mybase}/rpmbuild/BUILD/%{myversion}/Local/Makefile
cp %{mybase}/rpmbuild/BUILD/%{myversion}/exim_monitor/EDITME %{mybase}/rpmbuild/BUILD/%{myversion}/Local/eximon.conf
sed -i -e 's/EXIM_USER=$/EXIM_USER=exim/g' "%{mybase}/rpmbuild/BUILD/%{myversion}/Local/Makefile"
sed -i -e 's/LOOKUP_DNSDB=yes/#LOOKUP_DNSDB=yes/g' "%{mybase}/rpmbuild/BUILD/%{myversion}/Local/Makefile"
make
%install
rm -rf $RPM_BUILD_ROOT
#%{__mkdir_p} '%{buildroot}%{_sbindir}'
make install
%clean
rm -rf $RPM_BUILD_ROOT
%post
%postun
%files
Why is it using /tmp/BUILDROOT literally, instead of /tmp/rpmbuild, and are there other obvious things I'm doing wrong ? I've looked at a lot of other tutorials on rpmbuild, but aren't very clear on best practices or what happens during each phase.
Since the buildroot parm is not passed to rpmbuild, the default path is being used by your spec file:
BuildRoot: %{buildroot}
Try adding the buildroot parm... Add buildroot /tmp/rpmbuild to --define
Or if using a makefile:
BUILD_TMP=/tmp/rpmbuild
TOP_DIR=/tmp
rpmbuild -bb
--buildroot $(BUILD_TMP)
--topdir $(TOP_DIR)
$(SPEC_DIR)/testspec.spec
In my case rpm-build was missing.
So sudo yum install rpm-build solved the problem. Or if you use puppet:
package { 'rpm-build':
ensure => latest,
}

rpm build fails to make build root dir

I am working on making an rpm for a small program used within our enterprise. The %build section of the rpm process works. I'm having trouble with the install section. I've referenced this article response and I believe I am properly referring to the target location with respect to %{_buildroot}.
The program I'm making is to be installed as a system service. So, after the rpm actually is generated for this step, I've got to add the next step in my installation process which is to include the script that is installed to the init.d location and run that install. One step at a time though.
The build errors are as follows (omitting everything but %install):
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.eUDaCK
+ umask 022
+ cd /home/packager/rpmbuild/BUILD
+ '[' /home/packager/rpmbuild/BUILDROOT/o2arbitord-1.0-1.el6.x86_64 '!=' / ']'
+ rm -rf /home/packager/rpmbuild/BUILDROOT/o2arbitord-1.0-1.el6.x86_64
++ dirname /home/packager/rpmbuild/BUILDROOT/o2arbitord-1.0-1.el6.x86_64
+ mkdir -p /home/packager/rpmbuild/BUILDROOT
+ mkdir /home/packager/rpmbuild/BUILDROOT/o2arbitord-1.0-1.el6.x86_64
+ cd o2arbitord-1.0
+ LANG=C
+ export LANG
+ unset DISPLAY
+ install -m 555 /home/packager/rpmbuild/BUILD/o2arbitord-1.0/o2arbitord /home/packager/rpmbuild/BUILDROOT/o2arbitord-1.0-1.el6.x86_64/usr/sbin
install: cannot create regular file `/home/packager/rpmbuild/BUILDROOT/o2arbitord-1.0-1.el6.x86_64/usr/sbin': No such file or directory
error: Bad exit status from /var/tmp/rpm-tmp.eUDaCK (%install)
Now, my rpmbuild directory does not have the directory /home/packager/rpmbuild/BUILDROOT/o2arbitord-1.0-1.el6.x86_64/usr/sbin. While I know that's part of the problem, the rpmbuild process isn't making the directory /home/packager/rpmbuild/BUILDROOT/o2arbitord-1.0-1.el6.x86_64 either. What I don't understand about that one is: why? Looking at the script output above you can clearly see the line: mkdir /home/packager/rpmbuild/BUILDROOT/o2arbitord-1.0-1.el6.x86_64. So, why isn't the directory made?
How does the line BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) from whatever the definition of %{_buildroot} is? I thought that was the definition, but it appears to be something different.
For reference, my spec file
Name: o2arbitord
Version: 1.0
Release: 1%{?dist}
Summary: a daemon
Group: Applications/System
License: GPL
URL: http://My.site
Source0: %{name}-%{version}.tar.gz
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
BuildArch: x86_64
BuildRequires: libusb1-devel
#Requires:
%description
%prep
%setup -q
%build
make -f o2arbitord.mk
%install
install -m 555 %{_builddir}/%{name}-%{version}/%{name} %{buildroot}%{_sbindir}
%clean
rm -rf %{buildroot}
%files
%defattr(-,root,root,-)
/usr/sbin/o2arbitord
%changelog
You are attempting to install a file into a directory that doesn't exist (yet).
RPM only creates the %{buildroot} for you automatically. Anything under that you need to create yourself.
So when you run
install -m 555 %{_builddir}/%{name}-%{version}/%{name} %{buildroot}%{_sbindir}
where %{buildroot}%{_sbindir} expands to /home/packager/rpmbuild/BUILDROOT/o2arbitord-1.0-1.el6.x86_64/usr/sbin RPM has only created /home/packager/rpmbuild/BUILDROOT/o2arbitord-1.0-1.el6.x86_64 for you already.
You need to create the /usr/sbin part of that path and then copy the file into it.
You can do that with either
%{__mkdir_p} '%{buildroot}%{_sbindir}'
or
%{__install} -d '%{buildroot}%{_sbindir}'
Where
$ rpm -E '__mkdir_p = %{__mkdir_p}'
__mkdir_p = /bin/mkdir -p
$ rpm -E '__install = %{__install}'
__install = /usr/bin/install

Source RPM Can't Find Files

I'm trying to build an RPM of a node.js project I'm working on. The project's code is entirely contained in one directory and its subdirectories. Here's part of my build script:
Put everything in the SOURCES directory, except the node_modules
echo "Copying sources..."
cd $DIR/dashboard
tar -zcf $DIR/rpmbuild/SOURCES/project-$VERSION.tgz . --exclude=node_modules > /dev/null
cd $DIR
# Create the spec file
touch $DIR/rpmbuild/SPECS/specfile
# write to it
cat >$DIR/rpmbuild/SPECS/specfile <<EOL
Summary: [Summary]
Name: [Name]
Version: $VERSION
Release: 1
License: GPL
Group: Applications/WebApp
Source: [Name]-$VERSION.tgz
Vendor: None
Requires: nodejs
%description
[Description]
%prep
echo "in prep"
echo $(ls -al)
%setup -c
npm install
yes | ./compile_all.sh
mv app/index.html app/index_big.html
mv app/index_small.html app/index.html
%build
echo "Nothing to build!"
%install
mkdir -p /opt/project
mv -r ./ /opt/project
ln -s /opt/project/server_start /usr/local/bin
ln -s /opt/project/server_stop /usr/local/bin
%files
$DIR/rpmbuild/SOURCES
$DIR/rpmbuild/SPECS
EOL
HOME=`pwd` rpmbuild -bs $DIR/rpmbuild/SPECS/specfile
The compile_all.sh script just minifies the html, css, and javascript and concatenates them. index_small.html uses the smaller versions. $DIR points to the location of the script, which is one directory above the project code.
The script does indeed generate the source rpm. I've looked at it using mc, and inside CONTENTS.cpio there's the specfile and the tgz archive of the source code. However, trying to install doesn't work. With rpm -Vp project.rpm, I can see that it lists the specfile and the tgz archive as missing. With verbose mode enabled, I see something similar to:
Directories not explicitly included in package:
/home/USERNAME/rpmbuild/SPECS/
/home/USERNAME/rpmbuild/SOURCES`
My rpmbuild directory isn't in my home directory, it's in the same directory as the build script. This leads to my actual question: how can I point rpmbuild at the correct location?

How to set the rpmbuild destination folder

I noticed rpmbuild (-bb and --buildroot options) creates the .rpm in different locations depending of what OS are you using:
GNU/Linux Ubuntu <= 9.04: /usr/src/rpm/...
GNU/Linux Ubuntu >= 9.10: /home/rpmbuild/...
GNU/Linux Fedora: /usr/src/redhat/...
So how can I set manually the destination folder for all OS?
Replying myself, adding:
%define _rpmdir /outputdir
to .spec file.
You may want to use the command argument --define : For example, this will send the rpm files into the current directory.
rpmbuild anything.spec --bb --define "_rpmdir $(pwd)"
This will send the rpmsto output dir
rpmbuild anything.spec --bb --define "_rpmdir /outputdir"
Or perhaps something more complicated such as Custom gradle task for rpmbuild .
For me the solution was to set _topdir to a subdirectory called rpmbuild inside my project. I also set a few macros, to control the .rpm path:
rpm:
rpmbuild -bb package.spec -D "_topdir $(shell pwd)/rpmbuild" -D "SRC $(shell pwd)" -D "NAME $(NAME)" -D "ARCH $(ARCH)" -D "VERSION $(VERSION)" -D "RELEASE $(RELEASE)"
mv rpmbuild/RPMS/$(ARCH)/$(NAME)-$(VERSION)-$(RELEASE).$(ARCH).rpm ./
rm -rf rpmbuild
Then I use make to generate the .rpm file and move it. I prefer rpmbuild to operate inside its directory.
make rpm
package.spec is using these macros, e.g.
Name: %{NAME_PACKAGE}
Setting up the rpmbuild environment in /home/ http://www.linuxquestions.org/questions/linux-software-2/need-rpm-package-for-php-version-5-2-7-and-up-on-redhat-5-1-a-766486/#13
Actually it is not recommended to use /usr/src/**. I.e. by using /home/[name]/rpms/ you can work as unprivileged user. No su or sudo is required to build packages.
Just a tiny comment..
adding "%define _rpmdir /outputdir" to spec file is also support by rpmbuild in AIX OS