File: makefile.fpc

package info (click to toggle)
fpc 0.99.13-19991013-4
  • links: PTS
  • area: main
  • in suites: potato
  • size: 23,104 kB
  • ctags: 9,760
  • sloc: pascal: 253,711; ansic: 5,236; makefile: 3,855; yacc: 2,016; lex: 707; asm: 526; xml: 443; sh: 200; perl: 87; sed: 21; csh: 12; cpp: 1
file content (1199 lines) | stat: -rw-r--r-- 26,846 bytes parent folder | download | duplicates (2)
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
#
#   $Id: makefile.fpc,v 1.47 1999/09/27 08:08:15 peter Exp $
#   Copyright (c) 1999 by the Free Pascal Development Team
#
#   Common makefile for Free Pascal
#
#   See the file COPYING.FPC, included in this distribution,
#   for details about the copyright.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#

#####################################################################
# Autodetect OS (Linux or Dos or Windows NT)
# define inlinux when running under linux
# define inWinNT when running under WinNT
#####################################################################

# We want only / in the path !
override PATH:=$(subst \,/,$(PATH))

# Search for PWD and determine also if we are under linux
PWD=$(strip $(wildcard $(addsuffix /pwd.exe,$(subst ;, ,$(PATH)))))
ifeq ($(PWD),)
PWD=$(strip $(wildcard $(addsuffix /pwd,$(subst :, ,$(PATH)))))
ifeq ($(PWD),)
nopwd:
	@echo You need the GNU utils package to use this makefile!
	@echo Get ftp://tflily.fys.kuleuven.ac.be/pub/fpc/dist/go32v2/utilgo32.zip
	@exit
else
inlinux=1
endif
else
PWD:=$(firstword $(PWD))
endif

# Detect NT - NT sets OS to Windows_NT
ifndef inlinux
ifeq ($(OS),Windows_NT)
inWinNT=1
endif
endif

# Detect OS/2 - OS/2 has OS2_SHELL defined
ifndef inlinux
ifndef inWinNT
ifdef OS2_SHELL
inOS2=1
endif
endif
endif

# The extension of executables
ifdef inlinux
EXEEXT=
else
EXEEXT=.exe
endif


#####################################################################
# Check for FPCDIR environment
#####################################################################

ifndef FPCDIR
nofpcdir:
	@echo You need to set the FPCDIR environment variable to use
	@echo this Makefile.
	@echo Example: SET FPCDIR=/pp
	@exit
endif


#####################################################################
# Targets
#####################################################################

# What compiler to use ?
ifndef PP
ifdef inOS2
PP=ppos2$(EXEEXT)
else
PP=ppc386$(EXEEXT)
endif
endif

# Target OS
ifndef OS_TARGET
OS_TARGET=$(shell $(PP) -iTO)
endif

# Source OS
ifndef OS_SOURCE
OS_SOURCE=$(shell $(PP) -iSO)
endif

# CPU
ifndef CPU
CPU=$(shell $(PP) -iTP)
endif

# FPC version
FPC_VERSION=$(shell $(PP) -iV)

# Options
ifndef OPT
OPT=
endif

# assembler, redefine it if cross compiling
ifndef AS
AS=as
endif

# linker, but probably not used
ifndef LD
LD=ld
endif

# Release ? Then force OPT and don't use extra opts via commandline
ifdef RELEASE
override OPT:=-Xs -OG2p3 -n
endif

# Verbose settings (warning,note,info)
ifdef VERBOSE
override OPT+=-vwni
endif


#####################################################################
# Shell commands
#####################################################################

# To copy pograms
ifndef COPY
COPY=cp -fp
endif

# To move pograms
ifndef MOVE
MOVE=mv -f
endif

# Check delete program
ifndef DEL
DEL=rm -f
endif

# Check deltree program
ifndef DELTREE
DELTREE=rm -rf
endif

# To install files
ifndef INSTALL
ifdef inlinux
INSTALL=install -m 644
else
INSTALL=$(COPY)
# ginstall has the strange thing to stubify all .o files !
#INSTALL=ginstall -m 644
endif
endif

# To install programs
ifndef INSTALLEXE
ifdef inlinux
INSTALLEXE=install -m 755
else
INSTALLEXE=$(COPY)
# ginstall has the strange thing to stubify all .o files !
#INSTALLEXE=ginstall -m 755
endif
endif

# To make a directory.
ifndef MKDIR
ifdef inlinux
MKDIR=install -m 755 -d
else
MKDIR=ginstall -m 755 -d
endif
endif


#####################################################################
# Default Tools
#####################################################################

# ppas.bat / ppas.sh
ifdef inlinux
PPAS=ppas.sh
else
ifdef inOS2
PPAS=ppas.cmd
else
PPAS=ppas.bat
endif
endif

# The path which is search separated by spaces
ifdef inlinux
SEARCHPATH=$(subst :, ,$(PATH))
else
SEARCHPATH=$(subst ;, ,$(PATH))
endif

