Externals/common.mk - Fixed depenency issues
[tpg/acess2.git] / Externals / common.mk
1
2 # Acess2 OS - "Externals"
3 # - By John Hodge (thePowersGang)
4 #
5 # common.mk
6 # - Common makefile code for imported code
7
8 -include ../../Makefile.cfg
9
10 ifeq ($(ARCH),x86)
11  BFD := i586
12 else ifeq ($(ARCH),x86_64)
13  BFD := x86_64
14 else
15  $(error No BFD translation for $(ARCH) in Externals/common.mk)
16 endif
17
18 #PREFIX=$(ACESSDIR)/Externals/Output
19 #EPREFIX=$(ACESSDIR)/Externals/Output/$(BFD)
20 PREFIX=$(ACESSDIR)/Externals/Output/$(ARCH)
21 EPREFIX=$(PREFIX)
22 SYSROOT=$(ACESSDIR)/Externals/Output/sysroot-$(BFD)
23 HOST=$(BFD)-acess_proxy-elf
24
25 #
26 # DEPS : Dependencies for this program/library 
27 # TARBALL_PATTERN : $(wildcard ) format [glob] pattern
28 # TARBALL_TO_DIR : $(patsubst ) format conversion
29 # PATCHES : List of altered files in the source
30 #  > If patches/%.patch exists, the original is patched, else patches/% is copied in
31 # CONFIGURE_ARGS : Extra arguments to ./configure (ignoring host and prefix)
32 # [?]BTARGETS : Build targets (Defaults to all)
33 # [?]ARCHIVE : Optional forced archive (Defaults to latest)
34 # [?]CONFIGURE_LINE : Command to create makefile (defaults to autotools configure)
35 # [?]NOBDIR : Set to non-empty to disable use of a separate build dir
36 # [?]AUTORECONF : Set to non-empty to regenerate ./configure
37
38
39 BTARGETS ?= all
40 ITARGETS ?= install
41
42 _VERS := $(wildcard $(TARBALL_PATTERN))
43 _VERS := $(sort $(_VERS))
44 _LATEST := $(lastword $(_VERS))
45
46 ifeq ($(ARCHIVE),)
47  ifeq ($(_LATEST),)
48   $(warning Unable to find an archive matching $(TARBALL_PATTERN))
49   $(error No archive found)
50  endif
51  
52  ifneq ($(_LATEST),$(_VERS))
53   $(warning Multiple archvies found, picked $(_LATEST))
54  endif
55  ARCHIVE := $(_LATEST)
56 endif
57
58 DIR := $(patsubst $(TARBALL_TO_DIR_L),$(TARBALL_TO_DIR_R),$(ARCHIVE))
59
60 ifeq ($(NOBDIR),)
61  BDIR := build-$(DIR)
62 else
63  BDIR := $(DIR)
64 endif
65 SDIR := ../$(DIR)
66
67 CONFIGURE_LINE ?= $(SDIR)/configure --host=$(HOST) --prefix=$(PREFIX) --exec-prefix=$(EPREFIX) $(CONFIGURE_ARGS)
68
69 .PHONY: all clean install _patch _build
70
71 install: all
72         cd $(BDIR) && make $(ITARGETS)
73
74 all: $(DIR) _patch _build
75
76 clean:
77         rm -rf $(DIR) $(BDIR)
78
79 $(DIR): $(ARCHIVE)
80         tar -xf $(ARCHIVE)
81
82 $(DIR)/%: patches/%.patch
83         @echo [PATCH] $@
84         @tar -xf $(ARCHIVE) $@
85         @patch $@ $<
86
87 $(DIR)/%: patches/%
88         @echo [CP] $@
89         @mkdir -p $(dir $@)
90         @cp $< $@
91
92 PATCHED_FILES := $(addprefix $(DIR)/,$(PATCHES))
93 _patch: $(DIR) $(PATCHED_FILES)
94
95 CONFIGSCRIPT := $(BDIR)/$(firstword $(CONFIGURE_LINE))
96 PATCHED_ACFILES := $(filter %/configure.in %/config.sub, $(PATCHED_FILES))
97 $(warning $(CONFIGSCRIPT): $(PATCHED_ACFILES))
98
99 $(CONFIGSCRIPT): $(PATCHED_ACFILES)
100 ifeq ($(AUTORECONF),)
101 else
102         cd $(DIR) && autoreconf --force --install
103 endif
104
105 $(BDIR)/Makefile: _patch $(CONFIGSCRIPT) ../common.mk Makefile 
106         mkdir -p $(BDIR)
107         cd $(BDIR) && $(CONFIGURE_LINE)
108
109 _build: $(BDIR)/Makefile
110         cd $(BDIR) && make $(BTARGETS)
111

UCC git Repository :: git.ucc.asn.au