source: trunk/src/emx/Makefile@ 1133

Last change on this file since 1133 was 1133, checked in by bird, 22 years ago

Made it repect PATH_OBJ and BUILD_MODE env.vars.

  • Property cvs2svn:cvs-rev set to 1.41
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 11.2 KB
Line 
1# Central makefile for building the OS2/GCC C runtime
2#
3# InnoTek Systemberatung GmbH
4#
5# Copyright (c) 1994-1995 by Eberhard Mattes
6# Copyright (c) 2003 InnoTek Systemberatung GmbH
7#
8# Author: Andrew Zabolotny <[email protected]>
9# $Id: Makefile 1133 2004-01-31 23:57:51Z bird $
10#
11# All Rights Reserved
12#
13# Requires GNU Make.
14# In fact, this build system could be entitled "GNU Make Unleashed"
15#
16# For a brief description of how build system works please read build.txt
17#
18# Bootstrapping sequence using EMX gcc compiler:
19#
20# 1. Backup include/ctype.h and rename include/ctype.h-bootstrap to
21# include/ctype.h
22# 2. Run 'make os2', put the resulting library os2.a to emx/lib as _os2.a,
23# and convert it to .lib with emxomf: 'emxomf _os2.a'
24# 3. Now compile everything you wish this way: 'make LIBS=-l_os2'
25#
26
27# Build type control variables. You can set them right from command line,
28# e.g "make MODE=dbg"
29
30# Build mode: opt (optimization), dbg (debug)
31MODE = dbg
32# Base output directory
33OUT = out/
34# Base installation directory
35INS = out/$(MODE)/install/
36# CPU type (pretend we are portable ;-)
37CPU = 386
38# Name of this makefile
39ifndef MAKEFILE
40MAKEFILE = Makefile
41endif
42
43# Actual output directory (referenced with $.)
44. = $(OUT)$(MODE)/
45
46# overrides from the environment.
47ifdef PATH_OBJ
48ifndef PATH_OBJD
49PATH_OBJD := $(shell echo $(PATH_OBJ)|sed 's/^[a-zA-Z]://')
50endif
51OUT = $(PATH_OBJD)/emx/
52INS = $(PATH_OBJD)/builttools/usr/
53. = $(OUT)
54endif
55
56ifdef BUILD_MODE
57ifeq ($(BUILD_MODE),RELEASE)
58MODE = opt
59endif
60endif
61
62# Check if MODE has a valid value
63ifneq ($(filter-out /opt/ /dbg/ /prf/,/$(MODE)/),)
64$(error MODE should have one of the following values: opt, dbg, prf)
65endif
66
67# The object file format to use for tools (emxomf, ld and friends)
68TOOLFMT.dbg = omf
69TOOLFMT.opt = omf
70TOOLFMT.prf = omf
71TOOLFMT = $(TOOLFMT.$(MODE))
72
73# Use ash.exe which is quite fast (comparable to cmd.exe) but has more features
74SHELL := ash.exe
75
76# Source base directory.
77srcdir := $(shell pwd)
78
79# File name extensions
80# Executable files -- xxx$E
81E = .exe
82# DLL files --- xxx$D
83D = .dll
84# Library files --- xxx$A
85A = .$(if $(findstring omf,$(.TKIND)),lib,a)
86
87# Use the tool we built.
88GETTOOL ?= $.$(TOOLFMT)/$1$E
89# Use the tool we built if present
90GETTOOL2 ?= `test -f '$.$(TOOLFMT)/$1$E' && echo '$.$(TOOLFMT)/'`$1$E
91
92# The C compiler
93CC = gcc -c -Zmt -fmessage-length=150
94# The C compiler flags
95ifndef NO_LOCAL_HEADERS
96CFLAGS.INC += -Iinclude
97endif
98CFLAGS.INC += -Isrc/include
99CFLAGS = -Wall -Wmissing-prototypes -mstack-arg-probe $(CFLAGS.INC) $(CFLAGS.$(MODE)) $(CFLAGS.KIND)
100# The additional C compiler flags for different build modes
101CFLAGS.opt = -g -O3
102CFLAGS.dbg = -g -DDEBUG
103CFLAGS.prf = -g -O3 -pg
104CFLAGS.aout = -Zaout
105CFLAGS.omf = -Zomf
106CFLAGS.prof = -pg
107# The object files are put in subdirectory objectformat-targetkind,
108# we decompose object file name back and pick appropiate $CFLAGS
109CFLAGS.KIND = $(foreach x,$(subst -, ,$(firstword $(subst /, ,$(subst $.,,$@)))),$(CFLAGS.$x))
110# How to compile a .c file
111DO.COMPILE.c = $(CC) $(strip $(CFLAGS) $1) -o $@ $(srcdir)/$< -I$(dir $<)
112DO.COMPILE.s = $(call DO.COMPILE.c,-x assembler-with-cpp $1)
113
114# The linker
115LD = gcc
116# Linker flags
117LDFLAGS = $(LDFLAGS.$(MODE)) $(LDFLAGS.KIND) -Zmap -Zstack 1024 -Zhigh-mem $(LIBS)
118LDFLAGS.DLL = $(LDFLAGS) -Zdll
119# Linker flags for different build modes
120LDFLAGS.opt = -g -Zcrtdll=c_dll
121LDFLAGS.prf = -g -Zcrtdll=c_dll -lkProfile -LG:/kTaskMgr/Tree/lib/debug
122LDFLAGS.dbg = -g
123LDFLAGS.aout = -Zaout
124LDFLAGS.omf = -Zomf -Zlinker /PM:VIO -Zlinker /LINENUMBERS
125LDFLAGS.prof = -pg
126# Linker flags for different kinds of target
127LDFLAGS.KIND = $(foreach x,$(subst -, ,$(firstword $(subst /, ,$(subst $.,,$@)))),$(LDFLAGS.$x))
128# How to link a .exe file
129DO.LINK.exe = $(LD) $(strip $(LDFLAGS) $(filter-out -l%,$1)) -o $@ $(^O) $(^DEF) $(^LIB) $(filter -l%,$1)
130# How to link a .dll file
131DO.LINK.dll = $(LD) $(strip $(LDFLAGS.DLL) $(filter-out -l%,$1)) -o $@ $(^O) $(^DEF) $(^LIB) $(filter -l%,$1)
132
133# Pack executables and DLLs right after they are linked
134# bird: I don't care about space, only performance. So, we will only use
135# lxlite for stripping and sector aligning.
136# <rant> My explanation is that anything which is used frequently
137# enough will be in one of the caches, so unpacking the datasegment
138# for each new process is a waste of time. The code segment is
139# shared, data segment is not shared, but must be reloaded page by page
140# from the executable in new processes. </rant>
141# URG! we must not do this for ldstub.bin!
142ifeq ($(MODE),opt)
143DO.LINK.exe += $(if $(findstring .exe,$@), $(NL)cp $@ $(basename $@).dbg $(NL)lxlite /X /AS $@)
144DO.LINK.dll += $(NL)cp $@ $(basename $@).dbg $(NL)lxlite /F+ /AP:4096 /MRN /MLN /MF3 $@
145endif
146
147# emxbind tool
148EMXBIND = $(call GETTOOL2,emxbind)
149# emxbind flags
150EMXBINDFLAGS = -bq $(EMXBINDFLAGS.$(MODE))
151EMXBINDFLAGS.opt = -s
152EMXBINDFLAGS.prf =
153EMXBINDFLAGS.dbg =
154# Flags for emxbind
155DO.EMXBIND = $(EMXBIND) $(EMXBINDFLAGS) -o $@ $1
156
157# The macro assembler
158ifdef PATH_TOP
159ASM = $(PATH_TOP)/tools/x86.os2/masm/v6.0/binp/ml.exe -c
160else
161ASM = ml -c
162endif
163ASMFLAGS = -Cp -W3 -WX -VM -nologo
164# How to compile an .asm file
165DO.COMPILE.asm = $(ASM) $(ASMFLAGS) $1 -Fo$@ $<
166
167# The tool to create an archive
168AR = $(if $(findstring .lib,$@), $(call GETTOOL2,emxomfar),ar)
169ARFLAGS = crs
170DO.LIBRARY = $(call RM,$@); $(AR) $(ARFLAGS)$1 $@ $(^O)
171
172# The tool to extract exports from object files and archives,
173# removing unused stuff (like empty lines and comments)
174# and sorting alphabetically (looks nicer).
175EMXEXP = $(call GETTOOL2,emxexp)
176EMXEXPFLAGS = -u
177DO.EMXEXP = $(EMXEXP) $(strip $(EMXEXPFLAGS) $1) | sed -e "/^$$/d" -e "/^ *;/d" | sort -d >>$2
178
179# The tool to create import libraries
180IMPLIB = $(call GETTOOL2,emximp)
181IMPLIBFLAGS.prof = -m
182IMPLIBFLAGS.KIND = $(foreach x,$(subst -, ,$(firstword $(subst /, ,$(subst $.,,$@)))),$(IMPLIBFLAGS.$x))
183DO.IMPLIB = $(IMPLIB) -o $@ $(strip $1 $(IMPLIBFLAGS.KIND)) $(^I)\
184 $(if $(^O),$(NL)$(AR) rs $@ $(^O))
185
186# How to create dependencies
187MAKEDEP = makedep
188MAKEDEPFLAGS = $(CFLAGS.INC)
189DO.DEPS = $(MAKEDEP) $(MAKEDEPFLAGS) \
190 -I$(subst $(SPACE), -I,$(sort $(dir $^))) -I$. -p$(@D)/ -c -S -f$@ $^
191
192# How to convert an a.out file to the OMF format
193# Emxomf depends on two libs, we have to detect wethere or not emxomf is built
194# or not. Unfortunately make isn't up to the job of figuring this out, so we
195# must use the shell.
196EMXOMF = $(call GETTOOL2,emxomf)
197DO.EMXOMF = $(EMXOMF) $(strip $1 -o) $@ $(if $<,$<, $(subst /omf/,/aout/,$(@:.obj=.o)) )
198
199# How to copy some file to installation directory
200# In optimize mode we have to strip the libraries after copying
201INSTALL=$(call CP,$1,$2)
202ifeq ($(MODE),opt)
203INSTALL += $(if $(filter-out %.a,$2),$(NL)strip --strip-debug $2)
204INSTALL += $(if $(filter-out %.lib,$2),$(NL)emxomf -s $2)
205endif
206
207# How to filter just the object files from $^
208^O = $(filter %.o,$^)
209# Just the .imp files from $^
210^I = $(filter %.imp,$^)
211# How to filter just the .def files from $^
212^DEF = $(filter %.def,$^)
213# How to filter the libraries from $^
214^LIB = $(strip $(filter %.a,$^) $(filter %.lib,$^))
215
216# A newline
217define NL
218
219
220endef
221# Opening and closing brackets (for use inside variable expansions)
222OB := (
223CB := )
224COMMA := ,
225SPACE := $(EMPTY) $(EMPTY)
226# Text output separator (cannot begin with '-', echo thinks its a switch)
227SEP := ==========================================================================
228
229# How to remove one or more files without questions
230RM = rm -f $1
231# How to remove one or more directories without questions
232RMDIR = rm -rf $1
233# How to copy several files to a directory
234CP = cp $1 $2
235# Miscelaneous tools
236MKDIR = mkdir.exe -p $1
237# How to update a file only if it has been changed
238UPDATE = (cmp -s $1 $2 || mv -f $1 $2) && rm -f $1
239# How to touch a file
240TOUCH = touch $1
241# Re-build the original string including the ',' between args. Also escape
242# dollars since otherwise ash would expand them.
243ECHOIZE = $(subst $$,\$$,$1$(strip $(subst $(SPACE)$(COMMA),$(COMMA),$(foreach x,2 3 4 5 6 7 8 9,$(if $($x),$(COMMA) $($x))))))
244# How to output a text string (with appended newline)
245ECHO = echo "$(call ECHOIZE,$1,$2,$3,$4,$5,$6,$7,$8,$9)"
246# Same but append the text to a file (given with first argument)
247FECHO = echo "$(call ECHOIZE,$2,$3,$4,$5,$6,$7,$8,$9)" >> "$1"
248# How to replace the source file extension with a .o extension
249OBJEXT = $(patsubst %.s,%.o,$(patsubst %.asm,%.o,$(patsubst %.c,%.o,$1)))
250# Compute object file path given source file path (except the $. prefix)
251OBJFILE = $(addprefix $(.TKIND.DIR),$(call OBJEXT,$1))
252
253#------------ Variables appended by submakefiles ------------
254# The list of available modules
255MODULES :=
256# The help text for module list
257DO.HELP.MODULES :=
258# The help about public makefile variables
259DO.HELP.VARS := $(call ECHO, MODE={dbg|opt|prf} - choose between debug, optimized and profiled build modes.)$(NL)
260DO.HELP.VARS += $(call ECHO, OBJF={omf|aout} - build object files in omf or a.out format.)$(NL)
261# The list of work directories needeed for building all targets
262TARGDIRS :=
263# Build rules (_@_ replaced by name of generated makefile)
264RULES :=
265# The list of dependency files
266TARGDEPEND :=
267# The list of installed files
268INS.FILES :=
269
270.PHONY: default help all libs tools clean install install cleandep \
271 cleandepend dep depend depdone
272.SUFFIXES:
273.SUFFIXES: .c .cpp .asm .s .o .exe .dll .a .lib .obj
274
275# Default target
276default: help
277
278#------------ Submakefiles ------------
279ifndef SUBMAK
280SUBMAK := version.smak $(wildcard src/*/*.smak) include/include.smak $(wildcard bsd/*/*.smak) $(wildcard gnu/*/*.smak)
281endif
282
283# include template rules
284include templates.smak
285
286# Include all submakefiles
287-include $(SUBMAK)
288
289# Sort and remove duplicate directories
290TARGDIRS := $(sort $(TARGDIRS))
291# Find out which directories are needed for installation
292INSDIRS := $(sort $(dir $(INS.FILES)))
293
294#------------ Global targets ------------
295help:
296 @$(call ECHO,$(SEP))
297 @$(call ECHO,Welcome to $(PACKAGE) version $(VERSION) build system!)
298 @$(call ECHO,$(COPYRIGHT))
299 @$(call ECHO,To build something, type 'make {target} {vars}', where {target} is one of:)
300 @$(call ECHO, all - build all available modules)
301 @$(call ECHO, {module-name} - build just a particular module)
302 @$(call ECHO, tools - build just the tools)
303 @$(call ECHO, libs - build all libraries)
304 @$(call ECHO, clean - remove all generated files (remove all built files))
305 @$(call ECHO, install - generate a installation tree in $(INS))
306 @$(call ECHO, dep - generate dependency files for all changed targets)
307 @$(call ECHO, cleandep - remove all dependency file)
308 @$(call ECHO,$(SEP))
309 @$(call ECHO,There are a number of variables than can be set in the make)
310 @$(call ECHO,command line to control various aspects of compilation:)
311 @$(DO.HELP.VARS)
312 @$(call ECHO,$(SEP))
313 @$(call ECHO,The following modules are included in this package:)
314 @$(DO.HELP.MODULES)
315 @$(call ECHO,$(SEP))
316
317all: $(MODULES)
318
319clean:
320 $(call RMDIR,$(OUT))
321
322cleandep cleandepend:
323 $(call RM,$(TARGDEPEND))
324
325dep depend:
326 @$(MAKE) --no-print-directory BUILD_DEPS=1 depdone
327
328depdone:
329 @$(call ECHO,Dependency files succesfully updated)
330
331install: all $(INSDIRS) $(INS.FILES)
332
333$. $(INSDIRS) $(TARGDIRS):
334 $(call MKDIR,$@)
335
336# bird: add rule for forcibly re-generating the rules.
337rules:
338 @$(call ECHO,smak don't generate rules anylonger!)
339
340# The general a.out -> OMF conversion rule for object files
341$.omf/%.obj:
342 $(call DO.EMXOMF)
343
344# The general a.out -> OMF conversion rule for libraries
345$.omf%.lib:
346 $(call DO.EMXOMF)
347
Note: See TracBrowser for help on using the repository browser.