# ldconfig to rebuild .so cache
ifdef inlinux
LDCONFIG=ldconfig
else
LDCONFIG=
endif

# Where is the ppumove program ?
ifndef PPUMOVE
PPUMOVE=ppumove
endif

# diff
ifndef DIFF
DIFF=$(strip $(wildcard $(addsuffix /diff$(EXEEXT),$(SEARCHPATH))))
ifeq ($(DIFF),)
DIFF=
else
export DIFF:=$(firstword $(DIFF))
endif
endif

# cmp
ifndef CMP
CMP=$(strip $(wildcard $(addsuffix /cmp$(EXEEXT),$(SEARCHPATH))))
ifeq ($(CMP),)
CMP=
else
export CMP:=$(firstword $(CMP))
endif
endif

# echo
ifndef ECHO
ECHO=$(strip $(wildcard $(addsuffix /echo$(EXEEXT),$(SEARCHPATH))))
ifeq ($(ECHO),)
export ECHO:=echo
else
export ECHO:=$(firstword $(ECHO))
endif
endif

# gdate/date
ifndef DATE
DATE=$(strip $(wildcard $(addsuffix /date$(EXEEXT),$(SEARCHPATH))))
ifeq ($(DATE),)
DATE=$(strip $(wildcard $(addsuffix /gdate$(EXEEXT),$(SEACHPATH))))
ifeq ($(DATE),)
DATE=
else
export DATE:=$(firstword $(DATE))
endif
else
export DATE:=$(firstword $(DATE))
endif
endif

# Sed
ifndef SED
SED=$(strip $(wildcard $(addsuffix /sed$(EXEEXT),$(SEARCHPATH))))
ifeq ($(SED),)
SED=
else
export SED:=$(firstword $(SED))
endif
endif

# Look if UPX is found for go32v2 and win32. We can't use $UPX becuase
# upx uses that one itself (PFV)
ifndef UPXPROG
ifeq ($(OS_TARGET),go32v2)
UPXPROG=1
endif
ifeq ($(OS_TARGET),win32)
UPXPROG=1
endif
ifdef UPXPROG
UPXPROG=$(strip $(wildcard $(addsuffix /upx$(EXEEXT),$(SEARCHPATH))))
ifeq ($(UPX),)
UPXPROG=
else
export UPXPROG:=$(firstword $(UPX))
endif
else
UPXPROG=
endif
endif

# ZipProg, you can't use Zip as the var name (PFV)
ifndef ZIPPROG
ZIPPROG=$(strip $(wildcard $(addsuffix /zip$(EXEEXT),$(SEARCHPATH))))
ifeq ($(ZIPPROG),)
ZIPPROG=
else
export ZIPPROG:=$(firstword $(ZIPPROG)) -D9 -r
endif
endif

ifndef ZIPEXT
ZIPEXT=.zip
endif


#####################################################################
# Default Directories
#####################################################################

# Base dir
ifdef PWD
BASEDIR:=$(shell $(PWD))
else
BASEDIR=.
endif

# set the directory to the rtl base
ifndef RTLDIR
ifdef RTL
RTLDIR:=$(RTL)/$(OS_TARGET)
else
RTLDIR:=$(FPCDIR)/rtl/$(OS_TARGET)
endif
endif

# specify where units are.
ifndef UNITDIR
ifdef UNITS
UNITDIR=$(UNITS)/$(OS_TARGET)
else
UNITDIR=$(FPCDIR)/units/$(OS_TARGET)
endif
endif

