What does this line do in this GNU Makefile

Pulling out a snippet of code from a GNU Makefile, what exactly do these lines of code do.  Please explain line-by-line.
========================================
create_tilt_heading: Makefile $(CREATE_TILT_HEADING_DOTO)
      $(LD) -o $@ $(LDFLAGS) $(CREATE_TILT_HEADING_DOTO) $(LIBS)

Where:

CREATE_TILT_HEADING_DOTO = \
  cfar.o cmdlineopts.o dtime.o endian_utils.o fft.o file_utils.o \
  create_tilt_heading.o math_utils.o scan_params_file.o snr_sort.o

create_tilt_heading.o: create_tilt_heading.c Makefile $(DOTH) $(DOTL)
      $(CC) -c $(CFLAGS) -o $@ $<

DOTH = \
  Covmat.h Propmode.h Read_fft_data.h Readmode.h array_params.h cfar.h Rotate.h \
  cmdlineopts.h complex_divide.h complex_mult.h complex_sqrt.h complex_sum.h \
  data_types.h dtime.h endian_utils.h fft.h file_utils.h lss_file_header.h lss_file_header_legacy_defs.h \
  math_utils.h min_max.h my_printf.h params.h proc_params.h raw_ts.h \
  scan_params_file.h snr_sort.h standard.h tps.h types.h trigtbl.h

DOTL = \
  scan_params_file.l

CC           = gcc

CFLAGS       = -Wall $(ADDL_CFLAGS) -I$(TOMCRYPT)/src/headers

ADDL_CFLAGS  = -O3 -g # -std=c99 # -pg

TOMCRYPT     = /export/home/LSS_TOOLS/TOM/libtomcrypt-1.16

LD           = $(CC)

LDFLAGS      = $(CFLAGS) -L/usr/local/lib -L$(TOMCRYPT)

LIBS         = -lfl -lm -ltomcrypt
VWrestle97Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Duncan RoeSoftware DeveloperCommented:
You asked about:

create_tilt_heading: Makefile $(CREATE_TILT_HEADING_DOTO)
      $(LD) -o $@ $(LDFLAGS) $(CREATE_TILT_HEADING_DOTO) $(LIBS)

The make command works with targets. The final program you want to make is a target, but so are many intermediate files, such as those with a name ending .o. In general, targets depend on a list of files  (input files or other targets). These files are called the target's dependencies.  The way the target depend on them is, that if any of the dependencies are more recently modified than the target then the target must be re-made. After that it will be more recently modified than any of its dependencies, so will be "up to date".

The purpose of make is to build or rebuild one or more targets using as few commands as possible (e.g. as few compiler invocations as possible). The alternative would be a shell script that always re-compiles everything, but that would get frustratingly slow for a large system, especially if you'd only changed one component of it.

The line you ask about is telling make how to make the "create_tilt_heading" target. Make can tell it is doing that rather than say defining a macro called create_tilt_heading, because the operator in the line is : (colon) (and not = or := as it would be for a macro definition).

After the colon comes a list of create_tilt_heading's dependencies. The slightly unusual feature is the the Makefile is itself a dependency. What that is saying to make is "if the Makefile has been modified since create_tilt_heading was last built, you must rebuild create_tilt_heading". The last change to Makefile could have made a difference to the way create_tilt_heading is built. It might not have done of course, but there's no easy way of telling so we have the rule.
The rest of the dependencies are a list of object (.o) files. These are created by compiling source files. It's usual to specify .o files as dependencies rather than source files (.c files say) because you otherwise would be re-compiling all your .c files every time you changed just one of them. The .o file is an example of an intermediate target as I mentioned earlier: make has built-in rules to generate them from most language suffices. Being targets, make will check their time last modified against that of the relevant source file.

