/[baselayout]/trunk/src/Makefile
Gentoo

Contents of /trunk/src/Makefile

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2561 - (hide annotations) (download)
Sun Apr 8 17:39:59 2007 UTC (7 years ago) by uberlord
File size: 5640 byte(s)
Only use some gcc flags if gcc actually supports them.
1 uberlord 2547 # Copyright 1999-2007 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3    
4     CC ?= gcc
5    
6     CFLAGS ?= -Wall -O2 -pipe
7 uberlord 2561
8     # Saying that, this function only works with GNU Make :/
9     check_gcc=$(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
10     then echo "$(1)"; else echo "$(2)"; fi)
11    
12     # Luckily we can do this more long winded thing with pmake used by the BSDs
13     # FIXME: Look into making this into a loop
14     WAFTST != if $(CC) -Wextra -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
15     then echo "-Wdeclaration-after-statement"; fi
16     WSEQ != if $(CC) -Wextra -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
17     then echo "-Wsequence-point"; fi
18     WEXTRA != if $(CC) -Wextra -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
19     then echo "-Wextra"; fi
20    
21     # Loads of nice flags to ensure our code is good
22 uberlord 2547 CFLAGS += -pedantic -std=c99 \
23 uberlord 2548 -Wall -Wunused -Wimplicit -Wshadow -Wformat=2 \
24 uberlord 2547 -Wmissing-declarations -Wno-missing-prototypes -Wwrite-strings \
25     -Wbad-function-cast -Wnested-externs -Wcomment -Winline \
26 uberlord 2561 -Wchar-subscripts -Wcast-align -Wno-format-nonliteral \
27     $(call check_gcc, -Wdeclaration-after-statement) \
28     $(call check_gcc, -Wsequence-point) \
29     $(call check_gcc, -Wextra) $(WAFTST) $(WSEQ) $(WEXTRA)
30 uberlord 2547
31     # For debugging. -Werror is pointless due to ISO C issues with dlsym
32     #CFLAGS += -ggdb
33    
34     DESTDIR =
35     LIB = lib
36    
37     LIBEINFOSOVER = 0
38     LIBEINFOSO = libeinfo.so.$(LIBRCSOVER)
39     LIBEINFOOBJS= libeinfo.o
40    
41     LIBRCSOVER = 0
42     LIBRCSO = librc.so.$(LIBRCSOVER)
43     LIBRCOBJS= librc.o librc-depend.o librc-daemon.o librc-misc.o librc-strlist.o
44    
45     LIB_TARGETS = $(LIBEINFOSO) $(LIBRCSO)
46     BIN_TARGETS = rc-status
47 uberlord 2559 SBIN_TARGETS = env-update rc rc-update runscript start-stop-daemon
48     PRIV_BIN_TARGETS = fstabinfo mountinfo rc-depend
49 uberlord 2547 SYS_WHITELIST = env_whitelist
50    
51 uberlord 2550 TARGET = $(LIB_TARGETS) $(BIN_TARGETS) $(SBIN_TARGETS) $(PRIV_BIN_TARGETS)
52 uberlord 2547
53     RCLINKS = einfon einfo ewarnn ewarn eerrorn eerror ebegin eend ewend \
54     eindent eoutdent eflush color_terminal \
55     veinfo vewarn vebegin veend vewend veindent veoutdent \
56     service_starting service_inactive service_started \
57     service_stopping service_stopped \
58     service_inactive service_wasinactive \
59     service_coldplugged \
60     mark_service_starting mark_service_inactive mark_service_started \
61     mark_service_stopping mark_service_stopped \
62     mark_service_inactive mark_service_wasinactive \
63     mark_service_coldplugged \
64     get_options save_options \
65     is_runlevel_start is_runlevel_stop service_started_daemon
66    
67     # Quick hack to make my life easier on BSD and Linux
68     ifeq ($(OS),)
69     OS=$(shell uname -s)
70     ifneq ($(OS),Linux)
71     OS=BSD
72     endif
73     endif
74    
75     ifeq ($(OS),Linux)
76     LDLIBS_RC = -ldl
77     LDLIBS_RS = -ldl
78     # Shouldn't need this, but it's the easiest workaround for silly
79     # Linux headers that don't work with -std=c99
80     override CFLAGS += -D_GNU_SOURCE
81     endif
82     ifeq ($(OS),BSD)
83     override LDLIBS += -lkvm
84     endif
85    
86     HAVE_PAM =
87     ifdef HAVE_PAM
88     CFLAGS_SSD = -DHAVE_PAM
89     LDLIBS_SSD = -lpam
90     endif
91    
92     # We also define _BSD_SOURCE so both Linux and the BSDs get a few
93     # handy functions which makes our lives a lot easier
94 uberlord 2560 override CFLAGS += -DLIB=\"$(LIB)\"
95 uberlord 2547
96     # IMPORTANT!!!
97     # Remove this when releasing as it's a security risk
98     # However, this does save us using libtool when we're testing
99     # NOTE: The toplevel Makefile for baselayout will automatically
100     # disable then when doing `make dist`
101     ##override LDFLAGS += -Wl,-rpath .
102    
103     all: $(TARGET)
104    
105     $(LIBEINFOOBJS): CFLAGS += -fPIC
106     $(LIBEINFOSO): LDLIBS =
107     $(LIBEINFOSO): $(LIBEINFOOBJS)
108     $(CC) -fPIC -shared -Wl,-soname,$(LIBEINFOSO) -o $(LIBEINFOSO) $(LIBEINFOOBJS)
109     ln -sf $(LIBEINFOSO) libeinfo.so
110    
111     $(LIBRCOBJS): CFLAGS += -fPIC
112     $(LIBRCSO): $(LIBRCOBJS)
113     $(CC) -fPIC -shared -Wl,-soname,$(LIBRCSO) -o $(LIBRCSO) $(LIBRCOBJS)
114     ln -sf $(LIBRCSO) librc.so
115    
116     splash: CFLAGS += -fPIC
117     splash: splash.o
118     $(CC) -fPIC -shared -Wl,-soname,splash.so -o splash.so splash.o
119    
120     env-update: $(LIBEINFOSO) $(LIBRCSO) env-update.o
121    
122     fstabinfo: $(LIBEINFOSO) fstabinfo.o
123    
124     mountinfo: $(LIBEINFOSO) $(LIBRCSO) mountinfo.o
125    
126     rc-depend: $(LIBEINFOSO) $(LIBRCSO) rc-depend.o
127    
128     rc-status: $(LIBEINFOSO) $(LIBRCSO) rc-status.o
129    
130     rc-update: $(LIBEINFOSO) $(LIBRCSO) rc-update.o
131    
132     rc: LDLIBS += $(LDLIBS_RC)
133     rc: $(LIBEINFOSO) $(LIBRCSO) rc-plugin.o rc.o
134    
135     runscript: LDLIBS += $(LDLIBS_RS)
136     runscript: $(LIBEINFOSO) $(LIBRCSO) rc-plugin.o runscript.o
137    
138     start-stop-daemon: CFLAGS += $(CFLAGS_SSD)
139     start-stop-daemon: LDLIBS += $(LDLIBS_SSD)
140     start-stop-daemon: $(LIBEINFOSO) $(LIBRCSO) start-stop-daemon.o
141    
142     links: rc
143     for x in $(RCLINKS) $(RCPRIVLINKS); do ln -sf rc $$x; done
144    
145     install: $(TARGET)
146     install -m 0755 -d $(DESTDIR)/$(LIB)
147     install -m 0755 $(LIB_TARGETS) $(DESTDIR)/$(LIB)
148     ln -sf $(LIBEINFOSO) $(DESTDIR)/$(LIB)/libeinfo.so
149     ln -sf $(LIBRCSO) $(DESTDIR)/$(LIB)/librc.so
150     install -m 0755 -d $(DESTDIR)/usr/include
151     install -m 0644 einfo.h rc.h $(DESTDIR)/usr/include
152     install -m 0755 -d $(DESTDIR)/bin
153     install -m 0755 $(BIN_TARGETS) $(DESTDIR)/bin
154     install -m 0755 -d $(DESTDIR)/sbin
155     install -m 0755 $(SBIN_TARGETS) $(DESTDIR)/sbin
156     install -m 0755 -d $(DESTDIR)/$(LIB)/rcscripts/conf.d
157     install -m 0644 $(SYS_WHITELIST) $(DESTDIR)/$(LIB)/rcscripts/conf.d
158     install -m 0755 -d $(DESTDIR)/$(LIB)/rcscripts/bin
159 uberlord 2550 install -m 0755 $(PRIV_BIN_TARGETS) $(DESTDIR)/$(LIB)/rcscripts/bin
160 uberlord 2547 for x in $(RCLINKS); do ln -sf $(DESTDIR)/sbin/rc $(DESTDIR)/$(LIB)/rcscripts/bin/$$x; done
161     if test "$(HAVE_PAM)" != "" ; then \
162     install -m 0755 -d $(DESTDIR)/etc/pam.d ; \
163     install -m 0644 start-stop-daemon.pam $(DESTDIR)/etc/pam.d/start-stop-daemon ; \
164     fi
165    
166     clean:
167     rm -f $(TARGET) $(RCLINKS) $(RCPRIVLINKS)
168     rm -f *.o *~ *.core *.so

  ViewVC Help
Powered by ViewVC 1.1.20