How to create makefile for compiling multiple programs - makefile

I have some problems with creating makefile. I have tried to compile some files from terminal and found right options for gcc to do this.
But I have some troubles with creating one makefile to do all this tasks.
Here are my commands that work.
gcc -c pstree.c -DHAVE_CONFIG_H -I.
gcc -o hello pstree.o -L/usr/lib/ -ltinfo
gcc -c fuser.c -DHAVE_CONFIG_H -I.
gcc -c -o libsignals.a signals.c
gcc -o hello fuser.o -L/usr/lib/ -L. -lsignals
gcc -c -o libsignals.a signals.c
gcc -o hello killall.o -L/usr/lib/ -L. -lsignals
gcc -c killall.c -DHAVE_CONFIG_H -I.
How can I make a Makefile for executing these commands?

killall: hello\ fuser.o
gcc -c -o libsignals.a signals.c
gcc -o hello killall.o -L/usr/lib/ -L. -lsignals
gcc -c killall.c -DHAVE_CONFIG_H -I.
fuser: hello\ pstree.o
gcc -c fuser.c -DHAVE_CONFIG_H -I.
gcc -c -o libsignals.a signals.c
gcc -o hello\ fuser.o -L/usr/lib/ -L. -lsignals
pstree:
gcc -c pstree.c -DHAVE_CONFIG_H -I.
gcc -o hello\ pstree.o -L/usr/lib/ -ltinfo
clean:
rm -rf *.o
I wrote very very dirty you can define cc variable such as:
CC = gcc
CFLAGS = -g -Wall -I.
LIBS = -L/usr/lib/ -lsignals
and so on.....
Mine is very dirty ....
NOTE: Before each line of intending you have to use TAB, not space.
usage :
make clean
make killall

Related

Manually link two targets

I am trying to convert a (sloppy) Makefile into a CMakeLists.txt to better work with my IDE (CLion).
My Makefile is as follows:
all:
gcc -MD -fno-builtin -nostdinc -fno-stack-protector -Os -g -m32 -I. -c -o bin/boot0.o boot/boot0/boot0.S
ld -nostdlib -m elf_i386 -N -e start -Ttext 0x7c00 -o bin/boot0.elf bin/boot0.o
objcopy -S -O binary bin/boot0.elf bin/boot0
gcc -MD -fno-builtin -nostdinc -fno-stack-protector -Os -g -m32 -I. -c -o bin/boot1.o boot/boot1/boot1.S
gcc -MD -fno-builtin -nostdinc -fno-stack-protector -Os -g -m32 -I. -c -o bin/boot1main.o boot/boot1/boot1main.c
gcc -MD -fno-builtin -nostdinc -fno-stack-protector -Os -g -m32 -I. -c -o bin/boot1lib.o boot/boot1/boot1lib.c
gcc -MD -fno-builtin -nostdinc -fno-stack-protector -Os -g -m32 -I. -c -o bin/exec_kernel.o boot/boot1/exec_kernel.S
ld -nostdlib -m elf_i386 -N -e start -Ttext 0xd7000 -o bin/boot1.elf bin/boot1.o bin/boot1main.o bin/boot1lib.o bin/exec_kernel.o
objcopy -S -O binary bin/boot1.elf bin/boot1
gcc -MD -fno-builtin -nostdinc -fno-stack-protector -D_KERN_ -Ikern -Ikern/kern -I. -m32 -O0 -c -o bin/entry.o kern/init/entry.S
ld -o kernel -nostdlib -e start -m elf_i386 -Ttext=0x00100000 bin/entry.o -b binary
dd if=/dev/zero of=project0.img bs=512 count=256
parted -s project0.img "mktable msdos mkpart primary 63s -1s set 1 boot on"
dd if=bin/boot0 of=project0.img bs=446 count=1 conv=notrunc
dd if=bin/boo1 of=project0.img bs=512 count=62 seek=1 conv=notrunc
dd if=kern/init/kernel of=project0.img bs=512 seek=63 conv=notrunc
Mostly I am using make just to run the commands.
I am running into trouble with the fact that I have three different sets of linker flags (one each for boot0, boot1, and kern.)
Should I create separate CMakeLists.txt in each subdirectory (boot0, boot1, and kern) and then have a main one that runs each in turn and then handles the dd and parted usage, is there a better way to do this, or is CMake not an appropriate tool here?
Please have short-cuts for the compiler commands first. Then write the rule to create the first target on which the second target is dependent. Then since the first target is created; now use it to create the second target.

