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. else
  23. ifeq ($(findstring BeOS,$(OSTYPE)),BeOS)
  24. LDFLAGS+=-nostart
  25. else # UNIX or Win GCC
  26. LDFLAGS+=-shared
  27. endif
  28. endif
  29. ifeq ($(findstring DJGPP,$(OSTYPE)),)
  30. ifneq ($(GCC_WIN),1)
  31. CFLAGS+=-fPIC
  32. else
  33. # Cygwin and MinGW need an import library for a DLL
  34. LDFLAGS+=-Wl,--out-implib,libcd64dll.a
  35. endif
  36. endif
  37. # The next check is not really specific to FreeBSD or OpenBSD -- the version of
  38. # gcc I use is just old.
  39. ifeq ($(findstring FreeBSD,$(OSTYPE)),)
  40. ifeq ($(findstring OpenBSD,$(OSTYPE)),)
  41. CFLAGS+=-std=gnu99
  42. endif
  43. endif
  44. DEFAULT_BUILD=1
  45. # If the user passed anything, we are not a default build.
  46. ifdef LIBIEEE1284
  47. DEFAULT_BUILD=0
  48. else
  49. ifdef PPDEV
  50. DEFAULT_BUILD=0
  51. else
  52. ifdef PORTDEV
  53. DEFAULT_BUILD=0
  54. else
  55. ifdef RAWIO
  56. DEFAULT_BUILD=0
  57. endif
  58. endif
  59. endif
  60. endif
  61. ifeq ($(DEFAULT_BUILD),1)
  62. # Put default build options for each OS here
  63. ifeq ($(findstring DJGPP,$(OSTYPE)),DJGPP)
  64. RAWIO=1
  65. endif
  66. ifeq ($(findstring MINGW,$(OSTYPE)),MINGW)
  67. RAWIO=1
  68. endif
  69. ifeq ($(findstring CYGWIN,$(OSTYPE)),CYGWIN)
  70. RAWIO=1
  71. endif
  72. ifeq ($(findstring BeOS,$(OSTYPE)),BeOS)
  73. RAWIO=1
  74. endif
  75. ifeq ($(findstring OpenBSD,$(OSTYPE)),OpenBSD)
  76. # i386_iopl() is located in libi386.a (note the .a)
  77. LIBS+=/usr/lib/libi386.a
  78. LDFLAGS+=-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+=/usr/lib/libieee1284.a
  99. LDFLAGS+=-lieee1284
  100. endif
  101. ifdef PPDEV
  102. CFLAGS+=-DCD64_USE_PPDEV
  103. endif
  104. ifdef PORTDEV
  105. CFLAGS+=-DCD64_USE_PORTDEV
  106. endif
  107. ifdef RAWIO
  108. CFLAGS+=-DCD64_USE_RAWIO
  109. endif
  110. default: all
  111. ifeq ($(findstring DJGPP,$(OSTYPE)),DJGPP)
  112. all: libcd64.a
  113. else
  114. ifeq ($(GCC_WIN),1)
  115. all: libcd64.a cd64.dll
  116. else
  117. all: libcd64.a libcd64.so
  118. endif # GCC_WIN
  119. endif # DJGPP
  120. # libcd64 stuff
  121. cd64io.o: cd64io.c
  122. $(CC) $(CFLAGS) $^ -c -o $@
  123. cd64lib.o: cd64lib.c
  124. $(CC) $(CFLAGS) $^ -c -o $@
  125. libcd64.a: cd64lib.o cd64io.o
  126. ld -r $^ $(LIBS) -o $*.o
  127. # rm -f $@
  128. ar crs $@ $*.o
  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