1#------------------------------------------------------------------------------ 2# Makefile for GNAT for adabrowse 3# 4# This makefile assumes that the ASIS libraries are in 5# ADA_INCLUDE_PATH and ADA_OBJECTS_PATH. If this is not 6# the case, uncomment and edit the alternate definitions 7# of GCC_OPTIONS and LD_OPTIONS below, and comment the now 8# uncommented ones. 9# 10# 05-APR-2002 TW Initial version 11# 02-MAY-2002 TW Added 'nasty', changed the targets so they are macro refs. 12# 08-MAY-2002 TW Changed the makefile so that it uses 'get_gcc' to figure 13# out the name of the gcc used by GNAT. 14# 08-JUN-2003 TW Added the automatic configuration stuff (with or without 15# the project manager support). 16# 20-NOV-2003 TW Correction for splitting path lists: Unix has ':' as the 17# path separator, whereas Windows uses ';'! 18# 22-FEB-2005 TW Make sure to use ./get_gcc instead of plain get_gcc so that 19# the makefile also works if a user doesn't have the current 20# directory in the PATH. 21#------------------------------------------------------------------------------ 22 23# It is assumed that the pathes to your ASIS installation are in your 24# ADA_INCLUDE_PATH and ADA_OBJECTS_PATH! 25 26# This makefile has become pretty complicated, mainly because of things 27# which we figure out when the makefile is run: 28# 29# 1. We determine the compiler name used by gnatmake by default, and 30# generate a package spec AD.Setup containing this name. 31# 32# This is so because on some Linux installations, the compiler to 33# use for GNAT is not called "gcc" but "gnatgcc", and I want AdaBrowse 34# to default to this name. 35# 36# To get the compiler's name and to create AD.Setup, we build a small 37# utility program called get_gcc. 38# 39# 2. We figure out whether the GNAT sources are available. This is indicated 40# by variable GNATSRC being set to the directory where the GNAT sources 41# are. If this variable is set, and the directory actually contains the 42# GNAT sources, then we try to configure AdaBrowse such that it uses the 43# GNAT project manager. 44# 45# This is so because I don't want to distribute parts of the GNAT sources 46# with AdaBrowse. The reason is that the project manager and some files 47# it depends on differ between different GNAT versions, and furthermore 48# I think ACT wouldn't like my distributing extracts from the 3.15p and 49# 3.16a sources. Also, I'd have to add more and more extracts as new 50# compiler versions appeared. 51# 52# So the way chosen here is actually simpler: the GNAT sources, which 53# contain the project manager, are available from ACT, and users who 54# want project manager support in AdaBrowse can get them and then just 55# tell this makefile where they are. It isn't even necessary to try to 56# build GNAT. The only requiremnet is that the sources are consistent 57# with the GNAT and ASIS version used. 58# 59# To configure AdaBrowse, we build a utility program in subdirectory 60# ./config and run it. The program then tries to build (using gnatmake) 61# a dummy application using the project manager. If that succeeds, it 62# configures AdaBrowse by generating two files ad-projects-impl.ads 63# and ad-projects-impl-get_parent.adb. if building the dummy application 64# failes, these files are set up such that AdaBrowse doesn't use the 65# GNAT project manager. 66# 67# Only after these two configuration steps building of AdaBrowse proper 68# begins. 69# 70# And finally, this makefile is being complicated by the fact that the 71# it has to work with the ancient GNU make 3.77 (distributed with GNAT 3.15p). 72 73GCC_OPTIONS = -O2 74LD_OPTIONS = -lasis 75 76host := $(shell gcc -dumpmachine) 77 78RM := rm -f 79CP := cp 80ADABROWSE := adabrowse 81NASTY := nasty 82GET_GCC := get_gcc 83EXE := 84CONFIGURE := adconf 85PATH_SEP := : 86 87ifeq "$(findstring mingw32, $(host))" "mingw32" 88 # Assume we're on Windows 89 RM := cmd.exe /c del 90 CP := cmd.exe /c copy 91 ADABROWSE := adabrowse.exe 92 NASTY := nasty.exe 93 GET_GCC := get_gcc.exe 94 CONFIGURE := adconf.exe 95 EXE := .exe 96 PATH_SEP := ; 97endif 98 99# GNAT-specific gcc options: enable all warnings, and style checking. 100# The style checking flags are nearly as plain "-gnaty", but do not 101# check comment format, and do not require explicit specs for all 102# subprograms. I chose this setting because these two things do not 103# correspond at all to *my* style. 104 105GNAT_OPTIONS := -gnatwa -gnaty3abefhiklmprt 106 107GET_GCC_GEN = get_gcc.o get_gcc.ali 108GET_GCC_FULL = $(GET_GCC_GEN) get_gcc.txt get_gcc.use 109 110ifdef GNATSRC 111 112INTERNAL_GNAT_SRC := $(subst \,/,$(subst \\,/,$(GNATSRC))) 113INTERNAL_GNAT_SRC2 := $(INTERNAL_GNAT_SRC) 114 115# Check that this GNAT source directory is correct: 116ifeq "$(strip $(wildcard $(INTERNAL_GNAT_SRC)/prj-env.ads))" "" 117 118INTERNAL_GNAT_SRC := $(INTERNAL_GNAT_SRC2)/ada 119 120ifeq "$(strip $(wildcard $(INTERNAL_GNAT_SRC)/prj-env.ads))" "" 121 122INTERNAL_GNAT_SRC := $(INTERNAL_GNAT_SRC2)/src/ada 123 124ifeq "$(strip $(wildcard $(INTERNAL_GNAT_SRC)/prj-env.ads))" "" 125 126$(error GNAT sources not found) 127# 128# Unfortunately, the error function doesn't work with GNU make 3.77, 129# which is being distributed with GNAT 3.15p. (The GNAT 3.16a distribution 130# contains the current GNU make 3.79.1.) 131# 132# Hence we deliberately use a non-existing dependency to make make stop 133# with a halfway sensible message. 134 135adabrowse : Cannot_Find_GNAT_Sources 136 137endif 138 139endif 140 141endif 142 143endif 144 145# Figure out where the ASIS installation is. 146 147Include_Dirs := $(subst \,/, $(subst $(PATH_SEP), ,$(ADA_INCLUDE_PATH))) 148A4G_DIR := $(foreach dir,$(Include_Dirs),$(wildcard $(dir)/a4g.ali)) 149 150ifeq "$(strip $(A4G_DIR))" "" 151 152# ADA_INCLUDE_PATH had better contain the asis directory. 153$(error ADA_INCLUDE_PATH must contain the ASIS installation!) 154 155adabrowse : ASIS_Not_On_ADA_INCLUDE_PATH 156 157endif 158 159ASIS_DIR := $(strip $(dir $(word 1, $(A4G_DIR)))) 160 161ifeq "$(ASIS_DIR)" "" 162 163# Something went wrong. 164$(error Cannot figure out the ASIS installation directory!) 165 166adabrowse : ASIS_Not_Found 167 168endif 169 170ifdef ADABROWSE_GNATSRC 171 172# Set the pathes so that we can compile files from the GNAT source 173# distribution without problems. If we don't do that, we will not be 174# able to link, because the GNAT compiler sources also contain 175# the library sources. We must therefore make sure that the installed 176# library always comes first! 177 178# But don't do this only the variable comes from the command line, and if 179# ADABROWSE_GCC_LIB also is defined! 180 181ifneq "$(findstring command,$(origin ADABROWSE_GNATSRC))" "" 182 183ifdef ADABROWSE_GCC_LIB 184 185export ADA_INCLUDE_PATH:=$(ASIS_DIR)$(PATH_SEP)$(ADABROWSE_GCC_LIB)$(PATH_SEP)$(ADABROWSE_GNATSRC)$(PATH_SEP)$(ADA_INCLUDE_PATH) 186export ADA_OBJECTS_PATH:=$(ASIS_DIR)$(PATH_SEP)$(subst adainclude,adalib,$(ADABROWSE_GCC_LIB))$(PATH_SEP)$(ADA_OBJECTS_PATH) 187 188endif 189 190endif 191 192# The GNAT sources may of course use internal GNAT units, so we don't 193# want that warning. Also, we get spurious warnings on elaboration issues, 194# all in GNAT sources. Suppress this warning, too. 195 196GNAT_OPTIONS += -gnatwIL 197 198endif 199 200# MAIN TARGET: (first in this makefile) 201 202all: ./config/$(CONFIGURE) run-conf 203 $(MAKE) $(ADABROWSE) \ 204 ADABROWSE_GCC_LIB=$(dir $(subst \,/,$(shell $(shell ./get_gcc -gcc get_gcc.use) -print-libgcc-file-name)))adainclude \ 205 ADABROWSE_GNATSRC=$(INTERNAL_GNAT_SRC) 206 207# Configuration stuff. We build an executable adconf, which then figures out 208# from its parameters and by trying to compile a certain file whether or not 209# we do have project manager support. 210 211./config/$(CONFIGURE): get_gcc.use ./config/adconf.adb 212 cd ./config; gnatmake -q -I.. adconf 213 214# If adconf is called with two argument only (i.e., GNATSRC is not set), it 215# configures AdaBrowse not to use the project manager. 216# 217# If adconf is called with four arguments, it configures AdaBrowse such that 218# it *does* use the project manager, and then tries to compile the file 219# ad-projects-impl_yes.adb. If that fails, it retries again after having 220# made one single change to account for a difference between GNAT 3.15p and 221# 3.16a. If compilation still fails, it reverts to the configuration not 222# using the project manager. 223 224run-conf: 225 cd ./config; \ 226 ./$(CONFIGURE) $(shell ./get_gcc -gcc get_gcc.use) \ 227 $(ASIS_DIR) \ 228 $(INTERNAL_GNAT_SRC) \ 229 $(dir $(subst \,/,$(shell $(shell ./get_gcc -gcc get_gcc.use) -print-libgcc-file-name)))adainclude 230 -cd ./config; $(CP) ad-projects-impl.ads .. 231 -cd ./config; $(CP) ad-projects-impl_yes-get_parent.adb .. 232 233# All this 'get_gcc' stuff here is GNAT specific: we try to dynamically 234# figure out the name of the gcc used by GNAT. On some systems, it 235# appears that this name is "gnatgcc", not "gcc"! 236 237get_gcc.o : 238 gnatmake -q -c -f get_gcc.adb 239 240get_gcc.ali: 241 gnatmake -q -c -f get_gcc.adb 242 243$(GET_GCC): get_gcc.o get_gcc.ali get_gcc.adb 244 gnatmake -q get_gcc 245 246# Note: the dependency below first ensures that all the files we're 247# going to delete in the rm command actually exist. This is a work- 248# around for Win 2k, where make stops because cmd.exe /c del returns 249# a failure exit code because some files may not exist. However, they 250# must not exist when we run gnatmake, or we won't have the desired 251# output in get_gcc.err. (The trick is that the first line in that 252# file will be the compile command gnatmake uses for get_gcc.adb, 253# which will start with the compiler name.) 254 255get_gcc.use: $(GET_GCC) 256 $(RM) $(GET_GCC) $(GET_GCC_GEN) 257 gnatmake get_gcc 2>get_gcc.use 258 259# Ok, finally we can build adabrowse! The first dependency handles the 260# C file in the distribution. All the others may be regenerated. 261 262ifneq "$(EXE)" "" 263 264# On Windows, add a target "adabrowse" 265 266adabrowse: $(ADABROWSE) 267 -$(warning AdaBrowse built without reconfiguration) 268 269endif 270 271$(ADABROWSE): util-nl.o \ 272 ad-setup.ads \ 273 ad-projects-impl.ads ad-projects-impl_yes-get_parent.adb 274 gnatmake $(GCC_OPTIONS) adabrowse -cargs $(GNAT_OPTIONS) \ 275 -largs $(LD_OPTIONS) 276 strip $(ADABROWSE) 277 278$(NASTY): nasty.adb 279 gnatmake nasty -cargs $(GCC_OPTIONS) 280 281ad-setup.ads: get_gcc.use 282 $(shell ./get_gcc -setup get_gcc.use) 283 284util-nl.o: get_gcc.use util-nl.c 285 $(shell ./get_gcc -gcc get_gcc.use) -c $(GCC_OPTIONS) util-nl.c 286 287clean: 288 $(RM) $(ADABROWSE) $(NASTY) $(GET_GCC) *.o *.ali 289 290