ChkTeX install not working on OSX 10.10.4

i tried to setup a latex linter in atom. The one I found was linter-chktex. For it to be working I have to install ChkTeX. So I have downloaded it here. But every time I'm trying to make i get the following error:
FindErrs.c:39:10: fatal error: 'pcreposix.h' file not found
Can someone explain to me how to get it working?
EDIT: I fixed this error by giving the full path of pcreposix.h after locating it. make does work now and here is the log:
gcc -M -I. -I. -DHAVE_CONFIG_H -DSYSCONFDIR=\"/usr/local/etc\" -D__unix__ Utility.c > .Utility.d.tmp
sed 's,\(Utility\)\.o *:,\1.o .Utility.d : Makefile,g' .Utility.d.tmp > .Utility.d
rm -f .Utility.d.tmp 2>/dev/null
gcc -M -I. -I. -DHAVE_CONFIG_H -DSYSCONFDIR=\"/usr/local/etc\" -D__unix__ Resource.c > .Resource.d.tmp
sed 's,\(Resource\)\.o *:,\1.o .Resource.d : Makefile,g' .Resource.d.tmp > .Resource.d
rm -f .Resource.d.tmp 2>/dev/null
gcc -M -I. -I. -DHAVE_CONFIG_H -DSYSCONFDIR=\"/usr/local/etc\" -D__unix__ OpSys.c > .OpSys.d.tmp
sed 's,\(OpSys\)\.o *:,\1.o .OpSys.d : Makefile,g' .OpSys.d.tmp > .OpSys.d
rm -f .OpSys.d.tmp 2>/dev/null
gcc -M -I. -I. -DHAVE_CONFIG_H -DSYSCONFDIR=\"/usr/local/etc\" -D__unix__ FindErrs.c > .FindErrs.d.tmp
sed 's,\(FindErrs\)\.o *:,\1.o .FindErrs.d : Makefile,g' .FindErrs.d.tmp > .FindErrs.d
rm -f .FindErrs.d.tmp 2>/dev/null
gcc -M -I. -I. -DHAVE_CONFIG_H -DSYSCONFDIR=\"/usr/local/etc\" -D__unix__ ChkTeX.c > .ChkTeX.d.tmp
sed 's,\(ChkTeX\)\.o *:,\1.o .ChkTeX.d : Makefile,g' .ChkTeX.d.tmp > .ChkTeX.d
rm -f .ChkTeX.d.tmp 2>/dev/null
gcc -I. -I. -DHAVE_CONFIG_H -DSYSCONFDIR=\"/usr/local/etc\" -D__unix__ -g -O2 -Wstrict-prototypes -Wall -I/usr/local/Cellar/pcre/8.37/include -c ChkTeX.c -o ChkTeX.o
gcc -I. -I. -DHAVE_CONFIG_H -DSYSCONFDIR=\"/usr/local/etc\" -D__unix__ -g -O2 -Wstrict-prototypes -Wall -I/usr/local/Cellar/pcre/8.37/include -c FindErrs.c -o FindErrs.o
gcc -I. -I. -DHAVE_CONFIG_H -DSYSCONFDIR=\"/usr/local/etc\" -D__unix__ -g -O2 -Wstrict-prototypes -Wall -I/usr/local/Cellar/pcre/8.37/include -c OpSys.c -o OpSys.o
gcc -I. -I. -DHAVE_CONFIG_H -DSYSCONFDIR=\"/usr/local/etc\" -D__unix__ -g -O2 -Wstrict-prototypes -Wall -I/usr/local/Cellar/pcre/8.37/include -c Resource.c -o Resource.o
gcc -I. -I. -DHAVE_CONFIG_H -DSYSCONFDIR=\"/usr/local/etc\" -D__unix__ -g -O2 -Wstrict-prototypes -Wall -I/usr/local/Cellar/pcre/8.37/include -c Utility.c -o Utility.o
gcc -L/usr/local/Cellar/pcre/8.37/lib -lpcreposix -lpcre -o chktex ChkTeX.o FindErrs.o OpSys.o Resource.o Utility.o -ltermcap
But as soon as I try to sudo make install this error appears:
no ChkTeX.tex
make: no: No such file or directory
make: *** [ChkTeX.dvi] Error 1
But the ChkTeX.tex is in the directory.
I just had the same problem.
Turns out make does not find the file no in your directory. no is the content of the LATEX variable in the Makefile, if ./configure did not find a LaTeX distribution.
If you set the LATEX variable to the path of your latex executable, you can run sudo make install without a problem.
In my case (El Capitan) I had to put
LATEX=/usr/local/texlive/2015/bin/x86_64-darwin/latex
on line 48 of the makefile, and thereby replace
LATEX=no
to make it work.

