source: trunk/src/emx/Makefile.gmk@ 2009

Last change on this file since 2009 was 1941, checked in by bird, 21 years ago

builttools -> builtunix

  • Property cvs2svn:cvs-rev set to 1.4
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 12.4 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 <zap@cobra.ru>
9# $Id: Makefile.gmk 1941 2005-05-01 07:13:28Z 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.gmk
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)/builtunix/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=0
94# The C compiler flags
95ifndef NO_LOCAL_HEADERS
96CFLAGS.INC += -Iinclude
97endif
98CFLAGS.INC += -Isrc/include
99CFLAGS.INC += -Isrc/lib/bsd/include
100CFLAGS = -Wall -Wundef -Wmissing-prototypes -mstack-arg-probe $(CFLAGS.INC) $(CFLAGS.$(MODE)) $(CFLAGS.KIND)
101# The additional C compiler flags for different build modes
102CFLAGS.opt = -g -O3 -mcpu=pentium -mpreferred-stack-boundary=2 -malign-strings=2 -falign-loops=2 -falign-jumps=2 -falign-functions=3
103CFLAGS.dbg = -g -DDEBUG
104CFLAGS.prf = $(CFLAGS.opt) -pg
105CFLAGS.aout = -Zaout
106CFLAGS.omf = -Zomf
107CFLAGS.prof = -pg
108CFLAGS.log = -DDEBUG_LOGGING -D__LIBC_STRICT
109# The object files are put in subdirectory objectformat-targetkind,
110# we decompose object file name back and pick appropiate $CFLAGS
111CFLAGS.KIND = $(foreach x,$(subst -, ,$(firstword $(subst /, ,$(subst $.,,$@)))),$(CFLAGS.$x))
112# How to compile a .c file
113DO.COMPILE.c = $(CC) -std=gnu99 $(strip $(CFLAGS) $1) -o $@ $(srcdir)/$< -I$(dir $<)
114# '-std=gnu99' doesn't work with '-x assembler-with-cpp', therefor no $(call DO.COMPILE.c).
115DO.COMPILE.s = $(CC) -x assembler-with-cpp $(strip $(CFLAGS) $1) -o $@ $(srcdir)/$< -I$(dir $<)
116
117# The linker
118LD = gcc
119# Linker flags
120LDFLAGS = $(LDFLAGS.$(MODE)) $(LDFLAGS.KIND) -Zmap -Zstack 1024 -Zhigh-mem $(LIBS)
121LDFLAGS.DLL = $(LDFLAGS) -Zdll -Zfork
122# Linker flags for different build modes
123LDFLAGS.opt = -g -Zcrtdll=c_dll
124LDFLAGS.prf = -g -Zcrtdll=c_dll -lkProfile -LG:/kTaskMgr/Tree/lib/debug
125LDFLAGS.dbg = -g
126LDFLAGS.aout = -Zaout
127LDFLAGS.omf = -Zomf -Zlinker /PM:VIO -Zlinker /LINENUMBERS
128LDFLAGS.prof = -pg
129# Linker flags for different kinds of target
130LDFLAGS.KIND = $(foreach x,$(subst -, ,$(firstword $(subst /, ,$(subst $.,,$@)))),$(LDFLAGS.$x))
131# How to link a .exe file
132DO.LINK.exe = $(LD) $(strip $(LDFLAGS) $(filter-out -l%,$1)) -o $@ $(^O) $(^DEF) $(^LIB) $(filter -l%,$1)
133# How to link a .dll file
134DO.LINK.dll = $(LD) $(strip $(LDFLAGS.DLL) $(filter-out -l%,$1)) -o $@ $(^O) $(^DEF) $(^LIB) $(filter -l%,$1)
135
136# Pack executables and DLLs right after they are linked
137# bird: I don't care about space, only performance. So, we will only use
138# lxlite for stripping and sector aligning.
139# <rant> My explanation is that anything which is used frequently
140# enough will be in one of the caches, so unpacking the datasegment
141# for each new process is a waste of time. The code segment is
142# shared, data segment is not shared, but must be reloaded page by page
143# from the executable in new processes.
144# For further optimzations, we align pages on 4kb boundaries since this
145# is the JFS block size and thus should be most the efficient unit to read. </rant>
146# URG! we must not do this for ldstub.bin!
147ifeq ($(MODE),opt)
148LXLITE.FLAGS = /F+ /AP:4096 /MRN /MLN /MF1
149DO.LINK.exe += $(if $(findstring .exe,$@), $(NL)cp $@ $(basename $@).dbg $(NL)lxlite /X /AS $(subst /,\\,$@))
150DO.LINK.dll += $(NL)cp $@ $(basename $@).dbg $(NL)lxlite $(LXLITE.FLAGS) $(subst /,\\,$@)
151endif
152
153# emxbind tool
154EMXBIND = $(call GETTOOL2,emxbind)
155# emxbind flags
156EMXBINDFLAGS = -bq $(EMXBINDFLAGS.$(MODE))
157EMXBINDFLAGS.opt = -s
158EMXBINDFLAGS.prf =
159EMXBINDFLAGS.dbg =
160# Flags for emxbind
161DO.EMXBIND = $(EMXBIND) $(EMXBINDFLAGS) -o $@ $1
162
163# The macro assembler
164ifdef PATH_TOP
165ASM = $(PATH_TOP)/tools/x86.os2/masm/v6.0/binp/ml.exe -c
166else
167ASM = ml -c
168endif
169ASMFLAGS = -Cp -W3 -WX -VM -nologo
170# How to compile an .asm file
171DO.COMPILE.asm = $(ASM) $(ASMFLAGS) $1 -Fo$@ $<
172
173# The tool to create an archive
174AR = $(if $(findstring .lib,$@), $(call GETTOOL2,emxomfar),ar)
175ARFLAGS = crs
176DO.LIBRARY = $(call RM,$@); $(AR) $(ARFLAGS)$1 $@ $(^O)
177
178# The tool to extract exports from object files and archives,
179# removing unused stuff (like empty lines and comments)
180# and sorting alphabetically (looks nicer).
181EMXEXP = $(call GETTOOL2,emxexp)
182EMXEXPFLAGS = -u
183DO.EMXEXP = $(EMXEXP) $(strip $(EMXEXPFLAGS) $1) | sed -e "/^$$/d" -e "/^ *;/d" | sort -d >>$2
184
185# The tool to create import libraries
186IMPLIB = $(call GETTOOL2,emximp)
187IMPLIBFLAGS.prof = -m
188IMPLIBFLAGS.lazy = -l
189IMPLIBFLAGS.KIND = $(foreach x,$(subst -, ,$(firstword $(subst /, ,$(subst $.,,$@)))),$(IMPLIBFLAGS.$x))
190DO.IMPLIB = $(IMPLIB) -o $@ $(strip $1 $(IMPLIBFLAGS.KIND)) $(^IC)\
191 $(if $(^ID),\
192 $(NL)$(IMPLIB) -o $@.data$(suffix $@) $(strip $1) $(^ID)\
193 $(NL)$(call RMDIR,$@.tmpdir)\
194 $(NL)$(call MKDIR,$@.tmpdir)\
195 $(NL)cd $@.tmpdir && $(AR) x ../$(notdir $@.data$(suffix $@))\
196 $(NL)$(AR) rs $@ $@.tmpdir/* )\
197 $(if $(^O)$(^LIB),$(NL)$(AR) rs $@ $(^O) $(^LIB))
198
199# How to create dependencies
200MAKEDEP = makedep
201MAKEDEPFLAGS = $(CFLAGS.INC)
202DO.DEPS = $(MAKEDEP) $(MAKEDEPFLAGS) \
203 -I$(subst $(SPACE), -I,$(sort $(dir $^))) -I$. -p$(@D)/ -c -S -f$@ $^
204
205# How to convert an a.out file to the OMF format
206# Emxomf depends on two libs, we have to detect wethere or not emxomf is built
207# or not. Unfortunately make isn't up to the job of figuring this out, so we
208# must use the shell.
209EMXOMF = $(call GETTOOL2,emxomf)
210DO.EMXOMF = $(EMXOMF) $(strip $1 -o) $@ $(if $<,$<, $(subst /omf-prof/,/aout-prof/,$(subst /omf-log/,/aout-log/,$(subst /omf/,/aout/,$(@:.obj=.o)))) )
211
212# How to copy some file to installation directory
213# In optimize mode we have to strip the libraries after copying
214INSTALL=$(call CP,$1,$2)
215ifeq ($(MODE),opt)
216INSTALL += $(if $(filter-out %.a,$2),$(NL)strip --strip-debug $2)
217INSTALL += $(if $(filter-out %.lib,$2),$(NL)emxomf -s $2)
218endif
219
220# How to filter just the object files from $^
221^O = $(filter %.o,$^)
222# Just the .imp files from $^ excluing -data.imp files.
223^IC = $(filter-out %-data.imp,$(filter %.imp,$^))
224# Just the -data.imp files from $^
225^ID = $(filter %-data.imp,$^)
226# How to filter just the .def files from $^
227^DEF = $(filter %.def,$^)
228# How to filter the libraries from $^
229^LIB = $(strip $(filter %.a,$^) $(filter %.lib,$^))
230
231# A newline
232define NL
233
234
235endef
236# Opening and closing brackets (for use inside variable expansions)
237OB := (
238CB := )
239COMMA := ,
240SPACE := $(EMPTY) $(EMPTY)
241# Text output separator (cannot begin with '-', echo thinks its a switch)
242SEP := ==========================================================================
243
244# How to remove one or more files without questions
245RM = rm -f $1
246# How to remove one or more directories without questions
247RMDIR = rm -rf $1
248# How to copy several files to a directory
249CP = cp $1 $2
250# Miscelaneous tools
251MKDIR = mkdir.exe -p $1
252# How to update a file only if it has been changed
253UPDATE = (cmp -s $1 $2 || mv -f $1 $2) && rm -f $1
254# How to touch a file
255TOUCH = touch $1
256# Re-build the original string including the ',' between args. Also escape
257# dollars since otherwise ash would expand them.
258ECHOIZE = $(subst $$,\$$,$1$(strip $(subst $(SPACE)$(COMMA),$(COMMA),$(foreach x,2 3 4 5 6 7 8 9,$(if $($x),$(COMMA) $($x))))))
259# How to output a text string (with appended newline)
260ECHO = echo "$(call ECHOIZE,$1,$2,$3,$4,$5,$6,$7,$8,$9)"
261# Same but append the text to a file (given with first argument)
262FECHO = echo "$(call ECHOIZE,$2,$3,$4,$5,$6,$7,$8,$9)" >> "$1"
263# How to replace the source file extension with a .o extension
264OBJEXT = $(patsubst %.s,%.o,$(patsubst %.asm,%.o,$(patsubst %.c,%.o,$1)))
265# Compute object file path given source file path (except the $. prefix)
266OBJFILE = $(addprefix $(.TKIND.DIR),$(call OBJEXT,$1))
267
268#------------ Variables appended by submakefiles ------------
269# The list of available modules
270MODULES :=
271# The help text for module list
272DO.HELP.MODULES :=
273# The help about public makefile variables
274DO.HELP.VARS := $(call ECHO, MODE={dbg|opt|prf} - choose between debug, optimized and profiled build modes.)$(NL)
275DO.HELP.VARS += $(call ECHO, OBJF={omf|aout} - build object files in omf or a.out format.)$(NL)
276# The list of work directories needeed for building all targets
277TARGDIRS :=
278# Build rules (_@_ replaced by name of generated makefile)
279RULES :=
280# The list of dependency files
281TARGDEPEND :=
282# The list of installed files
283INS.FILES :=
284
285.PHONY: default help all libs tools clean install install cleandep \
286 cleandepend dep depend depdone
287.SUFFIXES:
288.SUFFIXES: .c .cpp .asm .s .o .exe .dll .a .lib .obj
289
290# Default target
291default: help
292
293#------------ Submakefiles ------------
294ifndef SUBMAK
295SUBMAK := version.smak $(wildcard src/*/*.smak) include/include.smak $(wildcard bsd/*/*.smak) $(wildcard gnu/*/*.smak)
296endif
297
298# include template rules
299include templates.smak
300
301# Include all submakefiles
302-include $(SUBMAK)
303
304# Sort and remove duplicate directories
305TARGDIRS := $(sort $(TARGDIRS))
306# Find out which directories are needed for installation
307INSDIRS := $(sort $(dir $(INS.FILES)))
308
309#------------ Global targets ------------
310help:
311 @$(call ECHO,$(SEP))
312 @$(call ECHO,Welcome to $(PACKAGE) version $(VERSION) build system!)
313 @$(call ECHO,$(COPYRIGHT))
314 @$(call ECHO,To build something, type 'make {target} {vars}', where {target} is one of:)
315 @$(call ECHO, all - build all available modules)
316 @$(call ECHO, {module-name} - build just a particular module)
317 @$(call ECHO, tools - build just the tools)
318 @$(call ECHO, libs - build all libraries)
319 @$(call ECHO, clean - remove all generated files (remove all built files))
320 @$(call ECHO, install - generate a installation tree in $(INS))
321 @$(call ECHO, dep - generate dependency files for all changed targets)
322 @$(call ECHO, cleandep - remove all dependency file)
323 @$(call ECHO,$(SEP))
324 @$(call ECHO,There are a number of variables than can be set in the make)
325 @$(call ECHO,command line to control various aspects of compilation:)
326 @$(DO.HELP.VARS)
327 @$(call ECHO,$(SEP))
328 @$(call ECHO,The following modules are included in this package:)
329 @$(DO.HELP.MODULES)
330 @$(call ECHO,$(SEP))
331
332all: $(MODULES)
333
334clean:
335 $(call RMDIR,$(OUT))
336
337cleandep cleandepend:
338 $(call RM,$(TARGDEPEND))
339
340dep depend:
341 @$(MAKE) -f $(MAKEFILE) --no-print-directory BUILD_DEPS=1 depdone
342
343depdone:
344 @$(call ECHO,Dependency files succesfully updated)
345
346install: all $(INSDIRS) $(INS.FILES)
347
348$. $(INSDIRS) $(TARGDIRS):
349 $(call MKDIR,$@)
350
351# bird: add rule for forcibly re-generating the rules.
352rules:
353 @$(call ECHO,smak don't generate rules anylonger!)
354
355# The general a.out -> OMF conversion rules for object files
356$.omf/%.obj:
357 $(call DO.EMXOMF)
358$.omf-log/%.obj:
359 $(call DO.EMXOMF)
360$.omf-prof/%.obj:
361 $(call DO.EMXOMF)
362
363# The general a.out -> OMF conversion rule for libraries
364$.omf%.lib:
365 $(call MKDIR, $(dir $@))
366 $(call DO.EMXOMF)
367
368#
369# Checkout rule
370#
371checkout update up:
372 cvs -q update -d -P 2>&1 | tee up.log
373
374
Note: See TracBrowser for help on using the repository browser.