The second line tells make what command to use to build the create_tilt_heading target. Make will skip the command if create_tilt_heading was already up to date as described above. That is how make minimizes the number of commands to create the eventual target(s).
You can't easily see, but this line *must* start with a tab character. That is how make differentiates it from being another dependency line or macro definition. "cat -A Makefile" will show you the tabs.
The special Make argument $@ expands to the target being created. (There is also a special target $^ which expands to all the dependencies, but that can't be used here because the dependencies include Makefile).
So, the second line expands to:

  gcc -o create_tilt_heading -Wall  -O3 -g -I/export/home/LSS_TOOLS/TOM/libtomcrypt-1.16/src/headers -L/usr/local/lib -L/export/home/LSS_TOOLS/TOM/libtomcrypt-1.16  cfar.o cmdlineopts.o dtime.o endian_utils.o fft.o file_utils.o create_tilt_heading.o math_utils.o scan_params_file.o snr_sort.o -lfl -lm -ltomcrypt

2 things to note:

1. The line "ADDL_CFLAGS  = -O3 -g # -std=c99 # -pg" contains a comment (first # sign and everything following) so expands to "-O3 -g"
2.
create_tilt_heading.o: create_tilt_heading.c Makefile $(DOTH) $(DOTL)
      $(CC) -c $(CFLAGS) -o $@ $<
is itself a rule telling make how to produce create_tilt_heading.o. See if you can now work out what it does.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VWrestle97Author Commented:
Can you please provide me more explanation on the following lines?

>> -Wall  -O3 -g -I/export/home/LSS_TOOLS/TOM/libtomcrypt-1.16/src/headers

This is as much as I understand - and please correct me if I am wrong - "-Wall -03 -g" displays all warnings at level 3 of all warnings/errors during the debuging process that is executed when Make builds the create_tilt_heading target.  If -g was removed from this command, then would that stop all warnings/errors from being displayed?  And what is the significance of the -I include statement; is that where the header files of DOTH is supposed to be stored, and the "src" folder in that path where the source files for those header files supposed to be stored for the command to find the files that need to be compiled?  And should that "export" folder be in the same folder as where my Makefile is stored?  Does all my .c files belong in the "src" folder or can it also exsist in the same folder with my Makefile?  And where should I put my .l file?

>> -L/usr/local/lib
I know that -L is to shcek symlink times, but it is not clear to me why it is needed.  Also, exactly what type of files should be stored in lib... or why does it need this command?

>> -L/export/home/LSS_TOOLS/TOM/libtomcrypt-1.16
Is this just another path that has files that the command "-Wall -03 -g" needs to compile to create the target?

>>lfl -lm -ltomcrypt
I think this has something to do with flex, but still not clear how it is used or it's purpose.  Please exlpain further.
0
Duncan RoeSoftware DeveloperCommented:
These are options to the GNU C compiler, gcc. You should have the entire gcc manual installed on your system - accessed by the command "info gcc". Also "man gcc" will tell you briefly about all gcc's options. In brief and from memory:

-Wall - turn on all common warnings

-O3 - optimization level 3. This is a moderately high level of optimization

-g - compile for debugging with the GNU source-level debugger gdb. Gdb does work with optimized programs, but results can be confusing to the novice (and others:)

-I/export/home/LSS_TOOLS/TOM/libtomcrypt-1.16/src/headers - tells gcc to look in /export/home/LSS_TOOLS/TOM/libtomcrypt-1.16/src/headers for files mentined in #include lines (as well as the usual place /usr/include)

-L/usr/local/lib - tells gcc's loader to look for library files in /usr/local/lib when building executables (as well as the usual place /usr/lib)

-L/export/home/LSS_TOOLS/TOM/libtomcrypt-1.16 - another place where gcc's loader should look for library files (generally file with suffices .a or .so)

-lfl -lm -ltomcrypt - these are library arguments to gcc's loader.
   -lfl means "load the library called libfl (.a or .so) - on my system it will find /usr/lib/libfl.a)
   -lm  - load libm - finds /usr/lib/libm.so which is a symbolic link to /lib/libm.so.6
   -ltomcrypt - load libtomcrypt which I don't have but on your system is probably in /export/home/LSS_TOOLS/TOM/libtomcrypt-1.16

===============================================================================

Ok you asked for an explanation of a couple of lines in a Makefile and I hope I've given you that. Feel free to ask any more questions you have.
But ... what are you trying to do? Simply use libtomcrypt? Put you application code wherever you like in that case - but NOT in libtomcrypt-1.16/src - it simply doesn't belong there
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

VWrestle97Author Commented:
I am trying to take someone else's code that was designed to run on Linux, and I am moving it to run on a Windows XP computer with Cygwin.  I am having trouble getting the Makefile to complete the process due to an "undeclared identifier" and I was thinking it is because the files are not in a location where the Makefile can find them.

The libtomcrypt library is supposed to build into another set of C code that uses the libtomcrypt.  Are you familiar with libtomcrypt?  

>>tells gcc to look in /export/home/LSS_TOOLS/TOM/libtomcrypt-1.16/src/headers for files mentined in #include lines (as well as the usual place /usr/include)

Does this mean that as long as all the header files of "DOTH" (or all the projects .C files that have include <xxxx.h> and include "xxxx.h" in the code) are stored in /usr/include, then I don't need to store them in /export/home/LSS_TOOLS/TOM/libtomcrypt-1.16/src/headers anymore?  The header files that need to be included in these locations, are they only limited to the files associated with the target or should I put all of the projects header files in the specified location?

What about the DOTL = scan_params_file.l; where is this file supposed to go?



0
Duncan RoeSoftware DeveloperCommented:
I am not familiar with libtomcrypt, but I just downloaded it to have a look.
Please post the *exact* error message you are getting (some lines of output before and after would help too), also the output from "make --version" on your system and if possible also on the system where the Makefile ran OK.
The difference between #include <xxxx.h> and #include "xxxx.h" is that the one with double-quotes will look in the current directory. -I affects them both. Yes you could put everything in /usr/include but I would caution against that - it's really not what you are supposed to do. IN BRIEF: LEAVE THEM WHERE THEY ARE

I see you're not asking about some lines from and makefile in libtomcrypt, which is just another library you need to build, install and use.

scan_params_file.l ( I assume pronounced "scan_params_file.ell) is an input file to lex, or possibly flex (which stands for [fast] LEXival analyzer generator). Type "man lex" or "man flex" to see what it does. The output from lex is C code which then has to be compiled. The file may well be in the same directory as the other source files but I can't say for sure.

Does the package you are asking about have a configure script? Did you run it under Cygwin? If you copied the package from Linux, did you run "make distclean" first?

What package are you trying to build actually?
0
VWrestle97Author Commented:
>>the *exact* error message you are getting (some lines of output before and after would help too)

==============================================
$ make
gcc -c -Wall -O3 -g  -I/export/home/TOOLS/TOM/libtomcrypt-1.16/src/headers -
o scan_params_file.o scan_params_file.c
scan_params_file.l: In function `range_check':
scan_params_file.l:212: warning: int format, uint32_t arg (arg 4)
scan_params_file.l:212: warning: int format, uint32_t arg (arg 4)
scan_params_file.l: In function `scan_params_file':
.
.
.
scan_params_file.l:900: error: `MAXINT' undeclared (first use in this function)
scan_params_file.l:900: error: (Each undeclared identifier is reported only once

scan_params_file.l:900: error: for each function it appears in.)
scan_params_file.l:908: warning: int format, uint32_t arg (arg 4)
scan_params_file.l:908: warning: int format, uint32_t arg (arg 4)
scan_params_file.l:919: warning: int format, uint32_t arg (arg 4)
scan_params_file.l:919: warning: int format, uint32_t arg (arg 6)
.
.
.
scan_params_file.l:2232: warning: int format, uint32_t arg (arg 4)
scan_params_file.l:2232: warning: int format, long int arg (arg 7)
scan_params_file.l:2244: warning: int format, uint32_t arg (arg 4)
scan_params_file.l:2244: warning: int format, uint32_t arg (arg 4)
.
.
.
scan_params_file.l:2302: warning: unsigned int format, uint32_t arg (arg 3)
scan_params_file.l:2302: warning: unsigned int format, uint32_t arg (arg 4)
scan_params_file.l:2302: warning: unsigned int format, uint32_t arg (arg 3)
scan_params_file.l:2302: warning: unsigned int format, uint32_t arg (arg 4)
scan_params_file.l:2305: warning: int format, uint32_t arg (arg 4)
scan_params_file.l:2305: warning: int format, uint32_t arg (arg 4)
scan_params_file.l:2308: warning: int format, uint32_t arg (arg 4)
scan_params_file.l:2308: warning: int format, uint32_t arg (arg 6)
.
.
.
scan_params_file.l: At top level:
scan_params_file.c:6925: warning: 'yyunput' defined but not used
make: *** [scan_params_file.o] Error 1
==================================================================

>> the output from "make --version" on your system

$ make -version
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 i686-pc-cygwin


>> and if possible also on the system where the Makefile ran OK.

Sorry, I don't have access to that computer

>> have a configure script? Did you run it under Cygwin?

What do you mean by "configure script"?  This program ran under Linux but I don't know if it ever ran on Cygwin; but I am currently trying to run it on a Windows XP computer with Cygwin installed.  

If you copied the package from Linux, did you run "make distclean" first?

$ make distclean
make: *** No rule to make target `distclean'.  Stop.

$ make clean
rm -f *.[o]

After the "make clean", running make still gives me the same error.

I am trying to build a package that takes in data from an external Hard-drive and decrypts the data so it can be analyzed on Matlab.
0
olehbCommented:
Currently you have only one simple error: in scan_params_file function MAXINT identifier is used. In Linux it's a macros defined in system headers. Basically you have 2 choices:
1. Include appropriate system header in scan_params_file.c
grep MAXINT /usr/include/*
/usr/include/values.h:#define   MAXINT          INT_MAX

put in scan_params_file.c
#include <values.h>

2. put that macros directly in scan_params_file.c before it is used
#ifndef MAXINT
#define MAXINT 2147483647
#endif /** MAXINT **/
0
olehbCommented:
I meant in a scan_params_file function MAXINT identifier is used while it is not defined.
0
Duncan RoeSoftware DeveloperCommented:
>> What do you mean by "configure script"?
You asked about a GNU Makefile originally and if the Makefile had come from a GNU package then there would likely have been a configure script in there as well. But that's not the case so don't worry about it.

You should really raise a separate question for your lex problem, now it is determined that is what you have. You asked originally about the meaning of lines in a Makefile and that Q is answered. I asked for the error message to verify whether there was a problem with the Makefile and there isn't one. Lex is a whole other ball game.

If you can see MAXINT  in scan_params_file.l then I would replace it with INT_MAX. Otherwise I think you can put #includes in a .l file but they have to be in an area delimited by lines "%{" and "%}".  scan_params_file.l may already have such an area, else you'll need to make one.
0
VWrestle97Author Commented:
I added the include lines into scan_params_file.l just as you recommended as shown below but didn't work, why?  

So I then replace INT_MAX and now it works, but now I am getting another error when I run "make"; it looks like the error occurs when the make gets to the sub-target "make create_tile_heading".  Why am I getting this error if "TOMCRYPT = /export/home/TOOLS/TOM/libtomcrypt-1.16" is declared in my Makefile and the path exists on my computer?

gcc -o create_tilt_heading -Wall -O3 -g  -I/export/home/TOOLS/TOM/libtomcryp
t-1.16/src/headers -L/usr/local/lib -L/export/home/TOOLS/TOM/libtomcrypt-1.1
6 cfar.o cmdlineopts.o dtime.o endian_utils.o fft.o file_utils.o create_tilt_hea
ding.o math_utils.o scan_params_file.o snr_sort.o -lfl -lm -ltomcrypt
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/ld: cannot find
 -ltomcrypt
collect2: ld returned 1 exit status
make: *** [create_tilt_heading] Error 1
==========================================
%{

/* RCS patterns
 *   $Id: $
 *   $Revision: $
 */

#include <sys/types.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

/* added to fix MAXINT undeclared error */
#include <ldap.h>
#include <usb.h>

.
.
.
%}
=======================================
0
olehbCommented:
Well, you have passed 1st stage, code is compiled, and now you have linker error (ld - the GNU linker).
"ld: cannot find -ltomcrypt" means linker can't find tomcrypt library. Either you have not installed it or linker doesn't know path to it. Most probably it is not installed in your system so you have to fix that and there are 2 way, easy and hard. If there is compiled package in cygwin then you have to download, build, and install it by yourself. To check if it is reachable by ld use a following command (print all known shared libs in a system and filter tomcrypt):

ldconfig -p| grep  tomcrypt
0
VWrestle97Author Commented:
$ ldconfig -p|grep tomcrypt
bash: ldconfig: command not found

Can you please tell me more about the compiled package?  I think I may need more help with this.
0
VWrestle97Author Commented:
I installed all packages that Cygwin offers using their Setup.exe version 2.573.2.2 and selected from one of their downloading URL sites.  I couldn't find a linker.  I don't think Cygwin offers the command for "ldconfig".  

So, which way is the hard way?
0
olehbCommented:
I used Cygwin years ago, now I use only pure Linux development so it's not easy to explain all nuances. Hard way is to download http://libtom.org/files/crypt-1.17.tar.bz2 , compile and install it on a cygwin box. IMHO it will be not an easy task even for seasoned developer as I skimmed their changelog a little and found following comment:
-- Removed "makefile.cygwin_dll" as it's not really used by anyone and not worth the effort (hell I hardly maintain the MSVC makefiles ...)
0
Duncan RoeSoftware DeveloperCommented:
The standard libtomcrypt build just builds a static (.a) library, you should be fine with that even under Cygwin. As root:

mkdir -p /export/home/TOOLS/TOM
cd /export/home/TOOLS/TOM
tar -xjf  ~/crypt-1.17.tar.bz2     # Assumes you downloaded to your home dir; else supply path
cd libtomcrypt-1.17                  # If this fails, ls to see what directory was created and cd there
make                                          # Will make libtomcrypt.a

In your Makefile, change references to libtomcrypt-1.16 to be to libtomcrypt-1.17

make should now find libtomcrypt
0
VWrestle97Author Commented:
Ok, I did a "make" for libtomcrypt-1.17 as you specified and made 1.16 1o 1.17 change in my Makefile, But still getting the same error when I "make" my Makefile.  Why wouldn't it create libtomcrypt.a in /lib?
==================================
scan_params_file.l: At top level:
scan_params_file.c:6827: warning: 'yyunput' defined but not used
gcc -c -Wall -O3 -g  -I/export/home/TOOLS/TOM/libtomcrypt-1.17/src/headers -
o snr_sort.o snr_sort.c
gcc -o create_tilt_heading -Wall -O3 -g  -I/export/home/TOOLS/TOM/libtomcryp
t-1.17/src/headers -L/usr/local/lib -L/export/home/TOOLS/TOM/libtomcrypt-1.1
7 cfar.o cmdlineopts.o dtime.o endian_utils.o fft.o file_utils.o create_tilt_hea
ding.o math_utils.o scan_params_file.o snr_sort.o -lfl -lm -ltomcrypt
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/ld: cannot find
 -ltomcrypt
collect2: ld returned 1 exit status
make: *** [create_tilt_heading] Error 1
===================================
0
Duncan RoeSoftware DeveloperCommented:
Try this:

cd /export/home/TOOLS/TOM/libtomcrypt-1.17
ls -ltr

What are the most recently generated files? (They should still be visible on the screen)

Also, see what makefiles are available:

ls Ma* ma*

in 1.16, the default makefile was for linux to make a .a and there was another makefile for linux to make a .so

You don't want to make a .so (Cygwin uses Microsoft dll's AFAIK). A .a should work though. Also see if you can make a .a in libtomcrypt-1.16 (change your Makefile back if you can).
0
VWrestle97Author Commented:
These are the results:

paez@fc498817526740e /home/morestuff/tools/lss17/export/home/tools/tom
$ ls -ltr -al
total 3440
-rwx------+ 1 paez None 1919172 Sep 11 15:05 libtomcrypt-1.16.tgz
drwx------+ 7 paez None       0 Jan 22 17:38 libtomcrypt-1.16
-rwx------+ 1 paez None 1599215 Jan 29 09:12 crypt-1.17.tar.bz2
drwx------+ 7 paez None       0 Jan 29 09:40 libtomcrypt-1.17
drwx------+ 3 paez None       0 Jan 29 09:49 ..
drwx------+ 4 paez None       0 Jan 29 09:49 .

paez@fc498817526740e /home/morestuff/tools/lss17/export/home/ltools/tom
$ ls Ma* ma*
ls: cannot access Ma*: No such file or directory
ls: cannot access ma*: No such file or directory

>>see if you can make a .a in libtomcrypt-1.16 (change your Makefile back if you can).

I also tried to make "libtomcrypt-1.16" and then make on my project, but no .a file was found in /lib
0
VWrestle97Author Commented:
Just in case you wanted to know for the more generic path:
=======================================
paez@fc498817526740e /home/morestuff/tools/lss17
$ ls Ma* ma*
Makefile            main_beamforming_3d.c  main_mfp_th_az_file.c   math_utils.h
Makefile_new        main_mfp_bft.c         main_mfp_th_az_file2.c  math_utils.o
Makefile_old        main_mfp_bft_th.c      main_mfp_th_xyz.c
main_beamforming.c  main_mfp_th_adr.c      math_utils.c
=======================================
0
Duncan RoeSoftware DeveloperCommented:
You did the ls commands one level too high. I said cd /export/home/TOOLS/TOM/libtomcrypt-1.17 and you only did cd /export/home/TOOLS/TOM. Try again, there should be lots of files starting ma. For comparison, try the .16 directory as well. Type "make clean" before typing make, the linux binaries may not be suitable.
0
VWrestle97Author Commented:
Thanks for the help.  I got the program working.  I was actually waiting for a response from the  EE community because I would like to give everyone more points than splitting just 500 pts.  I want to wait another day to hear back from them.  If I don't, I guess I will just have to split the 500pts.
0
VWrestle97Author Commented:
Thank you for the help!  I wish I could give more but I was told that is against the rules.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Software

From novice to tech pro — start learning today.