QtCreator can't use G++ for cross compiling. Must be a configuration issue

When I try to compile a code for VAR SOM AM33 using QTCreator I get this error:
c -pipe -g -Wall -W -D_REENTRANT -fPIE -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../buscaTexto -I. -I/opt/qt5devtools/sysroots/cortexa8t2hf-vfp-neon-oe-linux-gnueabi/usr/include/qt5 -I/opt/qt5devtools/sysroots/cortexa8t2hf-vfp-neon-oe-linux-gnueabi/usr/include/qt5/QtWidgets -I/opt/qt5devtools/sysroots/cortexa8t2hf-vfp-neon-oe-linux-gnueabi/usr/include/qt5/QtGui -I/opt/qt5devtools/sysroots/cortexa8t2hf-vfp-neon-oe-linux-gnueabi/usr/include/qt5/QtCore -I. -I. -I/opt/qt5devtools/sysroots/cortexa8t2hf-vfp-neon-oe-linux-gnueabi/usr/lib/qt5/mkspecs/linux-oe-g++ -o main.o ../buscaTexto/main.cpp
make: c: Command not found
QTCreator's qmake generates a Makefile including this:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o ../buscaTexto/main.cpp
And $(CXX) is defined as following:
CXX = $(OE_QMAKE_CXX)
I know this is wrong because when I compile this code for PC I haven't any error and the Makefile define CXX as following:
CXX = g++
So It runs:
g++ c -pipe -g -Wall -W -D_REENTRANT -fPIE -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../buscaTexto -I. -I/opt/qt5devtools/sysroots/cortexa8t2hf-vfp-neon-oe-linux-gnueabi/usr/include/qt5 -I/opt/qt5devtools/sysroots/cortexa8t2hf-vfp-neon-oe-linux-gnueabi/usr/include/qt5/QtWidgets -I/opt/qt5devtools/sysroots/cortexa8t2hf-vfp-neon-oe-linux-gnueabi/usr/include/qt5/QtGui -I/opt/qt5devtools/sysroots/cortexa8t2hf-vfp-neon-oe-linux-gnueabi/usr/include/qt5/QtCore -I. -I. -I/opt/qt5devtools/sysroots/cortexa8t2hf-vfp-neon-oe-linux-gnueabi/usr/lib/qt5/mkspecs/linux-oe-g++ -o main.o ../buscaTexto/main.cpp
The value of OE_QMAKE_CXX is defined in the file /opt/qt5devtools/sysroots/i686-arago-linux/environment-setup.d/qt5.sh as following:
export OE_QMAKE_CXX=$CXX
Makefile's header includes this:
# Command: /opt/qt5devtools/sysroots/i686-arago-linux/usr/bin/qt5/qmake -spec linux-oe-g++ CONFIG+=debug -o Makefile ../buscaTexto/buscaTexto.pro
the file /opt/qt5devtools/sysroots/cortexa8t2hf-vfp-neon-oe-linux-gnueabi/usr/lib/qt5/mkspecs/linux-oe-g++/qmake.conf defines:
QMAKE_CXX = $(OE_QMAKE_CXX)
but the file /opt/qt5devtools/sysroots/cortexa8t2hf-vfp-neon-oe-linux-gnueabi/usr/lib/qt5/mkspecs/linux-arm-gnueabi-g++/qmake.conf defines:
QMAKE_CXX = arm-linux-gnueabi-g++
I don't know why QtCreator uses linux-oe-g++ because I have configured all for using linux-arm-gnueabi-g++.
Can someone help me?
Thank you.
I've solved this issue. The solution is here:
http://wiki.wandboard.org/index.php/Setup_QT_creator_for_developing_QT_apps_on_wandboard

