skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

Makefile (6225B)


      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 $(error Your make ($(MAKE_VERSION)) is too old. You need $(make_need) or newer)
     13 endif
     14 
     15 -include config.mak
     16 include package/deps.mak
     17 
     18 version_m := $(basename $(version))
     19 version_M := $(basename $(version_m))
     20 version_l := $(basename $(version_M))
     21 CPPFLAGS_ALL := $(CPPFLAGS_AUTO) $(CPPFLAGS)
     22 CFLAGS_ALL := $(CFLAGS_AUTO) $(CFLAGS)
     23 LDFLAGS_ALL := $(LDFLAGS_AUTO) $(LDFLAGS)
     24 LDLIBS_ALL := $(LDLIBS_AUTO) $(LDLIBS)
     25 AR := $(CROSS_COMPILE)ar
     26 RANLIB := $(CROSS_COMPILE)ranlib
     27 STRIP := $(CROSS_COMPILE)strip
     28 INSTALL := ./tools/install.sh
     29 
     30 TYPES := size uid gid pid time dev ino
     31 
     32 ALL_SRCS := $(sort $(wildcard src/lib*/*.c))
     33 ALL_DOBJS := $(ALL_SRCS:%.c=%.lo)
     34 ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),)
     35 ALL_SOBJS := $(ALL_SRCS:%.c=%.o)
     36 CFLAGS_SHARED := -fPIC
     37 else
     38 ALL_SOBJS := $(ALL_DOBJS)
     39 CFLAGS_SHARED :=
     40 endif
     41 ALL_LIBS := $(SHARED_LIBS) $(STATIC_LIBS)
     42 BUILT_INCLUDES := \
     43 src/include/$(package)/sysdeps.h \
     44 src/include/$(package)/uint16.h \
     45 src/include/$(package)/uint32.h \
     46 src/include/$(package)/uint64.h \
     47 src/include/$(package)/types.h \
     48 src/include/$(package)/ip46.h
     49 ALL_INCLUDES := $(sort $(BUILT_INCLUDES) $(wildcard src/include/$(package)/*.h))
     50 ALL_SYSDEPS := $(wildcard $(sysdeps)/*)
     51 ALL_DATA := $(wildcard src/etc/*)
     52 
     53 all: config.mak $(ALL_LIBS) $(ALL_INCLUDES) $(ALL_SYSDEPS) $(ALL_DATA)
     54 
     55 clean:
     56 	@exec rm -f $(ALL_LIBS) $(ALL_BINS) $(ALL_SOBJS) $(ALL_DOBJS) $(BUILT_INCLUDES)
     57 
     58 distclean: clean
     59 	@exec rm -rf config.mak src/include/$(package)/config.h sysdeps.cfg
     60 
     61 tgz: distclean
     62 	@. package/info && \
     63 	rm -rf /tmp/$$package-$$version && \
     64 	cp -a . /tmp/$$package-$$version && \
     65 	cd /tmp && \
     66 	tar -zpcv --owner=0 --group=0 --numeric-owner --exclude=.git* -f /tmp/$$package-$$version.tar.gz $$package-$$version && \
     67 	exec rm -rf /tmp/$$package-$$version
     68 
     69 strip: $(ALL_LIBS)
     70 ifneq ($(strip $(STATIC_LIBS)),)
     71 	exec $(STRIP) -x -R .note -R .comment $(STATIC_LIBS)
     72 endif
     73 ifneq ($(strip $(SHARED_LIBS)),)
     74 	exec $(STRIP) -R .note -R .comment $(SHARED_LIBS)
     75 endif
     76 
     77 install: install-sysconf install-sysdeps install-dynlib install-lib install-include
     78 install-sysconf: $(ALL_DATA:src/etc/%=$(DESTDIR)$(sysconfdir)/%)
     79 install-sysdeps: $(ALL_SYSDEPS:$(sysdeps)/%=$(DESTDIR)$(sysdepdir)/%)
     80 install-dynlib: $(SHARED_LIBS:lib%.so.xyzzy=$(DESTDIR)$(dynlibdir)/lib%.so)
     81 install-lib: $(STATIC_LIBS:lib%.a.xyzzy=$(DESTDIR)$(libdir)/lib%.a)
     82 install-include: $(ALL_INCLUDES:src/include/$(package)/%.h=$(DESTDIR)$(includedir)/$(package)/%.h)
     83 
     84 ifneq ($(exthome),)
     85 
     86 $(DESTDIR)$(exthome): $(DESTDIR)$(home)
     87 	exec $(INSTALL) -l $(notdir $(home)) $(DESTDIR)$(exthome)
     88 
     89 update: $(DESTDIR)$(exthome)
     90 
     91 global-links: $(DESTDIR)$(exthome) $(SHARED_LIBS:lib%.so.xyzzy=$(DESTDIR)$(sproot)/library.so/lib%.so.$(version_M))
     92 
     93 $(DESTDIR)$(sproot)/library.so/lib%.so.$(version_M): $(DESTDIR)$(dynlibdir)/lib%.so.$(version_M)
     94 	exec $(INSTALL) -D -l ..$(subst $(sproot),,$(exthome))/library.so/$(<F) $@
     95 
     96 .PHONY: update global-links
     97 
     98 endif
     99 
    100 $(DESTDIR)$(sysconfdir)/%: src/etc/%
    101 	exec $(INSTALL) -D -m 644 $< $@
    102 
    103 $(DESTDIR)$(sysdepdir)/%: $(sysdeps)/%
    104 	exec $(INSTALL) -D -m 644 $< $@
    105 
    106 $(DESTDIR)$(dynlibdir)/lib%.so $(DESTDIR)$(dynlibdir)/lib%.so.$(version_M): lib%.so.xyzzy
    107 	$(INSTALL) -D -m 755 $< $@.$(version) && \
    108 	$(INSTALL) -l $(@F).$(version) $@.$(version_M) && \
    109 	exec $(INSTALL) -l $(@F).$(version_M) $@
    110 
    111 $(DESTDIR)$(libdir)/lib%.a: lib%.a.xyzzy
    112 	exec $(INSTALL) -D -m 644 $< $@
    113 
    114 $(DESTDIR)$(includedir)/$(package)/%.h: src/include/$(package)/%.h
    115 	exec $(INSTALL) -D -m 644 $< $@
    116 
    117 %.o: %.c
    118 	exec $(CC) $(CPPFLAGS_ALL) $(CFLAGS_ALL) -c -o $@ $<
    119 
    120 %.lo: %.c
    121 	exec $(CC) $(CPPFLAGS_ALL) $(CFLAGS_ALL) $(CFLAGS_SHARED) -c -o $@ $<
    122 
    123 libskarnet.a.xyzzy: $(ALL_SOBJS)
    124 	exec $(AR) rc $@ $^
    125 	exec $(RANLIB) $@
    126 
    127 libskarnet.so.xyzzy: $(ALL_DOBJS)
    128 	exec $(CC) -o $@ $(CFLAGS_ALL) $(CFLAGS_SHARED) $(LDFLAGS_ALL) $(LDFLAGS_SHARED) -Wl,-soname,libskarnet.so.$(version_M) $^ $(SOCKET_LIB) $(SPAWN_LIB) $(SYSCLOCK_LIB) $(TAINNOW_LIB) $(TIMER_LIB) $(UTIL_LIB)
    129 
    130 .PHONY: it all clean distclean tgz strip install install-data install-sysdeps install-dynlib install-lib install-include
    131 
    132 .DELETE_ON_ERROR:
    133 
    134 src/include/$(package)/sysdeps.h: $(sysdeps)/sysdeps $(sysdeps)/target
    135 	exec tools/gen-sysdepsh.sh `cat $(sysdeps)/target` < $(sysdeps)/sysdeps > $@
    136 
    137 src/include/$(package)/uint16.h: $(sysdeps)/sysdeps src/headers/uint16-bswap src/headers/bits-header src/headers/bits-footer src/headers/bits-lendian src/headers/bits-bendian src/headers/bits-template src/headers/uint64-include src/include/$(package)/uint64.h
    138 	exec tools/gen-bits.sh $(sysdeps)/sysdeps 16 6 7 5 17 > $@
    139 
    140 src/include/$(package)/uint32.h: $(sysdeps)/sysdeps src/headers/uint32-bswap src/headers/bits-header src/headers/bits-footer src/headers/bits-lendian src/headers/bits-bendian src/headers/bits-template src/headers/uint64-include src/include/$(package)/uint64.h
    141 	exec tools/gen-bits.sh $(sysdeps)/sysdeps 32 11 13 9 33 > $@
    142 
    143 src/include/$(package)/uint64.h: $(sysdeps)/sysdeps src/headers/uint64-bswap src/headers/bits-header src/headers/bits-footer src/headers/bits-lendian src/headers/bits-bendian src/headers/bits-template src/headers/uint64-ulong64 src/headers/uint64-noulong64 src/headers/uint64-defs src/headers/uint64-macros
    144 	exec tools/gen-bits.sh $(sysdeps)/sysdeps 64 21 25 17 65 > $@
    145 
    146 src/include/$(package)/types.h: src/include/$(package)/uint16.h src/include/$(package)/uint32.h src/include/$(package)/uint64.h $(sysdeps)/sysdeps src/headers/types-header src/headers/types-footer src/headers/unsigned-template src/headers/signed-template
    147 	exec tools/gen-types.sh $(sysdeps)/sysdeps $(TYPES) > $@
    148 
    149 src/include/$(package)/ip46.h: src/include/$(package)/fmtscan.h src/include/$(package)/tai.h src/include/$(package)/socket.h $(sysdeps)/sysdeps src/headers/ip46-header src/headers/ip46-footer src/headers/ip46-with src/headers/ip46-without
    150 	@{ \
    151 	  cat src/headers/ip46-header ; \
    152 	  if $(ipv6) && grep -qF 'ipv6: yes' $(sysdeps)/sysdeps ; then cat src/headers/ip46-with ; \
    153 	  else cat src/headers/ip46-without ; \
    154 	  fi ; \
    155 	  exec cat src/headers/ip46-footer ; \
    156 	} > $@