ifeq ($(strip $(wildcard $(UNITDIR)/*)),)
UNITDIR=
endif

# set the prefix directory where to install everything
ifndef PREFIXINSTALLDIR
ifdef inlinux
PREFIXINSTALLDIR=/usr
else
PREFIXINSTALLDIR=/pp
endif
endif

# set the base directory where to install everything
ifndef BASEINSTALLDIR
ifdef inlinux
BASEINSTALLDIR=$(PREFIXINSTALLDIR)/lib/fpc/$(FPC_VERSION)
else
BASEINSTALLDIR=$(PREFIXINSTALLDIR)
endif
endif

# On linux, try to find where libgcc.a is.
ifdef inlinux
ifndef GCCLIBDIR
GCCLIBDIR:=$(shell dirname `(gcc -v 2>&1)| head -n 1| awk '{ print $$4 } '`)
endif
ifndef OTHERLIBDIR
OTHERLIBDIR:=$(shell grep -v "^\#" /etc/ld.so.conf | awk '{ ORS=" "; print $1 }')
endif
endif


#####################################################################
# Install Directories based on BASEINSTALLDIR
#####################################################################

# Linux binary really goes to baseinstalldir
ifndef LIBINSTALLDIR
ifdef inlinux
LIBINSTALLDIR=$(BASEINSTALLDIR)
else
LIBINSTALLDIR=$(BASEINSTALLDIR)/lib
endif
endif

# set the directory where to install the binaries
ifndef BININSTALLDIR
ifdef inlinux
BININSTALLDIR=$(PREFIXINSTALLDIR)/bin
else
BININSTALLDIR=$(BASEINSTALLDIR)/bin/$(OS_TARGET)
endif
endif

# Where the .msg files will be stored
ifndef MSGINSTALLDIR
MSGINSTALLDIR=$(BASEINSTALLDIR)/msg
endif

# Where the .msg files will be stored
ifndef SOURCEINSTALLDIR
SOURCEINSTALLDIR=$(BASEINSTALLDIR)/source
endif

# Where the doc files will be stored
ifndef DOCINSTALLDIR
ifdef inlinux
DOCINSTALLDIR=$(PREFIXINSTALLDIR)/doc/fpc/$(FPC_VERSION)
else
DOCINSTALLDIR=$(BASEINSTALLDIR)/doc
endif
endif

########################
# Unit Directories
########################

# this can be set to 'rtl' when the RTL units are installed
ifndef UNITPREFIX
UNITPREFIX=units
endif

# set the directory where to install the units.
ifndef UNITINSTALLDIR
UNITINSTALLDIR=$(BASEINSTALLDIR)/$(UNITPREFIX)/$(OS_TARGET)
endif

# set the directory where to install the units.
ifndef STATIC_UNITINSTALLDIR
STATIC_UNITINSTALLDIR=$(UNITINSTALLDIR)/static
endif

# set the directory where to install the units.
ifndef SHARED_UNITINSTALLDIR
SHARED_UNITINSTALLDIR=$(UNITINSTALLDIR)/shared
endif

# set the directory where to install the libs (must exist)
ifndef STATIC_LIBINSTALLDIR
STATIC_LIBINSTALLDIR=$(STATIC_UNITINSTALLDIR)
endif

# set the directory where to install the libs (must exist)
ifndef SHARED_LIBINSTALLDIR
ifdef inlinux
SHARED_LIBINSTALLDIR=$(PREFIXINSTALLDIR)/lib
else
SHARED_LIBINSTALLDIR=$(SHARED_UNITINSTALLDIR)
endif
endif


#####################################################################
# Compiler Command Line
#####################################################################

# Load commandline OPTDEF and add CPU define
override PPOPTDEF:=$(OPTDEF) -d$(CPU)

# Load commandline OPT and add target and unit dir to be sure
override PPOPT:=-T$(OS_TARGET) $(NEEDOPT) $(OPT)

# RTL first and then Unit dir (a unit can override RTLunit)
ifdef RTLDIR
override PPOPT+=$(addprefix -Fu,$(RTLDIR))
endif
ifdef UNITDIR
override PPOPT+=$(addprefix -Fu,$(UNITDIR))
endif
ifdef NEEDUNITDIR
override PPOPT+=$(addprefix -Fu,$(NEEDUNITDIR))
endif

# Library dirs
ifdef LIBDIR
override PPOPT+=$(addprefix -Fl,$(LIBDIR))
endif
ifdef NEEDLIBDIR
override PPOPT+=$(addprefix -Fl,$(NEEDLIBDIR))
endif

# Add GCC lib path if asked
ifdef NEEDGCCLIB
ifdef GCCLIBDIR
override PPOPT+=-Fl$(GCCLIBDIR)
endif
endif

# Add Other dirs path if asked
ifdef NEEDOTHERLIB
ifdef OTHERLIBDIR
override PPOPT+=$(addprefix -Fl,$(OTHERLIBDIR))
endif
endif

# Object dirs
ifdef OBJDIR
override PPOPT+=$(addprefix -Fo,$(OBJDIR))
endif
ifdef NEEDOBJDIR
override PPOPT+=$(addprefix -Fo,$(NEEDOBJDIR))
endif

# Add include dirs INC and PROCINC and OSINC
ifdef INC
override PPOPT+=$(addprefix -Fi,$(INC))
endif
ifdef PROCINC
override PPOPT+=$(addprefix -Fi,$(PROCINC))
endif
ifdef OSINC
override PPOPT+=$(addprefix -Fi,$(OSINC))
endif

# Target dirs
ifdef TARGETDIR
override PPOPT+=-FE$(TARGETDIR)
endif
ifdef UNITTARGETDIR
override PPOPT+=-FU$(UNITTARGETDIR)
endif

# Smartlinking
ifeq ($(SMARTLINK),YES)
override PPOPT+=-CX
endif

# Add defines from PPOPTDEF to PPOPT
override PPOPT:=$(PPOPT) $(PPOPTDEF)

# Was a config file specified ?
ifdef CFGFILE
override PPOPT:=$(PPOPT) @$(CFGFILE)
endif

override COMPILER=$(PP) $(PPOPT)


#####################################################################
# Default extensions
#####################################################################

# Default needed extensions (Go32v2,Linux)
LOADEREXT=.as
PPLEXT=.ppl
PPUEXT=.ppu
OEXT=.o
ASMEXT=.s
SMARTEXT=.sl
STATICLIBEXT=.a
SHAREDLIBEXT=.so
PACKAGESUFFIX=

# Go32v1
ifeq ($(OS_TARGET),go32v1)
PPUEXT=.pp1
OEXT=.o1
ASMEXT=.s1
SMARTEXT=.sl1
STATICLIBEXT=.a1
SHAREDLIBEXT=.so1
PACKAGESUFFIX=v1
endif

# Go32v2
ifeq ($(OS_TARGET),go32v2)
PACKAGESUFFIX=go32
endif

# Linux
ifeq ($(OS_TARGET),linux)
PACKAGESUFFIX=linux
endif

# Win32
ifeq ($(OS_TARGET),win32)
PPUEXT=.ppw
OEXT=.ow
ASMEXT=.sw
SMARTEXT=.slw
STATICLIBEXT=.aw
SHAREDLIBEXT=.dll
PACKAGESUFFIX=win32
endif

# OS/2
ifeq ($(OS_TARGET),os2)
PPUEXT=.ppo
ASMEXT=.so2
OEXT=.oo2
SMARTEXT=.so
STATICLIBEXT=.ao2
SHAREDLIBEXT=.dll
PACKAGESUFFIX=os2
endif

# library prefix
LIBPREFIX=lib
ifeq ($(OS_TARGET),go32v2)
LIBPREFIX=
endif
ifeq ($(OS_TARGET),go32v1)
LIBPREFIX=
endif

# determine which .pas extension is used
ifndef PASEXT
ifdef EXEOBJECTS
override TESTPAS:=$(strip $(wildcard $(addsuffix .pas,$(firstword $(EXEOBJECTS)))))
else
override TESTPAS:=$(strip $(wildcard $(addsuffix .pas,$(firstword $(UNITOBJECTS)))))
endif
ifeq ($(TESTPAS),)
PASEXT=.pp
else
PASEXT=.pas
endif
endif

# also call ppas if with command option -s
ifeq (,$(findstring -s ,$(COMPILER)))
EXECPPAS=
else
EXECPPAS=@$(PPAS)
endif

ifdef DATE
DATESTR=$(shell $(DATE) +%Y%m%d)
else
DATESTR=
endif


#####################################################################
# Export commandline values, so nesting use the same values
#####################################################################

# Makefile
export FPCDIR FPCMAKE

# Compiler info
export FPC_VERSION OS_SOURCE OS_TARGET CPU
export OPT OPTDEF PP RELEASE VERBOSE SMARTLINK

# Installation
export PREFIXINSTALLDIR PACKAGESUFFIX

# Directories
export GCCLIBDIR OTHERLIBDIR


#####################################################################
# General compile rules
#####################################################################

# Create Filenames
LOADEROFILES=$(addsuffix $(OEXT),$(LOADEROBJECTS))
EXEFILES=$(addsuffix $(EXEEXT),$(EXEOBJECTS))
EXEOFILES=$(addsuffix $(OEXT),$(EXEOBJECTS))
UNITPPUFILES=$(addsuffix $(PPUEXT),$(UNITOBJECTS))
UNITOFILES=$(addsuffix $(OEXT),$(UNITOBJECTS))
UNITAFILES=$(addsuffix $(STATICLIBEXT),$(UNITOBJECTS))

.PHONY : fpc_all fpc_units fpc_loaders fpc_exes \
	 fpc_staticlib fpc_sharedlib \
	 fpc_clean fpc_libsclean fpc_cleanall \
	 fpc_install fpc_staticinstall fpc_sharedinstall fpc_libinstall \
	 fpc_info fpc_cfginfo fpc_objectinfo fpc_installinfo fpc_filesinfo\
	 fpc_dirinfo

.SUFFIXES : $(EXEEXT) $(PPUEXT) $(OEXT) .pas .pp


#####################################################################
# Default
#####################################################################

ifdef DEFAULTUNITS
fpc_all: fpc_loaders fpc_units
else
fpc_all: fpc_loaders fpc_units fpc_exes
endif

fpc_loaders: $(LOADEROFILES)

fpc_units: $(UNITPPUFILES)

fpc_exes: $(EXEFILES)

# General compile rules, available for both possible PASEXT
%$(PPUEXT): %.pp
	$(COMPILER) $< $(REDIR)
	$(EXECPASS)

%$(PPUEXT): %.pas
	$(COMPILER) $< $(REDIR)
	$(EXECPASS)

%$(EXEEXT): %.pp
	$(COMPILER) $< $(REDIR)
	$(EXECPASS)

%$(EXEEXT): %.pas
	$(COMPILER) $< $(REDIR)
	$(EXECPASS)

%$(OEXT): %$(LOADEREXT)
	$(AS) -o $*$(OEXT) $<


#####################################################################
# Library
#####################################################################

# Default sharedlib units are all unit objects
ifndef SHAREDLIBUNITOBJECTS
SHAREDLIBUNITOBJECTS=$(UNITOBJECTS)
endif

fpc_staticlib:
	$(MAKE) libsclean
	$(MAKE) all SMARTLINK=YES

fpc_sharedlib: all
ifdef inlinux
ifndef LIBNAME
	@$(ECHO) LIBNAME not set
else
	$(PPUMOVE) $(SHAREDLIBUNITOBJECTS) -o$(LIBNAME)
endif
else
	@$(ECHO) Shared Libraries not supported
endif


#####################################################################
# Install rules
#####################################################################

fpc_showinstallfiles : all
ifndef DEFAULTUNITS
ifdef EXEOBJECTS
	@$(ECHO) $(addprefix "\n"$(BININSTALLDIR)/,$(EXEFILES))
endif
endif
ifdef LOADEROBJECTS
	@$(ECHO) $(addprefix "\n"$(UNITINSTALLDIR)/,$(LOADEROFILES))
endif
ifdef UNITOBJECTS
	@$(ECHO) $(addprefix "\n"$(UNITINSTALLDIR)/,$(wildcard $(UNITPPUFILES) $(UNITOFILES) $(UNITAFILES)))
endif
ifdef EXTRAINSTALLUNITS
	@$(ECHO) $(addprefix "\n"$(UNITINSTALLDIR)/,$(wildcard $(addsuffix $(OEXT),$(EXTRAINSTALLUNITS)) $(addsuffix $(STATICLIBEXT),$(EXTRAINSTALLUNITS)) $(addsuffix $(PPUEXT),$(EXTRAINSTALLUNITS))))
endif

fpc_install : all
	$(MAKE) fpc_install2

fpc_install2 :
# Create UnitInstallFiles
ifdef EXTRAINSTALLUNITS
override EXTRAINSTALLFILES=$(wildcard $(addsuffix $(OEXT),$(EXTRAINSTALLUNITS)) $(addsuffix $(STATICLIBEXT),$(EXTRAINSTALLUNITS)) $(addsuffix $(PPUEXT),$(EXTRAINSTALLUNITS)))
endif
ifndef DEFAULTUNITS
ifdef EXEOBJECTS
	$(MKDIR) $(BININSTALLDIR)
# Compress the exes if upx is defined
ifdef UPXPROG
	-$(UPXPROG) $(EXEFILES)
endif
	$(INSTALLEXE) $(EXEFILES) $(BININSTALLDIR)
endif
endif
ifdef LOADEROBJECTS
	$(MKDIR) $(UNITINSTALLDIR)
	$(INSTALL) $(LOADEROFILES) $(UNITINSTALLDIR)
endif
ifdef UNITOBJECTS
	$(MKDIR) $(UNITINSTALLDIR)
	$(INSTALL) $(wildcard $(UNITPPUFILES) $(UNITOFILES) $(UNITAFILES)) $(UNITINSTALLDIR)
endif
ifneq ($(wildcard $(addsuffix $(OEXT),$(EXTRAINSTALLUNITS)) $(addsuffix $(STATICLIBEXT),$(EXTRAINSTALLUNITS)) $(addsuffix $(PPUEXT),$(EXTRAINSTALLUNITS))),)
	$(MKDIR) $(UNITINSTALLDIR)
	$(INSTALL) $(wildcard $(addsuffix $(OEXT),$(EXTRAINSTALLUNITS)) $(addsuffix $(STATICLIBEXT),$(EXTRAINSTALLUNITS)) $(addsuffix $(PPUEXT),$(EXTRAINSTALLUNITS))) $(UNITINSTALLDIR)
endif


# Target for the sharedlib install which is not avail for all targets
ifdef inlinux
SHAREDINSTALL=sharedinstall
else
SHAREDINSTALL=
endif

fpc_staticinstall: staticlib
	$(MKDIR) $(STATIC_UNITINSTALLDIR)
	$(INSTALL) $(UNITINSTALLFILES) $(STATIC_UNITINSTALLDIR)
	$(MKDIR) $(STATIC_LIBINSTALLDIR)
	$(INSTALLEXE) *$(STATICLIBEXT) $(STATIC_LIBINSTALLDIR)

fpc_sharedinstall: sharedlib
	$(MKDIR) $(SHARED_UNITINSTALLDIR)
ifdef UNITINSTALLFILES
	$(INSTALL) $(UNITINSTALLFILES) $(SHARED_UNITINSTALLDIR)
else
	$(INSTALL) $(UNITOFILES) $(SHARED_UNITINSTALLDIR)
endif
	$(MKDIR) $(SHARED_LIBINSTALLDIR)
	$(INSTALLEXE) *$(SHAREDLIBEXT) $(SHARED_LIBINSTALLDIR)


fpc_libinstall: staticinstall $(SHAREDINSTALL)


#####################################################################
# Zip
#####################################################################

# Temporary path to pack a file
ifndef PACKDIR
ifndef inlinux
PACKDIR=pack_tmp
else
PACKDIR=/tmp/fpc-pack
endif
endif

# Test dir if none specified
ifndef PACKAGEDIR
PACKAGEDIR=$(BASEDIR)
endif

# Add .zip/.tar.gz extension
ifdef ZIPNAME
ifndef inlinux
override ZIPNAME:=$(ZIPNAME)$(ZIPEXT)
endif
endif

# Default target which is call before zipping
ifndef ZIPTARGET
ZIPTARGET=install
endif

# Note: This will not remove the zipfile first
fpc_zipinstalladd:
ifndef ZIPNAME
	@$(ECHO) Please specify ZIPNAME!
	@exit
else
	$(MAKE) $(ZIPTARGET) PREFIXINSTALLDIR=$(PACKDIR)
ifdef inlinux
	gzip -d $(PACKAGEDIR)/$(ZIPNAME).tar.gz
	cd $(PACKDIR) ; tar rv --file $(PACKAGEDIR)/$(ZIPNAME).tar * ; cd $(BASEDIR)
	gzip $(PACKAGEDIR)/$(ZIPNAME).tar
else
	cd $(PACKDIR) ; $(ZIPPROG) $(PACKAGEDIR)/$(ZIPNAME) * ; cd $(BASEDIR)
endif
	$(DELTREE) $(PACKDIR)
endif

# First remove the zip and then install
fpc_zipinstall:
ifndef ZIPNAME
	@$(ECHO) Please specify ZIPNAME!
	@exit
else
	$(DEL) $(PACKAGEDIR)/$(ZIPNAME)
	$(MAKE) $(ZIPTARGET) PREFIXINSTALLDIR=$(PACKDIR)
ifdef inlinux
	cd $(PACKDIR) ; tar cvz --file $(PACKAGEDIR)/$(ZIPNAME).tar.gz * ; cd $(BASEDIR)
else
	cd $(PACKDIR) ; $(ZIPPROG) $(PACKAGEDIR)/$(ZIPNAME) * ; cd $(BASEDIR)
endif
	$(DELTREE) $(PACKDIR)
endif


#####################################################################
# Clean rules
#####################################################################

fpc_clean:
	make fpc_clean2

fpc_clean2:
ifdef EXEOBJECTS
	-$(DEL) $(EXEFILES) $(EXEOFILES)
endif
ifdef LOADEROBJECTS
	-$(DEL) $(LOADEROFILES)
endif
ifdef UNITOBJECTS
	-$(DEL) $(wildcard $(UNITPPUFILES) $(UNITOFILES) $(UNITAFILES))
endif
ifneq ($(wildcard $(addsuffix $(OEXT),$(EXTRACLEANUNITS)) $(addsuffix $(STATICLIBEXT),$(EXTRACLEANUNITS)) $(addsuffix $(PPUEXT),$(EXTRACLEANUNITS))) ,)
	-$(DEL) $(wildcard $(addsuffix $(OEXT),$(EXTRACLEANUNITS)) $(addsuffix $(STATICLIBEXT),$(EXTRACLEANUNITS)) $(addsuffix $(PPUEXT),$(EXTRACLEANUNITS)))
endif
	-$(DEL) $(PPAS) link.res log

fpc_libsclean: clean
	-$(DEL) *$(STATICLIBEXT) *$(SHAREDLIBEXT) *$(PPLEXT)

fpc_cleanall:
ifdef EXEOBJECTS
	-$(DEL) $(EXEFILES)
endif
	-$(DEL) *$(OEXT) *$(PPUEXT) *$(ASMEXT) *$(STATICLIBEXT) *$(SHAREDLIBEXT) *$(PPLEXT)
	-$(DELTREE) *$(SMARTEXT)


#####################################################################
# Depend rules
#####################################################################

fpc_depend:
	makedep $(UNITOBJECTS)


#####################################################################
# Info rules
#####################################################################

fpc_info: fpc_cfginfo fpc_objectinfo fpc_toolsinfo fpc_installinfo\
	  fpc_dirinfo

fpc_cfginfo:
	@$(ECHO)
	@$(ECHO)  == Configuration info ==
	@$(ECHO)
	@$(ECHO)  FPCDir.... $(FPCDIR)
	@$(ECHO)  FPCMake... $(FPCMAKE)
	@$(ECHO)
	@$(ECHO)  Version... $(FPC_VERSION)
	@$(ECHO)  CPU....... $(CPU)
	@$(ECHO)  Source.... $(OS_SOURCE)
	@$(ECHO)  Target.... $(OS_TARGET)
	@$(ECHO)

fpc_dirinfo:
ifdef inlinux
	@$(ECHO)
	@$(ECHO)  == Directory info ==
	@$(ECHO)
ifdef NEEDGCCLIB
	@$(ECHO)  GCC library is needed.
endif
ifdef NEEDOTHERLIB
	@$(ECHO)  Other library is needed.
endif
	@$(ECHO)  Basedir......... $(BASEDIR)
	@$(ECHO)
	@$(ECHO)  GCC library..... $(GCCLIBDIR)
	@$(ECHO)  Other library... $(OTHERLIBDIR)
	@$(ECHO)

endif

fpc_toolsinfo:
	@$(ECHO)
	@$(ECHO)  == Tools info ==
	@$(ECHO)
	@$(ECHO)  Pwd....... $(PWD)
	@$(ECHO)  Echo...... $(ECHO)
ifdef SED
	@$(ECHO)  Sed....... $(SED)
endif
ifdef DATE
	@$(ECHO)  Date...... $(DATE)
endif
ifdef DIFF
	@$(ECHO)  Diff...... $(DIFF)
endif
ifdef CMP
	@$(ECHO)  Cmp....... $(CMP)
endif
ifdef UPXPROG
	@$(ECHO)  Upx....... $(UPXPROG)
endif
ifdef ZIPPROG
	@$(ECHO)  Zip....... $(ZIPPROG)
endif
	@$(ECHO)

fpc_objectinfo:
	@$(ECHO)
	@$(ECHO)  == Object info ==
	@$(ECHO)
	@$(ECHO)  LoaderObjects..... $(LOADEROBJECTS)
	@$(ECHO)  UnitObjects....... $(UNITOBJECTS)
	@$(ECHO)  ExeObjects........ $(EXEOBJECTS)
	@$(ECHO)
	@$(ECHO)  ExtraCleanUnits... $(EXTRACLEANUNITS)
	@$(ECHO)  ExtraInstallUnits. $(EXTRAINSTALLUNITS)
	@$(ECHO)  ExtraInstallUnits. $(EXTRAINSTALLFILES)
	@$(ECHO)
	@$(ECHO)  == Unit info ==
	@$(ECHO)
	@$(ECHO)  UnitInstallFiles. $(UNITINSTALLFILES)
	@$(ECHO)  UnitCleanFiles... $(UNITCLEANFILES)
	@$(ECHO)

fpc_installinfo:
	@$(ECHO)
	@$(ECHO)  == Install info ==
	@$(ECHO)
	@$(ECHO)  DateStr.............. $(DATESTR)
	@$(ECHO)  PackageSuffix........ $(PACKAGESUFFIX)
	@$(ECHO)
	@$(ECHO)  BaseInstallDir....... $(BASEINSTALLDIR)
	@$(ECHO)  BinInstallDir........ $(BININSTALLDIR)
	@$(ECHO)  UnitInstallDir....... $(UNITINSTALLDIR)
	@$(ECHO)  StaticUnitInstallDir. $(STATIC_UNITINSTALLDIR)
	@$(ECHO)  SharedUnitInstallDir. $(SHARED_UNITINSTALLDIR)
	@$(ECHO)  LibInstallDir........ $(LIBINSTALLDIR)
	@$(ECHO)  StaticLibInstallDir.. $(STATIC_LIBINSTALLDIR)
	@$(ECHO)  SharedLibInstallDir.. $(SHARED_LIBINSTALLDIR)
	@$(ECHO)  MsgInstallDir........ $(MSGINSTALLDIR)
	@$(ECHO)  DocInstallDir........ $(DOCINSTALLDIR)
	@$(ECHO)

# try to get the files in the currentdir
PASFILES:=$(wildcard *.pas)
PPFILES:=$(wildcard *.pp)
INCFILES:=$(wildcard *.inc)
MSGFILES:=$(wildcard *.msg)
ASFILES:=$(wildcard *.as)

fpc_filesinfo:
	@$(ECHO)
	@$(ECHO)  == Files info ==
	@$(ECHO)
ifdef PASFILES
	@$(ECHO)  Pas files are $(PASFILES)
endif
ifdef PPFILES
	@$(ECHO)  PP  files are $(PPFILES)
endif
ifdef INCFILES
	@$(ECHO)  Inc files are $(INCFILES)
endif
ifdef MSGFILES
	@$(ECHO)  Msg files are $(MSGFILES)
endif
ifdef ASFILES
	@$(ECHO)  As  files are $(ASFILES)
endif

#
# $Log: makefile.fpc,v $
# Revision 1.47  1999/09/27 08:08:15  peter
#   * fixed smartlinking switch
#
# Revision 1.46  1999/08/30 12:07:43  pierre
#  * use unitdir only if existing and non empty
#
# Revision 1.45  1999/08/19 06:50:25  michael
# + Changes from Sebastian Gunther
#
# Revision 1.44  1999/08/13 15:35:37  peter
#   * UPX -> UPXPROG, because upx 0.80+ use the environment itself
#
# Revision 1.43  1999/08/09 22:19:46  peter
#   * classes vmt changed to only positive addresses
#   * sharedlib creation is working
#
# Revision 1.42  1999/07/22 16:13:32  peter
#   * install,clean fixes
#
# Revision 1.41  1999/07/21 14:21:00  peter
#   * install works again
#
# Revision 1.40  1999/07/17 14:22:54  peter
#   * ECHO is now again without @
#
# Revision 1.39  1999/07/17 11:30:23  peter
#   * merged
#
# Revision 1.38  1999/07/16 13:45:24  peter
#   * 0.99.12b updates
#   * merges
#
# Revision 1.37  1999/07/05 21:37:35  peter
#   * display extraunits in info
#
# Revision 1.36  1999/07/01 18:20:01  jonas
#   * changed RELEASE=1 processor option from -Op2 to -Op3
#
# Revision 1.35  1999/06/18 11:03:08  peter
#   * merged
#
# Revision 1.34  1999/06/18 10:11:18  peter
#   * merged
#
# Revision 1.33  1999/06/13 22:43:23  peter
#   * merged from fixes
#
# Revision 1.32  1999/06/11 13:31:14  hajny
#   * fixes for OS/2
#
# Revision 1.31.2.5  1999/07/17 11:29:02  peter
#   * more extrainstallunits,extracleanunits updates
#
# Revision 1.31.2.4  1999/07/16 13:40:56  peter
#   + extrainstallunits,extracleanunits
#
# Revision 1.31.2.3  1999/06/18 10:55:31  peter
#   * version fixes
#   * EXTRAUNITS to set extra units that are build and needs to be cleaned
#
# Revision 1.31.2.2  1999/06/18 10:07:27  peter
#   * rtl/linux and units/linux also for linux installs
#
# Revision 1.31.2.1  1999/06/13 22:36:38  peter
#   * install msg files in msg/ instead of bin for not linux
#
# Revision 1.31  1999/06/10 15:02:08  peter
#   * last fixes for 0.99.12 release
#
# Revision 1.30  1999/06/03 09:36:31  peter
#   * first things for sharedlib to work again
#
# Revision 1.29  1999/06/01 13:27:24  peter
#   * updates for linux
#
# Revision 1.28  1999/05/30 11:33:04  peter
#   * releasever removed, fpc_version will be used
#
# Revision 1.27  1999/05/16 02:37:30  peter
#   + fpc_showinstallfiles to show which files will be added to the system
#
# Revision 1.26  1999/05/14 22:46:21  peter
#   * patch for comments in ld.so.conf
#
# Revision 1.25  1999/05/12 16:17:07  peter
#   + utils_X targets
#   * missing export of prefixinstalldir
#
# Revision 1.24  1999/05/11 00:48:12  peter
#   * fixed some typos
#
# Revision 1.23  1999/05/10 15:18:43  peter
#   * NEEDOTHERLIB define to load ld.so.conf for linux
#
# Revision 1.22  1999/05/04 23:20:42  pierre
#  + FPC_VERSION (with shell $(PP) -iV)
#
# Revision 1.21  1999/05/03 22:38:10  peter
#   * typo with -TP which should be -iTP
#
# Revision 1.20  1999/05/03 22:29:04  peter
#   * os_source,os_target depends now on the compiler
#   * cpu depends on the compiler
#   * datestr y2k proof
#
# Revision 1.19  1999/05/03 18:04:58  peter
#   + sourceinstalldir
#
# Revision 1.18  1999/04/29 15:52:38  peter
#   * better gcclib dir detection
#
# Revision 1.17  1999/04/20 12:33:32  michael
# + Fixed GCCLIB detection. Added fpc_dirinfo target
#
# Revision 1.16  1999/04/20 12:07:49  michael
# Added autodetect of gcc lib for linux
#
# Revision 1.15  1999/04/16 20:12:35  michael
# + install target now correctly takes the BASEINSTALLDIR on linux
#
# Revision 1.14  1999/04/08 10:16:17  peter
#   * zipinstall for linux with .tar.gz
#
# Revision 1.13  1999/04/01 22:52:28  peter
#   * don't override pasext if set
#
# Revision 1.12  1999/03/29 16:04:58  peter
#   * place -T as the first parameter on the commandline so a OPT=-A can
#     overwrite it
#
# Revision 1.11  1999/03/16 00:46:55  peter
#   * makefile.fpc targets start with fpc_
#   * small updates for install scripts
#
# Revision 1.10  1999/03/12 21:01:30  michael
# + Changed clean and libsclean to fpc_target
#
# Revision 1.9	1999/03/11 17:54:00  peter
#   * better check for makefile.fpc
#   * check if cmp exists
#
# Revision 1.8	1999/03/09 01:35:47  peter
#   * makefile.fpc updates and defaultfpcdir var
#
#