How to make automake less ugly?

I recently learned how to use automake, and I'm somewhat annoyed that my compile commands went from a bunch of:
g++ -O2 -Wall -c fileName.cpp
To a bunch of:
depbase=`echo src/Unit.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
g++ -DHAVE_CONFIG_H -I. -I./src -g -O2 -MT src/Unit.o -MD -MP -MF $depbase.Tpo -c -o src/Unit.o src/Unit.cpp &&\
mv -f $depbase.Tpo $depbase.Po
Is there any way to clean this up? I can usually easily pick out warning messages, but now the wall of text to read though is 3x bigger and much weirder.
I know what my flags are, so making it just says "Compiling xxx.cpp" for each file would be perfect.
As of automake 1.11, you can greatly clean up the output using the silent-rules option. For example:
$ # First, make without silent rules
$ make
make all-am
gcc -DHAVE_CONFIG_H -I. -g -O2 -MT foo.o -MD -MP -MF .deps/foo.Tpo -c -o foo.o foo.c
mv -f .deps/foo.Tpo .deps/foo.Po
/bin/sh ./libtool --tag=CC --mode=link gcc -g -O2 -o foo foo.o
libtool: link: gcc -g -O2 -o foo foo.o
gcc -DHAVE_CONFIG_H -I. -g -O2 -MT bar.o -MD -MP -MF .deps/bar.Tpo -c -o bar.o bar.c
mv -f .deps/bar.Tpo .deps/bar.Po
/bin/sh ./libtool --tag=CC --mode=link gcc -g -O2 -o bar bar.o
libtool: link: gcc -g -O2 -o bar bar.o
gcc -DHAVE_CONFIG_H -I. -g -O2 -MT baz.o -MD -MP -MF .deps/baz.Tpo -c -o baz.o baz.c
mv -f .deps/baz.Tpo .deps/baz.Po
/bin/sh ./libtool --tag=CC --mode=link gcc -g -O2 -o baz baz.o
libtool: link: gcc -g -O2 -o baz baz.o
gcc -DHAVE_CONFIG_H -I. -g -O2 -MT qux.o -MD -MP -MF .deps/qux.Tpo -c -o qux.o qux.c
mv -f .deps/qux.Tpo .deps/qux.Po
/bin/sh ./libtool --tag=CC --mode=link gcc -g -O2 -o qux qux.o
libtool: link: gcc -g -O2 -o qux qux.o
$ # Now, use the silent rules
$ ./configure --enable-silent-rules > /dev/null
$ make clean all
rm -f foo bar baz qux
rm -rf .libs _libs
rm -f *.o
rm -f *.lo
make all-am
CC foo.o
CCLD foo
CC bar.o
CCLD bar
CC baz.o
CCLD baz
CC qux.o
CCLD qux
All that is needed is to add "silent-rules" to the invocation
of AM_INIT_AUTOMAKE in configure.ac, and add the option
--enable-silent-rules when you invoke configure. (There
was much debate about requiring the option to be added
at configure time when this feature was added, and there
is an easy workaround to make it unnecessary.) Note that
with silent-rules enabled, you can still get verbose
output by running 'make V=1'
I did a bit of googling around as I am in the same boat, the autoconf tools do a nice job but it kind of wrecks your eyes when the text whizzes by and no way of knowing what was that about... here is a link to a blog that mentions a tool to do this and make it look like neater just like how you see a kernel build does the magic i.e.
Compiling foo.so
Linking foo.so
Here is another link to a tool that is called prettify automake.

Programming in Lua on OS X?

What can I use to program Lua script on Mac OS X? I'm looking for something that I can use to compile/interpret Lua script on OS X.
My preferred way:
brew install lua
Thanks, Max!
And if you need to know how to install Homebrew, see Link and:
/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
The Lua source easily compiles with no changes on the mac. It will build lua (the interpreter which can act on a source script, a pre-compiled script or interactively) and luac which can be used to pre-compile source scripts.
From the lua.org website: http://luabinaries.luaforge.net/download.html. The ones you want are the darwin binaries (they say Mac OS X in the description).
My favorite way (from the shell):
sudo port install lua
I LOVE macports!
Here is my terminal session from compiling and installing Lua from source, basically following these directions. I already had Apple's Developer Tools installed, and /usr/local/bin was already in my PATH, so I was able to skip some of the more time-consuming and/or tedious steps in the directions.
$ cd ~/Downloads
$ tar -xf lua-5.1.4.tar
$ cd lua-5.1.4
$ make macosx
cd src && make macosx
make all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-lreadline"
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lapi.o lapi.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lcode.o lcode.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o ldebug.o ldebug.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o ldo.o ldo.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o ldump.o ldump.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lfunc.o lfunc.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lgc.o lgc.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o llex.o llex.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lmem.o lmem.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lobject.o lobject.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lopcodes.o lopcodes.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lparser.o lparser.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lstate.o lstate.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lstring.o lstring.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o ltable.o ltable.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o ltm.o ltm.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lundump.o lundump.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lvm.o lvm.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lzio.o lzio.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lauxlib.o lauxlib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lbaselib.o lbaselib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o ldblib.o ldblib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o liolib.o liolib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lmathlib.o lmathlib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o loslib.o loslib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o ltablib.o ltablib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lstrlib.o lstrlib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o loadlib.o loadlib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o linit.o linit.c
ar rcu liblua.a lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o lstrlib.o loadlib.o linit.o
ranlib liblua.a
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lua.o lua.c
gcc -o lua lua.o liblua.a -lm -lreadline
gcc -O2 -Wall -DLUA_USE_LINUX -c -o luac.o luac.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o print.o print.c
gcc -o luac luac.o print.o liblua.a -lm -lreadline
$ make test
src/lua test/hello.lua
Hello world, from Lua 5.1!
$ sudo make install INSTALL_TOP=/usr/local
Password:
cd src && mkdir -p /usr/local/bin /usr/local/include /usr/local/lib /usr/local/man/man1 /usr/local/share/lua/5.1 /usr/local/lib/lua/5.1
cd src && install -p -m 0755 lua luac /usr/local/bin
cd src && install -p -m 0644 lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp /usr/local/include
cd src && install -p -m 0644 liblua.a /usr/local/lib
cd doc && install -p -m 0644 lua.1 luac.1 /usr/local/man/man1
$ lua
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> print "Hi"
Hi
> = 2 + 3
5
> ^c
$ cd test
$ lua factorial.lua
0! = 1
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5040
8! = 40320
9! = 362880
10! = 3628800
11! = 39916800
12! = 479001600
13! = 6227020800
14! = 87178291200
15! = 1307674368000
16! = 20922789888000
If you don't want to compile your own Lua binaries, you can try ZeroBrane Studio Lua IDE, which comes packaged as a .dmg file for OSX. It's an IDE that allows you to edit and debug your Lua scripts. If you are just starting with Lua, it also includes 50+ examples and demo scripts, as well as integrated instructions on running them, so you won't be facing an empty screen not knowing where to start.
I just recently found Rudix—a maintained collection of precompiled Unix software for Mac.
While I'm sure you've already figured out a way of installing Lua, I came across your question by Googling the same thing. For anyone that's interested, here's the link to a recent Lua 5.1.4 dmg.

Resources