Skip to contentSkip to conversation

Making "make" auto-strip and auto-clean

DISCUSSION Shriramana Sharma 4 participants 5 messages Feb 26, 2006

lore
Share & tools
lore
#0 lore raw

I would like make to always

1. strip the executable it created
2. remove the *.o files it created

after it has compiled the target executable. How do I do this? What do I add to the makefile? The current default command I am using is:

pan: pan.o libswe.a
gcc -g -O2 -o pan pan.o -L. -lswe -lm

Thanks.

Signature · 3 lines
Tux #395953 resides at http://samvit.org
playing with KDE 3.51 on SUSE Linux 10.0
$ date [] CCE +2006-02-26 W08-7 UTC+0530
#1 lore raw

Hello Shriramana Sharma,

Quoted 10 lines · On Sun, 26 Feb 2006 09:35:27 +0530 Shriramana Sharma <[email protected]> wrote:

I would like make to always

1. strip the executable it created
2. remove the *.o files it created

after it has compiled the target executable. How do I do this? What do I add to the makefile? The current default command I am using is:

pan: pan.o libswe.a
gcc -g -O2 -o pan pan.o -L. -lswe -lm

First, if you always want to strip, no need to add -g. Then:

all: pan strip clean

pan: pan.o libswe.a

	gcc -O2 -o $@ pan.o -L. -lswe -lm

strip: pan
strip $<

clean:
-rm -f pan.o

Or something similar..

Regards,

Signature · 1 line
wwp
#2 lore raw

Sunday, 26 February 2006 14:26 samaye tvayaa likhitam:

Quoted 1 line

First, if you always want to strip, no need to add -g.

If I do not add -g do I gain nothing by strip?

Quoted 1 line

all: pan strip clean

I got the idea. Thanks.

Signature · 3 lines
Tux #395953 resides at http://samvit.org
playing with KDE 3.51 on SUSE Linux 10.0
$ date [] CCE +2006-02-26 W08-7 UTC+0530
#3 lore raw
In reply to Shriramana Sharma

Hello Shiramana,

Quoted 9 lines · Shriramana Sharma

I would like make to always

1. strip the executable
2. remove the *.o files it created

after it has compiled the target executable. How do I do this? What do I add to the makefile? The current default command I am using is:

pan: pan.o libswe.a gcc -g -O2 -o pan pan.o -L. -lswe -lm

I'm not sure I understand your question.
Here's my answer, though:

pan: pan.o libswe.a
gcc -g -O2 -o pan pan.o -L. -lswe -lm
strip pan
rm -f *.o

Leslie

Signature · 2 lines
gpg --keyserver pgp.mit.edu --recv-keys 0x52D70289
http://nic-nac-project.de/~skypher/
#4 lore raw
In reply to Shriramana Sharma
Quoted 7 lines · Shriramana Sharma

I would like make to always

1. strip the executable it created
2. remove the *.o files it created

after it has compiled the target executable. How do I do this? What do I add to the makefile?

CC = gcc
CFLAGS = -g -O2
LDFLAGS = -L.
LOADLIBES = -lswe -lm

default: pan strip clean

pan: pan.o libswe.a
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) $(LOADLIBES)

strip: pan
strip $<

clean:
rm -f *.o

That way, "make" with no arguments will build the executable, strip it and remove the object files, while you can perform individual steps by specifying specific targets. E.g. to build the executable without stripping or cleaning (once the project becomes non-trivial, you /will/ want to do this), you can use "make pan".

A Makefile isn't supposed to just run a specific sequence of commands every time; you can use a script for that. It's meant to allow you to:

+ Perform incremental recompilation (which requires leaving the object files around).

+ Perform partial compilation (which requires breaking the build process into individual targets).

+ Compile with non-default settings (which requires using variables instead of hardcoding programs and options into the commands).

+ Handle large numbers of files without having to write a rule for every file (by using pattern rules and automatic variables).

Signature · 1 line
Glynn Clements <[email protected]>