Makefile (4751B)
1 # 2 # This Makefile requires GNU make. 3 # 4 # Do not make changes here. 5 # Use the included .mak files. 6 # 7 8 it: all 9 10 make_need := 3.81 11 ifeq "" "$(strip $(filter $(make_need), $(firstword $(sort $(make_need) $(MAKE_VERSION)))))" 12 fail := $(error Your make ($(MAKE_VERSION)) is too old. You need $(make_need) or newer) 13 endif 14 15 CC = $(error Please use ./configure first) 16 17 STATIC_LIBS := 18 SHARED_LIBS := 19 INTERNAL_LIBS := 20 EXTRA_TARGETS := 21 LIB_DEFS := 22 23 define library_definition 24 LIB$(firstword $(subst =, ,$(1))) := lib$(lastword $(subst =, ,$(1))).$(if $(DO_ALLSTATIC),a,so).xyzzy 25 ifdef DO_SHARED 26 SHARED_LIBS += lib$(lastword $(subst =, ,$(1))).so.xyzzy 27 endif 28 ifdef DO_STATIC 29 STATIC_LIBS += lib$(lastword $(subst =, ,$(1))).a.xyzzy 30 endif 31 endef 32 33 -include config.mak 34 include package/targets.mak 35 36 $(foreach var,$(LIB_DEFS),$(eval $(call library_definition,$(var)))) 37 38 include package/deps.mak 39 40 version_m := $(basename $(version)) 41 version_M := $(basename $(version_m)) 42 version_l := $(basename $(version_M)) 43 CPPFLAGS_ALL := $(CPPFLAGS_AUTO) $(CPPFLAGS) 44 CFLAGS_ALL := $(CFLAGS_AUTO) $(CFLAGS) 45 ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),) 46 CFLAGS_SHARED := -fPIC 47 else 48 CFLAGS_SHARED := 49 endif 50 LDFLAGS_ALL := $(LDFLAGS_AUTO) $(LDFLAGS) 51 AR := $(CROSS_COMPILE)ar 52 RANLIB := $(CROSS_COMPILE)ranlib 53 STRIP := $(CROSS_COMPILE)strip 54 INSTALL := ./tools/install.sh 55 56 ALL_BINS := $(LIBEXEC_TARGETS) $(BIN_TARGETS) 57 ALL_LIBS := $(SHARED_LIBS) $(STATIC_LIBS) $(INTERNAL_LIBS) 58 ALL_INCLUDES := $(wildcard src/include/$(package)/*.h) 59 60 all: $(ALL_LIBS) $(ALL_BINS) $(ALL_INCLUDES) $(EXTRA_INCLUDES) 61 62 clean: 63 @exec rm -f $(ALL_LIBS) $(ALL_BINS) $(wildcard src/*/*.o src/*/*.lo) $(EXTRA_TARGETS) 64 65 distclean: clean 66 @exec rm -f config.mak src/include/$(package)/config.h 67 68 tgz: distclean 69 @. package/info && \ 70 rm -rf /tmp/$$package-$$version && \ 71 cp -a . /tmp/$$package-$$version && \ 72 cd /tmp && \ 73 tar -zpcv --owner=0 --group=0 --numeric-owner --exclude=.git* -f /tmp/$$package-$$version.tar.gz $$package-$$version && \ 74 exec rm -rf /tmp/$$package-$$version 75 76 strip: $(ALL_LIBS) $(ALL_BINS) 77 ifneq ($(strip $(STATIC_LIBS)),) 78 exec $(STRIP) -x -R .note -R .comment $(STATIC_LIBS) 79 endif 80 ifneq ($(strip $(ALL_BINS)$(SHARED_LIBS)),) 81 exec $(STRIP) -R .note -R .comment $(ALL_BINS) $(SHARED_LIBS) 82 endif 83 84 install: install-dynlib install-libexec install-bin install-lib install-include 85 install-dynlib: $(SHARED_LIBS:lib%.so.xyzzy=$(DESTDIR)$(dynlibdir)/lib%.so) 86 install-libexec: $(LIBEXEC_TARGETS:%=$(DESTDIR)$(libexecdir)/%) 87 install-bin: $(BIN_TARGETS:%=$(DESTDIR)$(bindir)/%) 88 install-lib: $(STATIC_LIBS:lib%.a.xyzzy=$(DESTDIR)$(libdir)/lib%.a) 89 install-include: $(ALL_INCLUDES:src/include/$(package)/%.h=$(DESTDIR)$(includedir)/$(package)/%.h) $(EXTRA_INCLUDES:src/include/%.h=$(DESTDIR)$(includedir)/%.h) 90 91 ifneq ($(exthome),) 92 93 $(DESTDIR)$(exthome): $(DESTDIR)$(home) 94 exec $(INSTALL) -l $(notdir $(home)) $(DESTDIR)$(exthome) 95 96 update: $(DESTDIR)$(exthome) 97 98 global-links: $(DESTDIR)$(exthome) $(SHARED_LIBS:lib%.so.xyzzy=$(DESTDIR)$(sproot)/library.so/lib%.so.$(version_M)) $(BIN_TARGETS:%=$(DESTDIR)$(sproot)/command/%) 99 100 $(DESTDIR)$(sproot)/command/%: $(DESTDIR)$(home)/command/% 101 exec $(INSTALL) -D -l ..$(subst $(sproot),,$(exthome))/command/$(<F) $@ 102 103 $(DESTDIR)$(sproot)/library.so/lib%.so.$(version_M): $(DESTDIR)$(dynlibdir)/lib%.so.$(version_M) 104 exec $(INSTALL) -D -l ..$(subst $(sproot),,$(exthome))/library.so/$(<F) $@ 105 106 .PHONY: update global-links 107 108 endif 109 110 $(DESTDIR)$(dynlibdir)/lib%.so $(DESTDIR)$(dynlibdir)/lib%.so.$(version_M): lib%.so.xyzzy 111 $(INSTALL) -D -m 755 $< $@.$(version) && \ 112 $(INSTALL) -l $(@F).$(version) $@.$(version_M) && \ 113 exec $(INSTALL) -l $(@F).$(version_M) $@ 114 115 $(DESTDIR)$(libexecdir)/% $(DESTDIR)$(bindir)/%: % package/modes 116 exec $(INSTALL) -D -m 600 $< $@ 117 grep -- ^$(@F) < package/modes | { read name mode owner && \ 118 if [ x$$owner != x ] ; then chown -- $$owner $@ ; fi && \ 119 chmod $$mode $@ ; } 120 121 $(DESTDIR)$(libdir)/lib%.a: lib%.a.xyzzy 122 exec $(INSTALL) -D -m 644 $< $@ 123 124 $(DESTDIR)$(includedir)/$(package)/%.h: src/include/$(package)/%.h 125 exec $(INSTALL) -D -m 644 $< $@ 126 127 $(DESTDIR)$(includedir)/%.h: src/include/%.h 128 exec $(INSTALL) -D -m 644 $< $@ 129 130 %.o: %.c 131 exec $(CC) $(CPPFLAGS_ALL) $(CFLAGS_ALL) -c -o $@ $< 132 133 %.lo: %.c 134 exec $(CC) $(CPPFLAGS_ALL) $(CFLAGS_ALL) $(CFLAGS_SHARED) -c -o $@ $< 135 136 $(ALL_BINS): 137 exec $(CC) -o $@ $(CFLAGS_ALL) $(LDFLAGS_ALL) $(LDFLAGS_NOSHARED) $^ $(EXTRA_LIBS) $(LDLIBS) 138 139 lib%.a.xyzzy: 140 exec $(AR) rc $@ $^ 141 exec $(RANLIB) $@ 142 143 lib%.so.xyzzy: 144 exec $(CC) -o $@ $(CFLAGS_ALL) $(CFLAGS_SHARED) $(LDFLAGS_ALL) $(LDFLAGS_SHARED) -Wl,-soname,$(patsubst lib%.so.xyzzy,lib%.so.$(version_M),$@) $^ $(EXTRA_LIBS) $(LDLIBS) 145 146 .PHONY: it all clean distclean tgz strip install install-dynlib install-bin install-lib install-include 147 148 .DELETE_ON_ERROR: