Makefile.fpc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. #
  2. # Makefile.fpc for Free Pascal Compiler
  3. #
  4. [package]
  5. name=compiler
  6. version=2.0.0
  7. [target]
  8. programs=pp
  9. dirs=utils
  10. [compiler]
  11. targetdir=.
  12. unittargetdir=$(CPU_UNITDIR)/units/$(FULL_TARGET)
  13. unitdir=$(COMPILERSOURCEDIR)
  14. includedir=$(PPC_TARGET)
  15. [require]
  16. packages=rtl
  17. tools=diff cmp
  18. [install]
  19. fpcpackage=y
  20. [default]
  21. fpcdir=..
  22. [prerules]
  23. # Don't export version it can change after the first compile
  24. unexport FPC_VERSION FPC_COMPILERINFO
  25. # Which platforms are ready for inclusion in the cycle
  26. CYCLETARGETS=i386 powerpc sparc arm x86_64 powerpc64
  27. # All supported targets used for clean
  28. ALLTARGETS=$(CYCLETARGETS) m68k
  29. # Allow ALPHA, POWERPC, POWERPC64, M68K, I386 defines for target cpu
  30. ifdef ALPHA
  31. PPC_TARGET=alpha
  32. endif
  33. ifdef POWERPC
  34. PPC_TARGET=powerpc
  35. endif
  36. ifdef POWERPC64
  37. PPC_TARGET=powerpc64
  38. endif
  39. ifdef SPARC
  40. PPC_TARGET=sparc
  41. endif
  42. ifdef M68K
  43. PPC_TARGET=m68k
  44. endif
  45. ifdef I386
  46. PPC_TARGET=i386
  47. endif
  48. ifdef X86_64
  49. PPC_TARGET=x86_64
  50. endif
  51. ifdef ARM
  52. PPC_TARGET=arm
  53. endif
  54. # Default is to generate a compiler for the same
  55. # platform as CPU_TARGET (a native compiler)
  56. ifndef PPC_TARGET
  57. PPC_TARGET=$(CPU_TARGET)
  58. endif
  59. # Default is to generate a compiler for the same
  60. # target as OS_TARGET (a native compiler)
  61. ifndef PPC_OS
  62. PPC_OS=$(OS_TARGET)
  63. endif
  64. # Where to place the unit files.
  65. CPU_UNITDIR=$(PPC_TARGET)
  66. # RTL
  67. UTILSDIR=../utils
  68. # Directories containing compiler sources
  69. COMPILERSOURCEDIR=$(PPC_TARGET) systems
  70. # Utils used by compiler development/installation
  71. COMPILERUTILSDIR=utils
  72. # Default language for the compiler
  73. ifndef FPCLANG
  74. FPCLANG=e
  75. endif
  76. # Local options for the compiler only
  77. ifndef LOCALOPT
  78. LOCALOPT:=$(OPT)
  79. endif
  80. # Options for the RTL only when cycling
  81. ifndef RTLOPT
  82. RTLOPT:=$(OPT)
  83. endif
  84. # Make OPT empty. It is copied to LOCALOPT and RTLOPT
  85. override OPT=
  86. # Message files
  87. MSGFILES=$(wildcard msg/error*.msg)
  88. # ppcSUFFIX
  89. ifeq ($(PPC_TARGET),i386)
  90. CPUSUF=386
  91. endif
  92. ifeq ($(PPC_TARGET),alpha)
  93. CPUSUF=axp
  94. endif
  95. ifeq ($(PPC_TARGET),m68k)
  96. CPUSUF=68k
  97. endif
  98. ifeq ($(PPC_TARGET),powerpc)
  99. CPUSUF=ppc
  100. endif
  101. ifeq ($(PPC_TARGET),powerpc64)
  102. CPUSUF=ppc64
  103. endif
  104. ifeq ($(PPC_TARGET),sparc)
  105. CPUSUF=sparc
  106. endif
  107. ifeq ($(PPC_TARGET),x86_64)
  108. CPUSUF=x64
  109. endif
  110. ifeq ($(PPC_TARGET),arm)
  111. CPUSUF=arm
  112. endif
  113. # Do not define the default -d$(CPU_TARGET) because that
  114. # will conflict with our -d$(PPC_TARGET)
  115. NOCPUDEF=1
  116. # Default message file
  117. MSGFILE=msg/error$(FPCLANG).msg
  118. # Define Unix also for Linux
  119. ifeq ($(OS_TARGET),linux)
  120. ifneq ($(findstring 1.0.,$(FPC_VERSION)),)
  121. override LOCALOPT+=-dUNIX
  122. endif
  123. endif
  124. ifeq ($(OS_TARGET),freebsd)
  125. ifneq ($(findstring 1.0.,$(FPC_VERSION)),)
  126. override LOCALOPT+=-dUNIX
  127. endif
  128. endif
  129. REVINC:=$(wildcard revision.inc)
  130. ifneq ($(REVINC),)
  131. override LOCALOPT+=-dREVINC
  132. ifeq ($(REVSTR),)
  133. SVNVERSION:=$(wildcard svnversion$(EXEEXT))
  134. REVSTR:=$(shell svnversion .)
  135. export REVSTR
  136. endif
  137. endif
  138. # set correct defines (-d$(CPU_TARGET) is automaticly added in makefile.fpc)
  139. override LOCALOPT+=-d$(PPC_TARGET) -dGDB -dBROWSERLOG
  140. # i386 specific
  141. ifeq ($(PPC_TARGET),i386)
  142. override LOCALOPT+=-Fux86
  143. endif
  144. # x86_64 specific
  145. ifeq ($(PPC_TARGET),x86_64)
  146. override LOCALOPT+=-Fux86
  147. endif
  148. # PowerPC specific
  149. ifeq ($(PPC_TARGET),powerpc)
  150. override LOCALOPT+=-Fuppcgen
  151. endif
  152. # PowerPC64 specific
  153. ifeq ($(PPC_TARGET),powerpc64)
  154. override LOCALOPT+=-Fuppcgen
  155. endif
  156. # m68k specific
  157. ifeq ($(PPC_TARGET),m68k)
  158. override LOCALOPT+=-dNOOPT
  159. endif
  160. # Sparc specific
  161. ifeq ($(PPC_TARGET),sparc)
  162. override LOCALOPT+=
  163. endif
  164. # m68k specific with low stack
  165. ifeq ($(PPC_TARGET),m68k)
  166. ifeq ($(OS_TARGET),amiga)
  167. override LOCALOPT+=-Ct
  168. endif
  169. endif
  170. # ARM specific
  171. ifeq ($(PPC_TARGET),arm)
  172. override LOCALOPT+=-dNOOPT
  173. endif
  174. [rules]
  175. #####################################################################
  176. # Setup Targets
  177. #####################################################################
  178. ifeq ($(OS_TARGET),win32)
  179. ifdef CMP
  180. override DIFF:=$(CMP) -i218
  181. endif
  182. endif
  183. # Add Local options
  184. override COMPILER+=$(LOCALOPT)
  185. # Disable optimizer when compiled with 1.0.x
  186. ifneq ($(findstring 1.0.,$(FPC_VERSION)),)
  187. override COMPILER:=$(patsubst -O%,,$(COMPILER))
  188. endif
  189. #####################################################################
  190. # PASDoc
  191. #####################################################################
  192. PASDOC:=$(strip $(wildcard $(addsuffix /pasdoc.exe,$(SEARCHPATH))))
  193. ifeq ($(PASDOC),)
  194. PASDOC:=$(strip $(wildcard $(addsuffix /pasdoc,$(SEARCHPATH))))
  195. endif
  196. ifeq ($(PASDOC),)
  197. PASDOC:=../projects/pasdoc/bin/pasdoc
  198. else
  199. PASDOC:=$(firstword $(PASDOC))
  200. endif
  201. #####################################################################
  202. # Setup os-independent filenames
  203. #####################################################################
  204. ifndef EXENAME
  205. EXENAME=ppc$(CPUSUF)$(EXEEXT)
  206. endif
  207. PPEXENAME=pp$(EXEEXT)
  208. TEMPNAME=ppc$(SRCEXEEXT)
  209. PPCROSSNAME=ppcross$(CPUSUF)$(SRCEXEEXT)
  210. TEMPNAME1=ppc1$(EXEEXT)
  211. TEMPNAME2=ppc2$(EXEEXT)
  212. TEMPNAME3=ppc3$(EXEEXT)
  213. MAKEDEP=ppdep$(EXEEXT)
  214. MSG2INC=./msg2inc$(EXEEXT)
  215. ifdef CROSSINSTALL
  216. INSTALLEXEFILE=$(PPCROSSNAME)
  217. else
  218. INSTALLEXEFILE=$(EXENAME)
  219. endif
  220. #####################################################################
  221. # CPU targets
  222. #####################################################################
  223. PPC_TARGETS=i386 m68k powerpc sparc arm x86_64 powerpc64 alpha vis ia64
  224. .PHONY: $(PPC_TARGETS)
  225. $(PPC_TARGETS):
  226. $(MAKE) PPC_TARGET=$@ CPU_UNITDIR=$@ all
  227. alltargets: $(ALLTARGETS)
  228. #####################################################################
  229. # Default makefile
  230. #####################################################################
  231. .PHONY: all compiler echotime ppuclean execlean clean distclean
  232. all: compiler $(addsuffix _all,$(TARGET_DIRS))
  233. compiler: $(COMPILER_UNITTARGETDIR) $(COMPILER_TARGETDIR) $(EXENAME)
  234. ifeq ($(MAKELEVEL),0)
  235. ifndef STARTTIME
  236. ifdef DATE
  237. STARTTIME:=$(shell $(DATE) +%T)
  238. else
  239. STARTTIME:=unknown
  240. endif
  241. endif
  242. endif
  243. export STARTTIME
  244. ifdef DATE
  245. ENDTIME=$(shell $(DATE) +%T)
  246. else
  247. ENDTIME:=unknown
  248. endif
  249. echotime:
  250. @echo Start $(STARTTIME) now $(ENDTIME)
  251. ppuclean:
  252. -$(DEL) *$(OEXT) *$(PPUEXT) *$(RSTEXT) *$(ASMEXT) *$(STATICLIBEXT) *$(SHAREDLIBEXT) *$(PPLEXT)
  253. -$(DEL) $(addsuffix /*$(PPUEXT),$(COMPILERSOURCEDIR))
  254. tempclean:
  255. -$(DEL) $(PPCROSSNAME) $(TEMPNAME) $(TEMPNAME1) $(TEMPNAME2) $(TEMPNAME3) $(MSG2INC)
  256. execlean :
  257. -$(DEL) ppc386$(EXEEXT) ppcaxp$(EXEEXT) ppc68k$(EXEEXT) ppcx64$(EXEEXT) ppcppc$(EXEEXT) ppcsparc$(EXEEXT) $(EXENAME)
  258. $(addsuffix _clean,$(ALLTARGETS)):
  259. -$(DELTREE) $(addprefix $(subst _clean,,$@),/units)
  260. -$(DEL) $(addprefix $(subst _clean,,$@)/,*$(OEXT) *$(PPUEXT) *$(RSTEXT) *$(ASMEXT) *$(STATICLIBEXT) *$(SHAREDLIBEXT) *$(PPLEXT))
  261. -$(DEL) $(addprefix $(subst _clean,,$@)/,ppc386$(EXEEXT) ppcaxp$(EXEEXT) ppc68k$(EXEEXT) ppcx64$(EXEEXT) ppcppc$(EXEEXT) ppcppc$(EXEEXT) $(EXENAME))
  262. cycleclean: cleanall $(addsuffix _clean,$(PPC_TARGET))
  263. -$(DEL) $(EXENAME)
  264. clean: tempclean execlean cleanall $(addsuffix _clean,$(PPC_TARGET)) $(addsuffix _clean,$(TARGET_DIRS))
  265. distclean: tempclean execlean cleanall $(addsuffix _clean,$(ALLTARGETS)) $(addsuffix _distclean,$(TARGET_DIRS))
  266. #####################################################################
  267. # Make targets
  268. #####################################################################
  269. $(MSG2INC): $(COMPILER_TARGETDIR) $(COMPILER_UNITTARGETDIR) $(COMPILERUTILSDIR)/msg2inc.pp
  270. $(COMPILER) -FE. $(COMPILERUTILSDIR)/msg2inc.pp
  271. # The msgtxt.inc only depends on the error?.msg file, not on msg2inc,
  272. # because that one will be new almost everytime
  273. msgtxt.inc: $(MSGFILE)
  274. $(MAKE) $(MSG2INC)
  275. $(MSG2INC) $(MSGFILE) msg msg
  276. msg: msgtxt.inc
  277. # Make only the compiler
  278. $(EXENAME) : $(wildcard *.pas) $(wildcard *.inc) msg \
  279. $(wildcard systems/*.pas) $(wilcard systems/*.inc) \
  280. $(wildcard $(PPC_TARGET)/*.pas) $(wildcard $(PPC_TARGET)/*.inc)
  281. ifneq ($(REVSTR),)
  282. $(ECHOREDIR) "'$(REVSTR)'" > revision.inc
  283. endif
  284. $(COMPILER) pp.pas
  285. $(EXECPPAS)
  286. $(MOVE) $(COMPILER_TARGETDIR)/$(PPEXENAME) $(EXENAME)
  287. #####################################################################
  288. # Cycle targets
  289. #
  290. # 1. Source CPU = Target CPU and Source OS = Target OS
  291. # Normal cycle
  292. #
  293. # 2. Source CPU = Target CPU and Source OS <> Target OS
  294. # First source native compiler
  295. # Second target native compiler (skipped for cross installation)
  296. #
  297. # 3. Source CPU <> Target CPU
  298. # First source native compiler
  299. # Second cross compiler
  300. # Third target native compiler (skipped for cross installation)
  301. #
  302. #####################################################################
  303. ifeq ($(CPU_SOURCE),$(PPC_TARGET))
  304. ifeq ($(OS_SOURCE),$(OS_TARGET))
  305. ##########################
  306. # Normal cycle
  307. #
  308. # Used to avoid unnecessary steps
  309. ifdef DIFF
  310. ifdef OLDFPC
  311. DIFFRESULT:=$(shell $(DIFF) $(OLDFPC) $(FPC))
  312. else
  313. DIFFRESULT=Not equal
  314. endif
  315. else
  316. DIFFRESULT=No diff program
  317. endif
  318. ifndef DIFFRESULT
  319. next :
  320. @echo $(OLDFPC) and $(FPC) are equal
  321. $(COPY) $(FPC) $(EXENAME)
  322. else
  323. next :
  324. $(MAKE) rtlclean rtl
  325. $(MAKE) cycleclean compiler
  326. $(MAKE) echotime
  327. endif
  328. $(TEMPNAME1) :
  329. $(MAKE) 'OLDFPC=' next
  330. -$(DEL) $(TEMPNAME1)
  331. $(MOVE) $(EXENAME) $(TEMPNAME1)
  332. $(TEMPNAME2) : $(TEMPNAME1)
  333. $(MAKE) 'FPC=$(BASEDIR)/$(TEMPNAME1)' 'OLDFPC=' next
  334. -$(DEL) $(TEMPNAME2)
  335. $(MOVE) $(EXENAME) $(TEMPNAME2)
  336. $(TEMPNAME3) : $(TEMPNAME2)
  337. $(MAKE) 'FPC=$(BASEDIR)/$(TEMPNAME2)' 'OLDFPC=$(BASEDIR)/$(TEMPNAME1)' next
  338. -$(DEL) $(TEMPNAME3)
  339. $(MOVE) $(EXENAME) $(TEMPNAME3)
  340. cycle:
  341. $(MAKE) tempclean $(TEMPNAME3)
  342. $(MAKE) 'FPC=$(BASEDIR)/$(TEMPNAME3)' 'OLDFPC=$(BASEDIR)/$(TEMPNAME2)' next
  343. $(DIFF) $(TEMPNAME3) $(EXENAME)
  344. $(MAKE) $(addsuffix _all,$(TARGET_DIRS)) 'FPC=$(BASEDIR)/$(EXENAME)'
  345. $(MAKE) echotime
  346. else
  347. ##########################
  348. # Cross Target cycle
  349. #
  350. cycle:
  351. # ppc (source native)
  352. $(MAKE) OS_TARGET=$(OS_SOURCE) CROSSBINDIR="" BINUTILSPREFIX="" CROSSCYCLEBOOTSTRAP=1 rtlclean rtl
  353. $(MAKE) OS_TARGET=$(OS_SOURCE) EXENAME=$(TEMPNAME) CROSSBINDIR="" BINUTILSPREFIX="" CROSSCYCLEBOOTSTRAP=1 cycleclean compiler
  354. # ppcross<ARCH> (source native)
  355. $(MAKE) 'FPC=$(BASEDIR)/$(TEMPNAME)' OS_TARGET=$(OS_SOURCE) CROSSBINDIR="" BINUTILSPREFIX="" CROSSCYCLEBOOTSTRAP=1 rtlclean rtl
  356. $(MAKE) 'FPC=$(BASEDIR)/$(TEMPNAME)' OS_TARGET=$(OS_SOURCE) EXENAME=$(PPCROSSNAME) CROSSBINDIR="" BINUTILSPREFIX="" CROSSCYCLEBOOTSTRAP=1 cycleclean compiler
  357. # ppc<ARCH> (target native)
  358. ifndef CROSSINSTALL
  359. $(MAKE) 'FPC=$(BASEDIR)/$(PPCROSSNAME)' rtlclean rtl
  360. $(MAKE) 'FPC=$(BASEDIR)/$(PPCROSSNAME)' cycleclean compiler
  361. endif
  362. endif
  363. else
  364. ##########################
  365. # Cross CPU cycle
  366. #
  367. # ppc1 = native
  368. # ppc2 = cross running on this platform
  369. # ppc3/ppcXXX = native (skipped for cross installation)
  370. #
  371. cycle:
  372. # ppc (source native)
  373. $(MAKE) OS_TARGET=$(OS_SOURCE) CPU_TARGET=$(CPU_SOURCE) CROSSBINDIR="" BINUTILSPREFIX="" CROSSCYCLEBOOTSTRAP=1 rtlclean rtl
  374. $(MAKE) OS_TARGET=$(OS_SOURCE) CPU_TARGET=$(CPU_SOURCE) EXENAME=$(TEMPNAME) CROSSBINDIR="" BINUTILSPREFIX="" CROSSCYCLEBOOTSTRAP=1 cycleclean compiler
  375. # ppcross<ARCH> (source native)
  376. $(MAKE) 'FPC=$(BASEDIR)/$(TEMPNAME)' OS_TARGET=$(OS_SOURCE) CPU_TARGET=$(CPU_SOURCE) CROSSBINDIR="" BINUTILSPREFIX="" CROSSCYCLEBOOTSTRAP=1 rtlclean rtl
  377. $(MAKE) 'FPC=$(BASEDIR)/$(TEMPNAME)' OS_TARGET=$(OS_SOURCE) CPU_TARGET=$(CPU_SOURCE) PPC_TARGET=$(CPU_TARGET) EXENAME=$(PPCROSSNAME) CROSSBINDIR="" BINUTILSPREFIX="" CROSSCYCLEBOOTSTRAP=1 cycleclean compiler
  378. # ppc<ARCH> (target native)
  379. ifndef CROSSINSTALL
  380. $(MAKE) 'FPC=$(BASEDIR)/$(PPCROSSNAME)' rtlclean rtl
  381. $(MAKE) 'FPC=$(BASEDIR)/$(PPCROSSNAME)' cycleclean compiler
  382. endif
  383. endif
  384. cycledep:
  385. $(MAKE) cycle USEDEPEND=1
  386. extcycle:
  387. $(MAKE) cycle OPT='-n -OG2p3 -gl -CRriot -dEXTDEBUG'
  388. cvstest:
  389. $(MAKE) cycle 'LOCALOPT=-n -Se' 'RTLOPT=-n -Se'
  390. ##########################
  391. # Full cycle
  392. #
  393. # 1. build a compiler using cycle
  394. # 2. remove all .ppufiles
  395. # 3. build all supported cross compilers except the
  396. # current PPC_TARGET which was already build
  397. #
  398. full: fullcycle
  399. fullcycle:
  400. $(MAKE) cycle
  401. $(MAKE) ppuclean
  402. $(MAKE) $(filter-out $(PPC_TARGET),$(CYCLETARGETS)) 'FPC=$(BASEDIR)/$(EXENAME)'
  403. #####################################################################
  404. # Docs
  405. #####################################################################
  406. htmldocs:
  407. $(PASDOC) -p -h -o html$(PATHSEP)$(PPC_TARGET) -d fpc -d gdb -d $(PPC_TARGET) -u $(PPC_TARGET) $(PPC_TARGET)$(PATHSEP)*.pas systems$(PATHSEP)*.pas *.pas
  408. #####################################################################
  409. # Installation
  410. #####################################################################
  411. .PHONY: quickinstall install installsym
  412. MSGINSTALLDIR=$(INSTALL_BASEDIR)/msg
  413. override PPEXEFILE:=$(wildcard $(EXENAME))
  414. ifdef UNIXHier
  415. PPCCPULOCATION=$(INSTALL_BASEDIR)
  416. else
  417. PPCCPULOCATION=$(INSTALL_BINDIR)
  418. endif
  419. # This will only install the ppcXXX executable, not the message files etc.
  420. quickinstall: $(addsuffix _install,$(TARGET_DIRS))
  421. # Install ppcXXX executable, for a cross installation we install
  422. # the ppcrossXXX as ppcXXX. The target native build ppcXXX is not used
  423. # for this installation type
  424. ifneq ($(INSTALLEXEFILE),)
  425. ifdef UPXPROG
  426. -$(UPXPROG) $(INSTALLEXEFILE)
  427. endif
  428. $(MKDIR) $(PPCCPULOCATION)
  429. $(INSTALLEXE) $(INSTALLEXEFILE) $(PPCCPULOCATION)/$(INSTALLEXEFILE)
  430. endif
  431. install: quickinstall
  432. ifndef CROSSINSTALL
  433. ifdef UNIXHier
  434. $(MKDIR) $(INSTALL_BASEDIR)
  435. $(INSTALLEXE) $(COMPILERUTILSDIR)/samplecfg $(INSTALL_BASEDIR)/samplecfg
  436. endif
  437. $(MKDIR) $(MSGINSTALLDIR)
  438. $(INSTALL) $(MSGFILES) $(MSGINSTALLDIR)
  439. endif
  440. # This also installs a link from bin to the actual executable.
  441. # The .deb does that later.
  442. installsymlink: install
  443. ifneq ($(PPCCPULOCATION),$(INSTALL_BINDIR))
  444. $(MKDIR) $(INSTALL_BINDIR)
  445. ln -sf $(INSTALL_BASEDIR)/$(EXENAME) $(INSTALL_BINDIR)/$(EXENAME)
  446. endif
  447. #####################################################################
  448. # RTL
  449. #####################################################################
  450. .PHONY: rtl rtlclean rtlinstall
  451. rtl:
  452. $(MAKE) -C $(PACKAGEDIR_RTL) 'OPT=$(RTLOPT)' all
  453. rtlclean:
  454. $(MAKE) -C $(PACKAGEDIR_RTL) clean
  455. rtlinstall:
  456. $(MAKE) -C $(PACKAGEDIR_RTL) install
  457. #####################################################################
  458. # local user configurable file
  459. # in makefile.loc you can add any desired target
  460. #####################################################################
  461. localmake:=$(strip $(wildcard makefile.loc))
  462. ifdef localmake
  463. include ./$(localmake)
  464. endif