2 # Makefile for compiling insserv tool
4 # Author: Werner Fink, <werner@suse.de>
8 INSCONF = /etc/insserv.conf
10 #DEBUG = -DDEBUG=1 -Wpacked
15 DATE = $(shell date +'%d%b%y' | tr '[:lower:]' '[:upper:]')
21 COPTS = -g $(RPM_OPT_FLAGS)
23 ARCH = $(shell uname -i)
25 COPTS = -g -O3 -mcpu=i586 -mtune=i686
30 CFLAGS = -W -Wall $(COPTS) $(DEBUG) $(LOOPS) -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 \
31 $(ISSUSE) -DINITDIR=\"$(INITDIR)\" -DINSCONF=\"$(INSCONF)\" -pipe
32 CLOOP = -falign-loops=0
33 LDFLAGS = -Wl,-O,3,--relax
36 CFLAGS += -DUSE_RPMLIB=1
37 LDFLAGS += -Wl,--as-needed
44 INSTBINFLAGS = -m 0700
45 INSTBIN = install $(INSTBINFLAGS)
46 INSTSRPFLAGS = -m 0700
47 INSTSRP = install $(INSTSRPFLAGS)
48 INSTDOCFLAGS = -c -m 0444
49 INSTDOC = install $(INSTDOCFLAGS)
50 INSTCONFLAGS = -c -m 0644
51 INSTCON = install $(INSTDOCFLAGS)
54 SDOCDIR = $(DESTDIR)/usr/share/man/man8
55 SBINDIR = $(DESTDIR)/sbin
56 CONFDIR = $(DESTDIR)/etc
57 LSBDIR = $(DESTDIR)/lib/lsb
58 USRLSBDIR = $(DESTDIR)/usr/lib/lsb
61 # Determine if a library provides a specific function
62 # Fist argument is the function to test, the second
63 # one is the library its self.
65 CTEST = $(CC) -nostdinc -fno-builtin -o /dev/null -xc
66 cc-function = $(shell printf 'void *$(1)();\nint main(){return($(1)(0)?0:1);}'|$(CTEST) - -l$(2:lib%=%) > /dev/null 2>&1 && echo $(1))
72 TODO = insserv insserv.8
76 insserv: insserv.o listing.o
77 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
79 listing.o: listing.c listing.h config.h .system
80 $(CC) $(CFLAGS) $(CLOOP) -c $<
82 insserv.o: insserv.c listing.h config.h .system
83 $(CC) $(CFLAGS) $(CLOOP) -c $<
87 config.h: ADRESSES = ^\#\s*if\s+defined\(HAS_[[:alnum:]_]+\)\s+&&\s+defined\(_ATFILE_SOURCE\)
88 config.h: FUNCTIONS = $(shell sed -rn '/$(ADRESSES)/{ s/.*defined\(HAS_([[:alnum:]_]+)\).*/\1/p; }' listing.h)
90 @echo '/* Generated automatically by running make -- do not edit */' > config.h
91 @echo '#ifndef CONFIG_H' >> config.h
92 @echo '#define CONFIG_H' >> config.h
93 @for def in $(foreach func,$(FUNCTIONS),$(call cc-function,$(func),libc)); do \
94 echo "#define HAS_$$def"; \
96 @echo '#endif' >> config.h
98 ifeq ($(ISSUSE),-DSUSE)
99 insserv.8: insserv.8.in .system
100 sed -r '\!@@(ELSE|NOT)_SUSE@@!,\!@@END_SUSE@@!d;\!@@(BEGIN|END)_SUSE@@!d' < $< > $@
102 insserv.8: insserv.8.in .system
103 sed -r '\!@@BEGIN_SUSE@@!,\!@@(ELSE|END)_SUSE@@!d;\!@@(NOT|END)_SUSE@@!d' < $< > $@
106 .system: SYSTEM=$(shell cat .system 2> /dev/null)
108 @test "$(SYSTEM)" = "$(ISSUSE)$(DEBUG)" || echo "$(ISSUSE)$(DEBUG)" > .system
114 $(RM) *.o *~ $(TODO) config.h .depend.* .system
116 ifneq ($(MAKECMDGOALS),clean)
118 -include .depend.listing .depend.insserv
120 .depend.listing:: listing.c listing.h
121 @$(CC) $(CFLAGS) -M listing.c >$@ 2>/dev/null
123 .depend.insserv:: insserv.c listing.h
124 @$(CC) $(CFLAGS) -M insserv.c >$@ 2>/dev/null
132 ifeq ($(ISSUSE),-DSUSE)
134 $(MKDIR) $(DESTDIR)/usr/lib
135 $(MKDIR) $(USRLSBDIR)
137 $(INSTBIN) insserv $(SBINDIR)/
138 $(INSTDOC) insserv.8 $(SDOCDIR)/
139 $(INSTCON) insserv.conf $(CONFDIR)/
140 ifeq ($(ISSUSE),-DSUSE)
141 $(INSTCON) init-functions $(LSBDIR)/
142 $(INSTSRP) install_initd $(USRLSBDIR)/
143 $(INSTSRP) remove_initd $(USRLSBDIR)/
162 insserv-$(VERSION).lsm
165 $(MKDIR) insserv-$(VERSION)/tests
167 Title: insserv tool for boot scripts\n\
168 Version: $(VERSION)\n\
169 Entered-date: $(DATE)\n\
170 Description: Used for enabling of installed boot scripts\n\
171 x by scanning comment headers which are LSB conform.\n\
172 Keywords: boot service control, LSB\n\
173 Author: Werner Fink <werner@suse.de>\n\
174 Maintained-by: Werner Fink <werner@suse.de>\n\
175 Primary-site: sunsite.unc.edu /pub/Linux/system/daemons/init\n\
176 x @UNKNOWN insserv-$(VERSION).tar.gz\n\
177 Alternate-site: ftp.suse.com /pub/projects/init\n\
178 Platforms: Linux with System VR2 or higher boot scheme\n\
179 Copying-policy: GPL\n\
180 End" | sed 's@^ @@g;s@^x@@g' > insserv-$(VERSION).lsm
181 for file in $(FILES) ; do \
183 tests/*) cp -p $$file insserv-$(VERSION)/tests/ ;; \
184 *) cp -p $$file insserv-$(VERSION)/ ;; \
187 tar -cps -zf insserv-$(VERSION).tar.gz insserv-$(VERSION)/
188 $(RMDIR) insserv-$(VERSION)
189 set -- `gzip -l insserv-$(VERSION).tar.gz | tail -1` ; \
190 sed "s:@UNKNOWN:$$1:" < insserv-$(VERSION).lsm > \
191 insserv-$(VERSION).lsm.tmp ; \
192 mv insserv-$(VERSION).lsm.tmp insserv-$(VERSION).lsm