Updated with Tizen:Base source codes
[external/procps.git] / Makefile
1 # procps Makefile
2 # Albert Cahalan, 2002-2004
3 #
4 # Recursive make is considered harmful:
5 # http://google.com/search?q=%22recursive+make+considered+harmful%22
6 #
7 # For now this Makefile uses explicit dependencies. The project
8 # hasn't grown big enough to need something complicated, and the
9 # dependency tracking files are an ugly annoyance.
10 #
11 # This file includes */module.mk files which add on to variables:
12 # FOO += bar/baz
13 #
14 #
15 # Set (or uncomment) SKIP if you wish to avoid something.
16 # For example, you may prefer the /bin/kill from util-linux or bsdutils.
17
18
19 VERSION      := 3
20 SUBVERSION   := 2
21 MINORVERSION := 8
22 TARVERSION   := $(VERSION).$(SUBVERSION).$(MINORVERSION)
23
24 ############ vars
25
26 # so you can disable them or choose alternates
27 ldconfig := ldconfig
28 ln_f     := ln -f
29 ln_sf    := ln -sf
30 install  := install -D --owner 0 --group 0
31
32 # Lame x86-64 /lib64 and /usr/lib64 abomination:
33 lib64    := lib$(shell [ -d /lib64 ] && echo 64)
34
35 usr/bin                  := $(DESTDIR)/usr/bin/
36 bin                      := $(DESTDIR)/bin/
37 sbin                     := $(DESTDIR)/sbin/
38 usr/proc/bin             := $(DESTDIR)/usr/bin/
39 man1                     := $(DESTDIR)/usr/share/man/man1/
40 man5                     := $(DESTDIR)/usr/share/man/man5/
41 man8                     := $(DESTDIR)/usr/share/man/man8/
42 lib                      := $(DESTDIR)/$(lib64)/
43 usr/lib                  := $(DESTDIR)/usr/$(lib64)/
44 usr/include              := $(DESTDIR)/usr/include/
45
46 #SKIP     := $(bin)kill $(man1)kill.1
47
48 BINFILES := $(usr/bin)uptime $(usr/bin)tload $(usr/bin)free $(usr/bin)w \
49             $(usr/bin)top $(usr/bin)vmstat $(usr/bin)watch $(usr/bin)skill \
50             $(usr/bin)snice $(bin)kill $(sbin)sysctl $(usr/bin)pmap \
51             $(usr/proc/bin)pgrep $(usr/proc/bin)pkill $(usr/bin)slabtop \
52             $(usr/proc/bin)pwdx
53
54 MANFILES := $(man1)uptime.1 $(man1)tload.1 $(man1)free.1 $(man1)w.1 \
55             $(man1)top.1 $(man1)watch.1 $(man1)skill.1 $(man1)kill.1 \
56             $(man1)snice.1 $(man1)pgrep.1 $(man1)pkill.1 $(man1)pmap.1 \
57             $(man5)sysctl.conf.5 $(man8)vmstat.8 $(man8)sysctl.8 \
58             $(man1)slabtop.1 $(man1)pwdx.1
59
60 TARFILES := AUTHORS BUGS NEWS README TODO COPYING COPYING.LIB \
61             Makefile procps.lsm procps.spec v t README.top CodingStyle \
62             sysctl.conf minimal.c $(notdir $(MANFILES)) dummy.c \
63             uptime.c tload.c free.c w.c top.c vmstat.c watch.c skill.c \
64             sysctl.c pgrep.c top.h pmap.c slabtop.c pwdx.c
65
66 # Stuff (tests, temporary hacks, etc.) left out of the standard tarball
67 # plus the top-level Makefile to make it work stand-alone.
68 _TARFILES := Makefile
69
70 CURSES := -lncurses
71
72 # This seems about right for the dynamic library stuff.
73 # Something like this is probably needed to make the SE Linux
74 # library loading not conflict with embedded systems stuff.
75 #
76 #ifeq ($(SHARED),1)
77 #ldl := -ldl
78 #LIBTYPE := -DSHAREDLIB
79 #else
80 #LIBTYPE := -DSTATICLIB
81 #endif
82
83 # Preprocessor flags.
84 PKG_CPPFLAGS := -D_GNU_SOURCE -I proc
85 CPPFLAGS     := -I/usr/include/ncurses
86 ALL_CPPFLAGS := $(PKG_CPPFLAGS) $(CPPFLAGS)
87
88 # Left out -Wconversion due to noise in glibc headers.
89 # Left out -Wunreachable-code and -Wdisabled-optimization
90 # because gcc spews many useless warnings with them.
91 #
92 # Since none of the PKG_CFLAGS things are truly required
93 # to compile procps, they might best be moved to CFLAGS.
94 # On the other hand, they aren't normal -O -g things either.
95 #
96 # Note that -O2 includes -fomit-frame-pointer only if the arch
97 # doesn't lose some debugging ability.
98 #
99 PKG_CFLAGS   := -fno-common -ffast-math \
100   -W -Wall -Wshadow -Wcast-align -Wredundant-decls \
101   -Wbad-function-cast -Wcast-qual -Wwrite-strings -Waggregate-return \
102   -Wstrict-prototypes -Wmissing-prototypes
103 # Note that some stuff below is conditional on CFLAGS containing
104 # an option that starts with "-g". (-g, -g2, -g3, -ggdb, etc.)
105 CFLAGS       := -O2 -s
106 ALL_CFLAGS   := $(PKG_CFLAGS) $(CFLAGS)
107
108 PKG_LDFLAGS  := -Wl,-warn-common
109 LDFLAGS      :=
110 ALL_LDFLAGS  := $(PKG_LDFLAGS) $(LDFLAGS)
111
112 ############ Add some extra flags if gcc allows
113
114 ifneq ($(MAKECMDGOALS),clean)
115 ifneq ($(MAKECMDGOALS),tar)  
116 ifneq ($(MAKECMDGOALS),extratar)
117 ifneq ($(MAKECMDGOALS),beta)
118
119 # Unlike the kernel one, this check_gcc goes all the way to
120 # producing an executable. There might be a -m64 that works
121 # until you go looking for a 64-bit curses library.
122 check_gcc = $(shell if $(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) dummy.c $(ALL_LDFLAGS) $(1) -o /dev/null $(CURSES) > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
123
124 # Be 64-bit if at all possible. In a cross-compiling situation, one may
125 # do "make m64=-m32 lib64=lib" to produce 32-bit executables. DO NOT
126 # attempt to use a 32-bit executable on a 64-bit kernel. Packagers MUST
127 # produce separate executables for ppc and ppc64, s390 and s390x,
128 # i386 and x86-64, mips and mips64, sparc and sparc64, and so on.
129 # Failure to do so will cause data corruption.
130 m64 := $(call check_gcc,-m64,$(call check_gcc,-mabi=64,))
131 ALL_CFLAGS += $(m64)
132
133 ALL_CFLAGS += $(call check_gcc,-Wdeclaration-after-statement,)
134 ALL_CFLAGS += $(call check_gcc,-Wpadded,)
135 ALL_CFLAGS += $(call check_gcc,-Wstrict-aliasing,)
136
137 # Adding -fno-gcse might be good for those files which
138 # use computed goto.
139 #ALL_CFLAGS += $(call check_gcc,-fno-gcse,)
140
141 # if not debugging, enable things that could confuse gdb
142 ifeq (,$(findstring -g,$(filter -g%,$(CFLAGS))))
143 ALL_CFLAGS += $(call check_gcc,-fweb,)
144 ALL_CFLAGS += $(call check_gcc,-frename-registers,)
145 ALL_CFLAGS += $(call check_gcc,-fomit-frame-pointer,)
146 endif
147
148 # in case -O3 is enabled, avoid bloat
149 ALL_CFLAGS += $(call check_gcc,-fno-inline-functions,)
150
151 endif
152 endif
153 endif
154 endif
155
156 ############ misc.
157
158 # free.c pmap.c sysctl.c uptime.c vmstat.c watch.c pgrep.c skill.c tload.c top.c w.c
159 # utmp.c oldtop.c tmp-junk.c minimal.c
160
161 .SUFFIXES:
162 .SUFFIXES: .a .o .c .s .h
163
164 .PHONY: all clean do_all install tar extratar beta
165
166 ALL := $(notdir $(BINFILES))
167
168 CLEAN := $(notdir $(BINFILES))
169
170 DIRS :=
171
172 INSTALL := $(BINFILES) $(MANFILES)
173
174 # want this rule first, use := on ALL, and ALL not filled in yet
175 all: do_all
176
177 -include */module.mk
178
179 do_all:    $(ALL)
180
181 junk := DEADJOE *~ *.o core gmon.out
182
183 # Remove $(junk) from all $(DIRS)
184 CLEAN += $(junk) $(foreach dir,$(DIRS),$(addprefix $(dir), $(junk)))
185
186 ##########
187 # not maintained because it isn't really needed:
188 #
189 #SRC :=
190 #OBJ := $(patsubst %.c,%.o, $(filter %.c,$(SRC)))
191 #
192 #ifneq ($(MAKECMDGOALS),clean)
193 #-include $(OBJ:.o=.d)
194 #endif
195 #
196 #%.d: %.c
197 #       depend.sh $(ALL_CPPFLAGS) $(ALL_CFLAGS) $< > $@
198 ############
199
200 # don't want to type "make procps-$(TARVERSION).tar.gz"
201 tar: $(TARFILES)
202         mkdir procps-$(TARVERSION)
203         (tar cf - $(TARFILES)) | (cd procps-$(TARVERSION) && tar xf -)
204         tar cf procps-$(TARVERSION).tar procps-$(TARVERSION)
205         gzip -9 procps-$(TARVERSION).tar
206
207 extratar: $(_TARFILES)
208         mkdir procps-$(TARVERSION)
209         (tar cf - $(_TARFILES)) | (cd procps-$(TARVERSION) && tar xf -)
210         tar cf extra-$(TARVERSION).tar procps-$(TARVERSION)
211         gzip -9 extra-$(TARVERSION).tar
212
213 beta: $(TARFILES) $(_TARFILES)
214         mkdir beta-$(TARVERSION)
215         (tar cf - $(TARFILES) $(_TARFILES)) | (cd beta-$(TARVERSION) && tar xf -)
216         tar cf beta-$(TARVERSION).tar beta-$(TARVERSION)
217         gzip -9 beta-$(TARVERSION).tar
218
219 clean:
220         rm -f $(CLEAN)
221
222 ###### install
223
224 $(BINFILES) : all
225         $(install) --mode a=rx $(notdir $@) $@
226
227 $(MANFILES) : all
228         $(install) --mode a=r $(notdir $@) $@
229
230 install: $(filter-out $(SKIP) $(addprefix $(DESTDIR),$(SKIP)),$(INSTALL))
231         cd $(usr/bin) && $(ln_f) skill snice
232         cd $(usr/proc/bin) && $(ln_f) pgrep pkill
233
234 ############ prog.c --> prog.o
235
236 top.o : top.h
237
238 %.o : %.c
239         $(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) -c -o $@ $<
240
241 w.o:    w.c
242         $(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) $(W_SHOWFROM) -c $<
243
244 ############ prog.o --> prog
245
246 pmap w uptime tload free sysctl vmstat utmp pgrep skill pwdx: % : %.o $(LIBPROC)
247         $(CC) $(ALL_CFLAGS) $^ $(ALL_LDFLAGS) -o $@
248
249 slabtop top: % : %.o $(LIBPROC)
250         $(CC) $(ALL_CFLAGS) $^ $(ALL_LDFLAGS) -o $@ $(CURSES)
251
252 watch: % : %.o
253         $(CC) $(ALL_CFLAGS) $^ $(ALL_LDFLAGS) -o $@ $(CURSES)
254
255 ############ progX --> progY
256
257 snice kill: skill
258         $(ln_f) skill $@
259
260 pkill: pgrep
261         $(ln_f) pgrep pkill