Makefile 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. CC=gcc
  2. ifdef DEBUG
  3. # I think we only use gnu99 instead of c99 due to va_args extensions.
  4. CFLAGS=-I. -Wall -W -pg -g -pedantic -ansi -DDEBUG
  5. else
  6. CFLAGS=-I. -Wall -W -O6 -funroll-loops -fexpensive-optimizations
  7. endif
  8. ifndef DJGPP
  9. # uname is not available by default under DOS
  10. OSTYPE=$(shell uname -s)
  11. else
  12. OSTYPE=DJGPP
  13. endif
  14. GCC_WIN=0
  15. ifeq ($(findstring MINGW,$(OSTYPE)),MINGW)
  16. GCC_WIN=1
  17. endif
  18. ifeq ($(findstring CYGWIN,$(OSTYPE)),CYGWIN)
  19. GCC_WIN=1
  20. endif
  21. ifdef DJGPP
  22. LDFLAGS=
  23. else
  24. ifeq ($(findstring BeOS,$(OSTYPE)),BeOS)
  25. LDFLAGS=-nostart
  26. else # Unix or Win GCC
  27. LDFLAGS=-shared
  28. endif
  29. endif
  30. ifeq ($(findstring DJGPP,$(OSTYPE)),)
  31. ifneq ($(GCC_WIN),1)
  32. CFLAGS+=-fPIC
  33. else
  34. # Cygwin and MinGW need an import library for a DLL
  35. LDFLAGS+=-Wl,--out-implib,libcd64dll.a
  36. endif
  37. endif
  38. # The next check is not really specific to FreeBSD or OpenBSD -- the version of
  39. # gcc I use is just old.
  40. ifeq ($(findstring FreeBSD,$(OSTYPE)),)
  41. ifeq ($(findstring OpenBSD,$(OSTYPE)),)
  42. CFLAGS+=-std=gnu99
  43. endif
  44. endif
  45. DEFAULT_BUILD=1
  46. # If the user passed anything, we are not a default build.
  47. ifdef LIBIEEE1284
  48. DEFAULT_BUILD=0
  49. else
  50. ifdef PPDEV
  51. DEFAULT_BUILD=0
  52. else
  53. ifdef PORTDEV
  54. DEFAULT_BUILD=0
  55. else
  56. ifdef RAWIO
  57. DEFAULT_BUILD=0
  58. endif
  59. endif
  60. endif
  61. endif
  62. ifeq ($(DEFAULT_BUILD),1)
  63. # Put default build options for each OS here
  64. ifeq ($(findstring DJGPP,$(OSTYPE)),DJGPP)
  65. RAWIO=1
  66. endif
  67. ifeq ($(findstring MINGW,$(OSTYPE)),MINGW)
  68. RAWIO=1
  69. endif
  70. ifeq ($(findstring CYGWIN,$(OSTYPE)),CYGWIN)
  71. RAWIO=1
  72. endif
  73. ifeq ($(findstring BeOS,$(OSTYPE)),BeOS)
  74. RAWIO=1
  75. endif
  76. ifeq ($(findstring OpenBSD,$(OSTYPE)),OpenBSD)
  77. # i386_iopl() is located in libi386.a (note the .a)
  78. LIBS+=-L/usr/lib -li386
  79. RAWIO=1
  80. endif
  81. ifeq ($(findstring FreeBSD,$(OSTYPE)),FreeBSD)
  82. RAWIO=1
  83. endif
  84. ifeq ($(findstring Linux,$(OSTYPE)),Linux)
  85. ifeq ($(shell if test -r /usr/include/ieee1284.h; then echo 1; else echo 0; fi),1)
  86. LIBIEEE1284=1
  87. endif
  88. ifeq ($(shell if test -r /usr/include/linux/ppdev.h; then echo 1; else echo 0; fi),1)
  89. PPDEV=1
  90. endif
  91. PORTDEV=1
  92. RAWIO=1
  93. endif
  94. endif # DEFAULT_BUILD = 1
  95. # Now for backend-specific defs
  96. ifdef LIBIEEE1284
  97. CFLAGS+=-DCD64_USE_LIBIEEE1284
  98. LIBS+=-lieee1284
  99. endif
  100. ifdef PPDEV
  101. CFLAGS+=-DCD64_USE_PPDEV
  102. endif
  103. ifdef PORTDEV
  104. CFLAGS+=-DCD64_USE_PORTDEV
  105. endif
  106. ifdef RAWIO
  107. CFLAGS+=-DCD64_USE_RAWIO
  108. endif
  109. default: all
  110. ifeq ($(findstring DJGPP,$(OSTYPE)),DJGPP)
  111. all: libcd64.a
  112. else
  113. ifeq ($(GCC_WIN),1)
  114. all: libcd64.a cd64.dll
  115. else
  116. all: libcd64.a libcd64.so
  117. endif # GCC_WIN
  118. endif # DJGPP
  119. # libcd64 stuff
  120. cd64io.o: cd64io.c
  121. $(CC) $(CFLAGS) $^ -c -o $@
  122. cd64lib.o: cd64lib.c
  123. $(CC) $(CFLAGS) $^ -c -o $@
  124. libcd64.a: cd64lib.o cd64io.o
  125. ld -r $^ $(LIBS) -o $*.o
  126. # rm -f $@
  127. ar crs $@ $*.o
  128. LDFLAGS+=$(LIBS)
  129. ifeq ($(GCC_WIN),1)
  130. cd64.dll: cd64lib.o cd64io.o
  131. else
  132. libcd64.so: cd64lib.o cd64io.o
  133. endif
  134. # rm -f $@
  135. $(CC) $^ $(LDFLAGS) -o $@
  136. clean:
  137. rm -f *.o *.so *.dll *.a a.out