migration from private to rsa
[external/insserv.git] / Makefile
1 #
2 # Makefile for compiling insserv tool
3 #
4 # Author: Werner Fink,  <werner@suse.de>
5 #
6
7 INITDIR  =      /etc/init.d
8 INSCONF  =      /etc/insserv.conf
9 #DESTDIR =      /tmp/root
10 #DEBUG   =      -DDEBUG=1 -Wpacked
11 DEBUG    =
12 ISSUSE   =      -DSUSE
13 DESTDIR  =
14 VERSION  =      1.12.0
15 DATE     =      $(shell date +'%d%b%y' | tr '[:lower:]' '[:upper:]')
16
17 #
18 # Architecture
19 #
20 ifdef RPM_OPT_FLAGS
21           COPTS = -g $(RPM_OPT_FLAGS)
22 else
23            ARCH = $(shell uname -i)
24 ifeq ($(ARCH),i386)
25           COPTS = -g -O3 -mcpu=i586 -mtune=i686
26 else
27           COPTS = -g -O2
28 endif
29 endif
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
34            LIBS =
35 ifdef USE_RPMLIB
36          CFLAGS += -DUSE_RPMLIB=1
37         LDFLAGS += -Wl,--as-needed
38            LIBS += -lrpm
39 endif
40              CC = gcc
41              RM = rm -f
42           MKDIR = mkdir -p
43           RMDIR = rm -rf
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)
52            LINK = ln -sf
53 #
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
59
60 #
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.
64 #
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))
67
68 #
69 # The rules
70 #
71
72 TODO    =       insserv insserv.8
73
74 all:            $(TODO)
75
76 insserv:        insserv.o listing.o
77         $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
78
79 listing.o:      listing.c listing.h config.h .system
80         $(CC) $(CFLAGS) $(CLOOP) -c $<
81
82 insserv.o:      insserv.c listing.h config.h .system
83         $(CC) $(CFLAGS) $(CLOOP) -c $<
84
85 listing.h:      .system
86
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)
89 config.h:       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"; \
95          done >> config.h
96         @echo '#endif' >> config.h
97
98 ifeq ($(ISSUSE),-DSUSE)
99 insserv.8:      insserv.8.in .system
100         sed -r '\!@@(ELSE|NOT)_SUSE@@!,\!@@END_SUSE@@!d;\!@@(BEGIN|END)_SUSE@@!d' < $< > $@
101 else
102 insserv.8:      insserv.8.in .system
103         sed -r '\!@@BEGIN_SUSE@@!,\!@@(ELSE|END)_SUSE@@!d;\!@@(NOT|END)_SUSE@@!d' < $< > $@
104 endif
105
106 .system:        SYSTEM=$(shell cat .system 2> /dev/null)
107 .system:        .force
108         @test "$(SYSTEM)" = "$(ISSUSE)$(DEBUG)" || echo "$(ISSUSE)$(DEBUG)" > .system
109
110 .force:
111
112 .PHONY:         clean
113 clean:
114         $(RM) *.o *~ $(TODO) config.h .depend.* .system
115
116 ifneq ($(MAKECMDGOALS),clean)
117
118 -include        .depend.listing .depend.insserv
119
120 .depend.listing::       listing.c listing.h
121         @$(CC) $(CFLAGS) -M listing.c >$@ 2>/dev/null
122
123 .depend.insserv::       insserv.c listing.h
124         @$(CC) $(CFLAGS) -M insserv.c >$@ 2>/dev/null
125
126 endif
127
128 install:        $(TODO)
129         $(MKDIR)   $(SBINDIR)
130         $(MKDIR)   $(SDOCDIR)
131         $(MKDIR)   $(CONFDIR)
132 ifeq ($(ISSUSE),-DSUSE)
133         $(MKDIR)   $(LSBDIR)
134         $(MKDIR)   $(DESTDIR)/usr/lib
135         $(MKDIR)   $(USRLSBDIR)
136 endif
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)/
144 endif
145
146 #
147 # Make distribution
148 #
149 FILES   = README         \
150           COPYING        \
151           CHANGES        \
152           Makefile       \
153           listing.c      \
154           listing.h      \
155           insserv.8.in   \
156           insserv.c      \
157           insserv.conf   \
158           init-functions \
159           remove_initd   \
160           install_initd  \
161           tests/suite    \
162           insserv-$(VERSION).lsm
163
164 dest:   clean
165         $(MKDIR) insserv-$(VERSION)/tests
166         @echo -e "Begin3\n\
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 \
182             case "$$file" in \
183             tests/*) cp -p $$file insserv-$(VERSION)/tests/ ;; \
184             *)       cp -p $$file insserv-$(VERSION)/ ;; \
185             esac; \
186         done
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