summaryrefslogtreecommitdiff
path: root/makefiles/Makefile.tools
blob: 0747062507ceffbc3a03f8d3ba3dbd18d3156870 (plain)
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
# Tools Makefile fragment
#
# Expected inputs:
#
# COMPONENT_TYPE	Type of component:
# 				binary		-	Executable binary
# 				lib-static	-	Static library
# 				lib-shared	-	Shared library
#
# Optional inputs:
#
# BUILD			Type of build to perform:
# 				release		-	Release build (default)
# 				debug		-	Debug build
# OPTCFLAGS		Optional compiler flags for $(BUILD)
# OPTLDFLAGS		Optional linker flags for $(BUILD)
# TARGET		Target platform (defaults to host)
#

###############################################################################
# Sanity checks
###############################################################################

ifeq ($(COMPONENT_TYPE),)
  $(error COMPONENT_TYPE not set)
endif

# Default build to release
ifeq ($(BUILD),)
  BUILD := release
endif

###############################################################################
# Host/target platform detection
###############################################################################

HOST := $(shell uname -s)
ifeq ($(HOST),)
  # Don't ask
  HOST := riscos
else
  ifeq ($(HOST),RISC OS)
    HOST := riscos
  endif
endif

ifeq ($(TARGET),)
  # Default target to host. Please add exceptions as required.
  TARGET := $(HOST)
endif

# Now setup our tooling
ifeq ($(TARGET),riscos)
  ifeq ($(HOST),riscos)
    # Building on native RISC OS
    GCCSDK_INSTALL_ENV ?= <NSLibs$$Dir>

    CC := gcc
    GENHTML := echo
    INSTALL := echo
    LCOV := echo
    PKGCONFIG :=

    # This is nasty, but needed because $(CURDIR) will 
    # contain colons, and thus confuse make mightily
    $(shell SetMacro Alias$$$(COMPONENT)pwd Set %0 <FileSwitch$$CurrentFilingSystem>:|<FileSwitch$$<FileSwitch$$CurrentFilingSystem>$$CSD>|mUnset Alias$$$(COMPONENT)pwd)
    $(shell $(COMPONENT)pwd $(COMPONENT)$$Dir)
    CURDIR := <$(COMPONENT)$$Dir>
  else
    # Cross compiling for RISC OS
    GCCSDK_INSTALL_ENV ?= /home/riscos/env
    GCCSDK_INSTALL_CROSSBIN ?= /home/riscos/cross/bin

    AR := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*ar)
    CC := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*gcc)
    GENHTML := echo
    LCOV := echo
    PKGCONFIG := $(GCCSDK_INSTALL_ENV)/ro-pkg-config
 
    ifneq ($(findstring arm-unknown-riscos-gcc,$(CC)),)
      EXEEXT := ,e1f
    else
      EXEEXT := ,ff8
    endif
  endif

  CFLAGS := $(CFLAGS) -mpoke-function-name -I$(GCCSDK_INSTALL_ENV)/include
  LDFLAGS := $(LDFLAGS) -L$(GCCSDK_INSTALL_ENV)/lib

  # Default prefix
  PREFIX ?= $(GCCSDK_INSTALL_ENV)
endif

##############################################################################
# Tool defaults
##############################################################################

CP ?= cp

DOXYGEN ?= doxygen

ECHO ?= echo

GENHTML ?= genhtml

INSTALL ?= install

LCOV ?= lcov

MAKE ?= make

MKDIR ?= mkdir
MKDIRFLAGS ?= -p

PERL ?= perl

PKGCONFIG ?= pkg-config

SED ?= sed

TOUCH ?= touch

###############################################################################
# Default compiler/linker flags
###############################################################################

ifeq ($(BUILD),release)
  OPTCFLAGS ?= -DNDEBUG -O2
else
  OPTCFLAGS ?= -g -O0
  OPTLDFLAGS ?= -g
endif

CFLAGS := $(CFLAGS) $(OPTCFLAGS)
LDFLAGS := $(LDFLAGS) $(OPTLDFLAGS)

###############################################################################
# lib-shared defaults
###############################################################################

# Default library extension
ifeq ($(COMPONENT_TYPE),lib-static)
  LIBEXT ?= .a
else
  LIBEXT ?= .so
endif

# If we're building a shared library, modify the flags appropriately
ifeq ($(COMPONENT_TYPE),lib-shared)
  # Default CFLAGS/LDFLAGS for shared libraries
  SHAREDCFLAGS ?= -fPIC -DPIC
  SHAREDLDFLAGS ?= -shared
endif

###############################################################################
# Other settings
###############################################################################

# If GCC can cope with simultaneous build & dep, do that as it's faster
ifneq ($(GCCVER),2)
  CC_CAN_BUILD_AND_DEP ?= yes
endif