Sponsored Content
Top Forums Shell Programming and Scripting Help understanding makefile: static pattern rules Post 302829839 by drl on Saturday 6th of July 2013 08:07:23 AM
Old 07-06-2013
Hi.

I think you are reporting the use of a static rule, followed by an implicit rule. If you run make on the Makefile as described at Static Usage - GNU `make' , then I think you will generate the object files foo.o and bar.o. If you then run make foo the implicit rule will be invoked, and you will get the executable foo, as noted here:
Code:
#!/usr/bin/env bash

# @(#) s1	Demonstrate static GNU make rule.
# See:
# http://www.gnu.org/software/make/manual/html_node/Static-Usage.html#Static-Usage

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C make

FILE=${1-Makefile}

pl " Input data file $FILE:"
head $FILE

rm -f *.o foo bar
pl " Results for running command \"make\":"
make

pl " Results for running command \"make foo\":"
make foo

rm -f *.o foo bar
pl " Results for running command \"make foo\", no extant .o files:"
make foo

exit 0

producing:
Code:
$ ./s1 

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0.8 (lenny) 
bash GNU bash 3.2.39
make GNU Make 3.81

-----
 Input data file Makefile:
objects = foo.o bar.o

all: $(objects)

$(objects): %.o: %.c
	$(CC) -c $(CFLAGS) $< -o $@


-----
 Results for running command "make":
cc -c  foo.c -o foo.o
cc -c  bar.c -o bar.o

-----
 Results for running command "make foo":
cc   foo.o   -o foo

-----
 Results for running command "make foo", no extant .o files:
cc -c  foo.c -o foo.o
cc   foo.o   -o foo

Best wishes ... cheers, drl
This User Gave Thanks to drl For This Post:
 

10 More Discussions You Might Find Interesting

1. Programming

Understanding this Makefile

I have this program which has lots of source files in the directories src src/dir1 src/dir2 src/dir3... and so on I am trying to understand the following Makefile: CC = gcc CFLAGS= -g -c -D_REENTRANT SOURCES = src/main.c src/dir1/a.c src/dir1/b.c src/dir2/x.c src/dir2/y.c ...and so on... (5 Replies)
Discussion started by: the_learner
5 Replies

2. UNIX for Advanced & Expert Users

Priority of rules in Makefile!!!

Consider in a makefile i have the target defined as: pgm: a.o b.o cmd; To build .o, 2 rules are defind .pc.o: cmds .c.o: cmds My question is which rule will take priority for compiling a.o and b.o when the target pgm is built. Despite the positoning of the 2 rules, .c.o... (1 Reply)
Discussion started by: quintet
1 Replies

3. Shell Programming and Scripting

How to change a Makefile from building static library to shared library?

Hi: I have a library that it only offers Makefile for building static library. It built libxxx.a file. How do I in any way build a shared library? (either changin the Makefile or direct script or command to build shared library) Thanks. (1 Reply)
Discussion started by: cpthk
1 Replies

4. IP Networking

I need HELP to Set up Coyote Linux router with 1 static IP & 64 internal static IP

hello, i need help on setting my coyote linux, i've working on this for last 5 days, can't get it to work. I've been posting this message to coyote forum, and other linux forum, but haven't get any answer yet. Hope someone here can help me...... please see my attached picture first. ... (0 Replies)
Discussion started by: dlwoaud
0 Replies

5. Programming

Adding a Static Library (libtimer.a) to the Makefile

Hi, The following is my Makefile, I wanted to add a staic library named libtimer.a. I'm using the following Makefile. Please let me know how to add this static library: Makefile:- It produces "usbserial" executable. Thanks, S (1 Reply)
Discussion started by: suryaemlinux
1 Replies

6. Programming

Static and Shared Library in Makefile

I am having a devil of a time with a very simple make file. The program needs two shared and one static library. If I link the shared libraries only like below the mysql test app works ... (1 Reply)
Discussion started by: jadsys
1 Replies

7. Programming

Even the Static cURL Library Isn't Static

I'm writing a program which uses curl to be run on Linux PCs which will be used by a number of different users. I cannot make the users all install curl on their individual machines, so I have tried to link curl in statically, rather than using libcurl.so. I downloaded the source and created a... (8 Replies)
Discussion started by: BrandonShw
8 Replies

8. Shell Programming and Scripting

Understanding pattern matching used in a grep command

I have the following code. I want to remove the --sort=num/num/... and am using grep to exclude it as shown below: I have a bit of problem figuring out the use of - at the front echo "--sort=4/5/6" | grep -ivE '-((sort|group)=+/+(/+)*)$' Now suppose I want to remove --quiet I can... (7 Replies)
Discussion started by: kristinu
7 Replies

9. Programming

Need help changing a makefile to static linking

Hi all, I'm having a hard time compiling a plugin (softhddevice) for the video disk recorder software (vdr). Unfortunately the last official version of the plugin was published back in 2013 and even worse it has to be compiled against ffmpeg. The last working version of ffmpeg was 2.8.x,... (0 Replies)
Discussion started by: ACorner
0 Replies

10. UNIX for Beginners Questions & Answers

Help understanding a line in makefile

I have a big makefile that I am trying to get my head around, this line is what is confusing me. LDFLAGS = -Wl,-rpath-link,$(SYSROOT)/lib/arm-linux-gnueabihf,-rpath-link,$(SYSROOT)/usr/lib/arm-linux-gnueabihf --sysroot=$(SYSROOT) -L$(SYSROOT)/lib -L$(SYSROOT)/usr/lib... (5 Replies)
Discussion started by: sesefsefs
5 Replies
Devel::BeginLift(3pm)					User Contributed Perl Documentation				     Devel::BeginLift(3pm)

NAME
Devel::BeginLift - make selected sub calls evaluate at compile time SYNOPSIS
use Devel::BeginLift qw(foo baz); use vars qw($i); BEGIN { $i = 0 } sub foo { "foo: $_[0] "; } sub bar { "bar: $_[0] "; } for (1 .. 3) { print foo($i++); print bar($i++); } no Devel::BeginLift; print foo($i++); outputs - foo: 0 bar: 1 foo: 0 bar: 2 foo: 0 bar: 3 foo: 4 DESCRIPTION
Devel::BeginLift 'lifts' arbitrary sub calls to running at compile time - sort of a souped up version of "use constant". It does this via some slightly insane perlguts magic. import use Devel::BeginLift qw(list of subs); Calls Devel::BeginLift->setup_for(__PACKAGE__ => @list_of_subs); unimport no Devel::BeginLift; Calls Devel::BeginLift->teardown_for(__PACKAGE__); setup_for Devel::BeginLift->setup_for($package => @subnames); Installs begin lifting magic (unless already installed) and registers "${package}::$name" for each member of @subnames to be executed when parsed and replaced with its output rather than left for runtime. teardown_for Devel::BeginLift->teardown_for($package); Deregisters all subs currently registered for $package and uninstalls begin lifting magic is number of teardown_for calls matches number of setup_for calls. setup_for_cv $id = Devel::BeginLift->setup_for_cv(&code); Same as "setup_for", but only registers begin lifting magic for one code reference. Returns an id to be used in "teardown_for_cv". teardown_for_cv Devel::BeginLift->teardown_for_cv($id); Deregisters begin lifting magic referred to by $id. AUTHOR
Matt S Trout - <mst@shadowcatsystems.co.uk> Company: http://www.shadowcatsystems.co.uk/ Blog: http://chainsawblues.vox.com/ LICENSE
This library is free software under the same terms as perl itself perl v5.14.2 2012-04-22 Devel::BeginLift(3pm)
All times are GMT -4. The time now is 12:49 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy