aboutsummaryrefslogtreecommitdiffstats
path: root/GNUmakefile
diff options
context:
space:
mode:
Diffstat (limited to 'GNUmakefile')
-rw-r--r--GNUmakefile283
1 files changed, 133 insertions, 150 deletions
diff --git a/GNUmakefile b/GNUmakefile
index d484ff5..c895dd1 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -1,163 +1,146 @@
-prefix = /usr/local
-bindir = $(prefix)/bin
-libdir = $(prefix)/lib
-datadir = $(prefix)/share
-includedir = $(prefix)/include
-luainclude =
-luapath =
-luacpath =
-LUAC =
-
-# backwards compatible install paths
-ifneq ($(origin lua52include), undefined)
-luainclude = $(lua52include)
-endif
+# non-recursive prologue
+sp := $(sp).x
+dirstack_$(sp) := $(d)
+d := $(abspath $(lastword $(MAKEFILE_LIST))/..)
-ifneq ($(origin lua52path), undefined)
-luapath = $(lua52path)
-endif
+ifeq ($(origin GUARD_$(d)), undefined)
+GUARD_$(d) := 1
-ifneq ($(origin lua52cpath), undefined)
-luacpath = $(lua52cpath)
-endif
+#
+# E N V I R O N M E N T C O N F I G U R A T I O N
+#
+include $(d)/../GNUmakefile
-# call helper to derive our Lua paths
-ENV = CC CPPFLAGS prefix bindir libdir datadir includedir \
- luainclude luapath luacpath LUAC
-$(shell env $(foreach V, $(ENV), $(V)="$(call $(V))") ../mk/lua.path make > .config)
-include .config
+#
+# C O M P I L A T I O N F L A G S
+#
+OS_$(d) = $(shell $(d)/../mk/vendor.os)
+CC_$(d) = $(shell $(d)/../mk/vendor.cc)
+LUAPATH_$(d) = $(shell env CC="$(CC)" CPPFLAGS="$(CPPFLAGS)" LDFLAGS="$(LDFLAGS)" $(<D)/../mk/lua.path -krxm3 -I$(DESTDIR)$(includedir) -I/usr/include -I/usr/local/include -P$(DESTDIR)$(bindir) -P$(bindir) -L$(DESTDIR)$(libdir) -L$(libdir) -v$(1) $(2))
-VENDOR.OS = $(shell ../mk/vendor.os)
-VENDOR.CC = $(shell env CC="${CC}" ../mk/vendor.cc)
+CPPFLAGS_$(d) = $(CPPFLAGS_$(abspath $(@D)/../..))
+CFLAGS_$(d) = $(CFLAGS_$(abspath $(@D)/../..))
+LDFLAGS_$(d) = $(LDFLAGS_$(abspath $(@D)/../..))
+SOFLAGS_$(d) = $(SOFLAGS_$(abspath $(@D)/../..))
-ifneq ($(luainclude),)
-CPPFLAGS = -I$(luainclude)
+ifeq ($(CC_$(d)), sunpro)
+CPPFLAGS_$(d) += -DOPENSSL_NO_EC
endif
-ifeq ($(VENDOR.CC), sunpro)
-DFLAGS = -g
-CFLAGS = -xcode=pic13 $(DFLAGS)
-CPPFLAGS += -DOPENSSL_NO_EC
-else
-DFLAGS = -g -Wall -Wextra -Wno-deprecated-declarations -Wno-unused
-CFLAGS = -fPIC $(DFLAGS)
-endif
+LDFLAGS_$(d) += -lssl -lcrypto
-LDFLAGS = -lssl -lcrypto
+#
+# C O M P I L A T I O N R U L E S
+#
+#all: $(d)/openssl.so
+
+define BUILD_$(d)
+
+.INTERMEDIATE: liblua$(1)-openssl
+
+$$(d)/$(1)/openssl.so: $$(d)/$(1)/openssl.o
+ $$(CC) -o $$@ $$^ $$(SOFLAGS_$$(abspath $$(@D)/..)) $$(SOFLAGS) $$(LDFLAGS_$$(abspath $$(@D)/..)) $$(LDFLAGS)
+
+$$(d)/$(1)/openssl.o: $$(d)/openssl.c $$(d)/compat52.h
+ test "$$(notdir $$(@D))" = "$$(call LUAPATH_$$(<D), $$(notdir $$(@D)), version)"
+ $$(MKDIR) -p $$(@D)
+ $$(CC) $$(CFLAGS_$$(<D)) $$(CFLAGS) $$(call LUAPATH_$$(<D), $$(notdir $$(@D)), cppflags) $$(CPPFLAGS_$$(<D)) $$(CPPFLAGS) -c -o $$@ $$<
+
+liblua$(1)-openssl: $$(d)/$(1)/openssl.so
+
+all: liblua$(1)-openssl
+
+endef # BUILD_$(d)
+
+$(eval $(call BUILD_$(d),5.1))
+
+$(eval $(call BUILD_$(d),5.2))
+
+
+#
+# I N S T A L L & U N I N S T A L L R U L E S
+#
+define INSTALL_$(d)
+
+LUAC$(1)_$(d) = $$(or $$(call LUAPATH_$(d), $(1), luac), true)
+
+MODS$(1)_$(d) = \
+ $$(DESTDIR)$(2)/_openssl.so \
+ $$(DESTDIR)$(3)/openssl/bignum.lua \
+ $$(DESTDIR)$(3)/openssl/pubkey.lua \
+ $$(DESTDIR)$(3)/openssl/x509.lua \
+ $$(DESTDIR)$(3)/openssl/x509/name.lua \
+ $$(DESTDIR)$(3)/openssl/x509/altname.lua \
+ $$(DESTDIR)$(3)/openssl/x509/chain.lua \
+ $$(DESTDIR)$(3)/openssl/x509/store.lua \
+ $$(DESTDIR)$(3)/openssl/ssl/context.lua \
+ $$(DESTDIR)$(3)/openssl/ssl.lua \
+ $$(DESTDIR)$(3)/openssl/digest.lua \
+ $$(DESTDIR)$(3)/openssl/hmac.lua \
+ $$(DESTDIR)$(3)/openssl/cipher.lua
+
+.INTERMEDIATE: liblua$(1)-openssl-install
+
+$$(DESTDIR)$(2)/_openssl.so: $$(d)/$(1)/openssl.so
+ $$(MKDIR) -p $$(@D)
+ $$(CP) -p $$< $$@
+
+$$(DESTDIR)$(3)/openssl/%.lua: $$(d)/openssl.%.lua
+ $$(MKDIR) -p $$(@D)
+ $$(CP) -p $$< $$@
+
+$$(DESTDIR)$(3)/openssl/x509/%.lua: $$(d)/openssl.x509.%.lua
+ $$(MKDIR) -p $$(@D)
+ $$(CP) -p $$< $$@
+
+$$(DESTDIR)$(3)/openssl/ssl/%.lua: $$(d)/openssl.ssl.%.lua
+ $$(MKDIR) -p $$(@D)
+ $$(CP) -p $$< $$@
+
+$$(DESTDIR)$(3)/openssl/ssl/%.lua: $$(d)/openssl.ssl.%.lua
+ $$(MKDIR) -p $$(@D)
+ $$(CP) -p $$< $$@
+
+liblua$(1)-openssl-install: $$(MODS$(1)_$$(d))
+
+.PHONY: liblua$(1)-openssl-uninstall uninstall
+
+liblua$(1)-openssl-uninstall:
+ $$(RM) -f $$(MODS$(1)_$(d))
+ -$$(RMDIR) $$(DESTDIR)$(3)/openssl/x509
+ -$$(RMDIR) $$(DESTDIR)$(3)/openssl/ssl
+ -$$(RMDIR) $$(DESTDIR)$(3)/openssl
+
+uninstall: liblua$(1)-openssl-uninstall
+
+endef # INSTALL_$(d)
+
+
+$(eval $(call INSTALL_$(d),5.1,$$(lua51cpath),$$(lua51path)))
+
+$(eval $(call INSTALL_$(d),5.2,$$(lua52cpath),$$(lua52path)))
+
+
+#
+# C L E A N R U L E S
+#
+.PHONY: $(d)/clean $(d)/clean~ clean clean~
+
+$(d)/clean:
+ $(RM) -fr $(@D)/*.so $(@D)/*.o $(@D)/*.dSYM $(@D)/5.1 $(@D)/5.2
+
+$(d)/clean~: $(d)/clean
+ $(RM) -f $(@D)/*~
+
+clean: $(d)/clean
+
+clean~: $(d)/clean~
-ifeq ($(VENDOR.OS), Darwin)
-SOFLAGS = -bundle -undefined dynamic_lookup
-else
-SOFLAGS = -shared
-endif
+endif # include guard
-all: openssl.so
-
-openssl.so: openssl.o
- $(CC) -o $@ $^ $(SOFLAGS) $(LDFLAGS)
-
-openssl.o: openssl.c compat52.h
- $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
-
-
-install: $(DESTDIR)$(luacpath)/_openssl.so \
- $(DESTDIR)$(luapath)/openssl/bignum.lua \
- $(DESTDIR)$(luapath)/openssl/pubkey.lua \
- $(DESTDIR)$(luapath)/openssl/x509.lua \
- $(DESTDIR)$(luapath)/openssl/x509/name.lua \
- $(DESTDIR)$(luapath)/openssl/x509/altname.lua \
- $(DESTDIR)$(luapath)/openssl/x509/chain.lua \
- $(DESTDIR)$(luapath)/openssl/x509/store.lua \
- $(DESTDIR)$(luapath)/openssl/ssl/context.lua \
- $(DESTDIR)$(luapath)/openssl/ssl.lua \
- $(DESTDIR)$(luapath)/openssl/digest.lua \
- $(DESTDIR)$(luapath)/openssl/hmac.lua \
- $(DESTDIR)$(luapath)/openssl/cipher.lua
-
-$(DESTDIR)$(luacpath)/_openssl.so: openssl.so
- mkdir -p $(@D)
- cp -p $< $@
-
-$(DESTDIR)$(luapath)/openssl/bignum.lua: openssl.bignum.lua
- mkdir -p $(@D)
- cp -p $< $@
-
-$(DESTDIR)$(luapath)/openssl/pubkey.lua: openssl.pubkey.lua
- mkdir -p $(@D)
- cp -p $< $@
-
-$(DESTDIR)$(luapath)/openssl/x509.lua: openssl.x509.lua
- mkdir -p $(@D)
- cp -p $< $@
-
-$(DESTDIR)$(luapath)/openssl/x509/name.lua: openssl.x509.name.lua
- mkdir -p $(@D)
- cp -p $< $@
-
-$(DESTDIR)$(luapath)/openssl/x509/altname.lua: openssl.x509.altname.lua
- mkdir -p $(@D)
- cp -p $< $@
-
-$(DESTDIR)$(luapath)/openssl/x509/chain.lua: openssl.x509.chain.lua
- mkdir -p $(@D)
- cp -p $< $@
-
-$(DESTDIR)$(luapath)/openssl/x509/store.lua: openssl.x509.store.lua
- mkdir -p $(@D)
- cp -p $< $@
-
-$(DESTDIR)$(luapath)/openssl/ssl/context.lua: openssl.ssl.context.lua
- mkdir -p $(@D)
- cp -p $< $@
-
-$(DESTDIR)$(luapath)/openssl/ssl.lua: openssl.ssl.lua
- mkdir -p $(@D)
- cp -p $< $@
-
-$(DESTDIR)$(luapath)/openssl/digest.lua: openssl.digest.lua
- mkdir -p $(@D)
- cp -p $< $@
-
-$(DESTDIR)$(luapath)/openssl/hmac.lua: openssl.hmac.lua
- mkdir -p $(@D)
- cp -p $< $@
-
-$(DESTDIR)$(luapath)/openssl/cipher.lua: openssl.cipher.lua
- mkdir -p $(@D)
- cp -p $< $@
-
-
-.PHONY: clean clean~ help
-
-clean:
- rm -f *.so *.o
- rm -f .config
-
-clean~: clean
- rm -f *~
-
-help:
- @echo "Available targets:"
- @echo ""
- @echo " all - build all binary targets"
- @echo "openssl.so - build openssl.so module"
- @echo " install - install openssl modules"
- @echo " clean - rm binary targets, object files, debugging symbols, etc"
- @echo " clean~ - clean + rm *~"
- @echo " help - echo this help message"
- @echo ""
- @echo "Some important Make variables:"
- @echo ""
- @echo " prefix - path to install root"
- @echo 'luainclude - path to Lua headers ($$(prefix)/include/lua/5.2)'
- @echo ' luapath - install path for Lua modules ($$(prefix)/share/lua/5.2)'
- @echo ' luacpath - install path for Lua C modules ($$(prefix)/lib/lua/5.2)'
- @echo ' LUAC - path to luac utility ($$(bindir)/luac)'
- @echo ""
- @echo "(NOTE: all the common GNU-style paths are supported, including"
- @echo "prefix, bindir, libdir, datadir, includedir, and DESTDIR.)"
- @echo ""
- @echo "Report bugs to <william@25thandClement.com>"
+# non-recursive epilogue
+d := $(dirstack_$(sp))
+sp := $(basename $(sp))