1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
|
##
## Some make rules
##
ifdef MODULE
ifeq ($(PRELOAD_MODULES),1)
MODULE_TARGETS := $(MODULE).a $(MODULE).lc
else
MODULE_TARGETS := $(MODULE).so $(MODULE).lc
endif
TARGETS := $(TARGETS) $(MODULE_TARGETS)
endif
ifdef LUA_SOURCES
LUA_COMPILED := $(subst .lua,.lc, $(LUA_SOURCES))
TARGETS := $(TARGETS) $(LUA_COMPILED)
endif
# Main targets
######################################
.PHONY: subdirs
.PHONY: subdirs-clean
.PHONY: subdirs-realclean
.PHONY: subdirs-install
.PHONY: _install
.PHONY: _exports
all: subdirs _exports $(TARGETS)
clean: subdirs-clean _clean
realclean: subdirs-realclean _clean _realclean
install: subdirs-install _install
ifdef MAKE_EXPORTS
# Exports
######################################
EXPORTS_C = exports.c
EXPORTS_H = exports.h
TO_CLEAN := $(TO_CLEAN) $(EXPORTS_C) $(EXPORTS_H)
_exports: $(EXPORTS_C)
# this funny syntax (more than one pattern-based target) is meant to tell Make
# that this rule makes BOTH of these targets. Look at the last paragraph of
# http://www.gnu.org/software/make/manual/html_node/Pattern-Intro.html
%xports.c %xports.h: $(SOURCES) $(MKEXPORTS_EXTRA_DEPS)
$(MKEXPORTS) -module $(MAKE_EXPORTS) -o $(EXPORTS_C) -h $(EXPORTS_H) \
$(SOURCES) $(MKEXPORTS_EXTRAS)
# Exports documentation
######################################
EXPORTS_DOC = exports.tex
TO_CLEAN := $(TO_CLEAN) $(EXPORTS_DOC)
_exports_doc: $(EXPORTS_DOC)
$(EXPORTS_DOC): $(SOURCES) $(LUA_SOURCES) $(MKEXPORTS_EXTRA_DEPS)
$(MKEXPORTS) -mkdoc -module $(MAKE_EXPORTS) -o $(EXPORTS_DOC) \
$(SOURCES) $(LUA_SOURCES) $(MKEXPORTS_EXTRAS)
else # !MAKE_EXPORTS
EXPORTS_C =
EXPORTS_H =
EXPORTS_DOC =
endif # !MAKE_EXPORTS
# Compilation and linking
######################################
OBJS=$(subst .c,.o,$(SOURCES) $(EXPORTS_C))
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
ifdef MODULE
ifneq ($(PRELOAD_MODULES),1)
CFLAGS += -fPIC -DPIC
LD_SHAREDFLAGS=-shared
# notion might not link to Xext, so modules will have to link to it themselves
# if they need it:
LIBS += $(X11_LIBS)
$(MODULE).so: $(OBJS) $(EXT_OBJS)
$(CC) $(LD_SHAREDFLAGS) $(LDFLAGS) $(OBJS) $(EXT_OBJS) $(LIBS) -o $@
module_install: module_stub_install
$(INSTALLDIR) $(DESTDIR)$(MODULEDIR)
$(INSTALL) -m $(BIN_MODE) $(MODULE).so $(DESTDIR)$(MODULEDIR)
else # PRELOAD_MODULES
PICOPT=-fPIC -DPIC
LINKOPT=-shared
$(MODULE).a: $(OBJS) $(EXT_OBJS)
$(AR) $(ARFLAGS) $@ $+
$(RANLIB) $@
module_install: module_stub_install
endif # PRELOAD_MODULES
module_stub_install:
$(INSTALLDIR) $(DESTDIR)$(LCDIR)
$(INSTALL) -m $(DATA_MODE) $(MODULE).lc $(DESTDIR)$(LCDIR)
ifndef MODULE_STUB
$(MODULE).lc:
echo "ioncore.load_module('$(MODULE)') package.loaded['$(MODULE)']=true" | $(LUAC) -o $@ -
else
LUA_SOURCES += $(MODULE_STUB)
endif #MODULE_STUB
endif# !MODULE
# Clean rules
######################################
_clean:
$(RM) -f $(TO_CLEAN) core *.d *.lc $(OBJS)
_realclean:
$(RM) -f $(TO_REALCLEAN) $(TARGETS)
# Lua rules
######################################
%.lc: %.lua
$(LUAC) -o $@ $<
lc_install:
$(INSTALLDIR) $(DESTDIR)$(LCDIR)
for i in $(LUA_COMPILED); do \
$(INSTALL) -m $(DATA_MODE) $$i $(DESTDIR)$(LCDIR); \
done
etc_install:
$(INSTALLDIR) $(DESTDIR)$(ETCDIR)
for i in $(ETC); do \
$(INSTALL) -m $(DATA_MODE) $$i $(DESTDIR)$(ETCDIR); \
done
# Dependencies
######################################
CFLAGS += -MMD
-include *.d
# Subdirectories
######################################
ifdef SUBDIRS
subdirs:
set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i; done
subdirs-clean:
set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i clean; done
subdirs-realclean:
set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i realclean; done
subdirs-install:
set -e; for i in $(INSTALL_SUBDIRS); do $(MAKE) -C $$i install; done
endif
# Localisation
######################################
TO_CLEAN += potfiles_c potfiles_lua
_potfiles:
echo "$(SOURCES)"|tr ' ' '\n' > potfiles_c
echo "$(LUA_SOURCES) $(ETC)"|tr ' ' '\n' > potfiles_lua
|