Makefile 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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+=/usr/lib/libi386.a
  79. LDFLAGS+=-L/usr/lib -li386
  80. RAWIO=1
  81. endif
  82. ifeq ($(findstring FreeBSD,$(OSTYPE)),FreeBSD)
  83. RAWIO=1
  84. endif
  85. ifeq ($(findstring Linux,$(OSTYPE)),Linux)
  86. ifeq ($(shell if test -r /usr/include/ieee1284.h; then echo 1; else echo 0; fi),1)
  87. LIBIEEE1284=1
  88. endif
  89. ifeq ($(shell if test -r /usr/include/linux/ppdev.h; then echo 1; else echo 0; fi),1)
  90. PPDEV=1
  91. endif
  92. PORTDEV=1
  93. RAWIO=1
  94. endif
  95. endif # DEFAULT_BUILD = 1
  96. # Now for backend-specific defs
  97. ifdef LIBIEEE1284
  98. CFLAGS+=-DCD64_USE_LIBIEEE1284
  99. LIBS+=/usr/lib/libieee1284.a
  100. LDFLAGS+=-lieee1284
  101. endif
  102. ifdef PPDEV
  103. CFLAGS+=-DCD64_USE_PPDEV
  104. endif
  105. ifdef PORTDEV
  106. CFLAGS+=-DCD64_USE_PORTDEV
  107. endif
  108. ifdef RAWIO
  109. CFLAGS+=-DCD64_USE_RAWIO
  110. endif
  111. default: all
  112. ifeq ($(findstring DJGPP,$(OSTYPE)),DJGPP)
  113. all: libcd64.a
  114. else
  115. ifeq ($(GCC_WIN),1)
  116. all: libcd64.a cd64.dll
  117. else
  118. all: libcd64.a libcd64.so
  119. endif # GCC_WIN
  120. endif # DJGPP
  121. # libcd64 stuff
  122. cd64io.o: cd64io.c
  123. $(CC) $(CFLAGS) $^ -c -o $@
  124. cd64lib.o: cd64lib.c
  125. $(CC) $(CFLAGS) $^ -c -o $@
  126. libcd64.a: cd64lib.o cd64io.o
  127. ld -r $^ $(LIBS) -o $*.o
  128. # rm -f $@
  129. ar crs $@ $*.o
  130. ifeq ($(GCC_WIN),1)
  131. cd64.dll: cd64lib.o cd64io.o
  132. else
  133. libcd64.so: cd64lib.o cd64io.o
  134. endif
  135. # rm -f $@
  136. $(CC) $^ $(LDFLAGS) -o $@
  137. clean:
  138. rm -f *.o *.so *.dll *.a a.out